Skip to content

Commit 0aface0

Browse files
committed
Add failing test for postgres importer
Signed-off-by: Tushar Goel <[email protected]>
1 parent edce07b commit 0aface0

File tree

3 files changed

+94
-10
lines changed

3 files changed

+94
-10
lines changed

vulnerabilities/models.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,15 @@ def get_or_create_from_purl(self, purl: PackageURL):
328328
# when there are 2 packages one with qualifiers and one without
329329
# qualifiers, having all other fields same, this raises MultipleObjectsReturned
330330
# so we are filling out the fields with empty value to avoid this
331-
for field in PackageURL._fields:
332-
# name, type, and version are required fields
333-
if field not in purl_fields:
334-
if field == "namespace":
335-
purl_fields[field] = ""
336-
if field == "qualifiers":
337-
purl_fields[field] = {}
338-
if field == "subpath":
339-
purl_fields[field] = ""
331+
# for field in PackageURL._fields:
332+
# # name, type, and version are required fields
333+
# if field not in purl_fields:
334+
# if field == "namespace":
335+
# purl_fields[field] = ""
336+
# if field == "qualifiers":
337+
# purl_fields[field] = {}
338+
# if field == "subpath":
339+
# purl_fields[field] = ""
340340

341341
package, _ = Package.objects.get_or_create(**purl_fields)
342342
return package
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[
2+
{
3+
"aliases": [
4+
"CVE-2020-10733"
5+
],
6+
"summary": "Windows installer runs executables from uncontrolled directoriesmore details",
7+
"affected_packages": [
8+
{
9+
"package": {
10+
"type": "generic",
11+
"namespace": null,
12+
"name": "postgresql",
13+
"version": null,
14+
"qualifiers": {},
15+
"subpath": null
16+
},
17+
"affected_version_range": "vers:generic/9.6.0|10.0.0|11.0.0|12.0.0",
18+
"fixed_version": "12.3"
19+
},
20+
{
21+
"package": {
22+
"type": "generic",
23+
"namespace": null,
24+
"name": "postgresql",
25+
"version": null,
26+
"qualifiers": {
27+
"os": "windows"
28+
},
29+
"subpath": null
30+
},
31+
"affected_version_range": "vers:generic/9.6.0|10.0.0|11.0.0|12.0.0",
32+
"fixed_version": "12.3"
33+
},
34+
{
35+
"package": {
36+
"type": "generic",
37+
"namespace": null,
38+
"name": "postgresql",
39+
"version": null,
40+
"qualifiers": {},
41+
"subpath": null
42+
},
43+
"affected_version_range": "vers:generic/9.6.0|10.0.0|11.0.0|12.0.0",
44+
"fixed_version": "12.3"
45+
}
46+
],
47+
"references": [
48+
{
49+
"reference_id": "",
50+
"url": "https://www.postgresql.org/support/security/CVE-2020-10733/",
51+
"severities": [
52+
{
53+
"system": "cvssv3",
54+
"value": "6.7"
55+
},
56+
{
57+
"system": "cvssv3_vector",
58+
"value": [
59+
"AV:L/AC:H/PR:L/UI:R/S:U/C:H/I:H/A:H"
60+
]
61+
}
62+
]
63+
},
64+
{
65+
"reference_id": "",
66+
"url": "https://www.postgresql.org/about/news/postgresql-123-118-1013-9618-and-9522-released-2038/",
67+
"severities": []
68+
}
69+
],
70+
"date_published": null
71+
}
72+
]

vulnerabilities/tests/test_postgresql.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
99

10+
import json
1011
import os
11-
from unittest import TestCase
1212

13+
from django.test import TestCase
1314
from packageurl import PackageURL
1415

1516
from vulnerabilities import severity_systems
17+
from vulnerabilities.import_runner import process_advisories
1618
from vulnerabilities.importer import AdvisoryData
1719
from vulnerabilities.importer import Reference
1820
from vulnerabilities.importer import VulnerabilitySeverity
1921
from vulnerabilities.importers.postgresql import to_advisories
22+
from vulnerabilities.improve_runner import ImproveRunner
23+
from vulnerabilities.improve_runner import process_inferences
24+
from vulnerabilities.improvers.default import DefaultImprover
2025
from vulnerabilities.tests import util_tests
2126
from vulnerabilities.utils import AffectedPackage
2227

@@ -35,3 +40,10 @@ def test_to_advisories(self):
3540
result = [data.to_dict() for data in advisories]
3641
expected_file = os.path.join(TEST_DATA, f"parse-advisory-postgresql-expected.json")
3742
util_tests.check_results_against_json(result, expected_file)
43+
44+
def test_run_default_improver(self):
45+
with open(os.path.join(TEST_DATA, "improver-data.json")) as f:
46+
raw_data = json.load(f)
47+
advisories = [AdvisoryData.from_dict(data) for data in raw_data]
48+
process_advisories(advisories, "postgresql")
49+
ImproveRunner(DefaultImprover).run()

0 commit comments

Comments
 (0)