Skip to content

Commit e0bd42d

Browse files
committed
Add tests for istio importer
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent c54a7eb commit e0bd42d

4 files changed

Lines changed: 69 additions & 192 deletions

File tree

vulnerabilities/importers/istio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import saneyaml
1515
from dateutil import parser
1616
from packageurl import PackageURL
17+
from univers.version_constraint import VersionConstraint
1718
from univers.version_range import GitHubVersionRange
1819
from univers.version_range import GolangVersionRange
1920
from univers.versions import SemverVersion

vulnerabilities/tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def no_rmtree(monkeypatch):
2929
"test_apache_tomcat.py",
3030
"test_api.py",
3131
"test_elixir_security.py",
32-
"test_istio.py",
3332
"test_models.py",
3433
"test_msr2019.py",
3534
"test_package_managers.py",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"aliases": [
4+
"CVE-2019-12243"
5+
],
6+
"summary": "Incorrect access control.",
7+
"affected_packages": [
8+
{
9+
"package": {
10+
"type": "golang",
11+
"namespace": null,
12+
"name": "istio",
13+
"version": null,
14+
"qualifiers": null,
15+
"subpath": null
16+
},
17+
"affected_version_range": "vers:golang/>=1.1.0|<=1.1.15|>=1.2.0|<=1.2.6|>=1.3.0|<=1.3.1",
18+
"fixed_version": null
19+
},
20+
{
21+
"package": {
22+
"type": "github",
23+
"namespace": null,
24+
"name": "istio",
25+
"version": null,
26+
"qualifiers": null,
27+
"subpath": null
28+
},
29+
"affected_version_range": "vers:github/>=1.1.0|<=1.1.15|>=1.2.0|<=1.2.6|>=1.3.0|<=1.3.1",
30+
"fixed_version": null
31+
}
32+
],
33+
"references": [
34+
{
35+
"reference_id": "ISTIO-SECURITY-2019-001",
36+
"url": "https://istio.io/latest/news/security/ISTIO-SECURITY-2019-001/",
37+
"severities": []
38+
}
39+
],
40+
"date_published": "2019-05-28T00:00:00+00:00"
41+
}
42+
]

vulnerabilities/tests/test_istio.py

Lines changed: 26 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -8,198 +8,33 @@
88
#
99

1010
import os
11-
from collections import OrderedDict
12-
from unittest import TestCase
1311

14-
from packageurl import PackageURL
15-
16-
from vulnerabilities.importer import AdvisoryData
17-
from vulnerabilities.importer import Reference
1812
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
2214

2315
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

Comments
 (0)