88
99 "github.com/owenrumney/go-sarif/v3/pkg/report/v210/sarif"
1010 "github.com/stretchr/testify/assert"
11+ "github.com/stretchr/testify/require"
1112 "golang.org/x/exp/slices"
1213
1314 jfrogAppsConfig "github.com/jfrog/jfrog-apps-config/go"
@@ -19,6 +20,7 @@ import (
1920 "github.com/jfrog/jfrog-cli-security/utils/formats/sarifutils"
2021 "github.com/jfrog/jfrog-cli-security/utils/jasutils"
2122 "github.com/jfrog/jfrog-cli-security/utils/results"
23+ "github.com/jfrog/jfrog-cli-security/utils/severityutils"
2224 "github.com/jfrog/jfrog-cli-security/utils/techutils"
2325)
2426
@@ -593,3 +595,48 @@ func TestGetResultsToCompare(t *testing.T) {
593595 })
594596 }
595597}
598+
599+ func TestProcessSarifRuns (t * testing.T ) {
600+ wd , err := os .Getwd ()
601+ assert .NoError (t , err )
602+
603+ // Create dummy SARIF report.
604+ dummyReport := sarif .NewReport ()
605+ dummyReport .AddRun (sarifutils .CreateRunWithDummyResults (
606+ // Result below the minimum severity.
607+ sarifutils .CreateResultWithOneLocation (fmt .Sprintf ("file://%s" , filepath .Join (wd , "file1" )), 0 , 1 , 2 , 3 , "snippet" , "rule1" , "note" ),
608+ // Suppressed result.
609+ sarifutils .CreateResultWithOneLocation (fmt .Sprintf ("file://%s" , filepath .Join (wd , "file3" )), 0 , 0 , 0 , 0 , "snippet" , "rule1" , "warning" ).WithSuppressions ([]* sarif.Suppression {sarif .NewSuppression ()}),
610+ // Valid result.
611+ sarifutils .CreateResultWithOneLocation (fmt .Sprintf ("file://%s" , filepath .Join (wd , "dir" , "file2" )), 0 , 0 , 0 , 0 , "snippet" , "rule1" , "error" ),
612+ ))
613+
614+ processSarifRuns (dummyReport .Runs , wd , "docs URL" , severityutils .High )
615+ run := dummyReport .Runs [0 ]
616+
617+ // Check Invocation added.
618+ require .NotNil (t , run .Invocations )
619+ require .Len (t , run .Invocations , 1 )
620+ require .NotNil (t , run .Invocations [0 ].WorkingDirectory )
621+ require .NotNil (t , run .Invocations [0 ].WorkingDirectory .URI )
622+ require .Equal (t , * run .Invocations [0 ].WorkingDirectory .URI , utils .ToURI (wd ))
623+
624+ // Check driver info.
625+ driver := run .Tool .Driver
626+ require .NotNil (t , driver )
627+ require .NotNil (t , driver .Version )
628+ require .NotEmpty (t , * driver .Version )
629+ require .NotNil (t , driver .InformationURI )
630+ require .NotEmpty (t , * driver .InformationURI )
631+
632+ // Check severity level mapping.
633+ require .Len (t , driver .Rules , 1 )
634+ rule := driver .Rules [0 ]
635+ require .Equal (t , "8.9" , sarifutils .GetRuleProperty (severityutils .SarifSeverityRuleProperty , rule ))
636+
637+ // Check minimum severity and suppression filtering.
638+ require .Len (t , run .Results , 1 )
639+ // Check file paths are relative and with / separators.
640+ result := run .Results [0 ]
641+ require .Equal (t , "dir/file2" , sarifutils .GetLocationFileName (result .Locations [0 ]))
642+ }
0 commit comments