Skip to content

Commit 03ff5ee

Browse files
committed
Continue refactoring, add tests and clean up comments #970
Reference: #970 Signed-off-by: John M. Horan <[email protected]>
1 parent de3d685 commit 03ff5ee

7 files changed

+1736
-273
lines changed

vulnerabilities/importers/apache_tomcat.py

Lines changed: 137 additions & 207 deletions
Large diffs are not rendered by default.

vulnerabilities/tests/test_apache_tomcat.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
TEST_DATA = os.path.join(BASE_DIR, "test_data/apache_tomcat")
3030

3131

32-
# Temp test to flesh out `extract_advisories_from_page()` -- the method .
3332
def test_method_extract_advisories_from_page():
34-
# with open(os.path.join(TEST_DATA, "apache_tomcat_cve-2020-9484.html")) as f:
3533
with open(os.path.join(TEST_DATA, "apache_tomcat-selected-advisories.html")) as f:
3634
raw_data = f.read()
3735
extracted_advisories = ApacheTomcatImporter().extract_advisories_from_page(raw_data)
@@ -304,13 +302,11 @@ def test_extract_advisories_from_page_with_multiple_groups():
304302

305303
# This test is temporary -- just for running apache_tomcat.py using all HTML report pages.
306304
# Will replace with a REGEN-based test as with apache_httpd and postgresql.
307-
# Formely named `test_updated_advisories` before method was renamed `advisory_data()`
308305
def test_advisory_data():
309306
returned_advisories = ApacheTomcatImporter().advisory_data()
310307

311308

312309
def test_fetch_links():
313-
# retrieved_links = ApacheTomcatImporter().fetch_advisory_links(security_updates_home)
314310
retrieved_links = ApacheTomcatImporter().fetch_advisory_links(
315311
"https://tomcat.apache.org/security"
316312
)
@@ -332,26 +328,25 @@ def test_fetch_links():
332328
]
333329

334330

335-
# def test_to_version_ranges_test():
336331
def test_to_version_ranges():
337332
versions_data = [
338333
"1.0.0-2.0.0",
339-
"3.2.2-3.2.3?",
334+
"3.2.2-3.2.3",
340335
"3.3a-3.3.1",
341336
"9.0.0.M1 to 9.0.0.M9",
342337
"10.1.0-M1 to 10.1.0-M16",
343338
]
344339
fixed_versions = ["3.0.0", "3.3.1a"]
345340

346-
expected_versions_data = "vers:maven/>=1.0.0|<=2.0.0|!=3.0.0|>=3.2.2|<=3.2.3?|>=3.3a|<=3.3.1|!=3.3.1a|>=9.0.0.M1|<=9.0.0.M9|>=10.1.0-M1|<=10.1.0-M16"
341+
expected_versions_data = "vers:maven/>=1.0.0|<=2.0.0|!=3.0.0|>=3.2.2|<=3.2.3|>=3.3a|<=3.3.1|!=3.3.1a|>=9.0.0.M1|<=9.0.0.M9|>=10.1.0-M1|<=10.1.0-M16"
347342

348343
expected_MavenVersionRange_versions_data = MavenVersionRange(
349344
constraints=(
350345
VersionConstraint(comparator=">=", version=MavenVersion(string="1.0.0")),
351346
VersionConstraint(comparator="<=", version=MavenVersion(string="2.0.0")),
352347
VersionConstraint(comparator="!=", version=MavenVersion(string="3.0.0")),
353348
VersionConstraint(comparator=">=", version=MavenVersion(string="3.2.2")),
354-
VersionConstraint(comparator="<=", version=MavenVersion(string="3.2.3?")),
349+
VersionConstraint(comparator="<=", version=MavenVersion(string="3.2.3")),
355350
VersionConstraint(comparator=">=", version=MavenVersion(string="3.3a")),
356351
VersionConstraint(comparator="<=", version=MavenVersion(string="3.3.1")),
357352
VersionConstraint(comparator="!=", version=MavenVersion(string="3.3.1a")),
@@ -362,16 +357,21 @@ def test_to_version_ranges():
362357
)
363358
)
364359

