Skip to content

Commit 044414a

Browse files
committed
filter fixed and affected package based on input purl.type
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent e89b6fe commit 044414a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

vulntotal/datasources/vulnerablecode.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def datasource_advisory(self, purl) -> Iterable[VendorData]:
5353
for advisory in metadata_advisories[0]["affected_by_vulnerabilities"]:
5454
fetched_advisory = self.fetch_get_json(advisory["url"])
5555
self._raw_dump.append(fetched_advisory)
56-
yield parse_advisory(fetched_advisory)
56+
yield parse_advisory(fetched_advisory, purl)
5757

5858
@classmethod
5959
def supported_ecosystem(cls):
@@ -74,14 +74,18 @@ def supported_ecosystem(cls):
7474
}
7575

7676

77-
def parse_advisory(fetched_advisory) -> VendorData:
77+
def parse_advisory(fetched_advisory, purl) -> VendorData:
7878
aliases = [aliase["alias"] for aliase in fetched_advisory["aliases"]]
7979
affected_versions = []
8080
fixed_versions = []
8181
for instance in fetched_advisory["affected_packages"]:
82-
affected_versions.append(PackageURL.from_string(instance["purl"]).version)
82+
affected_purl = PackageURL.from_string(instance["purl"])
83+
if affected_purl.type == purl.type:
84+
affected_versions.append(affected_purl.version)
8385
for instance in fetched_advisory["fixed_packages"]:
84-
fixed_versions.append(PackageURL.from_string(instance["purl"]).version)
86+
fixed_purl = PackageURL.from_string(instance["purl"])
87+
if fixed_purl.type == purl.type:
88+
fixed_versions.append(fixed_purl.version)
8589
return VendorData(
8690
aliases=aliases, affected_versions=affected_versions, fixed_versions=fixed_versions
8791
)

vulntotal/tests/test_vulnerablecode.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pathlib import Path
1212

1313
from commoncode import testcase
14+
from packageurl import PackageURL
1415

1516
from vulnerabilities.tests import util_tests
1617
from vulntotal.datasources import vulnerablecode
@@ -23,6 +24,7 @@ def test_parse_advisory(self):
2324
advisory_file = self.get_test_loc("advisory.json")
2425
with open(advisory_file) as f:
2526
advisory = json.load(f)
26-
results = [vulnerablecode.parse_advisory(adv).to_dict() for adv in advisory]
27+
input_purl = PackageURL.from_string("pkg:maven/org.apache.tomcat/tomcat@10.1.0-M5")
28+
results = [vulnerablecode.parse_advisory(adv, input_purl).to_dict() for adv in advisory]
2729
expected_file = self.get_test_loc("parse_advisory-expected.json", must_exist=False)
2830
util_tests.check_results_against_json(results, expected_file)

0 commit comments

Comments
 (0)