removed ruleWithKSOpaDependency function along with tests

Signed-off-by: cbrom <kb.cbrom@gmail.com>
This commit is contained in:
cbrom
2023-11-22 11:24:44 +03:00
parent 7eb97fcba0
commit d45c97cef0
2 changed files with 1 additions and 45 deletions
+1 -14
View File
@@ -3,7 +3,6 @@ package cautils
import (
"golang.org/x/mod/semver"
"github.com/armosec/utils-go/boolutils"
"github.com/kubescape/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling/apis"
)
@@ -33,7 +32,7 @@ func (policies *Policies) Set(frameworks []reporthandling.Framework, version str
}
}
if !ruleWithKSOpaDependency(frameworks[i].Controls[j].Rules[r].Attributes) && isRuleKubescapeVersionCompatible(frameworks[i].Controls[j].Rules[r].Attributes, version) && isControlFitToScanScope(frameworks[i].Controls[j], scanningScope) {
if isRuleKubescapeVersionCompatible(frameworks[i].Controls[j].Rules[r].Attributes, version) && isControlFitToScanScope(frameworks[i].Controls[j], scanningScope) {
compatibleRules = append(compatibleRules, frameworks[i].Controls[j].Rules[r])
}
}
@@ -55,18 +54,6 @@ func (policies *Policies) Set(frameworks []reporthandling.Framework, version str
}
}
func ruleWithKSOpaDependency(attributes map[string]interface{}) bool {
if attributes == nil {
return false
}
if val, ok := attributes["armoOpa"]; ok { // TODO - make global
if s, ok := val.(string); ok {
return boolutils.StringToBool(s)
}
}
return false
}
// Checks that kubescape version is in range of use for this rule
// In local build (BuildNumber = ""):
// returns true only if rule doesn't have the "until" attribute
@@ -9,37 +9,6 @@ import (
"github.com/stretchr/testify/assert"
)
func TestRuleWithKSOpaDependency(t *testing.T) {
t.Run("return false when attributes is nil", func(t *testing.T) {
result := ruleWithKSOpaDependency(nil)
assert.False(t, result)
})
t.Run("returns false when attributes does not contain armoOpa key", func(t *testing.T) {
attributes := map[string]interface{}{
"key": "value",
}
result := ruleWithKSOpaDependency(attributes)
assert.False(t, result)
})
t.Run("returns false when attributes contain armoOpa key with non bool value", func(t *testing.T) {
attributes := map[string]interface{}{
"armoOpa": true,
}
result := ruleWithKSOpaDependency(attributes)
assert.False(t, result)
})
t.Run("returns true when attributes contain armoOpa key with value true", func(t *testing.T) {
attributes := map[string]interface{}{
"armoOpa": "true",
}
result := ruleWithKSOpaDependency(attributes)
assert.True(t, result)
})
}
func TestIsScanningScopeMatchToControlScope(t *testing.T) {
tests := []struct {
scanScope reporthandling.ScanningScopeType