Skip to content

Commit

Permalink
unit test for "searchValue" property in query result Checkmarx#1846 (C…
Browse files Browse the repository at this point in the history
…heckmarx#1847)

Signed-off-by: Rogério Peixoto <[email protected]>
  • Loading branch information
rogeriopeixotocx authored Jan 29, 2021
1 parent 32a57f3 commit d6f25fc
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion test/queries_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ var (
"keyActualValue",
}

searchValueAllowedQueriesPath = []string{
"../assets/queries/ansible/azure/sensitive_port_is_exposed_to_entire_network",
"../assets/queries/cloudFormation/ec2_sensitive_port_is_publicly_exposed",
"../assets/queries/cloudFormation/elb_sensitive_port_is_exposed_to_entire_network",
"../assets/queries/terraform/aws/sensitive_port_is_exposed_to_entire_network",
"../assets/queries/terraform/aws/sensitive_port_is_exposed_to_small_public_network",
"../assets/queries/terraform/azure/sensitive_port_is_exposed_to_entire_network",
"../assets/queries/terraform/azure/sensitive_port_is_exposed_to_small_public_network",
}

searchValueProperty = "searchValue"

requiredQueryMetadataProperties = map[string]func(tb testing.TB, value interface{}, metadataPath string){
"id": func(tb testing.TB, value interface{}, metadataPath string) {
idValue := testMetadataFieldStringType(tb, value, "id", metadataPath)
Expand Down Expand Up @@ -152,12 +164,28 @@ func testQueryHasGoodReturnParams(t *testing.T, entry queryEntry) {
for _, requiredProperty := range requiredQueryResultProperties {
_, ok := m[requiredProperty]
require.True(t, ok, fmt.Sprintf(
"query '%s' doesn't include paramert '%s' in response",
"query '%s' doesn't include parameter '%s' in response",
path.Base(entry.dir),
requiredProperty,
))
}

if sliceContains(searchValueAllowedQueriesPath, entry.dir) {
_, ok := m[searchValueProperty]
require.True(t, ok, fmt.Sprintf(
"query '%s' doesn't include parameter '%s' in response",
path.Base(entry.dir),
searchValueProperty,
))
} else {
_, ok := m[searchValueProperty]
require.False(t, ok, fmt.Sprintf(
"query '%s' should not include parameter '%s' in response",
path.Base(entry.dir),
searchValueProperty,
))
}

return model.Vulnerability{}, nil
},
trk,
Expand Down

0 comments on commit d6f25fc

Please sign in to comment.