@@ -30,6 +30,14 @@ describe("General tests", () => {
30
30
const bugDetectorDirectory = path . join ( __dirname , "general" ) ;
31
31
const friendlyFilePath = path . join ( bugDetectorDirectory , "FRIENDLY" ) ;
32
32
const evilFilePath = path . join ( bugDetectorDirectory , "jaz_zer" ) ;
33
+ const errorPattern =
34
+ / C o m m a n d I n j e c t i o n i n e x e c S y n c \( \) : c a l l e d w i t h ' j a z _ z e r ' / g;
35
+
36
+ function expectErrorToBePrintedOnce ( output ) {
37
+ const matches = output . match ( errorPattern ) ;
38
+ expect ( matches ) . toBeTruthy ( ) ;
39
+ expect ( matches . length ) . toBe ( 1 ) ;
40
+ }
33
41
34
42
// Delete files created by the tests.
35
43
beforeEach ( ( ) => {
@@ -48,6 +56,8 @@ describe("General tests", () => {
48
56
fuzzTest . execute ( ) ;
49
57
} ) . toThrow ( FuzzingExitCode ) ;
50
58
expect ( fs . existsSync ( friendlyFilePath ) ) . toBeFalsy ( ) ;
59
+ // check that the stdout has the following line only once: "Command Injection in execSync(): called with 'jaz_zer'"
60
+ expectErrorToBePrintedOnce ( fuzzTest . stdout ) ;
51
61
} ) ;
52
62
53
63
it ( "Call with EVIL string; SYNC" , ( ) => {
@@ -60,6 +70,7 @@ describe("General tests", () => {
60
70
fuzzTest . execute ( ) ;
61
71
} ) . toThrow ( FuzzingExitCode ) ;
62
72
expect ( fs . existsSync ( friendlyFilePath ) ) . toBeFalsy ( ) ;
73
+ expectErrorToBePrintedOnce ( fuzzTest . stdout ) ;
63
74
} ) ;
64
75
65
76
it ( "Call with FRIENDLY string; ASYNC" , ( ) => {
@@ -92,6 +103,7 @@ describe("General tests", () => {
92
103
fuzzTest . execute ( ) ;
93
104
} ) . toThrow ( FuzzingExitCode ) ;
94
105
expect ( fs . existsSync ( friendlyFilePath ) ) . toBeFalsy ( ) ;
106
+ expectErrorToBePrintedOnce ( fuzzTest . stdout ) ;
95
107
} ) ;
96
108
97
109
it ( "Call with EVIL string; With done callback; With try/catch" , ( ) => {
@@ -104,6 +116,7 @@ describe("General tests", () => {
104
116
fuzzTest . execute ( ) ;
105
117
} ) . toThrow ( FuzzingExitCode ) ;
106
118
expect ( fs . existsSync ( friendlyFilePath ) ) . toBeFalsy ( ) ;
119
+ expectErrorToBePrintedOnce ( fuzzTest . stdout ) ;
107
120
} ) ;
108
121
109
122
it ( "Call with EVIL string; With done callback; With timeout" , ( ) => {
@@ -192,7 +205,7 @@ describe("General tests", () => {
192
205
. sync ( false )
193
206
. fuzzEntryPoint ( "ForkModeCallOriginalEvilAsync" )
194
207
. dir ( bugDetectorDirectory )
195
- . runs ( 200 )
208
+ . runs ( 10 )
196
209
. forkMode ( 3 )
197
210
. build ( ) ;
198
211
fuzzTest . execute ( ) ;
@@ -242,6 +255,7 @@ describe("General tests", () => {
242
255
fuzzTest . execute ( ) ;
243
256
} ) . toThrow ( JestRegressionExitCode ) ;
244
257
expect ( fs . existsSync ( friendlyFilePath ) ) . toBeFalsy ( ) ;
258
+ expectErrorToBePrintedOnce ( fuzzTest . stderr ) ;
245
259
} ) ;
246
260
247
261
it ( "Jest: Test with EVIL command; ASYNC" , ( ) => {
@@ -257,6 +271,7 @@ describe("General tests", () => {
257
271
fuzzTest . execute ( ) ;
258
272
} ) . toThrow ( JestRegressionExitCode ) ;
259
273
expect ( fs . existsSync ( friendlyFilePath ) ) . toBeFalsy ( ) ;
274
+ expectErrorToBePrintedOnce ( fuzzTest . stderr ) ;
260
275
} ) ;
261
276
262
277
it ( "Jest: Test with FRIENDLY command" , ( ) => {
@@ -300,6 +315,7 @@ describe("General tests", () => {
300
315
process . platform === "win32" ? JestRegressionExitCode : FuzzingExitCode
301
316
) ;
302
317
expect ( fs . existsSync ( friendlyFilePath ) ) . toBeFalsy ( ) ;
318
+ expectErrorToBePrintedOnce ( fuzzTest . stderr ) ;
303
319
} ) ;
304
320
305
321
it ( "Jest: Fuzzing mode; Test with FRIENDLY command" , ( ) => {
@@ -330,6 +346,7 @@ describe("General tests", () => {
330
346
fuzzTest . execute ( ) ;
331
347
} ) . toThrow ( JestRegressionExitCode ) ;
332
348
expect ( fs . existsSync ( friendlyFilePath ) ) . toBeFalsy ( ) ;
349
+ expectErrorToBePrintedOnce ( fuzzTest . stderr ) ;
333
350
} ) ;
334
351
335
352
it ( "Jest: Test with FRIENDLY command; Done callback" , ( ) => {
0 commit comments