Skip to content

Commit

Permalink
fix unit tests and some more rego linting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturRibeiro-CX committed Nov 15, 2024
1 parent 37edee3 commit 6d2d354
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ CxPolicy[result] {
}
}

issueType(str) = "MissingAttribute" {
str == ""
} else = "IncorrectValue"
issueType(str) = issueType {
issueType = "MissingAttribute"
str == ""
} else = issueType {
issueType = "IncorrectValue"
}

checkAllowPass(pwPolicy) = ".allow_pw_change" {
ansLib.isAnsibleFalse(pwPolicy.allow_pw_change)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CxPolicy[result] {
issueType("") = "MissingAttribute"

issueType(str) = "IncorrectValue" {
str != ""
str != ""
}

checkPwReusePrevent(pwPolicy) = ".password_reuse_prevent" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import future.keywords.in

CxPolicy[result] {
cats := ["StorageRead", "StorageWrite", "StorageDelete"]

some doc in input.document
[path, value] = walk(doc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ CxPolicy[result] {
}
}

isResFalse("false") = true
isResFalse("false") = true

isResFalse(false) = true
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ CxPolicy[result] {
}
}

isFalse(false) = true
isFalse(false) = true

isFalse("false") = true
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ CxPolicy[result] {

isResFalse("false") = true

isResFalse(false) = true
isResFalse(false) = true
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ CxPolicy[result] {
}
}

isResFalse("false") = true
isResFalse("false") = true

isResFalse(false) = true
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CxPolicy[result] {
}
}

isAttrTrue("true") = true
isAttrTrue("true") = true

isAttrTrue(true) = true

Expand Down
6 changes: 2 additions & 4 deletions assets/queries/dockerfile/update_instruction_alone/query.rego
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CxPolicy[result] {
install := [x | x := getDetail(commandRefactor, pkg_installer[packageManager][_]); count(x) > 0]
count(install) == 0

#Check if any of the next commands is RUN install Command and there is not Update Command
# Check if any of the next commands is RUN install Command and there is not Update Command
nextResources := array.slice(doc.command[name], n + 1, count(doc.command[name]))
nextResource := nextResources[_]
nextCommandRefactor := getRunCommand(nextResource)
Expand Down Expand Up @@ -110,9 +110,7 @@ getRunCommand(resource) = commandRefactor {
commandRefactor := [x | x := commandList[_]; x != ""]
}

getDetail(commandRefactor, value) = list {
list := [u | commandRefactor[u] == value]
}
getDetail(commandRefactor, value) := [u | commandRefactor[u] == value]

checkFollowedBy(first, after) {
first[_] < after[_]
Expand Down
9 changes: 5 additions & 4 deletions assets/queries/k8s/missing_app_armor_config/query.rego
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package Cx

import data.generic.common as common_lib
import data.generic.k8s as k8sLib
import future.keywords.in

types := {"initContainers", "containers"}

Expand All @@ -17,14 +18,14 @@ getMetadataInfo(document) = metadataInfo {
metadataInfo := {"metadata": metadata, "path": ""}
}

isValidAppArmorProfile("runtime/default") = true

isValidAppArmorProfile(profile) {
profile == "runtime/default"
} else {
startswith(profile, "localhost/")
}

CxPolicy[result] {
document := input.document[i]
some document in input.document
metadata := document.metadata

specInfo := k8sLib.getSpecInfo(document)
Expand All @@ -49,7 +50,7 @@ CxPolicy[result] {
}

CxPolicy[result] {
document := input.document[i]
some document in input.document
metadata := document.metadata

specInfo := k8sLib.getSpecInfo(document)
Expand Down
4 changes: 2 additions & 2 deletions assets/queries/openAPI/general/paths_object_empty/query.rego
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CxPolicy[result] {

# In yaml an empty object is parsed into null
check_paths_object(paths) {

Check failure on line 27 in assets/queries/openAPI/general/paths_object_empty/query.rego

View workflow job for this annotation

GitHub Actions / Run Regal Linter on Rego Files

Prefer pattern matching in function arguments. To learn more, see: https://docs.styra.com/regal/rules/idiomatic/equals-pattern-matching
paths == null
paths == null
} else {
count(paths) == 0
count(paths) == 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package Cx

import data.generic.common as common_lib
import data.generic.openapi as openapi_lib
import future.keywords.in

specificKeywords := {
"numeric": ["multipleOf", "maximum", "minimum", "exclusiveMaximum", "exclusiveMinimum"],
Expand All @@ -11,7 +12,7 @@ specificKeywords := {
}

CxPolicy[result] {
doc := input.document[i]
some doc in input.document
version := openapi_lib.check_openapi(doc)
version != "undefined"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ CxPolicy[result] {
}

exist(obj, key) {

Check failure on line 64 in assets/queries/terraform/aws/docdb_logging_disabled/query.rego

View workflow job for this annotation

GitHub Actions / Run Regal Linter on Rego Files

Custom function may be replaced by `in` and `object.keys`. To learn more, see: https://docs.styra.com/regal/rules/idiomatic/custom-has-key-construct
key in obj
_ = obj[key]
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ CxPolicy[result] {
}

has_key(obj, key) {

Check failure on line 67 in assets/queries/terraform/aws/mq_broker_logging_disabled/query.rego

View workflow job for this annotation

GitHub Actions / Run Regal Linter on Rego Files

Custom function may be replaced by `in` and `object.keys`. To learn more, see: https://docs.styra.com/regal/rules/idiomatic/custom-has-key-construct
key in obj
_ = obj[key]
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package Cx

import data.generic.terraform as tf_lib
import future.keywords.in

CxPolicy[result] {
msk_cluster := input.document[i].resource.aws_msk_cluster[name]
some doc in input.document
msk_cluster := doc.resource.aws_msk_cluster[name]
problems := checkEncryption(msk_cluster)
problems != "none"

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": "aws_msk_cluster",
"resourceName": tf_lib.get_specific_resource_name(msk_cluster, "aws_msk_cluster", name),
"searchKey": getSearchKey(problems, name),
Expand Down Expand Up @@ -42,6 +44,9 @@ getSearchKey(problems, name) = str {
str := concat("", [defaultSearchValue, problems])
}

getIssueType(problems) = "MissingAttribute" {
getIssueType(problems) = issueType {
issueType = "MissingAttribute"
problems == ""
} else = "IncorrectValue"
} else = issueType {
issueType = "IncorrectValue"
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ CxPolicy[result] {
}

exist(obj, key) {

Check failure on line 63 in assets/queries/terraform/aws/neptune_logging_disabled/query.rego

View workflow job for this annotation

GitHub Actions / Run Regal Linter on Rego Files

Custom function may be replaced by `in` and `object.keys`. To learn more, see: https://docs.styra.com/regal/rules/idiomatic/custom-has-key-construct
key in obj
_ = obj[key]
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ aclsDefaultActionAllow(network_rules) = reason {
}

has_key(x, k) {
some k in x
k in x
}

0 comments on commit 6d2d354

Please sign in to comment.