|
8 | 8 | import requests |
9 | 9 | from packageurl import PackageURL |
10 | 10 |
|
11 | | -from vulnerabilities.importer import AdvisoryData |
12 | 11 | from vulnerabilities.pipelines.v2_importers.postgresql_live_importer import ( |
13 | 12 | PostgreSQLLiveImporterPipeline, |
14 | 13 | ) |
@@ -48,55 +47,69 @@ def test_affected_version(monkeypatch): |
48 | 47 | pipeline = PostgreSQLLiveImporterPipeline(purl=purl) |
49 | 48 | pipeline.get_purl_inputs() |
50 | 49 | advisories = list(pipeline.collect_advisories()) |
51 | | - |
52 | | - assert len(advisories) == 1 |
53 | | - adv = advisories[0] |
54 | | - assert isinstance(adv, AdvisoryData) |
55 | | - assert adv.advisory_id == "CVE-2022-1234" |
| 50 | + assert [adv.to_dict() for adv in advisories] == [ |
| 51 | + { |
| 52 | + "advisory_id": "CVE-2022-1234", |
| 53 | + "affected_packages": [ |
| 54 | + { |
| 55 | + "affected_version_range": "vers:generic/10.0.0|10.1.0", |
| 56 | + "fixed_by_commit_patches": [], |
| 57 | + "fixed_version_range": "vers:generic/10.2.0", |
| 58 | + "introduced_by_commit_patches": [], |
| 59 | + "package": { |
| 60 | + "name": "postgresql", |
| 61 | + "namespace": "", |
| 62 | + "qualifiers": "", |
| 63 | + "subpath": "", |
| 64 | + "type": "generic", |
| 65 | + "version": "", |
| 66 | + }, |
| 67 | + } |
| 68 | + ], |
| 69 | + "aliases": [], |
| 70 | + "date_published": None, |
| 71 | + "patches": [], |
| 72 | + "references": [ |
| 73 | + { |
| 74 | + "reference_id": "", |
| 75 | + "reference_type": "", |
| 76 | + "url": "https://www.postgresql.org/support/security/CVE-2022-1234/", |
| 77 | + }, |
| 78 | + { |
| 79 | + "reference_id": "", |
| 80 | + "reference_type": "", |
| 81 | + "url": "https://www.postgresql.org/about/news/postgresql-175-169-1513-1418-and-1321-released-3072/", |
| 82 | + }, |
| 83 | + ], |
| 84 | + "severities": [ |
| 85 | + { |
| 86 | + "scoring_elements": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", |
| 87 | + "system": "cvssv3", |
| 88 | + "value": "9.8", |
| 89 | + } |
| 90 | + ], |
| 91 | + "summary": "Issue affects all", |
| 92 | + "url": "https://www.postgresql.org/support/security/", |
| 93 | + "weaknesses": [], |
| 94 | + } |
| 95 | + ] |
56 | 96 |
|
57 | 97 |
|
58 | 98 | def test_unaffected_version(monkeypatch): |
59 | 99 | html = HTML_BASE.format(affected="10.0, 10.1", fixed="10.2", summary="Issue affects all") |
60 | 100 | monkeypatch.setattr(requests, "get", lambda url: DummyResponse(html)) |
61 | 101 |
|
62 | | - purl = PackageURL(type="generic", name="postgresql", version="10.2") |
| 102 | + purl = PackageURL(type="generic", name="postgresql", version="14.3") |
63 | 103 | pipeline = PostgreSQLLiveImporterPipeline(purl=purl) |
64 | 104 | pipeline.get_purl_inputs() |
65 | 105 | advisories = list(pipeline.collect_advisories()) |
66 | 106 |
|
67 | 107 | assert len(advisories) == 0 |
68 | 108 |
|
69 | 109 |
|
70 | | -def test_qualifier_filtering(monkeypatch): |
71 | | - html = HTML_BASE.format(affected="12.0, 12.1", fixed="12.2", summary="Windows-specific issue") |
72 | | - monkeypatch.setattr(requests, "get", lambda url: DummyResponse(html)) |
73 | | - |
74 | | - purl = PackageURL( |
75 | | - type="generic", name="postgresql", version="12.1", qualifiers={"os": "windows"} |
76 | | - ) |
77 | | - pipeline = PostgreSQLLiveImporterPipeline(purl=purl) |
78 | | - pipeline.get_purl_inputs() |
79 | | - advisories = list(pipeline.collect_advisories()) |
80 | | - assert len(advisories) == 1 |
81 | | - |
82 | | - purl = PackageURL(type="generic", name="postgresql", version="12.1", qualifiers={"os": "linux"}) |
83 | | - pipeline = PostgreSQLLiveImporterPipeline(purl=purl) |
84 | | - pipeline.get_purl_inputs() |
85 | | - advisories = list(pipeline.collect_advisories()) |
86 | | - assert len(advisories) == 0 |
87 | | - |
88 | | - |
89 | 110 | def test_invalid_purl(): |
90 | 111 | pipeline = PostgreSQLLiveImporterPipeline() |
91 | 112 |
|
92 | 113 | pipeline.inputs = {"purl": "pkg:pypi/postgresql@10.1"} |
93 | 114 | with pytest.raises(ValueError): |
94 | 115 | pipeline.get_purl_inputs() |
95 | | - |
96 | | - pipeline.inputs = {"purl": "pkg:generic/notpostgresql@10.1"} |
97 | | - with pytest.raises(ValueError): |
98 | | - pipeline.get_purl_inputs() |
99 | | - |
100 | | - pipeline.inputs = {"purl": "pkg:generic/postgresql"} |
101 | | - with pytest.raises(ValueError): |
102 | | - pipeline.get_purl_inputs() |
|
0 commit comments