forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Checkmarx#4468 from Checkmarx/tests/e2e-negative-t…
…ests feat(e2e): added negative tests for queries-path
- Loading branch information
Showing
10 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...es/queries/invalid/invalid_metadata/terraform/athena_database_not_encrypted/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "b2315cae-b110-4426-81e0-80bb8640cddZ" | ||
"queryName": "Athena Database Not Encrypted" | ||
"severity": "high" | ||
"category": "Encryption", | ||
"descriptionText": "AWS Athena Database data in S3 should be encrypted", | ||
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/athena_database#encryption_configuration", | ||
"platform": "Terraform", | ||
"descriptionID": "c90feea8" | ||
} |
16 changes: 16 additions & 0 deletions
16
...mples/queries/invalid/invalid_metadata/terraform/athena_database_not_encrypted/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
|
||
CxPolicy[result] { | ||
resource := input.document[i].resource.aws_athena_database[name] | ||
not common_lib.valid_key(resource, "encryption_configuration") | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("aws_athena_database[{{%s}}]", [name]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": sprintf("aws_athena_database[{{%s}}] encryption_configuration is defined", [name]), | ||
"keyActualValue": sprintf("aws_athena_database[{{%s}}] encryption_configuration is missing", [name]), | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...mples/queries/invalid/missing_metadata/terraform/athena_database_not_encrypted/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
|
||
CxPolicy[result] { | ||
resource := input.document[i].resource.aws_athena_database[name] | ||
not common_lib.valid_key(resource, "encryption_configuration") | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("aws_athena_database[{{%s}}]", [name]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": sprintf("aws_athena_database[{{%s}}] encryption_configuration is defined", [name]), | ||
"keyActualValue": sprintf("aws_athena_database[{{%s}}] encryption_configuration is missing", [name]), | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../samples/queries/valid/single_query/terraform/athena_database_not_encrypted/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "b2315cae-b110-4426-81e0-80bb8640cddZ", | ||
"queryName": "Athena Database Not Encrypted", | ||
"severity": "high", | ||
"category": "Encryption", | ||
"descriptionText": "AWS Athena Database data in S3 should be encrypted", | ||
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/athena_database#encryption_configuration", | ||
"platform": "Terraform", | ||
"descriptionID": "c90feea8" | ||
} |
16 changes: 16 additions & 0 deletions
16
...res/samples/queries/valid/single_query/terraform/athena_database_not_encrypted/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
|
||
CxPolicy[result] { | ||
resource := input.document[i].resource.aws_athena_database[name] | ||
not common_lib.valid_key(resource, "encryption_configuration") | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("aws_athena_database[{{%s}}]", [name]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": sprintf("aws_athena_database[{{%s}}] encryption_configuration is defined", [name]), | ||
"keyActualValue": sprintf("aws_athena_database[{{%s}}] encryption_configuration is missing", [name]), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package testcases | ||
|
||
// E2E-CLI-051 - Kics scan command with --queries-path | ||
// should load and execute queries found in the provided path | ||
func init() { //nolint | ||
testSample := TestCase{ | ||
Name: "should load and execute queries from a custom path [E2E-CLI-051]", | ||
Args: args{ | ||
Args: []cmdArgs{ | ||
[]string{"scan", "--queries-path", "fixtures/samples/queries/valid/single_query", "-p", "fixtures/samples/bom-positive.tf"}, | ||
[]string{"scan", "--queries-path", "fixtures/samples/queries/invalid/invalid_metadata", "-p", "fixtures/samples/bom-positive.tf"}, | ||
[]string{"scan", "--queries-path", "fixtures/samples/queries/invalid/missing_metadata", "-p", "fixtures/samples/bom-positive.tf"}, | ||
[]string{"scan", "--queries-path", "fixtures/samples/invalid_path", "-p", "fixtures/samples/bom-positive.tf"}, | ||
}, | ||
}, | ||
WantStatus: []int{50, 0, 0, 126}, | ||
} | ||
|
||
Tests = append(Tests, testSample) | ||
} |