@@ -421,6 +421,46 @@ describe("process scan results", () => {
421421 expect ( data . name ) . toBe ( "Scan results for myimage:mytag" ) ;
422422 expect ( data . output . annotations ) . toContainEqual ( { "annotation_level" : "warning" , "end_line" : 1 , "message" : "CVE-2019-14697 Severity=High Package=musl-1.1.18-r3 Type=APKG Fix=1.1.18-r4 Url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-14697" , "path" : "Dockerfile" , "start_line" : 1 , "title" : "Vulnerability found: CVE-2019-14697" } ) ;
423423 expect ( data . output . annotations ) . not . toContainEqual ( { "path" : "Dockerfile" , "start_line" : 1 , "end_line" : 1 , "annotation_level" : "warning" , "message" : "CVE-2011-3374 Severity=Negligible Package=apt-1.0 Type=APKG Fix=null Url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3374" , "title" : "Vulnerability found: CVE-2011-3374" } ) ;
424+ expect ( data . output . annotations ) . toContainEqual ( { "path" : "Dockerfile" , "start_line" : 1 , "end_line" : 1 , "annotation_level" : "warning" , "message" : "CVE-2019-14697 Severity=High Package=musl-utils-1.1.18-r3 Type=APKG Fix=1.1.18-r4 Url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-14697" , "title" : "Vulnerability found: CVE-2019-14697" } ) ;
425+ expect ( data . output . annotations ) . toContainEqual ( { "path" : "Dockerfile" , "start_line" : 1 , "end_line" : 1 , "annotation_level" : "warning" , "message" : "CVE-2019-14698 Severity=Medium Package=musl-utils-1.1.18-r3 Type=APKG Fix=1.1.18-r4 Url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-14698" , "title" : "Vulnerability found: CVE-2019-14698" } ) ;
426+ } )
427+
428+ it ( "generates a check run with unique vulnerability annotations" , async ( ) => {
429+ let data ;
430+ github . context = { repo : { repo : "foo-repo" , owner : "foo-owner" } } ;
431+
432+ core . getInput = jest . fn ( ) ;
433+ core . getInput . mockReturnValueOnce ( "foo" ) ;
434+
435+
436+ github . getOctokit = jest . fn ( ( ) => {
437+ return {
438+ rest : {
439+ checks : {
440+ create : async function ( receivedData ) {
441+ data = receivedData ;
442+ }
443+ }
444+ }
445+ }
446+ } ) ;
447+
448+ let scanResult = {
449+ ReturnCode : 0 ,
450+ Output : exampleReport ,
451+ Error : ""
452+ } ;
453+ core . getInput . mockReturnValueOnce ( "medium" )
454+ core . getInput . mockReturnValueOnce ( "true" )
455+
456+ await index . processScanResult ( scanResult ) ;
457+ expect ( github . getOctokit ) . toBeCalledWith ( "foo" ) ;
458+ expect ( data ) . not . toBeUndefined ( ) ;
459+ expect ( data . name ) . toBe ( "Scan results for myimage:mytag" ) ;
460+ //Should display the vulnerability with the highest severity
461+ expect ( data . output . annotations ) . toContainEqual ( { "path" : "Dockerfile" , "start_line" : 1 , "end_line" : 1 , "annotation_level" : "warning" , "message" : "CVE-2019-14697 Severity=High Package=musl-utils-1.1.18-r3 Type=APKG Fix=1.1.18-r4 Url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-14697" , "title" : "Vulnerability found: CVE-2019-14697" } ) ;
462+ expect ( data . output . annotations ) . not . toContainEqual ( { "path" : "Dockerfile" , "start_line" : 1 , "end_line" : 1 , "annotation_level" : "warning" , "message" : "CVE-2019-14698 Severity=Medium Package=musl-utils-1.1.18-r3 Type=APKG Fix=1.1.18-r4 Url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-14698" , "title" : "Vulnerability found: CVE-2019-14698" } ) ;
463+
424464 } )
425465
426466 it ( "generates a check run with gate annotations" , async ( ) => {
0 commit comments