Skip to content

Commit 3602fe9

Browse files
committed
Remove unneeded comments and test files, add changelog entry for apache_kafka #972
Reference: #972 Signed-off-by: John M. Horan <johnmhoran@gmail.com>
1 parent 502d85c commit 3602fe9

4 files changed

Lines changed: 9 additions & 252 deletions

File tree

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Release notes
22
=============
33

44

5+
Next Release
6+
------------
7+
8+
- We re-enabled support for the Apache Kafka vulnerabilities advisories importer.
9+
10+
511
Version v32.0.0rc2
612
--------------------
713

vulnerabilities/importers/apache_kafka.py

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

10-
import asyncio
11-
12-
# to test json print
13-
import json
1410

1511
import requests
1612
from bs4 import BeautifulSoup
1713
from packageurl import PackageURL
18-
19-
# import VersionConstraint to experiment
2014
from univers.version_constraint import VersionConstraint
2115
from univers.version_range import MavenVersionRange
2216
from univers.versions import MavenVersion
@@ -25,8 +19,9 @@
2519
from vulnerabilities.importer import AffectedPackage
2620
from vulnerabilities.importer import Importer
2721
from vulnerabilities.importer import Reference
28-
from vulnerabilities.package_managers import GitHubTagsAPI
2922

23+
# The entries below with `"action": "omit"` have no useful/reportable fixed or affected version data.
24+
# See https://kafka.apache.org/cve-list
3025
affected_version_range_mapping = {
3126
"CVE-2022-34917": {
3227
"action": "include",
@@ -97,15 +92,8 @@ def fetch_advisory_page(self):
9792
page = requests.get(self.GH_PAGE_URL)
9893
return page.content
9994

100-
# For now, don't use the GH API
101-
# def set_api(self):
102-
# self.version_api = GitHubTagsAPI()
103-
# asyncio.run(self.version_api.load_api(["apache/kafka"]))
104-
10595
def updated_advisories(self):
10696
advisory_page = self.fetch_advisory_page()
107-
# For now, don't use the GH API
108-
# self.set_api()
10997

11098
parsed_data = self.to_advisory(advisory_page)
11199
return self.batch_advisories(parsed_data)
@@ -155,8 +143,6 @@ def to_advisory(self, advisory_page):
155143
# hard-coded affected_version_range_mapping dictionary.
156144
if affected_version_range_mapping[cve_id]["action"] == "include":
157145

158-
# print("\ncve_id = {}".format(cve_id))
159-
160146
# These 2 variables (not used elsewhere) trigger the KeyError for changed/missing data.
161147
check_affected_versions_key = affected_version_range_mapping[cve_id][
162148
affected_versions_string
@@ -165,15 +151,6 @@ def to_advisory(self, advisory_page):
165151
fixed_versions_string
166152
]
167153

168-
# This calculates/prints the correct univers version value, which we can then use in the mapping dictionary.
169-
# We'll delete this and to_version_ranges_test() when no longer needed.
170-
affected_version_ranges_TEST = self.to_version_ranges_test(
171-
affected_versions_string_split_SPLIT, fixed_versions_string_split_SPLIT
172-
)
173-
# print("\naffected_version_ranges_TEST = {}".format(affected_version_ranges_TEST))
174-
# print("\naffected_versions_string = {}".format(affected_versions_string))
175-
# print("\nfixed_versions_string = {}".format(fixed_versions_string))
176-
177154
references = [
178155
Reference(url=self.ASF_PAGE_URL),
179156
Reference(
@@ -203,127 +180,4 @@ def to_advisory(self, advisory_page):
203180
)
204181
)
205182

206-
# print("\nadvisories[-1] = {}".format(advisories[-1]))
207-
# print("\nadvisories[-1].to_dict() = {}".format(advisories[-1].to_dict()))
208-
209-
# print("\n========================================")
210-
211-
# Print a dict of the advisories.
212-
# result = [data.to_dict() for data in advisories]
213-
# print("result = \n")
214-
# print(json.dumps(result, indent=4, sort_keys=False))
215-
216183
return advisories
217-
218-
# We use this to calculate the ranges for the hard-coded affected_version_range_mapping.
219-
# We'' delete this when no longer needed.
220-
def to_version_ranges_test(self, versions_data, fixed_versions):
221-
constraints = []
222-
223-
for version_item in versions_data:
224-
if "to" in version_item:
225-
version_item_split = version_item.split(" ")
226-
227-
constraints.append(
228-
VersionConstraint(
229-
comparator=">=",
230-
version=MavenVersion(version_item_split[0]),
231-
)
232-
)
233-
constraints.append(
234-
VersionConstraint(
235-
comparator="<=",
236-
version=MavenVersion(version_item_split[-1]),
237-
)
238-
)
239-
240-
elif "-" in version_item:
241-
version_item_split = version_item.split(" ")
242-
243-
constraints.append(
244-
VersionConstraint(
245-
comparator=">=",
246-
version=MavenVersion(version_item_split[0]),
247-
)
248-
)
249-
constraints.append(
250-
VersionConstraint(
251-
comparator="<=",
252-
version=MavenVersion(version_item_split[-1]),
253-
)
254-
)
255-
256-
elif "and later" in version_item:
257-
version_item_split = version_item.split(" ")
258-
259-
constraints.append(
260-
VersionConstraint(
261-
comparator=">=",
262-
version=MavenVersion(version_item_split[0]),
263-
)
264-
)
265-
266-
else:
267-
version_item_split = version_item.split(" ")
268-
269-
constraints.append(
270-
VersionConstraint(
271-
comparator="=",
272-
version=MavenVersion(version_item_split[0]),
273-
)
274-
)
275-
276-
for fixed_item in fixed_versions:
277-
if "to" in fixed_item:
278-
fixed_item_split = fixed_item.split(" ")
279-
280-
constraints.append(
281-
VersionConstraint(
282-
comparator=">=",
283-
version=MavenVersion(fixed_item_split[0]),
284-
).invert()
285-
)
286-
constraints.append(
287-
VersionConstraint(
288-
comparator="<=",
289-
version=MavenVersion(fixed_item_split[-1]),
290-
).invert()
291-
)
292-
293-
elif "-" in fixed_item:
294-
fixed_item_split = fixed_item.split(" ")
295-
296-
constraints.append(
297-
VersionConstraint(
298-
comparator=">=",
299-
version=MavenVersion(fixed_item_split[0]),
300-
).invert()
301-
)
302-
constraints.append(
303-
VersionConstraint(
304-
comparator="<=",
305-
version=MavenVersion(fixed_item_split[-1]),
306-
).invert()
307-
)
308-
309-
elif "and later" in fixed_item:
310-
fixed_item_split = fixed_item.split(" ")
311-
312-
constraints.append(
313-
VersionConstraint(
314-
comparator=">=",
315-
version=MavenVersion(fixed_item_split[0]),
316-
).invert()
317-
)
318-
319-
else:
320-
fixed_item_split = fixed_item.split(" ")
321-
322-
constraints.append(
323-
VersionConstraint(
324-
comparator="=",
325-
version=MavenVersion(fixed_item_split[0]),
326-
).invert()
327-
)
328-
329-
return MavenVersionRange(constraints=constraints)

vulnerabilities/tests/test_apache_kafka.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
99

10-
# temporarily import json to create output to analyze
11-
import json
1210
import os
1311

1412
import pytest
1513

1614
from vulnerabilities.importers.apache_kafka import ApacheKafkaImporter
17-
18-
# from vulnerabilities.package_managers import GitHubTagsAPI
1915
from vulnerabilities.tests import util_tests
2016

2117
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
22-
# Created cve-list-2022-12-06.html with a full copy of https://raw.githubusercontent.com/apache/kafka-site/asf-site/cve-list.html
18+
2319
TEST_DATA = os.path.join(
2420
BASE_DIR,
2521
"test_data/apache_kafka",
@@ -32,23 +28,10 @@ def test_to_advisory():
3228
advisories = ApacheKafkaImporter().to_advisory(raw_data)
3329
result = [data.to_dict() for data in advisories]
3430

35-
# TODO: We need to finish this test including the REGEN step. 2022-12-12 Monday 14:48:05. Done.
3631
expected_file = os.path.join(TEST_DATA, f"to-advisory-apache_kafka-expected.json")
3732
util_tests.check_results_against_json(result, expected_file)
3833

39-
# We generate these 2 files solely to vet the output and adjust the importer code.
40-
# with open(os.path.join(TEST_DATA, "jmh-test-01.txt"), "w") as f1:
41-
# for advisory_object in result:
42-
# f1.write(f"{advisory_object}\n\n")
43-
# for k, v in advisory_object.items():
44-
# f1.write(f"{k}: {v}\n\n")
45-
# f1.write(f"=================================================\n\n")
46-
47-
# with open(os.path.join(TEST_DATA, "test-advisories.json"), "w", encoding="utf-8") as f:
48-
# json.dump(result, f, ensure_ascii=False, indent=4)
49-
5034

51-
# Check for an unknown CVE value.
5235
def to_advisory_changed_cve():
5336
with open(os.path.join(TEST_DATA, "cve-list-changed-cve.html")) as f:
5437
raw_data = f.read()
@@ -62,7 +45,6 @@ def test_to_advisory_changed_cve_exception():
6245
assert "CVE-2022-34918" in str(excinfo.value)
6346

6447

65-
# Check for an unknown "Versions affected" value.
6648
def to_advisory_changed_versions_affected():
6749
with open(os.path.join(TEST_DATA, "cve-list-changed-versions-affected.html")) as f:
6850
raw_data = f.read()
@@ -76,7 +58,6 @@ def test_to_advisory_changed_versions_affected_exception():
7658
assert "2.8.0 - 2.8.1, 3.0.0 - 3.0.1, 3.1.0 - 3.1.1, 3.2.0 - 3.2.2" in str(excinfo.value)
7759

7860

79-
# Check for an unknown "Fixed versions" value.
8061
def to_advisory_changed_fixed_versions():
8162
with open(os.path.join(TEST_DATA, "cve-list-changed-fixed-versions.html")) as f:
8263
raw_data = f.read()

0 commit comments

Comments
 (0)