365-
# XXX: 2023-01-02 Monday 16:27:37. Error: AttributeError: 'ApacheTomcatImporter' object has no attribute 'to_version_ranges'
366-
# That's because I converted a method function to an independent function.
367-
# converted_versions_data = ApacheTomcatImporter().to_version_ranges(
368-
# versions_data, fixed_versions
369-
# )
370-
# Try this instead. It works!
371360
converted_versions_data = to_version_ranges(versions_data, fixed_versions)
372361

373-
# print("\nvers_test = {}\n".format(MavenVersionRange.from_string("vers:maven/>=1.0.0|<=2.0.0")))
374-
# print("\nconverted_versions_data = {}\n".format(converted_versions_data))
375-
376362
assert expected_MavenVersionRange_versions_data == converted_versions_data
377363
assert MavenVersionRange.from_string(expected_versions_data) == converted_versions_data
364+
365+
366+
# def test_to_version_ranges_invert():
367+
# # Do we want to prevent or alert to this type of conflict?
368+
# # And how do we test the desired behavior?
369+
# # versions_data = ["3.0.0"]
370+
# # fixed_versions = ["3.0.0", "3.3.1a"]
371+
372+
# versions_data = ["1.0.0-3.0.0"]
373+
# fixed_versions = ["1.0.0-3.0.0", "3.3.1a"]
374+
375+
# converted_versions_data = to_version_ranges(versions_data, fixed_versions)
376+
377+
# print("\n\nconverted_versions_data = {}\n".format(converted_versions_data))

