Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan - Add Xray version to Xray graph scan params #253

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
)

func TestXrayAuditNpmJson(t *testing.T) {
integration.InitAuditJavaScriptTest(t, scangraph.GraphScanMinXrayVersion)
output := testAuditNpm(t, string(format.Json), false)
validations.VerifyJsonResults(t, output, validations.ValidationParams{
SecurityViolations: 1,
Expand All @@ -46,6 +47,7 @@ func TestXrayAuditNpmJson(t *testing.T) {
}

func TestXrayAuditNpmSimpleJson(t *testing.T) {
integration.InitAuditJavaScriptTest(t, scangraph.GraphScanMinXrayVersion)
output := testAuditNpm(t, string(format.SimpleJson), true)
validations.VerifySimpleJsonResults(t, output, validations.ValidationParams{
SecurityViolations: 1,
Expand All @@ -55,7 +57,6 @@ func TestXrayAuditNpmSimpleJson(t *testing.T) {
}

func testAuditNpm(t *testing.T, format string, withVuln bool) string {
integration.InitAuditJavaScriptTest(t, scangraph.GraphScanMinXrayVersion)
_, cleanUp := securityTestUtils.CreateTestProjectEnvAndChdir(t, filepath.Join(filepath.FromSlash(securityTests.GetTestResourcesPath()), "projects", "package-managers", "npm", "npm"))
defer cleanUp()
// Run npm install before executing jfrog xr npm-audit
Expand Down Expand Up @@ -337,23 +338,24 @@ func testXrayAuditGradle(t *testing.T, format string) string {
}

func TestXrayAuditMavenJson(t *testing.T) {
output := testXscAuditMaven(t, string(format.Json))
integration.InitAuditJavaTest(t, scangraph.GraphScanMinXrayVersion)
output := testAuditMaven(t, string(format.Json))
validations.VerifyJsonResults(t, output, validations.ValidationParams{
Vulnerabilities: 1,
Licenses: 1,
})
}

func TestXrayAuditMavenSimpleJson(t *testing.T) {
output := testXscAuditMaven(t, string(format.SimpleJson))
integration.InitAuditJavaTest(t, scangraph.GraphScanMinXrayVersion)
output := testAuditMaven(t, string(format.SimpleJson))
validations.VerifySimpleJsonResults(t, output, validations.ValidationParams{
Vulnerabilities: 1,
Licenses: 1,
})
}

func testXscAuditMaven(t *testing.T, format string) string {
integration.InitAuditJavaTest(t, scangraph.GraphScanMinXrayVersion)
func testAuditMaven(t *testing.T, format string) string {
_, cleanUp := securityTestUtils.CreateTestProjectEnvAndChdir(t, filepath.Join(filepath.FromSlash(securityTests.GetTestResourcesPath()), "projects", "package-managers", "maven", "maven"))
defer cleanUp()
// Add dummy descriptor file to check that we run only specific audit
Expand Down
6 changes: 4 additions & 2 deletions commands/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,11 @@ func (scanCmd *ScanCommand) createIndexerHandlerFunc(file *spec.File, cmdResults
IncludeVulnerabilities: scanCmd.includeVulnerabilities,
ProjectKey: scanCmd.projectKey,
ScanType: services.Binary,
MultiScanId: cmdResults.MultiScanId,
XscVersion: cmdResults.XscVersion,
XrayVersion: cmdResults.XrayVersion,
}
params.MultiScanId = cmdResults.MultiScanId
params.XscVersion = cmdResults.XscVersion

if scanCmd.progress != nil {
scanCmd.progress.SetHeadlineMsg("Scanning 🔍")
}
Expand Down
6 changes: 3 additions & 3 deletions scans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestDockerScanWithProgressBar(t *testing.T) {

func TestDockerScanWithTokenValidation(t *testing.T) {
integration.InitScanTest(t, jasutils.DynamicTokenValidationMinXrayVersion)
testCli, cleanup := integration.InitNativeDockerTest(t)
testCli, cleanup := integration.InitNativeDockerTest(t, true)
defer cleanup()
// #nosec G101 -- Image with dummy token for tests
tokensImageToScan := "srmishj/inactive_tokens:latest"
Expand All @@ -131,7 +131,7 @@ func TestDockerScanWithTokenValidation(t *testing.T) {

func TestDockerScan(t *testing.T) {
integration.InitScanTest(t, "")
testCli, cleanup := integration.InitNativeDockerTest(t)
testCli, cleanup := integration.InitNativeDockerTest(t, true)
defer cleanup()

watchName, deleteWatch := securityTestUtils.CreateTestWatch(t, "docker-policy", "docker-watch", xrayUtils.Low)
Expand Down Expand Up @@ -190,7 +190,7 @@ func runDockerScan(t *testing.T, testCli *coreTests.JfrogCli, imageName, watchNa

func TestAdvancedSecurityDockerScan(t *testing.T) {
integration.InitScanTest(t, "")
testCli, cleanup := integration.InitNativeDockerTest(t)
testCli, cleanup := integration.InitNativeDockerTest(t, true)
defer cleanup()
runAdvancedSecurityDockerScan(t, testCli, "jfrog/demo-security:latest")
}
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/integration/test_integrationutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func InitScanTest(t *testing.T, minVersion string) {
testUtils.ValidateXrayVersion(t, minVersion)
}

func InitNativeDockerTest(t *testing.T) (mockCli *coreTests.JfrogCli, cleanUp func()) {
if !*configTests.TestDockerScan {
func InitNativeDockerTest(t *testing.T, isSkip bool) (mockCli *coreTests.JfrogCli, cleanUp func()) {
if isSkip && !*configTests.TestDockerScan {
t.Skip(getSkipTestMsg("Docker scan command integration (Ubuntu)", "--test.dockerScan"))
}
return InitTestWithMockCommandOrParams(t, false, cli.DockerScanMockCommand)
Expand Down
6 changes: 3 additions & 3 deletions xsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestXscAuditNpmSimpleJsonWithWatch(t *testing.T) {
func TestXscAuditMavenJson(t *testing.T) {
_, _, cleanUp := integration.InitXscTest(t)
defer cleanUp()
output := testXscAuditMaven(t, string(format.Json))
output := testAuditMaven(t, string(format.Json))
validations.VerifyJsonResults(t, output, validations.ValidationParams{
Vulnerabilities: 1,
Licenses: 1,
Expand All @@ -62,7 +62,7 @@ func TestXscAuditMavenJson(t *testing.T) {
func TestXscAuditMavenSimpleJson(t *testing.T) {
_, _, cleanUp := integration.InitXscTest(t)
defer cleanUp()
output := testXscAuditMaven(t, string(format.SimpleJson))
output := testAuditMaven(t, string(format.SimpleJson))
validations.VerifySimpleJsonResults(t, output, validations.ValidationParams{
Vulnerabilities: 1,
Licenses: 1,
Expand Down Expand Up @@ -102,7 +102,7 @@ func validateAnalyticsBasicEvent(t *testing.T, xrayVersion, xscVersion, output s
func TestAdvancedSecurityDockerScanWithXsc(t *testing.T) {
_, _, cleanUpXsc := integration.InitXscTest(t)
defer cleanUpXsc()
testCli, cleanupDocker := integration.InitNativeDockerTest(t)
testCli, cleanupDocker := integration.InitNativeDockerTest(t, false)
defer cleanupDocker()
runAdvancedSecurityDockerScan(t, testCli, "jfrog/demo-security:latest")
}
Loading