Skip to content

Commit

Permalink
add: category flag scanning e2e server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav-gogia committed Mar 8, 2021
1 parent f19e4f6 commit 9f22238
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/e2e/server/server_file_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,67 @@ var _ = Describe("Server File Scan", func() {
})
})

When("category is used", func() {
awsAmiIacFilePath, _ := filepath.Abs(filepath.Join(awsAmiViolationRelPath, "main.tf"))

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

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

When("multiple categories are sent but some of them are invalid", func() {
It("should receive a 400 bad request", func() {
bodyAttrs := make(map[string]string)
bodyAttrs["categories"] = " dATa pROtECtION, IDENTITY is Acess Management "

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

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)
bodyAttrs["categories"] = "DATA PROTECTION"

serverUtils.MakeFileScanRequest(awsAmiIacFilePath, requestURL, bodyAttrs, http.StatusOK)
})
})

When("category is wrongly formatted but valid", func() {
It("should receive violations result with 200 OK response", func() {
bodyAttrs := make(map[string]string)
bodyAttrs["categories"] = " dATa pROtECtION "

serverUtils.MakeFileScanRequest(awsAmiIacFilePath, requestURL, bodyAttrs, http.StatusOK)
})
})

When("multiple categories are sent and all of them are valid", func() {
It("should receive violations result with 200 OK response", func() {
bodyAttrs := make(map[string]string)
bodyAttrs["categories"] = " dATa pROtECtION, IDENTITY and Access Management "

serverUtils.MakeFileScanRequest(awsAmiIacFilePath, requestURL, bodyAttrs, http.StatusOK)
})
})
})

Context("resource is skipped", func() {
resourceSkipIacRelPath := filepath.Join(iacRootRelPath, "resource_skipping")

Expand Down
26 changes: 26 additions & 0 deletions test/e2e/server/server_remote_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,19 @@ var _ = Describe("Server Remote Scan", func() {
})
})

When("category value is invalid", func() {
It("should receive a 400 bad request response", func() {
errMessage := "json: cannot unmarshal number into Go struct field scanRemoteRepoReq.categories of type []string"
bodyAttrs := make(map[string]interface{})
bodyAttrs["remote_type"] = "git"
bodyAttrs["remote_url"] = awsAmiRepoURL
bodyAttrs["categories"] = 4

responseBytes := serverUtils.MakeRemoteScanRequest(requestURL, bodyAttrs, http.StatusBadRequest)
Expect(string(bytes.TrimSpace(responseBytes))).To(Equal(errMessage))
})
})

When("scan_rules value is invalid", func() {
It("should receive a 400 bad request response", func() {
errMessage := "json: cannot unmarshal string into Go struct field scanRemoteRepoReq.scan_rules of type []string"
Expand Down Expand Up @@ -400,6 +413,19 @@ var _ = Describe("Server Remote Scan", func() {
})
})

When("categories are used", func() {
When("categories are valid", func() {
It("should receive violations result with 200 OK response", func() {
bodyAttrs := make(map[string]interface{})
bodyAttrs["remote_type"] = "git"
bodyAttrs["remote_url"] = remoteRepoURL
bodyAttrs["categories"] = []string{"DATA PROTECTION", "compliance validation"}

serverUtils.MakeRemoteScanRequest(requestURL, bodyAttrs, http.StatusOK)
})
})
})

Context("resource is skipped", func() {

resourceSkipGoldenRelPath := filepath.Join(goldenFilesRelPath, "resource_skipping")
Expand Down

0 comments on commit 9f22238

Please sign in to comment.