Merge ~alexmurray/ubuntu-cve-tracker:speed-up-cvss-parsing-tests into ubuntu-cve-tracker:master

Proposed by Alex Murray
Status: Merged
Merge reported by: Steve Beattie
Merged at revision: f7ec1bee7f4ad1ccac25908ec220a865ce66e1b7
Proposed branch: ~alexmurray/ubuntu-cve-tracker:speed-up-cvss-parsing-tests
Merge into: ubuntu-cve-tracker:master
Diff against target: 43 lines (+9/-7)
1 file modified
scripts/test_cve_lib.py (+9/-7)
Reviewer Review Type Date Requested Status
Steve Beattie Approve
Review via email: mp+436982@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Steve Beattie (sbeattie) wrote :

Thanks, merged.

review: Approve
Revision history for this message
Steve Beattie (sbeattie) wrote :

> Thanks, merged.

Oh weird, this merge request isn't getting marked as merged by launchpad, because I had to rebase my merge on top of other commits; for some reason `git pull --rebase=merges` which is not supposed to rewrite non-local commits, did so anyway, changing the hash of Alex's commit.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/scripts/test_cve_lib.py b/scripts/test_cve_lib.py
index 5625935..cdfa1aa 100755
--- a/scripts/test_cve_lib.py
+++ b/scripts/test_cve_lib.py
@@ -9,21 +9,23 @@ import cve_lib
99
10def pytest_generate_tests(metafunc):10def pytest_generate_tests(metafunc):
11 if "cvss" in metafunc.fixturenames:11 if "cvss" in metafunc.fixturenames:
12 cvss = []12 cvss = {}
13 nvdcves = ['recent'] + \13 nvdcves = ['recent'] + \
14 [str(year) for year in range(2004, int(datetime.datetime.now().year))]14 [str(year) for year in range(2004, int(datetime.datetime.now().year))]
15 for nvdcve in nvdcves:15 for nvdcve in nvdcves:
16 nvdjson = os.path.join(os.path.dirname(os.path.realpath(__file__)),
17 '..', 'nvdcve-1.1-%s.json' % nvdcve)
16 try:18 try:
17 nvdjson = os.path.join(os.path.dirname(os.path.realpath(__file__)),
18 '..', 'nvdcve-1.1-%s.json' % nvdcve)
19 with open(nvdjson) as fp:19 with open(nvdjson) as fp:
20 js = json.load(fp)20 js = json.load(fp)
21 for cve in js["CVE_Items"]:21 for cve in js["CVE_Items"]:
22 if "baseMetricV3" in cve["impact"]:22 if "baseMetricV3" in cve["impact"] \
23 cvss.append(cve["impact"])23 and cve["impact"]["baseMetricV3"]["cvssV3"]["vectorString"] not in cvss:
24 # only test each vectorString once
25 cvss[cve["impact"]["baseMetricV3"]["cvssV3"]["vectorString"]] = cve["impact"]
24 except FileNotFoundError:26 except FileNotFoundError:
25 print("Failed to find %s to generate test cases..." % nvdjson, file=sys.stderr)27 print("Failed to find %s to generate test cases..." % nvdjson, file=sys.stderr)
26 metafunc.parametrize("cvss", cvss)28 metafunc.parametrize("cvss", [item for _, item in cvss.items()])
2729
28def test_cvss_empty():30def test_cvss_empty():
29 with pytest.raises(ValueError):31 with pytest.raises(ValueError):
@@ -113,7 +115,7 @@ class TestParseCVEFiles:
113 _test_file = os.path.join(TEST_DATA_DIR, "bad", cve_test_file)115 _test_file = os.path.join(TEST_DATA_DIR, "bad", cve_test_file)
114 assert os.path.exists(_test_file)116 assert os.path.exists(_test_file)
115 with pytest.raises(ValueError):117 with pytest.raises(ValueError):
116 cve = cve_lib.load_cve(_test_file, strict=True)118 _ = cve_lib.load_cve(_test_file, strict=True)
117119
118 def test_cve_missing_cvss_score_and_severity(self):120 def test_cve_missing_cvss_score_and_severity(self):
119 cve = cve_lib.load_cve(os.path.join(TEST_DATA_DIR, 'bad/cvss-vector-only'), strict=True)121 cve = cve_lib.load_cve(os.path.join(TEST_DATA_DIR, 'bad/cvss-vector-only'), strict=True)

Subscribers

People subscribed via source and target branches