|
8 | 8 | # |
9 | 9 |
|
10 | 10 | import os |
11 | | -from collections import OrderedDict |
12 | | -from unittest import TestCase |
13 | 11 |
|
14 | | -from packageurl import PackageURL |
15 | | - |
16 | | -from vulnerabilities.importer import AdvisoryData |
17 | | -from vulnerabilities.importer import Reference |
18 | 12 | from vulnerabilities.importers.istio import IstioImporter |
19 | | -from vulnerabilities.package_managers import GitHubTagsAPI |
20 | | -from vulnerabilities.package_managers import Version |
21 | | -from vulnerabilities.utils import AffectedPackage |
| 13 | +from vulnerabilities.tests import util_tests |
22 | 14 |
|
23 | 15 | BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
24 | | - |
25 | | - |
26 | | -class TestIstioImporter(TestCase): |
27 | | - @classmethod |
28 | | - def setUpClass(cls): |
29 | | - data_source_cfg = { |
30 | | - "repository_url": "", |
31 | | - } |
32 | | - cls.data_src = IstioImporter(1, config=data_source_cfg) |
33 | | - cls.data_src.version_api = GitHubTagsAPI( |
34 | | - { |
35 | | - "istio/istio": [ |
36 | | - Version(value="1.0.0"), |
37 | | - Version(value="1.1.0"), |
38 | | - Version(value="1.1.1"), |
39 | | - Version(value="1.1.17"), |
40 | | - Version(value="1.2.1"), |
41 | | - Version(value="1.2.7"), |
42 | | - Version(value="1.3.0"), |
43 | | - Version(value="1.3.1"), |
44 | | - Version(value="1.3.2"), |
45 | | - Version(value="1.9.1"), |
46 | | - ] |
47 | | - } |
48 | | - ) |
49 | | - |
50 | | - def test_get_data_from_md(self): |
51 | | - path = os.path.join(BASE_DIR, "test_data/istio/test_file.md") |
52 | | - actual_data = self.data_src.get_data_from_md(path) |
53 | | - expected_data = { |
54 | | - "title": "ISTIO-SECURITY-2019-001", |
55 | | - "subtitle": "Security Bulletin", |
56 | | - "description": "Incorrect access control.", |
57 | | - "cves": ["CVE-2019-12243"], |
58 | | - "cvss": "8.9", |
59 | | - "vector": "CVSS:3.0/AV:A/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:N/E:H/RL:O/RC:C", |
60 | | - "releases": ["1.1 to 1.1.15", "1.2 to 1.2.6", "1.3 to 1.3.1"], |
61 | | - "publishdate": "2019-05-28", |
62 | | - } |
63 | | - |
64 | | - assert expected_data == actual_data |
65 | | - |
66 | | - def test_process_file(self): |
67 | | - |
68 | | - path = os.path.join(BASE_DIR, "test_data/istio/test_file.md") |
69 | | - expected_data = [ |
70 | | - Advisory( |
71 | | - summary="Incorrect access control.", |
72 | | - vulnerability_id="CVE-2019-12243", |
73 | | - affected_packages=[ |
74 | | - AffectedPackage( |
75 | | - vulnerable_package=PackageURL( |
76 | | - type="golang", |
77 | | - name="istio", |
78 | | - version="1.1.0", |
79 | | - ), |
80 | | - patched_package=PackageURL( |
81 | | - type="golang", |
82 | | - name="istio", |
83 | | - version="1.1.17", |
84 | | - ), |
85 | | - ), |
86 | | - AffectedPackage( |
87 | | - vulnerable_package=PackageURL( |
88 | | - type="golang", |
89 | | - name="istio", |
90 | | - version="1.1.1", |
91 | | - ), |
92 | | - patched_package=PackageURL( |
93 | | - type="golang", |
94 | | - name="istio", |
95 | | - version="1.1.17", |
96 | | - ), |
97 | | - ), |
98 | | - AffectedPackage( |
99 | | - vulnerable_package=PackageURL( |
100 | | - type="golang", |
101 | | - name="istio", |
102 | | - version="1.2.1", |
103 | | - ), |
104 | | - patched_package=PackageURL( |
105 | | - type="golang", |
106 | | - name="istio", |
107 | | - version="1.2.7", |
108 | | - ), |
109 | | - ), |
110 | | - AffectedPackage( |
111 | | - vulnerable_package=PackageURL( |
112 | | - type="golang", |
113 | | - name="istio", |
114 | | - version="1.3.0", |
115 | | - ), |
116 | | - patched_package=PackageURL( |
117 | | - type="golang", |
118 | | - name="istio", |
119 | | - version="1.3.2", |
120 | | - ), |
121 | | - ), |
122 | | - AffectedPackage( |
123 | | - vulnerable_package=PackageURL( |
124 | | - type="golang", |
125 | | - name="istio", |
126 | | - version="1.3.1", |
127 | | - ), |
128 | | - patched_package=PackageURL( |
129 | | - type="golang", |
130 | | - name="istio", |
131 | | - version="1.3.2", |
132 | | - ), |
133 | | - ), |
134 | | - AffectedPackage( |
135 | | - vulnerable_package=PackageURL( |
136 | | - type="github", |
137 | | - name="istio", |
138 | | - version="1.1.0", |
139 | | - ), |
140 | | - patched_package=PackageURL( |
141 | | - type="github", |
142 | | - name="istio", |
143 | | - version="1.1.17", |
144 | | - ), |
145 | | - ), |
146 | | - AffectedPackage( |
147 | | - vulnerable_package=PackageURL( |
148 | | - type="github", |
149 | | - name="istio", |
150 | | - version="1.1.1", |
151 | | - ), |
152 | | - patched_package=PackageURL( |
153 | | - type="github", |
154 | | - name="istio", |
155 | | - version="1.1.17", |
156 | | - ), |
157 | | - ), |
158 | | - AffectedPackage( |
159 | | - vulnerable_package=PackageURL( |
160 | | - type="github", |
161 | | - name="istio", |
162 | | - version="1.2.1", |
163 | | - ), |
164 | | - patched_package=PackageURL( |
165 | | - type="github", |
166 | | - name="istio", |
167 | | - version="1.2.7", |
168 | | - ), |
169 | | - ), |
170 | | - AffectedPackage( |
171 | | - vulnerable_package=PackageURL( |
172 | | - type="github", |
173 | | - name="istio", |
174 | | - version="1.3.0", |
175 | | - ), |
176 | | - patched_package=PackageURL( |
177 | | - type="github", |
178 | | - name="istio", |
179 | | - version="1.3.2", |
180 | | - ), |
181 | | - ), |
182 | | - AffectedPackage( |
183 | | - vulnerable_package=PackageURL( |
184 | | - type="github", |
185 | | - name="istio", |
186 | | - version="1.3.1", |
187 | | - ), |
188 | | - patched_package=PackageURL( |
189 | | - type="github", |
190 | | - name="istio", |
191 | | - version="1.3.2", |
192 | | - ), |
193 | | - ), |
194 | | - ], |
195 | | - references=[ |
196 | | - Reference( |
197 | | - reference_id="ISTIO-SECURITY-2019-001", |
198 | | - url="https://istio.io/latest/news/security/ISTIO-SECURITY-2019-001/", |
199 | | - ) |
200 | | - ], |
201 | | - ) |
202 | | - ] |
203 | | - |
204 | | - found_data = self.data_src.process_file(path) |
205 | | - assert expected_data == found_data |
| 16 | +TEST_DIR = os.path.join(BASE_DIR, "test_data/istio") |
| 17 | + |
| 18 | + |
| 19 | +def test_istio_get_data_from_md(): |
| 20 | + path = os.path.join(TEST_DIR, "test_file.md") |
| 21 | + actual_data = IstioImporter().get_data_from_md(path) |
| 22 | + expected_data = { |
| 23 | + "title": "ISTIO-SECURITY-2019-001", |
| 24 | + "subtitle": "Security Bulletin", |
| 25 | + "description": "Incorrect access control.", |
| 26 | + "cves": ["CVE-2019-12243"], |
| 27 | + "cvss": "8.9", |
| 28 | + "vector": "CVSS:3.0/AV:A/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:N/E:H/RL:O/RC:C", |
| 29 | + "releases": ["1.1 to 1.1.15", "1.2 to 1.2.6", "1.3 to 1.3.1"], |
| 30 | + "publishdate": "2019-05-28", |
| 31 | + } |
| 32 | + |
| 33 | + assert expected_data == actual_data |
| 34 | + |
| 35 | + |
| 36 | +def test_istio_process_file(): |
| 37 | + path = os.path.join(TEST_DIR, "test_file.md") |
| 38 | + expected_file = os.path.join(TEST_DIR, f"istio-expected.json") |
| 39 | + result = [data.to_dict() for data in list(IstioImporter().process_file(path))] |
| 40 | + util_tests.check_results_against_json(result, expected_file) |
0 commit comments