Skip to content

Commit 8b99c6d

Browse files
committed
Add tests for istio improver
Signed-off-by: Tushar Goel <[email protected]>
1 parent 89342e5 commit 8b99c6d

File tree

2 files changed

+333
-0
lines changed

2 files changed

+333
-0
lines changed
Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
[
2+
{
3+
"vulnerability_id": null,
4+
"aliases": [
5+
"CVE-2019-12243"
6+
],
7+
"confidence": 100,
8+
"summary": "Incorrect access control.",
9+
"affected_purls": [
10+
{
11+
"type": "golang",
12+
"namespace": "istio.io",
13+
"name": "istio",
14+
"version": "1.1.0",
15+
"qualifiers": null,
16+
"subpath": null
17+
},
18+
{
19+
"type": "golang",
20+
"namespace": "istio.io",
21+
"name": "istio",
22+
"version": "1.1.1",
23+
"qualifiers": null,
24+
"subpath": null
25+
},
26+
{
27+
"type": "golang",
28+
"namespace": "istio.io",
29+
"name": "istio",
30+
"version": "1.1.2",
31+
"qualifiers": null,
32+
"subpath": null
33+
},
34+
{
35+
"type": "golang",
36+
"namespace": "istio.io",
37+
"name": "istio",
38+
"version": "1.1.3",
39+
"qualifiers": null,
40+
"subpath": null
41+
},
42+
{
43+
"type": "golang",
44+
"namespace": "istio.io",
45+
"name": "istio",
46+
"version": "1.1.4",
47+
"qualifiers": null,
48+
"subpath": null
49+
},
50+
{
51+
"type": "golang",
52+
"namespace": "istio.io",
53+
"name": "istio",
54+
"version": "1.1.5",
55+
"qualifiers": null,
56+
"subpath": null
57+
},
58+
{
59+
"type": "golang",
60+
"namespace": "istio.io",
61+
"name": "istio",
62+
"version": "1.1.6",
63+
"qualifiers": null,
64+
"subpath": null
65+
},
66+
{
67+
"type": "golang",
68+
"namespace": "istio.io",
69+
"name": "istio",
70+
"version": "1.1.7",
71+
"qualifiers": null,
72+
"subpath": null
73+
},
74+
{
75+
"type": "golang",
76+
"namespace": "istio.io",
77+
"name": "istio",
78+
"version": "1.1.8",
79+
"qualifiers": null,
80+
"subpath": null
81+
}
82+
],
83+
"fixed_purl": null,
84+
"references": [
85+
{
86+
"reference_id": "ISTIO-SECURITY-2019-001",
87+
"url": "https://istio.io/latest/news/security/ISTIO-SECURITY-2019-001/",
88+
"severities": []
89+
}
90+
],
91+
"weaknesses": []
92+
},
93+
{
94+
"vulnerability_id": null,
95+
"aliases": [
96+
"CVE-2019-12243"
97+
],
98+
"confidence": 100,
99+
"summary": "Incorrect access control.",
100+
"affected_purls": [
101+
{
102+
"type": "github",
103+
"namespace": "istio",
104+
"name": "istio",
105+
"version": "1.1.0",
106+
"qualifiers": null,
107+
"subpath": null
108+
},
109+
{
110+
"type": "github",
111+
"namespace": "istio",
112+
"name": "istio",
113+
"version": "1.1.1",
114+
"qualifiers": null,
115+
"subpath": null
116+
},
117+
{
118+
"type": "github",
119+
"namespace": "istio",
120+
"name": "istio",
121+
"version": "1.1.2",
122+
"qualifiers": null,
123+
"subpath": null
124+
},
125+
{
126+
"type": "github",
127+
"namespace": "istio",
128+
"name": "istio",
129+
"version": "1.1.3",
130+
"qualifiers": null,
131+
"subpath": null
132+
},
133+
{
134+
"type": "github",
135+
"namespace": "istio",
136+
"name": "istio",
137+
"version": "1.1.4",
138+
"qualifiers": null,
139+
"subpath": null
140+
},
141+
{
142+
"type": "github",
143+
"namespace": "istio",
144+
"name": "istio",
145+
"version": "1.1.5",
146+
"qualifiers": null,
147+
"subpath": null
148+
},
149+
{
150+
"type": "github",
151+
"namespace": "istio",
152+
"name": "istio",
153+
"version": "1.1.6",
154+
"qualifiers": null,
155+
"subpath": null
156+
},
157+
{
158+
"type": "github",
159+
"namespace": "istio",
160+
"name": "istio",
161+
"version": "1.1.7",
162+
"qualifiers": null,
163+
"subpath": null
164+
},
165+
{
166+
"type": "github",
167+
"namespace": "istio",
168+
"name": "istio",
169+
"version": "1.1.8",
170+
"qualifiers": null,
171+
"subpath": null
172+
}
173+
],
174+
"fixed_purl": null,
175+
"references": [
176+
{
177+
"reference_id": "ISTIO-SECURITY-2019-001",
178+
"url": "https://istio.io/latest/news/security/ISTIO-SECURITY-2019-001/",
179+
"severities": []
180+
}
181+
],
182+
"weaknesses": []
183+
},
184+
{
185+
"vulnerability_id": null,
186+
"aliases": [
187+
"CVE-2019-12243"
188+
],
189+
"confidence": 100,
190+
"summary": "Incorrect access control.",
191+
"affected_purls": [
192+
{
193+
"type": "golang",
194+
"namespace": "istio.io",
195+
"name": "istio",
196+
"version": "1.1.0",
197+
"qualifiers": null,
198+
"subpath": null
199+
},
200+
{
201+
"type": "golang",
202+
"namespace": "istio.io",
203+
"name": "istio",
204+
"version": "1.1.15",
205+
"qualifiers": null,
206+
"subpath": null
207+
},
208+
{
209+
"type": "golang",
210+
"namespace": "istio.io",
211+
"name": "istio",
212+
"version": "1.3.0",
213+
"qualifiers": null,
214+
"subpath": null
215+
},
216+
{
217+
"type": "golang",
218+
"namespace": "istio.io",
219+
"name": "istio",
220+
"version": "1.3.1",
221+
"qualifiers": null,
222+
"subpath": null
223+
},
224+
{
225+
"type": "golang",
226+
"namespace": "istio.io",
227+
"name": "istio",
228+
"version": "1.5.0",
229+
"qualifiers": null,
230+
"subpath": null
231+
}
232+
],
233+
"fixed_purl": null,
234+
"references": [
235+
{
236+
"reference_id": "ISTIO-SECURITY-2019-001",
237+
"url": "https://istio.io/latest/news/security/ISTIO-SECURITY-2019-001/",
238+
"severities": []
239+
}
240+
],
241+
"weaknesses": []
242+
},
243+
{
244+
"vulnerability_id": null,
245+
"aliases": [
246+
"CVE-2019-12243"
247+
],
248+
"confidence": 100,
249+
"summary": "Incorrect access control.",
250+
"affected_purls": [
251+
{
252+
"type": "github",
253+
"namespace": "istio",
254+
"name": "istio",
255+
"version": "1.1.0",
256+
"qualifiers": null,
257+
"subpath": null
258+
},
259+
{
260+
"type": "github",
261+
"namespace": "istio",
262+
"name": "istio",
263+
"version": "1.1.15",
264+
"qualifiers": null,
265+
"subpath": null
266+
},
267+
{
268+
"type": "github",
269+
"namespace": "istio",
270+
"name": "istio",
271+
"version": "1.3.0",
272+
"qualifiers": null,
273+
"subpath": null
274+
},
275+
{
276+
"type": "github",
277+
"namespace": "istio",
278+
"name": "istio",
279+
"version": "1.3.1",
280+
"qualifiers": null,
281+
"subpath": null
282+
},
283+
{
284+
"type": "github",
285+
"namespace": "istio",
286+
"name": "istio",
287+
"version": "1.5.0",
288+
"qualifiers": null,
289+
"subpath": null
290+
}
291+
],
292+
"fixed_purl": null,
293+
"references": [
294+
{
295+
"reference_id": "ISTIO-SECURITY-2019-001",
296+
"url": "https://istio.io/latest/news/security/ISTIO-SECURITY-2019-001/",
297+
"severities": []
298+
}
299+
],
300+
"weaknesses": []
301+
}
302+
]

