Skip to content

Commit

Permalink
Merge pull request #143 from kubescape/remvoe-armoBuiltin
Browse files Browse the repository at this point in the history
Update datastructuresmethods_test.go
  • Loading branch information
yuleib authored Nov 27, 2023
2 parents 83db3f4 + 899d7f5 commit 90813d5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions reporthandling/datastructuresmethods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,28 @@ func TestListResourcesIDs(t *testing.T) {
}

func TestControl_GetAttackTrackCategories(t *testing.T) {
validControlJson := `{"name":"TEST","attributes":{"armoBuiltin":true,"controlTypeTags":["security","compliance"],"attackTracks":[{"attackTrack": "container","categories": ["Execution","Initial access"]}]},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
validControlJson := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"],"attackTracks":[{"attackTrack": "container","categories": ["Execution","Initial access"]}]},"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(validControlJson), &validControl)
assert.NoError(t, err, err)
assert.Equal(t, []string{"Execution", "Initial access"}, validControl.GetAttackTrackCategories("container"))
assert.Equal(t, []string{}, validControl.GetAttackTrackCategories("test"))

invalidControlJson1 := `{"name":"TEST","attributes":{"armoBuiltin":true,"controlTypeTags":["security","compliance"],"attackTracks":{"container": "x"}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
invalidControlJson1 := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"],"attackTracks":{"container": "x"}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
var invalidControl1 Control
err = json.Unmarshal([]byte(invalidControlJson1), &invalidControl1)
assert.NoError(t, err, err)
assert.Equal(t, []string{}, invalidControl1.GetAttackTrackCategories("container"))

invalidControlJson2 := `{"name":"TEST","attributes":{"armoBuiltin":true,"controlTypeTags":["security","compliance"],"attack":{"container": "x"}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
invalidControlJson2 := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"],"attack":{"container": "x"}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
var invalidControl2 Control
err = json.Unmarshal([]byte(invalidControlJson2), &invalidControl2)
assert.NoError(t, err, err)
assert.Equal(t, []string{}, invalidControl2.GetAttackTrackCategories("container"))
}

func TestControl_GetAllAttackTracks(t *testing.T) {
validControlJson := `{"name":"TEST","attributes":{"armoBuiltin":true,"controlTypeTags":["security","compliance"],"attackTracks":[{"attackTrack": "container","categories": ["Execution","Initial access"]},{"attackTrack": "network","categories": ["Eavesdropping","Spoofing"]}]},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
validControlJson := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"],"attackTracks":[{"attackTrack": "container","categories": ["Execution","Initial access"]},{"attackTrack": "network","categories": ["Eavesdropping","Spoofing"]}]},"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(validControlJson), &validControl)
assert.NoError(t, err)
Expand All @@ -152,41 +152,41 @@ func TestControl_GetAllAttackTracks(t *testing.T) {
}
assert.ElementsMatch(t, expectedTracks, validControl.GetAllAttackTrackCategories())

invalidControlJson1 := `{"name":"TEST","attributes":{"armoBuiltin":true,"controlTypeTags":["security","compliance"],"attackTracks":{"container": "x"}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
invalidControlJson1 := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"],"attackTracks":{"container": "x"}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
var invalidControl1 Control
err = json.Unmarshal([]byte(invalidControlJson1), &invalidControl1)
assert.NoError(t, err)
assert.Nil(t, invalidControl1.GetAllAttackTrackCategories())

invalidControlJson2 := `{"name":"TEST","attributes":{"armoBuiltin":true,"controlTypeTags":["security","compliance"],"attack":{"container": "x"}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
invalidControlJson2 := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"],"attack":{"container": "x"}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
var invalidControl2 Control
err = json.Unmarshal([]byte(invalidControlJson2), &invalidControl2)
assert.NoError(t, err)
assert.Nil(t, invalidControl2.GetAllAttackTrackCategories())

// Case: control that has no "attackTracks" field
missingAttackTrackJson := `{"name":"TEST","attributes":{"armoBuiltin":true,"controlTypeTags":["security","compliance"]},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
missingAttackTrackJson := `{"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 missingAttackTrackControl Control
err = json.Unmarshal([]byte(missingAttackTrackJson), &missingAttackTrackControl)
assert.NoError(t, err)
assert.Nil(t, missingAttackTrackControl.GetAllAttackTrackCategories())

// Case: control that has "attackTracks" but it's an empty list
emptyAttackTrackJson := `{"name":"TEST","attributes":{"armoBuiltin":true,"controlTypeTags":["security","compliance"],"attackTracks":[]},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
emptyAttackTrackJson := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"],"attackTracks":[]},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
var emptyAttackTrackControl Control
err = json.Unmarshal([]byte(emptyAttackTrackJson), &emptyAttackTrackControl)
assert.NoError(t, err)
assert.Nil(t, emptyAttackTrackControl.GetAllAttackTrackCategories())
}

func TestControl_GetControlTypeTags(t *testing.T) {
validControlJson := `{"name":"TEST","attributes":{"armoBuiltin":true,"controlTypeTags":["security","compliance"],"attackTracks":{"container":["Privilege escalation"]}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
validControlJson := `{"name":"TEST","attributes":{"controlTypeTags":["security","compliance"],"attackTracks":{"container":["Privilege escalation"]}},"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(validControlJson), &validControl)
assert.NoError(t, err, err)
assert.Equal(t, []string{"security", "compliance"}, validControl.GetControlTypeTags())

missingAttributeControlJson := `{"name":"TEST","attributes":{"armoBuiltin":true,"attackTracks":{"container": "x"}},"description":"","remediation":"","rulesNames":["CVE-2022-0185"],"id":"C-0079","long_description":"","test":"","controlID":"C-0079","baseScore":4,"example":""}`
missingAttributeControlJson := `{"name":"TEST","attributes":{"attackTracks":{"container": "x"}},"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)
Expand Down

0 comments on commit 90813d5

Please sign in to comment.