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

Add advanced security tests for docker scan. #27

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
45 changes: 45 additions & 0 deletions scans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/jfrog/jfrog-cli-security/formats"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -233,6 +234,50 @@ func createTestWatch(t *testing.T) (string, func()) {
}
}

// JAS docker scan tests

func TestAdvancedSecurityDockerScan(t *testing.T) {
cleanup := initNativeDockerWithXrayTest(t)
defer cleanup()
runAdvancedSecurityDockerScan(t, "jfrog/demo-security:latest")
}

func runAdvancedSecurityDockerScan(t *testing.T, imageName string) {
// Pull image from docker repo
imageTag := path.Join(*securityTests.ContainerRegistry, securityTests.DockerVirtualRepo, imageName)
dockerPullCommand := container.NewPullCommand(containerUtils.DockerClient)
dockerPullCommand.SetCmdParams([]string{"pull", imageTag}).SetImageTag(imageTag).SetRepo(securityTests.DockerVirtualRepo).SetServerDetails(securityTests.XrDetails).SetBuildConfiguration(new(build.BuildConfiguration))
if assert.NoError(t, dockerPullCommand.Run()) {
defer commonTests.DeleteTestImage(t, imageTag, containerUtils.DockerClient)
args := []string{"docker", "scan", imageTag, "--server-id=default", "--format=simple-json", "--fail=false", "--min-severity=low", "--fixable-only"}

// Run docker scan on image
output := securityTests.PlatformCli.WithoutCredentials().RunCliCmdWithOutput(t, args...)
if assert.NotEmpty(t, output) {
verifyAdvancedSecurityScanResults(t, output)
}
}
}
Comment on lines +245 to +260
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have runDockerScan please modify it to fit your changes.
You can pass the verification method func to it...


func verifyAdvancedSecurityScanResults(t *testing.T, content string) {
var results formats.SimpleJsonResults
err := json.Unmarshal([]byte(content), &results)
assert.NoError(t, err)
// Verify that the scan succeeded, and that at least one "Applicable" status was received.
applicableStatusExists := false
for _, vulnerability := range results.Vulnerabilities {
if vulnerability.Applicable == string(utils.Applicable) {
applicableStatusExists = true
break
}
}
assert.True(t, applicableStatusExists)

// Verify that secretes detection succeeded.
assert.NotEqual(t, 0, len(results.Secrets))

}

// Curation tests

func TestCurationAudit(t *testing.T) {
Expand Down
Loading