vulnerabilities/tests/test_istio.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
99

10+
import json
1011
import os
12+
from unittest import mock
1113

14+
from vulnerabilities.importer import AdvisoryData
1215
from vulnerabilities.importers.istio import IstioImporter
16+
from vulnerabilities.importers.istio import IstioImprover
17+
from vulnerabilities.improvers.default import DefaultImprover
1318
from vulnerabilities.tests import util_tests
1419

1520
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -43,3 +48,29 @@ def test_istio_process_file():
4348
expected_file = os.path.join(TEST_DIR, f"istio-expected.json")
4449
result = [data.to_dict() for data in list(IstioImporter().process_file(path))]
4550
util_tests.check_results_against_json(result, expected_file)
51+
52+
53+
@mock.patch("vulnerabilities.importers.istio.IstioImprover.get_package_versions")
54+
def test_istio_improver(mock_response):
55+
advisory_file = os.path.join(TEST_DIR, f"istio-expected.json")
56+
expected_file = os.path.join(TEST_DIR, f"istio-improver-expected.json")
57+
with open(advisory_file) as exp:
58+
advisories = [AdvisoryData.from_dict(adv) for adv in (json.load(exp))]
59+
mock_response.return_value = [
60+
"1.1.0",
61+
"1.1.1",
62+
"1.1.2",
63+
"1.1.3",
64+
"1.1.4",
65+
"1.1.5",
66+
"1.1.6",
67+
"1.1.7",
68+
"1.1.8",
69+
]
70+
improvers = [IstioImprover(), DefaultImprover()]
71+
result = []
72+
for improver in improvers:
73+
for advisory in advisories:
74+
inference = [data.to_dict() for data in improver.get_inferences(advisory)]
75+
result.extend(inference)
76+
util_tests.check_results_against_json(result, expected_file)

0 commit comments

Comments
 (0)