Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Sep 14, 2023
1 parent 5e8bccd commit deaa75f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 78 deletions.
41 changes: 21 additions & 20 deletions xray/commands/audit/jas/common_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package jas

import (
"testing"

"github.com/jfrog/jfrog-cli-core/v2/xray/utils"
"github.com/owenrumney/go-sarif/v2/sarif"
"github.com/stretchr/testify/assert"
"testing"
)

func TestExcludeSuppressResults(t *testing.T) {
Expand All @@ -15,27 +16,27 @@ func TestExcludeSuppressResults(t *testing.T) {
}{
{
sarifResults: []*sarif.Result{
utils.GetDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet1", "ruleId1", "level1"),
utils.GetDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2"),
utils.CreateDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet1", "ruleId1", "level1"),
utils.CreateDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2"),
},
expectedOutput: []*sarif.Result{
utils.GetDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet1", "ruleId1", "level1"),
utils.GetDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2"),
utils.CreateDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet1", "ruleId1", "level1"),
utils.CreateDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2"),
},
},
{
sarifResults: []*sarif.Result{
utils.GetDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet1", "ruleId1", "level1").WithSuppression([]*sarif.Suppression{sarif.NewSuppression("")}),
utils.GetDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2"),
utils.CreateDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet1", "ruleId1", "level1").WithSuppression([]*sarif.Suppression{sarif.NewSuppression("")}),
utils.CreateDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2"),
},
expectedOutput: []*sarif.Result{
utils.GetDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2"),
utils.CreateDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2"),
},
},
{
sarifResults: []*sarif.Result{
utils.GetDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet1", "ruleId1", "level1").WithSuppression([]*sarif.Suppression{sarif.NewSuppression("")}),
utils.GetDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2").WithSuppression([]*sarif.Suppression{sarif.NewSuppression("")}),
utils.CreateDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet1", "ruleId1", "level1").WithSuppression([]*sarif.Suppression{sarif.NewSuppression("")}),
utils.CreateDummyResultWithOneLocation("", 0, 0, 0, 0, "snippet2", "ruleId2", "level2").WithSuppression([]*sarif.Suppression{sarif.NewSuppression("")}),
},
expectedOutput: []*sarif.Result{},
},
Expand All @@ -54,23 +55,23 @@ func TestAddScoreToRunRules(t *testing.T) {
expectedOutput []*sarif.ReportingDescriptor
}{
{
sarifRun: utils.GetRunWithDummyResults(
utils.GetDummyResultWithOneLocation("file1", 0, 0, 0, 0, "snippet", "rule1", "info"),
utils.GetDummyResultWithOneLocation("file2", 0, 0, 0, 0, "snippet", "rule1", "info"),
utils.GetDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule2", "warning"),
sarifRun: utils.CreateRunWithDummyResults(
utils.CreateDummyResultWithOneLocation("file1", 0, 0, 0, 0, "snippet", "rule1", "info"),
utils.CreateDummyResultWithOneLocation("file2", 0, 0, 0, 0, "snippet", "rule1", "info"),
utils.CreateDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule2", "warning"),
),
expectedOutput: []*sarif.ReportingDescriptor{
sarif.NewRule("rule1").WithProperties(sarif.Properties{"security-severity": "6.9"}),
sarif.NewRule("rule2").WithProperties(sarif.Properties{"security-severity": "6.9"}),
},
},
{
sarifRun: utils.GetRunWithDummyResults(
utils.GetDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule1", "none"),
utils.GetDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule2", "note"),
utils.GetDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule3", "info"),
utils.GetDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule4", "warning"),
utils.GetDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule5", "error"),
sarifRun: utils.CreateRunWithDummyResults(
utils.CreateDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule1", "none"),
utils.CreateDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule2", "note"),
utils.CreateDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule3", "info"),
utils.CreateDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule4", "warning"),
utils.CreateDummyResultWithOneLocation("file", 0, 0, 0, 0, "snippet", "rule5", "error"),
),
expectedOutput: []*sarif.ReportingDescriptor{
sarif.NewRule("rule1").WithProperties(sarif.Properties{"security-severity": "0.0"}),
Expand Down
32 changes: 16 additions & 16 deletions xray/utils/resultstable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ func TestGetApplicableCveValue(t *testing.T) {
{
scanResults: &ExtendedScanResults{
ApplicabilityScanResults: []*sarif.Run{
GetRunWithDummyResults(
GetDummyResultWithOneLocation("fileName1", 0, 1, 0, 0, "snippet1", "applic_testCve1", "info"),
GetDummyPassingResult("applic_testCve2"),
CreateRunWithDummyResults(
CreateDummyResultWithOneLocation("fileName1", 0, 1, 0, 0, "snippet1", "applic_testCve1", "info"),
CreateDummyPassingResult("applic_testCve2"),
),
},
EntitledForJas: true,
Expand All @@ -453,9 +453,9 @@ func TestGetApplicableCveValue(t *testing.T) {
{
scanResults: &ExtendedScanResults{
ApplicabilityScanResults: []*sarif.Run{
GetRunWithDummyResults(
GetDummyPassingResult("applic_testCve1"),
GetDummyResultWithOneLocation("fileName2", 1, 0, 0, 0, "snippet2", "applic_testCve2", "warning"),
CreateRunWithDummyResults(
CreateDummyPassingResult("applic_testCve1"),
CreateDummyResultWithOneLocation("fileName2", 1, 0, 0, 0, "snippet2", "applic_testCve2", "warning"),
),
},
EntitledForJas: true,
Expand All @@ -467,9 +467,9 @@ func TestGetApplicableCveValue(t *testing.T) {
{
scanResults: &ExtendedScanResults{
ApplicabilityScanResults: []*sarif.Run{
GetRunWithDummyResults(
GetDummyPassingResult("applic_testCve1"),
GetDummyResultWithOneLocation("fileName3", 0, 1, 0, 0, "snippet3", "applic_testCve2", "info"),
CreateRunWithDummyResults(
CreateDummyPassingResult("applic_testCve1"),
CreateDummyResultWithOneLocation("fileName3", 0, 1, 0, 0, "snippet3", "applic_testCve2", "info"),
),
},
EntitledForJas: true,
Expand All @@ -481,9 +481,9 @@ func TestGetApplicableCveValue(t *testing.T) {
{
scanResults: &ExtendedScanResults{
ApplicabilityScanResults: []*sarif.Run{
GetRunWithDummyResults(
GetDummyPassingResult("applic_testCve1"),
GetDummyPassingResult("applic_testCve2"),
CreateRunWithDummyResults(
CreateDummyPassingResult("applic_testCve1"),
CreateDummyPassingResult("applic_testCve2"),
),
},
EntitledForJas: true,
Expand All @@ -495,9 +495,9 @@ func TestGetApplicableCveValue(t *testing.T) {
{
scanResults: &ExtendedScanResults{
ApplicabilityScanResults: []*sarif.Run{
GetRunWithDummyResults(
GetDummyPassingResult("applic_testCve1"),
GetDummyResultWithOneLocation("fileName4", 1, 0, 0, 0, "snippet", "applic_testCve2", "warning"),
CreateRunWithDummyResults(
CreateDummyPassingResult("applic_testCve1"),
CreateDummyResultWithOneLocation("fileName4", 1, 0, 0, 0, "snippet", "applic_testCve2", "warning"),
),
},
EntitledForJas: true,
Expand All @@ -509,7 +509,7 @@ func TestGetApplicableCveValue(t *testing.T) {
{
scanResults: &ExtendedScanResults{
ApplicabilityScanResults: []*sarif.Run{
GetRunWithDummyResults(GetDummyPassingResult("applic_testCve1")),
CreateRunWithDummyResults(CreateDummyPassingResult("applic_testCve1")),
},
EntitledForJas: true},
cves: []services.Cve{{Id: "testCve1"}, {Id: "testCve2"}},
Expand Down
12 changes: 6 additions & 6 deletions xray/utils/sarifutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ func GetInvocationWorkingDirectory(invocation *sarif.Invocation) string {
return ""
}

func GetRunWithDummyResults(results ...*sarif.Result) *sarif.Run {
func CreateRunWithDummyResults(results ...*sarif.Result) *sarif.Run {
run := sarif.NewRunWithInformationURI("", "")
for _, result := range results {
run.AddResult(result)
}
return run
}

func GetDummyResultWithLocations(msg, ruleId, level string, locations ...*sarif.Location) *sarif.Result {
func CreateDummyResultWithLocations(msg, ruleId, level string, locations ...*sarif.Location) *sarif.Result {
return &sarif.Result{
Message: *sarif.NewTextMessage(msg),
Locations: locations,
Expand All @@ -277,7 +277,7 @@ func GetDummyResultWithLocations(msg, ruleId, level string, locations ...*sarif.
}
}

func GetDummyLocation(fileName string, startLine, startCol, endLine, endCol int, snippet string) *sarif.Location {
func CreateDummyLocation(fileName string, startLine, startCol, endLine, endCol int, snippet string) *sarif.Location {
return &sarif.Location{
PhysicalLocation: &sarif.PhysicalLocation{
ArtifactLocation: &sarif.ArtifactLocation{URI: &fileName},
Expand All @@ -290,17 +290,17 @@ func GetDummyLocation(fileName string, startLine, startCol, endLine, endCol int,
}
}

func GetDummyPassingResult(ruleId string) *sarif.Result {
func CreateDummyPassingResult(ruleId string) *sarif.Result {
kind := "pass"
return &sarif.Result{
Kind: &kind,
RuleID: &ruleId,
}
}

func GetDummyResultWithOneLocation(fileName string, startLine, startCol, endLine, endCol int, snippet, ruleId, level string) *sarif.Result {
func CreateDummyResultWithOneLocation(fileName string, startLine, startCol, endLine, endCol int, snippet, ruleId, level string) *sarif.Result {
return &sarif.Result{
Locations: []*sarif.Location{GetDummyLocation(fileName, startCol, startCol, endLine, endCol, snippet)},
Locations: []*sarif.Location{CreateDummyLocation(fileName, startCol, startCol, endLine, endCol, snippet)},
Level: &level,
RuleID: &ruleId,
}
Expand Down
Loading

0 comments on commit deaa75f

Please sign in to comment.