Skip to content

Commit

Permalink
fixed EqualFold check
Browse files Browse the repository at this point in the history
  • Loading branch information
dwertent committed Nov 14, 2021
1 parent ad86591 commit 3b7a257
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions exceptions/exceptionprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ func ListRuleExceptions(exceptionPolicies []armotypes.PostureExceptionPolicy, fr

func ruleHasExceptions(exceptionPolicy *armotypes.PostureExceptionPolicy, frameworkName, controlName, controlID, ruleName string) bool {
for _, posturePolicy := range exceptionPolicy.PosturePolicies {
if posturePolicy.FrameworkName == "" && posturePolicy.ControlName == "" && posturePolicy.RuleName == "" {
if posturePolicy.FrameworkName == "" && posturePolicy.ControlName == "" && posturePolicy.ControlID == "" && posturePolicy.RuleName == "" {
continue // empty policy -> ignore
}
if posturePolicy.FrameworkName != "" && strings.EqualFold(posturePolicy.FrameworkName, frameworkName) {
if posturePolicy.FrameworkName != "" && !strings.EqualFold(posturePolicy.FrameworkName, frameworkName) {
continue // policy does not match
}
if posturePolicy.ControlName != "" && strings.EqualFold(posturePolicy.ControlName, controlName) {
if posturePolicy.ControlName != "" && !strings.EqualFold(posturePolicy.ControlName, controlName) {
continue // policy does not match
}
if posturePolicy.ControlID != "" && strings.EqualFold(posturePolicy.ControlID, controlID) {
if posturePolicy.ControlID != "" && !strings.EqualFold(posturePolicy.ControlID, controlID) {
continue // policy does not match
}
if posturePolicy.RuleName != "" && strings.EqualFold(posturePolicy.RuleName, ruleName) {
if posturePolicy.RuleName != "" && !strings.EqualFold(posturePolicy.RuleName, ruleName) {
continue // policy does not match
}
return true // policies match
Expand Down
5 changes: 2 additions & 3 deletions exceptions/exceptionprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ func PostureExceptionPolicyAlertOnlyMock() *armotypes.PostureExceptionPolicy {
func TestListRuleExceptions(t *testing.T) {
exceptionPolicies := []armotypes.PostureExceptionPolicy{*PostureExceptionPolicyAlertOnlyMock()}
res1 := ListRuleExceptions(exceptionPolicies, "MITRE", "", "", "")
assert.Equal(t, len(res1), 1)
if len(res1) != 1 {
t.Errorf("expecting 1 exception")
}
res2 := ListRuleExceptions(exceptionPolicies, "", "hostPath mount", "", "")
if len(res2) != 0 {
t.Errorf("expecting 0 exception")
}
assert.Equal(t, len(res2), 0)
}

func TestRegexCompare(t *testing.T) {
Expand Down

0 comments on commit 3b7a257

Please sign in to comment.