Skip to content

Commit 03ebc7f

Browse files
🐛 fix aqua nonetype error #10585 (#10594)
1 parent 9a41075 commit 03ebc7f

3 files changed

Lines changed: 136 additions & 2 deletions

File tree

dojo/tools/aqua/parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def get_items(self, tree, test):
2424

2525
for node in vulnerabilityTree:
2626
resource = node.get("resource")
27-
vulnerabilities = node.get("vulnerabilities")
28-
27+
vulnerabilities = node.get("vulnerabilities", [])
28+
if vulnerabilities is None:
29+
vulnerabilities = []
2930
for vuln in vulnerabilities:
3031
item = get_item(resource, vuln, test)
3132
unique_key = resource.get("cpe") + vuln.get("name", "None")
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"image": "your_image:latest",
3+
"scan_started": {
4+
"seconds": 1567784942,
5+
"nanos": 28041437
6+
},
7+
"scan_duration": 25,
8+
"image_size": 565733981,
9+
"digest": "54bc57e4e876533bc61ba7bf229f0f9f96d137b787614c3d0d5c70c3578fe867",
10+
"os": "alpine",
11+
"version": "3.9.4",
12+
"resources": [
13+
{
14+
"resource": {
15+
"format": "apk",
16+
"name": "musl",
17+
"version": "1.1.20-r4",
18+
"arch": "x86_64",
19+
"cpe": "pkg:/alpine:3.9.4:musl:1.1.20-r4",
20+
"license": "MIT"
21+
},
22+
"scanned": true,
23+
"vulnerabilities": null
24+
}
25+
],
26+
"image_assurance_results": {
27+
"disallowed": true,
28+
"audit_required": true,
29+
"policy_failures": [
30+
{
31+
"policy_id": 1,
32+
"policy_name": "Default",
33+
"blocking": true,
34+
"controls": [
35+
"max_severity"
36+
]
37+
},
38+
{
39+
"policy_id": 6,
40+
"policy_name": "Assurance_policy",
41+
"blocking": true,
42+
"controls": [
43+
"max_score"
44+
]
45+
}
46+
],
47+
"checks_performed": [
48+
{
49+
"failed": true,
50+
"policy_id": 1,
51+
"policy_name": "Default",
52+
"control": "max_severity",
53+
"maximum_severity_allowed": "high",
54+
"maximum_severity_found": "high",
55+
"maximum_fixable_severity_found": "high",
56+
"no_fix_excluded": true
57+
},
58+
{
59+
"policy_id": 1,
60+
"policy_name": "Default",
61+
"control": "malware"
62+
},
63+
{
64+
"policy_id": 1,
65+
"policy_name": "Default",
66+
"control": "sensitive_data"
67+
},
68+
{
69+
"policy_id": 1,
70+
"policy_name": "Default",
71+
"control": "root_user"
72+
},
73+
{
74+
"failed": true,
75+
"policy_id": 6,
76+
"policy_name": "Assurance_policy",
77+
"control": "max_score",
78+
"maximum_score_allowed": 7,
79+
"maximum_score_found": 7.5,
80+
"maximum_fixable_score_found": 7.5,
81+
"no_fix_excluded": true
82+
},
83+
{
84+
"policy_id": 6,
85+
"policy_name": "Assurance_policy",
86+
"control": "malware"
87+
},
88+
{
89+
"policy_id": 6,
90+
"policy_name": "Assurance_policy",
91+
"control": "sensitive_data"
92+
},
93+
{
94+
"policy_id": 6,
95+
"policy_name": "Assurance_policy",
96+
"control": "root_user"
97+
}
98+
],
99+
"block_required": true
100+
},
101+
"vulnerability_summary": {
102+
"total": 24,
103+
"high": 5,
104+
"medium": 18,
105+
"low": 1,
106+
"negligible": 0,
107+
"sensitive": 0,
108+
"malware": 0,
109+
"score_average": 5.454168,
110+
"max_score": 7.5,
111+
"max_fixable_score": 7.5,
112+
"max_fixable_severity": "high"
113+
},
114+
"scan_options": {
115+
"scan_sensitive_data": true,
116+
"scan_malware": true,
117+
"scan_timeout": 3600000000000,
118+
"manual_pull_fallback": true,
119+
"save_adhoc_scans": true
120+
},
121+
"initiating_user": "chk",
122+
"data_date": 1567724137,
123+
"pull_name": "your_image:latest",
124+
"changed_result": false,
125+
"required_image_platform": "amd64:::",
126+
"scanned_image_platform": "amd64::linux:"
127+
}

unittests/tools/test_aqua_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ def test_aqua_parser_for_aqua_severity(self):
9292
self.assertEqual(2, d['Medium'])
9393
self.assertEqual(2, d['Low'])
9494
self.assertEqual(7, d['Info'])
95+
96+
def test_aqua_parser_issue_10585(self):
97+
with open("unittests/scans/aqua/issue_10585.json") as testfile:
98+
parser = AquaParser()
99+
findings = parser.get_findings(testfile, Test())
100+
self.assertEqual(0, len(findings))

0 commit comments

Comments
 (0)