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
1diff --git a/scripts/test_cve_lib.py b/scripts/test_cve_lib.py
2index 5625935..cdfa1aa 100755
3--- a/scripts/test_cve_lib.py
4+++ b/scripts/test_cve_lib.py
5@@ -9,21 +9,23 @@ import cve_lib
6
7 def pytest_generate_tests(metafunc):
8 if "cvss" in metafunc.fixturenames:
9- cvss = []
10+ cvss = {}
11 nvdcves = ['recent'] + \
12 [str(year) for year in range(2004, int(datetime.datetime.now().year))]
13 for nvdcve in nvdcves:
14+ nvdjson = os.path.join(os.path.dirname(os.path.realpath(__file__)),
15+ '..', 'nvdcve-1.1-%s.json' % nvdcve)
16 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:
20 js = json.load(fp)
21 for cve in js["CVE_Items"]:
22- if "baseMetricV3" in cve["impact"]:
23- cvss.append(cve["impact"])
24+ if "baseMetricV3" in cve["impact"] \
25+ and cve["impact"]["baseMetricV3"]["cvssV3"]["vectorString"] not in cvss:
26+ # only test each vectorString once
27+ cvss[cve["impact"]["baseMetricV3"]["cvssV3"]["vectorString"]] = cve["impact"]
28 except FileNotFoundError:
29 print("Failed to find %s to generate test cases..." % nvdjson, file=sys.stderr)
30- metafunc.parametrize("cvss", cvss)
31+ metafunc.parametrize("cvss", [item for _, item in cvss.items()])
32
33 def test_cvss_empty():
34 with pytest.raises(ValueError):
35@@ -113,7 +115,7 @@ class TestParseCVEFiles:
36 _test_file = os.path.join(TEST_DATA_DIR, "bad", cve_test_file)
37 assert os.path.exists(_test_file)
38 with pytest.raises(ValueError):
39- cve = cve_lib.load_cve(_test_file, strict=True)
40+ _ = cve_lib.load_cve(_test_file, strict=True)
41
42 def test_cve_missing_cvss_score_and_severity(self):
43 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