Skip to content

Commit b2c7f88

Browse files
committed
bug detectors: split up tests into several files
1 parent b831dcb commit b2c7f88

File tree

6 files changed

+382
-338
lines changed

6 files changed

+382
-338
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
* Copyright 2023 Code Intelligence GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/* eslint no-undef: 0 */
18+
const {
19+
FuzzTestBuilder,
20+
FuzzingExitCode,
21+
// eslint-disable-next-line @typescript-eslint/no-var-requires
22+
} = require("./helpers.js");
23+
// eslint-disable-next-line @typescript-eslint/no-var-requires
24+
const path = require("path");
25+
// eslint-disable-next-line @typescript-eslint/no-var-requires
26+
const fs = require("fs");
27+
28+
describe("Command injection", () => {
29+
const bugDetectorDirectory = path.join(__dirname, "command-injection");
30+
const friendlyFilePath = path.join(bugDetectorDirectory, "FRIENDLY");
31+
32+
// Delete files created by the tests.
33+
beforeEach(() => {
34+
fs.rmSync(friendlyFilePath, { force: true });
35+
});
36+
37+
it("exec with EVIL command", () => {
38+
const fuzzTest = new FuzzTestBuilder()
39+
.sync(false)
40+
.fuzzEntryPoint("execEVIL")
41+
.dir(bugDetectorDirectory)
42+
.build();
43+
expect(() => {
44+
fuzzTest.execute();
45+
}).toThrow(FuzzingExitCode);
46+
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
47+
});
48+
49+
it("exec with FRIENDLY command", () => {
50+
const fuzzTest = new FuzzTestBuilder()
51+
.sync(false)
52+
.fuzzEntryPoint("execFRIENDLY")
53+
.dir(bugDetectorDirectory)
54+
.build();
55+
fuzzTest.execute();
56+
expect(fs.existsSync(friendlyFilePath)).toBeTruthy();
57+
});
58+
59+
it("execFile with EVIL file", () => {
60+
const fuzzTest = new FuzzTestBuilder()
61+
.sync(false)
62+
.fuzzEntryPoint("execFileEVIL")
63+
.dir(bugDetectorDirectory)
64+
.build();
65+
expect(() => {
66+
fuzzTest.execute();
67+
}).toThrow(FuzzingExitCode);
68+
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
69+
});
70+
71+
it("execFile with FRIENDLY file", () => {
72+
const fuzzTest = new FuzzTestBuilder()
73+
.sync(false)
74+
.fuzzEntryPoint("execFileFRIENDLY")
75+
.dir(bugDetectorDirectory)
76+
.build();
77+
fuzzTest.execute();
78+
expect(fs.existsSync(friendlyFilePath)).toBeTruthy();
79+
});
80+
81+
it("execFileSync with EVIL file", () => {
82+
const fuzzTest = new FuzzTestBuilder()
83+
.sync(false)
84+
.fuzzEntryPoint("execFileSyncEVIL")
85+
.dir(bugDetectorDirectory)
86+
.build();
87+
expect(() => {
88+
fuzzTest.execute();
89+
}).toThrow(FuzzingExitCode);
90+
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
91+
});
92+
93+
it("execFileSync with FRIENDLY file", () => {
94+
const fuzzTest = new FuzzTestBuilder()
95+
.sync(false)
96+
.fuzzEntryPoint("execFileSyncFRIENDLY")
97+
.dir(bugDetectorDirectory)
98+
.build();
99+
fuzzTest.execute();
100+
expect(fs.existsSync(friendlyFilePath)).toBeTruthy();
101+
});
102+
103+
it("spawn with EVIL command", () => {
104+
const fuzzTest = new FuzzTestBuilder()
105+
.sync(false)
106+
.fuzzEntryPoint("spawnEVIL")
107+
.dir(bugDetectorDirectory)
108+
.build();
109+
expect(() => {
110+
fuzzTest.execute();
111+
}).toThrow(FuzzingExitCode);
112+
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
113+
});
114+
115+
it("spawn with FRIENDLY command", () => {
116+
const fuzzTest = new FuzzTestBuilder()
117+
.sync(false)
118+
.fuzzEntryPoint("spawnFRIENDLY")
119+
.dir(bugDetectorDirectory)
120+
.build();
121+
fuzzTest.execute();
122+
expect(fs.existsSync(friendlyFilePath)).toBeTruthy();
123+
});
124+
125+
it("spawnSync with EVIL command", () => {
126+
const fuzzTest = new FuzzTestBuilder()
127+
.sync(false)
128+
.fuzzEntryPoint("spawnSyncEVIL")
129+
.dir(bugDetectorDirectory)
130+
.build();
131+
expect(() => {
132+
fuzzTest.execute();
133+
}).toThrow(FuzzingExitCode);
134+
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
135+
});
136+
137+
it("spawnSync with FRIENDLY command", () => {
138+
const fuzzTest = new FuzzTestBuilder()
139+
.sync(false)
140+
.fuzzEntryPoint("spawnSyncFRIENDLY")
141+
.dir(bugDetectorDirectory)
142+
.build();
143+
fuzzTest.execute();
144+
expect(fs.existsSync(friendlyFilePath)).toBeTruthy();
145+
});
146+
147+
it("fork with EVIL command", () => {
148+
const fuzzTest = new FuzzTestBuilder()
149+
.sync(false)
150+
.fuzzEntryPoint("forkEVIL")
151+
.dir(bugDetectorDirectory)
152+
.build();
153+
expect(() => {
154+
fuzzTest.execute();
155+
}).toThrow(FuzzingExitCode);
156+
expect(fs.existsSync(friendlyFilePath)).toBeFalsy();
157+
});
158+
159+
it("fork with FRIENDLY command", () => {
160+
const fuzzTest = new FuzzTestBuilder()
161+
.sync(false)
162+
.fuzzEntryPoint("forkFRIENDLY")
163+
.dir(bugDetectorDirectory)
164+
.build();
165+
fuzzTest.execute();
166+
expect(fs.existsSync(friendlyFilePath)).toBeTruthy();
167+
});
168+
});

0 commit comments

Comments
 (0)