Skip to content

Commit

Permalink
And add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
hblankenship committed Nov 15, 2024
1 parent ceb1af7 commit 7bc0bfe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"detail": [
{
"description": "CRITICAL User root found as effective user, which is not on the allowed list",
"gate": "dockerfile",
"imageId": "d26f0119b9634091a541b081dd8bdca435ab52e114e4b4328575c0bc2c69768b",
"policyId": "RootUser",
"status": "warn",
"tag": "test/testimage:testtag",
"triggerId": "b2605c2ddbdb02b8e2365c9248dada5a",
"triggerName": "effective_user"
}
],
"digest": "sha256:8htz0bf942cfcd6hg8cf6435afd318b65d23e4c1a80044304c6e3ed20",
"finalAction": "stop",
"finalActionReason": "policy_evaluation",
"lastEvaluation": "2022-09-20T08:25:52Z",
"policyId": "9e104ade-7b57-4cdc-93fb-4949bf3b36b6",
"status": "fail",
"tag": "test/testimage:testtag"
}
]
10 changes: 10 additions & 0 deletions unittests/tools/test_anchorectl_policies_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ def test_anchore_engine_parser_has_many_findings(self):
parser = AnchoreCTLPoliciesParser()
findings = parser.get_findings(testfile, Test())
self.assertEqual(3, len(findings))

def test_anchore_engine_parser_has_one_finding_and_description_has_severity(self):
with open("unittests/scans/anchorectl_policies/one_violation_description_severity.json", encoding="utf-8") as testfile:
parser = AnchoreCTLPoliciesParser()
findings = parser.get_findings(testfile, Test())
self.assertEqual(1, len(findings))
singleFinding = findings[0]
self.assertEqual(singleFinding.severity, "Critical")
self.assertEqual(singleFinding.title, "RootUser - gate|dockerfile - trigger|b2605c2ddbdb02b8e2365c9248dada5a")
self.assertEqual(singleFinding.description, "CRITICAL User root found as effective user, which is not on the allowed list")

Check failure on line 37 in unittests/tools/test_anchorectl_policies_parser.py

View workflow job for this annotation

GitHub Actions / ruff-linting

Ruff (W292)

unittests/tools/test_anchorectl_policies_parser.py:37:136: W292 No newline at end of file

Check failure on line 37 in unittests/tools/test_anchorectl_policies_parser.py

View workflow job for this annotation

GitHub Actions / ruff-linting

Ruff (W292)

unittests/tools/test_anchorectl_policies_parser.py:37:136: W292 No newline at end of file

0 comments on commit 7bc0bfe

Please sign in to comment.