Skip to content

Commit

Permalink
fix static
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Dec 12, 2024
1 parent d632cb7 commit 74fc2ef
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 48 deletions.
76 changes: 38 additions & 38 deletions utils/results/conversion/convertor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,44 @@ func TestConvertResults(t *testing.T) {
// dockerScanInputResults := testUtils.ReadCmdScanResults(t, filepath.Join(testDataDir, "dockerscan", "docker_results.json"))

testCases := []struct {
cmdType utils.CommandType
contentFormat conversionFormat
cmdType utils.CommandType
contentFormat conversionFormat
// inputResults *results.SecurityCommandResults
expectedContentPath string
}{
{
cmdType: utils.SourceCode,
contentFormat: SimpleJson,
cmdType: utils.SourceCode,
contentFormat: SimpleJson,
// inputResults: auditInputResults,
expectedContentPath: filepath.Join(testDataDir, "audit", "audit_simple_json.json"),
},
{
cmdType: utils.SourceCode,
contentFormat: Sarif,
cmdType: utils.SourceCode,
contentFormat: Sarif,
// inputResults: auditInputResults,
expectedContentPath: filepath.Join(testDataDir, "audit", "audit_sarif.json"),
},
{
cmdType: utils.SourceCode,
contentFormat: Summary,
cmdType: utils.SourceCode,
contentFormat: Summary,
// inputResults: auditInputResults,
expectedContentPath: filepath.Join(testDataDir, "audit", "audit_summary.json"),
},
{
cmdType: utils.DockerImage,
contentFormat: SimpleJson,
cmdType: utils.DockerImage,
contentFormat: SimpleJson,
// inputResults: dockerScanInputResults,
expectedContentPath: filepath.Join(testDataDir, "dockerscan", "docker_simple_json.json"),
},
{
cmdType: utils.DockerImage,
contentFormat: Sarif,
cmdType: utils.DockerImage,
contentFormat: Sarif,
// inputResults: dockerScanInputResults,
expectedContentPath: filepath.Join(testDataDir, "dockerscan", "docker_sarif.json"),
},
{
cmdType: utils.DockerImage,
contentFormat: Summary,
cmdType: utils.DockerImage,
contentFormat: Summary,
// inputResults: dockerScanInputResults,
expectedContentPath: filepath.Join(testDataDir, "dockerscan", "docker_summary.json"),
},
Expand All @@ -85,7 +85,7 @@ func TestConvertResults(t *testing.T) {
for _, testCase := range testCases {
t.Run(fmt.Sprintf("%s convert to %s", testCase.cmdType, testCase.contentFormat), func(t *testing.T) {
var validationParams validations.ValidationParams
var inputResults *results.SecurityCommandResults
var inputResults *results.SecurityCommandResults
switch testCase.cmdType {
case utils.SourceCode:
inputResults, validationParams = getAuditTestResults(testCase.contentFormat == Summary)
Expand Down Expand Up @@ -156,7 +156,7 @@ func validateSummaryConversion(t *testing.T, expectedResults formats.ResultsSumm
// content, err := utils.GetAsJsonBytes(actualResults, true, true)
// assert.NoError(t, err)
// os.WriteFile("/Users/assafa/Documents/code/jfrog-projects/jfrog-cli-security/tests/testdata/output/dockerscan/docker_summary.json", content, 0644)

validations.ValidateCommandSummaryOutput(t, validationParams)
}

Expand Down Expand Up @@ -225,9 +225,9 @@ func getAuditTestResults(unique bool) (*results.SecurityCommandResults, validati
}},
},
},
IssueId: "XRAY-609848",
IssueId: "XRAY-609848",
ExtendedInformation: &services.ExtendedInformation{
ShortDescription: "ReDoS in Async may lead to denial of service while parsing",
ShortDescription: "ReDoS in Async may lead to denial of service while parsing",
JfrogResearchSeverity: "Low",
JfrogResearchSeverityReasons: []services.JfrogResearchSeverityReason{
{Name: "The reported CVSS was either wrongly calculated", Description: "The reported CVSS does not reflect the severity of the vulnerability", IsPositive: true},
Expand All @@ -237,7 +237,7 @@ func getAuditTestResults(unique bool) (*results.SecurityCommandResults, validati
},
{
Cves: []services.Cve{{
Id: "CVE-2020-8203",
Id: "CVE-2020-8203",
CvssV2Score: "5.8",
CvssV3Score: "7.4",
}},
Expand Down Expand Up @@ -301,7 +301,7 @@ func getAuditTestResults(unique bool) (*results.SecurityCommandResults, validati
},
Violations: []services.Violation{
{
ViolationType: utils.ViolationTypeSecurity.String(),
ViolationType: utils.ViolationTypeSecurity.String(),
Cves: []services.Cve{{
Id: "CVE-2024-39249",
}},
Expand All @@ -322,7 +322,7 @@ func getAuditTestResults(unique bool) (*results.SecurityCommandResults, validati
ExtendedInformation: &services.ExtendedInformation{JfrogResearchSeverity: "Low"},
},
{
ViolationType: utils.ViolationTypeSecurity.String(),
ViolationType: utils.ViolationTypeSecurity.String(),
Cves: []services.Cve{{
Id: "CVE-2018-3721",
}},
Expand All @@ -343,9 +343,9 @@ func getAuditTestResults(unique bool) (*results.SecurityCommandResults, validati
},
{
ViolationType: utils.ViolationTypeLicense.String(),
LicenseKey: "MIT",
LicenseName: "MIT full name",
Severity: severityutils.High.String(),
LicenseKey: "MIT",
LicenseName: "MIT full name",
Severity: severityutils.High.String(),
Components: map[string]services.Component{
"npm://lodash:4.17.0": {
ImpactPaths: [][]services.ImpactPathNode{{
Expand All @@ -361,8 +361,8 @@ func getAuditTestResults(unique bool) (*results.SecurityCommandResults, validati
},
Licenses: []services.License{
{
Key: "MIT",
Name: "MIT full name",
Key: "MIT",
Name: "MIT full name",
Components: map[string]services.Component{
"npm://lodash:4.17.0": {
ImpactPaths: [][]services.ImpactPathNode{{
Expand Down Expand Up @@ -522,11 +522,11 @@ func getDockerScanTestResults(unique bool) (*results.SecurityCommandResults, val
{ComponentId: "docker://platform.jfrog.io/swamp-docker/swamp:latest"},
{
ComponentId: "generic://sha256:f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595/sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
FullPath: "sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
FullPath: "sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
},
{
ComponentId: "deb://debian:bookworm:libssl3:3.0.13-1~deb12u1",
FullPath: "libssl3:3.0.13-1~deb12u1",
FullPath: "libssl3:3.0.13-1~deb12u1",
},
}},
},
Expand All @@ -546,11 +546,11 @@ func getDockerScanTestResults(unique bool) (*results.SecurityCommandResults, val
{ComponentId: "docker://platform.jfrog.io/swamp-docker/swamp:latest"},
{
ComponentId: "generic://sha256:f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595/sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
FullPath: "sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
FullPath: "sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
},
{
ComponentId: "deb://debian:bookworm:libssl3:3.0.13-1~deb12u1",
FullPath: "libssl3:3.0.13-1~deb12u1",
FullPath: "libssl3:3.0.13-1~deb12u1",
},
}},
},
Expand All @@ -559,11 +559,11 @@ func getDockerScanTestResults(unique bool) (*results.SecurityCommandResults, val
{ComponentId: "docker://platform.jfrog.io/swamp-docker/swamp:latest"},
{
ComponentId: "generic://sha256:f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595/sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
FullPath: "sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
FullPath: "sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
},
{
ComponentId: "deb://debian:bookworm:openssl:3.0.13-1~deb12u1",
FullPath: "openssl:3.0.13-1~deb12u1",
FullPath: "openssl:3.0.13-1~deb12u1",
},
}},
FixedVersions: []string{"[3.0.14-1~deb12u2]"},
Expand All @@ -575,7 +575,7 @@ func getDockerScanTestResults(unique bool) (*results.SecurityCommandResults, val
},
Violations: []services.Violation{
{
ViolationType: utils.ViolationTypeSecurity.String(),
ViolationType: utils.ViolationTypeSecurity.String(),
Cves: []services.Cve{{
Id: "CVE-2024-6119",
}},
Expand All @@ -587,19 +587,19 @@ func getDockerScanTestResults(unique bool) (*results.SecurityCommandResults, val
{ComponentId: "docker://platform.jfrog.io/swamp-docker/swamp:latest"},
{
ComponentId: "generic://sha256:f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595/sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
FullPath: "sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
FullPath: "sha256__f21c087a3964a446bce1aa4e3ec7cf82020dd77ad14f1cf4ea49cbb32eda1595.tar",
},
{
ComponentId: "deb://debian:bookworm:libssl3:3.0.13-1~deb12u1",
FullPath: "libssl3:3.0.13-1~deb12u1",
FullPath: "libssl3:3.0.13-1~deb12u1",
},
}},
},
},
IssueId: "XRAY-632747",
ExtendedInformation: &services.ExtendedInformation{JfrogResearchSeverity: "Medium"},
WatchName: "security-watch",
Policies: []services.Policy{{Policy: "debian-security"}},
WatchName: "security-watch",
Policies: []services.Policy{{Policy: "debian-security"}},
},
},
ScannedStatus: "completed",
Expand All @@ -614,7 +614,7 @@ func getDockerScanTestResults(unique bool) (*results.SecurityCommandResults, val
),
},
Invocations: []*sarif.Invocation{sarif.NewInvocation().WithWorkingDirectory(sarif.NewSimpleArtifactLocation("temp/folders/T/jfrog.cli.temp.-11-11"))},
Results: []*sarif.Result{validations.CreateDummyApplicableResults("CVE-2024-6119", formats.Location{File: "file:///usr/local/bin/node"})},
Results: []*sarif.Result{validations.CreateDummyApplicableResults("CVE-2024-6119", formats.Location{File: "file:///usr/local/bin/node"})},
},
)
// Secrets scan results
Expand Down
6 changes: 3 additions & 3 deletions utils/results/conversion/sarifparser/sarifparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type currentTargetState struct {
type scaParseParams struct {
CmdType utils.CommandType
IssueId, Summary, MarkdownDescription, CveScore, ImpactedPackagesName, ImpactedPackagesVersion string
Watch string
Watch string
GenerateTitleFunc func(depName string, version string, issueId string, watch string) string
Cves []formats.CveRow
Severity severityutils.Severity
Expand Down Expand Up @@ -352,7 +352,7 @@ func addSarifScaSecurityViolation(cmdType utils.CommandType, sarifResults *[]*sa
currentResults, currentRule := parseScaToSarifFormat(scaParseParams{
CmdType: cmdType,
IssueId: violation.IssueId,
Watch: violation.WatchName,
Watch: violation.WatchName,
Summary: violation.Summary,
MarkdownDescription: markdownDescription,
CveScore: maxCveScore,
Expand Down Expand Up @@ -391,7 +391,7 @@ func addSarifScaLicenseViolation(cmdType utils.CommandType, sarifResults *[]*sar
}
currentResults, currentRule := parseScaToSarifFormat(scaParseParams{
CmdType: cmdType,
Watch: violation.WatchName,
Watch: violation.WatchName,
IssueId: violation.LicenseKey,
Summary: getLicenseViolationSummary(impactedPackagesName, impactedPackagesVersion, violation.LicenseKey),
MarkdownDescription: markdownDescription,
Expand Down
2 changes: 1 addition & 1 deletion utils/results/conversion/summaryparser/summaryparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,4 @@ func getJasScansWatches(scans ...results.ScanResult[[]*sarif.Run]) (watches []st
}
}
return
}
}
4 changes: 2 additions & 2 deletions utils/validations/test_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func CreateDummySecretResult(id string, status jasutils.TokenValidationStatus, m
return &sarif.Result{
Message: *sarif.NewTextMessage(fmt.Sprintf("Secret %s were found", id)),
RuleID: utils.NewStrPtr(id),
Level: utils.NewStrPtr(severityutils.LevelInfo.String()),
Level: utils.NewStrPtr(severityutils.LevelInfo.String()),
Locations: []*sarif.Location{
sarifutils.CreateLocation(location.File, location.StartLine, location.StartColumn, location.EndLine, location.EndColumn, location.Snippet),
},
Expand Down Expand Up @@ -268,4 +268,4 @@ func CreateDummySastViolationResult(id string, level severityutils.SarifSeverity
result.PropertyBag.Properties[sarifutils.JasIssueIdSarifPropertyKey] = issueId
result.PropertyBag.Properties[sarifutils.PoliciesSarifPropertyKey] = policies
return result
}
}
6 changes: 2 additions & 4 deletions utils/validations/test_validate_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func ValidateSummaryIssuesCount(t *testing.T, params ValidationParams, results f
if scan.Vulnerabilities.SecretsResults != nil {
for _, counts := range *scan.Vulnerabilities.SecretsResults {
for status, count := range counts {
switch status {
case jasutils.Inactive.String():
if status == jasutils.Inactive.String() {
actualValues.InactiveSecretsVulnerabilities += count
}
}
Expand Down Expand Up @@ -95,8 +94,7 @@ func ValidateSummaryIssuesCount(t *testing.T, params ValidationParams, results f
if scan.Violations.SecretsResults != nil {
for _, counts := range *scan.Violations.SecretsResults {
for status, count := range counts {
switch status {
case jasutils.Inactive.String():
if status == jasutils.Inactive.String() {
actualValues.InactiveSecretsViolations += count
}
}
Expand Down

0 comments on commit 74fc2ef

Please sign in to comment.