vulnerabilities/tests/test_data/apache_tomcat/trace/record_of_all_affected_versions-2023-01-04-00.txt

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@
155155
[' 8.5.0 to 8.5.6']
156156
[' 8.5.0 to 8.5.6']
157157
[' 8.5.0 to 8.5.6']
158-
[' 8.5.0 to 8.5.4, 8.0.0.RC1 to 8.0.36']
159-
[' 8.5.0 to 8.5.4, 8.0.0.RC1 to 8.0.36']
160-
[' 8.5.0 to 8.5.4, 8.0.0.RC1 to 8.0.36']
161-
[' 8.5.0 to 8.5.4, 8.0.0.RC1 to 8.0.36']
162-
[' 8.5.0 to 8.5.4, 8.0.0.RC1 to 8.0.36']
163-
[' 8.5.0 to 8.5.2, 8.0.0.RC1 to 8.0.35']
158+
[' 8.5.0 to 8.5.4', '8.0.0.RC1 to 8.0.36']
159+
[' 8.5.0 to 8.5.4', '8.0.0.RC1 to 8.0.36']
160+
[' 8.5.0 to 8.5.4', '8.0.0.RC1 to 8.0.36']
161+
[' 8.5.0 to 8.5.4', '8.0.0.RC1 to 8.0.36']
162+
[' 8.5.0 to 8.5.4', '8.0.0.RC1 to 8.0.36']
163+
[' 8.5.0 to 8.5.2', '8.0.0.RC1 to 8.0.35']
164164
[' 8.0.0.RC1 to 8.0.30']
165165
[' 8.0.0.RC1 to 8.0.30']
166166
[' 8.0.0.RC1 to 8.0.30']
@@ -350,7 +350,7 @@
350350
[' 5.5.0-5.5.28']
351351
[' 5.5.0-5.5.27']
352352
[' 5.5.0-5.5.27']
353-
[' 5.5.0-5.5.27 (Memory Realm), 5.5.0-5.5.5 (DataSource and JDBC\n Realms)']
353+
[' 5.5.0-5.5.27 (Memory Realm)', '5.5.0-5.5.5 (DataSource and JDBC\n Realms)']
354354
[' 5.5.0-5.5.27']
355355
[' 5.5.0-5.5.27']
356356
[' 5.5.0-5.5.26']
@@ -360,71 +360,71 @@
360360
[' 5.5.9-5.5.25']
361361
[' 5.5.0-5.5.25']
362362
[' 5.5.11-5.5.25']
363-
[' 5.0.0-5.0.30, 5.5.0-5.5.24']
364-
[' 5.0.0-5.0.30, 5.5.0-5.5.24']
365-
[' 5.0.0-5.0.30, 5.5.0-5.5.24']
366-
[' 5.0.0-5.0.30, 5.5.0-5.5.24']
363+
[' 5.0.0-5.0.30', '5.5.0-5.5.24']
364+
[' 5.0.0-5.0.30', '5.5.0-5.5.24']
365+
[' 5.0.0-5.0.30', '5.5.0-5.5.24']
366+
[' 5.0.0-5.0.30', '5.5.0-5.5.24']
367367
[' 5.5.0-5.5.24']
368-
[' 5.0.0-5.0.30, 5.5.0-5.5.23']
369-
[' 5.0.0-5.0.30, 5.5.0-5.5.22']
370-
[' 5.0.0-5.0.30, 5.5.0-5.5.21']
371-
[' 5.0.0-5.0.30, 5.5.0-5.5.20']
372-
[' 5.0.0-5.0.SVN, 5.5.0-5.5.20']
368+
[' 5.0.0-5.0.30', '5.5.0-5.5.23']
369+
[' 5.0.0-5.0.30', '5.5.0-5.5.22']
370+
[' 5.0.0-5.0.30', '5.5.0-5.5.21']
371+
[' 5.0.0-5.0.30', '5.5.0-5.5.20']
372+
[' 5.0.0-5.0.SVN', '5.5.0-5.5.20']
373373
[' 5.5.10-5.5.20 (5.0.x unknown)']
374-
[' 5.0.0-5.0.30, 5.5.0-5.5.17']
375-
[' 5.0.0-5.0.30, 5.5.0-5.5.16']
376-
[' 5.0.0-5.0.30, 5.5.0-5.5.15']
377-
[' 5.0.0-5.0.30, 5.5.0-5.5.12']
378-
[' 5.0.0-5.0.30, 5.5.0-5.5.12']
379-
[' 5.0.0-5.0.30, 5.5.0-5.5.6']
374+
[' 5.0.0-5.0.30', '5.5.0-5.5.17']
375+
[' 5.0.0-5.0.30', '5.5.0-5.5.16']
376+
[' 5.0.0-5.0.30', '5.5.0-5.5.15']
377+
[' 5.0.0-5.0.30', '5.5.0-5.5.12']
378+
[' 5.0.0-5.0.30', '5.5.0-5.5.12']
379+
[' 5.0.0-5.0.30', '5.5.0-5.5.6']
380380
[' 5.5.0 (5.0.x unknown)']
381381
[' 4.1.0-4.1.39']
382382
[' 4.1.0-4.1.39']
383-
[' 4.1.0-4.1.39 (Memory Realm), 4.1.0-4.1.31 (JDBC Realm),\n 4.1.17-4.1.31 (DataSource Realm)']
383+
[' 4.1.0-4.1.39 (Memory Realm)', '4.1.0-4.1.31 (JDBC Realm),\n 4.1.17-4.1.31 (DataSource Realm)']
384384
[' 4.1.0-4.1.39']
385385
[' 4.1.0-4.1.39']
386386
[' 4.1.0-4.1.37']
387387
[' 4.1.0-4.1.37']
388388
[' 4.1.0-4.1.37']
389-
[' 4.0.1-4.0.6, 4.1.0-4.1.36']
390-
[' 4.0.1-4.0.6, 4.1.0-4.1.36']
391-
[' 4.0.0-4.0.6, 4.1.0-4.1.36']
392-
[' 4.0.1-4.0.6, 4.1.0-4.1.36']
389+
[' 4.0.1-4.0.6', '4.1.0-4.1.36']
390+
[' 4.0.1-4.0.6', '4.1.0-4.1.36']
391+
[' 4.0.0-4.0.6', '4.1.0-4.1.36']
392+
[' 4.0.1-4.0.6', '4.1.0-4.1.36']
393393
[' 4.1.0-4.1.36']
394-
[' 4.0.0-4.0.6, 4.1.0-4.1.36']
394+
[' 4.0.0-4.0.6', '4.1.0-4.1.36']
395395
[' 4.1.0-4.1.36']
396396
[' 4.1.0-4.1.36']
397-
[' 4.0.0-4.0.6, 4.1.0-4.1.36']
398-
[' 4.0.0-4.0.6, 4.1.0-4.1.34']
399-
[' 4.0.0-4.0.6, 4.1.0-4.1.34']
400-
[' 4.0.0-4.0.6, 4.1.0-4.1.34']
397+
[' 4.0.0-4.0.6', '4.1.0-4.1.36']
398+
[' 4.0.0-4.0.6', '4.1.0-4.1.34']
399+
[' 4.0.0-4.0.6', '4.1.0-4.1.34']
400+
[' 4.0.0-4.0.6', '4.1.0-4.1.34']
401401
[' 4.1.32-4.1.34 (4.0.x unknown)']
402402
[' 4.1.0-4.1.31']
403403
[' 4.1.28-4.1.31']
404-
[' 4.0.0-4.0.6, 4.1.0-4.1.31']
405-
[' 4.0.0-4.0.6, 4.1.0-4.1.31']
406-
[' 4.0.0-4.0.6, 4.1.0-4.1.31']
407-
[' 4.0.0-4.0.6, 4.1.0-4.1.31']
404+
[' 4.0.0-4.0.6', '4.1.0-4.1.31']
405+
[' 4.0.0-4.0.6', '4.1.0-4.1.31']
406+
[' 4.0.0-4.0.6', '4.1.0-4.1.31']
407+
[' 4.0.0-4.0.6', '4.1.0-4.1.31']
408408
[' 4.1.0-4.1.28']
409-
[' 4.0.0-4.0.5, 4.1.0-4.1.12']
410-
[' 4.0.0-4.0.5, 4.1.0-4.1.12']
411-
[' 4.0.0-4.0.4, 4.1.0-4.1.11']
412-
[' 4.0.0-4.0.2?, 4.0.3, 4.0.4-4.0.6?, 4.1.0-4.1.2?']
409+
[' 4.0.0-4.0.5', '4.1.0-4.1.12']
410+
[' 4.0.0-4.0.5', '4.1.0-4.1.12']
411+
[' 4.0.0-4.0.4', '4.1.0-4.1.11']
412+
['4.0.0-4.0.2', '4.0.3', '4.0.4-4.0.6', '4.1.0-4.1.2']
413413
[' 4.0.0-4.0.6']
414414
[' 4.0.0-4.0.6']
415415
[' 4.0.0-4.0.1']
416416
[' 4.0.0-4.0.1']
417417
[' Pre-release builds of 4.0.0']
418-
[' 3.0, 3.1-3.1.1, 3.2-3.2.4, 3.3a-3.3.1a']
419-
[' 3.0, 3.1-3.1.1, 3.2-3.2.4, 3.3a-3.3.1']
420-
[' 3.0, 3.1-3.1.1, 3.2-3.2.4, 3.3a-3.3.1']
421-
[' 3.0, 3.1-3.1.1, 3.2-3.2.4, 3.3a']
418+
[' 3.0', '3.1-3.1.1', '3.2-3.2.4', '3.3a-3.3.1a']
419+
[' 3.0', '3.1-3.1.1', '3.2-3.2.4', '3.3a-3.3.1']
420+
[' 3.0', '3.1-3.1.1', '3.2-3.2.4', '3.3a-3.3.1']
421+
[' 3.0', '3.1-3.1.1', '3.2-3.2.4', '3.3a']
422422
[' 3.2.3-3.2.4']
423-
['3.1-3.1.1, 3.2-3.2.4']
424-
['3.1-3.1.1, 3.2-3.2.4']
425-
[' 3.2?, 3.2.1, 3.2.2-3.2.3?']
426-
[' 3.0, 3.1-3.1.1, 3.2-3.2.1']
427-
[' 3.0, 3.1-3.1.1, 3.2-3.2.1']
423+
['3.1-3.1.1', '3.2-3.2.4']
424+
['3.1-3.1.1', '3.2-3.2.4']
425+
[' 3.2?', '3.2.1', '3.2.2-3.2.3?']
426+
[' 3.0', '3.1-3.1.1', '3.2-3.2.1']
427+
[' 3.0', '3.1-3.1.1', '3.2-3.2.1']
428428
[' 3.1']
429429
[' 3.1']
430430
[' 3.0']

0 commit comments

Comments
 (0)