Skip to content

Commit

Permalink
code nits: removed unwanted variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Suvarna Rokade committed Sep 6, 2021
1 parent 9ac6fea commit 4d15946
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
15 changes: 9 additions & 6 deletions test/e2e/vulnerability/vulnerability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ var _ = Describe("Vulnerabilty", func() {
resourceVulnerabilityIacRelPath := filepath.Join(iacRootRelPath, "resource_for_vulnerability_scan")
Context("resource with aws ecr registry image used which has vulnerabilities", func() {
iacDir := filepath.Join(resourceVulnerabilityIacRelPath, "aws_ecr_registry_used_in_resource")
It("should display vulnerabilities and exit with status code 0 since no violations found", func() {
It("should display vulnerabilities and vulnerability count should be present in scan summary", func() {
scanArgs := []string{"-p", policyRootRelPath, "-i", "terraform", "-d", iacDir, "-o", "json"}
vulnUtils.RunScanAndVerifyVulnerabilityOutputCount(terrascanBinaryPath, helper.ExitCodeZero, false, true, outWriter, errWriter, scanArgs...)
// exit code is zero since no violations are present for resource
vulnUtils.RunScanAndVerifyVulnerabilityCount(terrascanBinaryPath, helper.ExitCodeZero, 1, outWriter, errWriter, scanArgs...)
})
})
Context("resource with azure registry image used which has vulnerabilities", func() {
Expand All @@ -86,9 +87,10 @@ var _ = Describe("Vulnerabilty", func() {
os.Remove(tempFile.Name())
}
})
It("should display vulnerabilities and exit with status code 0 since no violations found", func() {
It("should display vulnerabilities and vulnerability count should be present in scan summary", func() {
scanArgs := []string{"-p", policyRootRelPath, "-i", "terraform", "-d", iacDir, "-o", "json"}
vulnUtils.RunScanAndVerifyVulnerabilityOutputCount(terrascanBinaryPath, helper.ExitCodeZero, false, true, outWriter, errWriter, scanArgs...)
// exit code is zero since no violations are present for resource
vulnUtils.RunScanAndVerifyVulnerabilityCount(terrascanBinaryPath, helper.ExitCodeZero, 1, outWriter, errWriter, scanArgs...)
})
})
Context("resource with google registry image used which has vulnerabilities", func() {
Expand All @@ -107,9 +109,10 @@ var _ = Describe("Vulnerabilty", func() {
os.Remove(tempFile.Name())
}
})
It("should display vulnerabilities and exit with status code 0 since no violations found", func() {
It("should display vulnerabilities and vulnerability count should be present in scan summary", func() {
scanArgs := []string{"-p", policyRootRelPath, "-i", "k8s", "-d", iacDir, "-o", "json"}
vulnUtils.RunScanAndVerifyVulnerabilityOutputCount(terrascanBinaryPath, helper.ExitCodeZero, false, true, outWriter, errWriter, scanArgs...)
// exit code is zero since no violations are present for resource
vulnUtils.RunScanAndVerifyVulnerabilityCount(terrascanBinaryPath, helper.ExitCodeZero, 1, outWriter, errWriter, scanArgs...)
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/vulnerability/vulnerabilty_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const (
VulnerabilityScanTimeout time.Duration = 2 * time.Minute
)

// RunScanAndVerifyVulnerabilityOutputCount runs the scan command with supplied paramters and checks scan summary output
func RunScanAndVerifyVulnerabilityOutputCount(terrascanBinaryPath string, exitCode int, isJunitXML, isStdOut bool, outWriter, errWriter io.Writer, args ...string) {
// RunScanAndVerifyVulnerabilityCount runs the scan command with supplied paramters and checks scan summary output
func RunScanAndVerifyVulnerabilityCount(terrascanBinaryPath string, exitCode, expectedCount int, outWriter, errWriter io.Writer, args ...string) {
session := RunScanCommandWithFindVulnerability(terrascanBinaryPath, exitCode, outWriter, errWriter, args...)
helper.CheckSummaryForVulnerabilities(session, isStdOut)
helper.CheckSummaryForVulnerabilities(session, expectedCount)
}

// RunScanCommandWithFindVulnerability with --find-vuln flag executes the scan command, validates exit code
Expand Down
11 changes: 4 additions & 7 deletions test/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,10 @@ func CompareActualSarifOutputWithGoldenSummaryRegex(session *gexec.Session, gold
}

// CheckSummaryForVulnerabilities is a helper function to check vulnerabilies exists
func CheckSummaryForVulnerabilities(session *gexec.Session, isStdOut bool) {
func CheckSummaryForVulnerabilities(session *gexec.Session, expectedCount int) {
var sessionBytes []byte
if isStdOut {
sessionBytes = session.Wait().Out.Contents()
} else {
sessionBytes = session.Wait().Err.Contents()
}

sessionBytes = session.Wait().Out.Contents()

sessionBytes = bytes.TrimSpace(sessionBytes)

Expand All @@ -448,5 +445,5 @@ func CheckSummaryForVulnerabilities(session *gexec.Session, isStdOut bool) {
gomega.Expect(sessionOutputSummary.Vulnerabilities).NotTo(gomega.BeNil())
gomega.Eventually(func() int {
return *sessionOutputSummary.Vulnerabilities
}).Should(gomega.BeNumerically(">", 0))
}).Should(gomega.BeNumerically(">=", expectedCount))
}

0 comments on commit 4d15946

Please sign in to comment.