Skip to content

Commit 719ac38

Browse files
authored
skip modules but keep their rpms (#305)
Sometimes RPMs are packed in a module. It's a little harder to detect the actual modules themselves on a running system, but we can still check their RPMs. This change allows skipping modules, but keeps their RPM children. Signed-off-by: Jason Shepherd <[email protected]>
1 parent c90f10d commit 719ac38

File tree

4 files changed

+11442
-20
lines changed

4 files changed

+11442
-20
lines changed

tools/redhat/redhat_osv/convert_redhat_test.py

+22-18
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,29 @@
88
class TestRedHatConverter(unittest.TestCase):
99
"""Test end-to-end convertion from RedHAt CSAF to OSV format"""
1010

11+
test_advisories = ["2024_4546", "2024_6220"]
12+
1113
def test_convert_redhat(self):
12-
""" Test a single demo CSAF file """
13-
modified_time = datetime.strptime("2024-09-02T14:30:00",
14-
"%Y-%m-%dT%H:%M:%S")
15-
csaf_file = "testdata/rhsa-2024_4546.json"
16-
expected_file = "testdata/RHSA-2024_4546.json"
17-
18-
with open(csaf_file, "r", encoding="utf-8") as fp:
19-
csaf_data = fp.read()
20-
converter = RedHatConverter()
21-
osv_data = converter.convert(csaf_data,
22-
modified_time.strftime(DATE_FORMAT))
23-
24-
assert osv_data[0] == "RHSA-2024:4546"
25-
result_data = json.loads(osv_data[1])
26-
27-
with open(expected_file, "r", encoding="utf-8") as fp:
28-
expected_data = json.load(fp)
29-
assert expected_data == result_data
14+
for test_advisory in self.test_advisories:
15+
""" Test a single demo CSAF file """
16+
modified_time = datetime.strptime("2024-09-02T14:30:00",
17+
"%Y-%m-%dT%H:%M:%S")
18+
csaf_file = f"testdata/rhsa-{test_advisory}.json"
19+
expected_file = f"testdata/RHSA-{test_advisory}.json"
20+
21+
with open(csaf_file, "r", encoding="utf-8") as fp:
22+
csaf_data = fp.read()
23+
converter = RedHatConverter()
24+
osv_data = converter.convert(csaf_data,
25+
modified_time.strftime(DATE_FORMAT))
26+
27+
advisory_id = test_advisory.replace("_", ":")
28+
assert osv_data[0] == f"RHSA-{advisory_id}"
29+
result_data = json.loads(osv_data[1])
30+
31+
with open(expected_file, "r", encoding="utf-8") as fp:
32+
expected_data = json.load(fp)
33+
assert expected_data == result_data
3034

3135

3236
if __name__ == '__main__':

tools/redhat/redhat_osv/csaf.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from dataclasses import dataclass, InitVar, field
44
from typing import Any, Iterable
55

6+
class RemediationParseError(ValueError):
7+
pass
68

79
@dataclass
810
class Remediation:
@@ -32,7 +34,7 @@ def __post_init__(self, csaf_product_id: str, cpes: dict[str, str],
3234
# We split the name from the rest of the 'version' data (EVRA). We store name as component.
3335
split_component_version = self.product_version.rsplit("-", maxsplit=2)
3436
if len(split_component_version) < 3:
35-
raise ValueError(
37+
raise RemediationParseError(
3638
f"Could not convert component into NEVRA: {self.product_version}"
3739
)
3840
# RHEL Modules have 4 colons in the name part of the NEVRA. If we detect a modular RPM
@@ -96,7 +98,12 @@ def __post_init__(self, csaf_vuln: dict[str, Any], cpes: dict[str, str],
9698
self.references = csaf_vuln["references"]
9799
self.remediations = []
98100
for product_id in csaf_vuln["product_status"]["fixed"]:
99-
self.remediations.append(Remediation(product_id, cpes, purls))
101+
try:
102+
self.remediations.append(Remediation(product_id, cpes, purls))
103+
except RemediationParseError:
104+
continue
105+
if not self.remediations:
106+
raise ValueError(f"Did not find any remediations for {self.cve_id}")
100107

101108

102109
def gen_dict_extract(key, var: Iterable):

0 commit comments

Comments
 (0)