@@ -52,14 +52,14 @@ describe('vulnerability-reporter', () => {
52
52
expect ( iastContext . vulnerabilities ) . to . be . an ( 'array' )
53
53
} )
54
54
55
- it ( 'should add multiple vulnerabilities' , ( ) => {
55
+ it ( 'should deduplicate same vulnerabilities' , ( ) => {
56
56
addVulnerability ( iastContext ,
57
57
vulnerabilityAnalyzer . _createVulnerability ( 'INSECURE_HASHING' , { value : 'sha1' } , - 555 ) )
58
58
addVulnerability ( iastContext ,
59
59
vulnerabilityAnalyzer . _createVulnerability ( 'INSECURE_HASHING' , { value : 'sha1' } , 888 ) )
60
60
addVulnerability ( iastContext ,
61
61
vulnerabilityAnalyzer . _createVulnerability ( 'INSECURE_HASHING' , { value : 'sha1' } , 123 ) )
62
- expect ( iastContext . vulnerabilities ) . to . have . length ( 3 )
62
+ expect ( iastContext . vulnerabilities ) . to . have . length ( 1 )
63
63
} )
64
64
65
65
it ( 'should add in the context evidence properties' , ( ) => {
@@ -260,7 +260,12 @@ describe('vulnerability-reporter', () => {
260
260
'[{"value":"SELECT id FROM u WHERE email = \'"},{"value":"[email protected] ","source":1},{"value":"\';"}]},' +
261
261
'"location":{"spanId":888,"path":"filename.js","line":99}}]}'
262
262
} )
263
- expect ( prioritySampler . setPriority ) . to . have . been . calledOnceWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
263
+
264
+ expect ( prioritySampler . setPriority ) . to . have . been . calledTwice
265
+ expect ( prioritySampler . setPriority . firstCall )
266
+ . to . have . been . calledWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
267
+ expect ( prioritySampler . setPriority . secondCall )
268
+ . to . have . been . calledWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
264
269
} )
265
270
266
271
it ( 'should send multiple vulnerabilities with same tainted source' , ( ) => {
@@ -313,7 +318,12 @@ describe('vulnerability-reporter', () => {
313
318
'[{"value":"UPDATE u SET name=\'"},{"value":"joe","source":0},{"value":"\' WHERE id=1;"}]},' +
314
319
'"location":{"spanId":888,"path":"filename.js","line":99}}]}'
315
320
} )
316
- expect ( prioritySampler . setPriority ) . to . have . been . calledOnceWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
321
+
322
+ expect ( prioritySampler . setPriority ) . to . have . been . calledTwice
323
+ expect ( prioritySampler . setPriority . firstCall )
324
+ . to . have . been . calledWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
325
+ expect ( prioritySampler . setPriority . secondCall )
326
+ . to . have . been . calledWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
317
327
} )
318
328
319
329
it ( 'should send once with multiple vulnerabilities' , ( ) => {
@@ -334,7 +344,13 @@ describe('vulnerability-reporter', () => {
334
344
'{"type":"INSECURE_HASHING","hash":1755238473,"evidence":{"value":"md5"},' +
335
345
'"location":{"spanId":-5,"path":"/path/to/file3.js","line":3}}]}'
336
346
} )
337
- expect ( prioritySampler . setPriority ) . to . have . been . calledOnceWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
347
+ expect ( prioritySampler . setPriority ) . to . have . been . calledThrice
348
+ expect ( prioritySampler . setPriority . firstCall )
349
+ . to . have . been . calledWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
350
+ expect ( prioritySampler . setPriority . secondCall )
351
+ . to . have . been . calledWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
352
+ expect ( prioritySampler . setPriority . thirdCall )
353
+ . to . have . been . calledWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
338
354
} )
339
355
340
356
it ( 'should send once vulnerability with one vulnerability' , ( ) => {
@@ -366,23 +382,6 @@ describe('vulnerability-reporter', () => {
366
382
expect ( prioritySampler . setPriority ) . to . have . been . calledOnceWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
367
383
} )
368
384
369
- it ( 'should not send duplicated vulnerabilities in multiple sends' , ( ) => {
370
- const iastContext = { rootSpan : span }
371
- addVulnerability ( iastContext ,
372
- vulnerabilityAnalyzer . _createVulnerability ( 'INSECURE_HASHING' , { value : 'sha1' } , 888 ,
373
- { path : 'filename.js' , line : 88 } ) )
374
- addVulnerability ( iastContext ,
375
- vulnerabilityAnalyzer . _createVulnerability ( 'INSECURE_HASHING' , { value : 'sha1' } , 888 ,
376
- { path : 'filename.js' , line : 88 } ) )
377
- sendVulnerabilities ( iastContext . vulnerabilities , span )
378
- sendVulnerabilities ( iastContext . vulnerabilities , span )
379
- expect ( span . addTags ) . to . have . been . calledOnceWithExactly ( {
380
- '_dd.iast.json' : '{"sources":[],"vulnerabilities":[{"type":"INSECURE_HASHING","hash":3410512691,' +
381
- '"evidence":{"value":"sha1"},"location":{"spanId":888,"path":"filename.js","line":88}}]}'
382
- } )
383
- expect ( prioritySampler . setPriority ) . to . have . been . calledOnceWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
384
- } )
385
-
386
385
it ( 'should not deduplicate vulnerabilities if not enabled' , ( ) => {
387
386
start ( {
388
387
iast : {
@@ -401,7 +400,11 @@ describe('vulnerability-reporter', () => {
401
400
'{"type":"INSECURE_HASHING","hash":3410512691,"evidence":{"value":"sha1"},"location":' +
402
401
'{"spanId":888,"path":"filename.js","line":88}}]}'
403
402
} )
404
- expect ( prioritySampler . setPriority ) . to . have . been . calledOnceWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
403
+ expect ( prioritySampler . setPriority ) . to . have . been . calledTwice
404
+ expect ( prioritySampler . setPriority . firstCall )
405
+ . to . have . been . calledWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
406
+ expect ( prioritySampler . setPriority . secondCall )
407
+ . to . have . been . calledWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
405
408
} )
406
409
407
410
it ( 'should add _dd.p.appsec trace tag with standalone enabled' , ( ) => {
0 commit comments