Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add func IsFixedByNetworkPolicy #151

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion reporthandling/datastructuresmethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
"golang.org/x/exp/slices"
)

const ActionRequiredAttribute string = "actionRequired"
const (
ActionRequiredAttribute string = "actionRequired"
ControlAttributeKeyIsFixedByNetworkPolicy string = "isFixedByNetworkPolicy"
)

// ==============================================================================================
// ========================== PostureReport =====================================================
Expand Down Expand Up @@ -443,6 +446,19 @@ func (control *Control) GetControlTypeTags() []string {
return []string{}
}

// returns true if control has attribute "isFixedByNetworkPolicy" and its value is true
func (control *Control) IsFixedByNetworkPolicy() bool {
if control.Attributes == nil {
return false
}
if v, exist := control.Attributes[ControlAttributeKeyIsFixedByNetworkPolicy]; exist {
if isFixedByNetworkPolicy, ok := v.(bool); ok {
return isFixedByNetworkPolicy
}
}
return false
}

func (control *Control) SupportSmartRemediation() bool {
typeTags := control.GetControlTypeTags()
return slices.Contains(typeTags, v1alpha1.ControlTypeTagSmartRemediation)
Expand Down
19 changes: 19 additions & 0 deletions reporthandling/datastructuresmethods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,22 @@ func TestControl_GetControlTypeTags(t *testing.T) {
assert.NoError(t, err, err)
assert.Equal(t, []string{}, missingAttributeControl.GetControlTypeTags())
}

func TestControl_IsFixedByNetworkPolicy(t *testing.T) {
validControlJsonNoAttributes := `{"name":"TEST","description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
var validControl Control
err := json.Unmarshal([]byte(validControlJsonNoAttributes), &validControl)
assert.NoError(t, err, err)
assert.False(t, validControl.IsFixedByNetworkPolicy())

validControlJson := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"],"isFixedByNetworkPolicy":true, "attackTracks":[{"attackTrack": "network","categories": ["Eavesdropping","Spoofing"]}]},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
err = json.Unmarshal([]byte(validControlJson), &validControl)
assert.NoError(t, err, err)
assert.True(t, validControl.IsFixedByNetworkPolicy())

missingAttributeControlJson := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"]},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
var missingAttributeControl Control
err = json.Unmarshal([]byte(missingAttributeControlJson), &missingAttributeControl)
assert.NoError(t, err, err)
assert.False(t, missingAttributeControl.IsFixedByNetworkPolicy())
}
Loading