Skip to content

Commit 41c2d1e

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into static_sca_violations_remediations
2 parents e96217e + a71f06e commit 41c2d1e

File tree

9 files changed

+355
-45
lines changed

9 files changed

+355
-45
lines changed

jas/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func processSarifRuns(sarifRuns []*sarif.Run, wd string, informationUrlSuffix st
236236
sarifRun.Results = excludeSuppressResults(sarifRun.Results)
237237
sarifRun.Results = excludeMinSeverityResults(sarifRun.Results, minSeverity)
238238
}
239+
sarifutils.ConvertRunsPathsToRelative(sarifRuns...)
239240
}
240241

241242
func fillMissingRequiredDriverInformation(defaultJasInformationUri, defaultVersion string, run *sarif.Run) {

jas/common_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
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+
}

sca/bom/buildinfo/technologies/gem/gem_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/jfrog/jfrog-cli-security/utils"
1313
)
1414

15-
var expectedUniqueDeps = []string{"rubygems://puma:5.6.9", "rubygems://nio4r:2.7.4"}
15+
var expectedUniqueDeps = []string{"rubygems://puma:5.6.9", "rubygems://nio4r:2.7.5"}
1616

1717
var expectedResult = &xrayUtils.GraphNode{
1818
Id: "root",
@@ -21,7 +21,7 @@ var expectedResult = &xrayUtils.GraphNode{
2121
Id: "rubygems://puma:5.6.9",
2222
Nodes: []*xrayUtils.GraphNode{
2323
{
24-
Id: "rubygems://nio4r:2.7.4",
24+
Id: "rubygems://nio4r:2.7.5",
2525
Nodes: []*xrayUtils.GraphNode{},
2626
},
2727
},
@@ -52,15 +52,15 @@ func TestBuildDependencyTree(t *testing.T) {
5252
}
5353

5454
// expectedUniqueDeps should be defined
55-
// expectedUniqueDeps := []string{"rubygems://puma:5.6.9", "rubygems://nio4r:2.7.4"}
55+
// expectedUniqueDeps := []string{"rubygems://puma:5.6.9", "rubygems://nio4r:2.7.5"}
5656
func TestCalculateUniqueDeps(t *testing.T) {
5757
var input = &xrayUtils.GraphNode{
5858
Nodes: []*xrayUtils.GraphNode{
5959
{
6060
Id: "rubygems://puma:5.6.9",
6161
Nodes: []*xrayUtils.GraphNode{
6262
{
63-
Id: "rubygems://nio4r:2.7.4",
63+
Id: "rubygems://nio4r:2.7.5",
6464
Nodes: []*xrayUtils.GraphNode{},
6565
},
6666
},

sca/bom/buildinfo/technologies/pnpm/pnpm_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestBuildDependencyTreeLimitedDepth(t *testing.T) {
4343
name: "With transitive dependencies",
4444
treeDepth: "1",
4545
expectedUniqueDeps: []string{
46-
"npm://axios:1.12.2",
46+
"npm://axios:1.13.1",
4747
"npm://balaganjs:1.0.0",
4848
"npm://yargs:13.3.0",
4949
"npm://zen-website:1.0.0",
@@ -53,7 +53,7 @@ func TestBuildDependencyTreeLimitedDepth(t *testing.T) {
5353
Nodes: []*xrayUtils.GraphNode{
5454
{
5555
Id: "npm://balaganjs:1.0.0",
56-
Nodes: []*xrayUtils.GraphNode{{Id: "npm://axios:1.12.2"}, {Id: "npm://yargs:13.3.0"}},
56+
Nodes: []*xrayUtils.GraphNode{{Id: "npm://axios:1.13.1"}, {Id: "npm://yargs:13.3.0"}},
5757
},
5858
},
5959
},

0 commit comments

Comments
 (0)