Skip to content

Commit

Permalink
add:
Browse files Browse the repository at this point in the history
1. scan e2e tests for --category flag
2. server e2e tests for category

mod:
1. server e2e terminate test
  • Loading branch information
gaurav-gogia committed Mar 9, 2021
1 parent 9f22238 commit f93fbad
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
4 changes: 4 additions & 0 deletions test/e2e/scan/config/invalid_category.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[categories]
list = [
"test"
]
39 changes: 39 additions & 0 deletions test/e2e/scan/scan_rules_filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
var (
terrascanConfigEnvName string = "TERRASCAN_CONFIG"
severityLevelIncorrectError string = "severity level not supported"
categoryIncorrectError string = "category not supported"
)

var _ = Describe("Scan command with rule filtering options", func() {
Expand Down Expand Up @@ -145,6 +146,38 @@ var _ = Describe("Scan command with rule filtering options", func() {
})
})
})

Context("category is specified", func() {
When("category specified is invalid", func() {
It("should error out and exit with status code 1", func() {
scanArgs := []string{scanUtils.ScanCommand, "-p", policyDir, "-d", iacDir, "-o", "json", "--categories", "test"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, scanArgs...)
Eventually(session, scanUtils.ScanTimeout).Should(gexec.Exit(helper.ExitCodeOne))
helper.ContainsErrorSubString(session, categoryIncorrectError)
})
})

When("valid category is specified", func() {
oldIacDir := iacDir
JustAfterEach(func() {
iacDir, err = filepath.Abs(filepath.Join(awsIacRelPath, "aws_ami_violation"))
})

JustAfterEach(func() {
iacDir = oldIacDir
})
Context("category specified is 'COMPLIANCE VALIDATION'", func() {
Context("iac file has violations with only 'DATA PROTECTION' category", func() {
It("should not report any violation and exit with status code 0", func() {
scanArgs := []string{scanUtils.ScanCommand, "-p", policyDir, "-d", iacDir, "-o", "json", "--categories", "COMPLIANCE VALIDATION"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, scanArgs...)
Eventually(session, scanUtils.ScanTimeout).Should(gexec.Exit(helper.ExitCodeZero))
})
})
})
})
})

})

Describe("rule filtering via config file", func() {
Expand Down Expand Up @@ -181,6 +214,12 @@ var _ = Describe("Scan command with rule filtering options", func() {
scanUtils.RunScanAndAssertErrorMessage(terrascanBinaryPath, helper.ExitCodeOne, scanUtils.ScanTimeout, severityLevelIncorrectError, outWriter, errWriter, scanArgs...)
})
})

Context("invalid category is specified in config file", func() {
It("should error out and exit with status code 3", func() {
Skip("skipping this test due to https://github.com/accurics/terrascan/issues/594, should be implemented when fixed")
})
})
})
})

Expand Down
10 changes: 0 additions & 10 deletions test/e2e/server/server_file_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,6 @@ var _ = Describe("Server File Scan", func() {
})
})

When("category is invalid", func() {
It("should receive a 400 bad request", func() {
bodyAttrs := make(map[string]string)
bodyAttrs["categories"] = "5"

serverUtils.MakeFileScanRequest(awsAmiIacFilePath, requestURL, bodyAttrs, http.StatusBadRequest)
Eventually(session.Err, serverUtils.ServerCommandTimeout).Should(gbytes.Say("category not supported"))
})
})

When("category is valid", func() {
It("should receive violations result with 200 OK response", func() {
bodyAttrs := make(map[string]string)
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ var _ = Describe("Server", func() {

Context("server is stopped", func() {
It("should gracefully exit", func() {
session.Terminate()
session.Interrupt()
Eventually(session).Should(gexec.Exit(helper.ExitCodeZero))
_, err := serverUtils.MakeHTTPRequest(http.MethodGet, healthCheckURL)
Expect(err).To(HaveOccurred())
})
Expand Down

0 comments on commit f93fbad

Please sign in to comment.