Skip to content

Commit 8b8a952

Browse files
authored
Fixes #142, #143 (#144)
Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent bbadb5f commit 8b8a952

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "appthreat-vulnerability-db"
3-
version = "6.0.5"
3+
version = "6.0.6"
44
description = "AppThreat's vulnerability database and package search library with a built-in sqlite based storage. OSV, CVE, GitHub, npm are the primary sources of vulnerabilities."
55
authors = [
66
{name = "Team AppThreat", email = "[email protected]"},

test/test_utils.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from vdb.lib import utils as utils
1+
from vdb.lib import utils
22

33

44
def test_normalise():
@@ -225,7 +225,7 @@ def test_version_build_compare():
225225

226226

227227
def test_version_build_compare1():
228-
sver, srest = utils.convert_to_semver("2.1.5.1-r3")
228+
sver, _ = utils.convert_to_semver("2.1.5.1-r3")
229229
assert sver
230230
res = utils.version_compare("2.1.5.1-r3", "1.2.1-r0", "2.1.5.1-r1")
231231
assert not res
@@ -631,7 +631,7 @@ def test_redhat_build_compare():
631631

632632

633633
def test_parse_uri():
634-
vendor, package, version, cve_type = utils.parse_cpe(
634+
vendor, package, version, _ = utils.parse_cpe(
635635
"cpe:2.3:o:google:android:9.0:*:*:*:*:*:*:*"
636636
)
637637
assert vendor == "google"
@@ -888,6 +888,18 @@ def test_purl_vers_convert():
888888
],
889889
"vers:deb/53.5",
890890
),
891+
(
892+
"generic",
893+
[
894+
{
895+
"version": "0.0.0",
896+
"status": "affected",
897+
"versionType": "generic",
898+
"lessThan": "001a3278b5572e52c0ecac0bd1157bf2599502b7",
899+
}
900+
],
901+
"vers:generic/<001a3278b5572e52c0ecac0bd1157bf2599502b7",
902+
),
891903
]
892904
for tt in test_tuples:
893905
assert utils.to_purl_vers(tt[0], tt[1]) == tt[2]
@@ -992,6 +1004,16 @@ def test_url_to_purl():
9921004
"qualifiers": None,
9931005
"subpath": None,
9941006
}
1007+
assert utils.url_to_purl(
1008+
"https://www.github.com/kiwitcms/kiwi/commit/ffb00450be52fe11a82a2507632c2328cae4ec9d"
1009+
) == {
1010+
"type": "github",
1011+
"namespace": "kiwitcms",
1012+
"name": "kiwi",
1013+
"version": "ffb00450be52fe11a82a2507632c2328cae4ec9d",
1014+
"qualifiers": None,
1015+
"subpath": None,
1016+
}
9951017

9961018

9971019
def test_vers_compare():

vdb/lib/utils.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ def __init__(self, msg):
5959

6060

6161
def load(d):
62-
"""Parses a python object from a JSON string. Every Object which should be loaded needs a constuctor that doesn't need any Arguments.
63-
Arguments: Dict object; the module which contains the class, the parsed object is instance of.
62+
"""
63+
Parses a python object from a JSON string.
64+
Every Object which should be loaded needs a constuctor that doesn't need any Arguments.
65+
Arguments: Dict object; the module which contains the class,
66+
the parsed object is instance of.
6467
"""
6568

6669
def _load(d1):
@@ -610,9 +613,11 @@ def version_compare(
610613
return False
611614
if mae:
612615
if VersionInfo.is_valid(compare_ver) and VersionInfo.is_valid(mae):
613-
cmp_value = VersionInfo.parse(compare_ver, optional_minor_and_patch=True).compare(mae)
616+
cmp_value = VersionInfo.parse(
617+
compare_ver, optional_minor_and_patch=True
618+
).compare(mae)
614619
return cmp_value < 0
615-
elif "." not in compare_ver and "." not in mae:
620+
if "." not in compare_ver and "." not in mae:
616621
compare_ver = re.split(r"[+~]", compare_ver)[0]
617622
mae = re.split(r"[+~]", mae)[0]
618623
exnum = list(filter(str.isdigit, compare_ver))
@@ -651,8 +656,12 @@ def version_compare(
651656
# Perform semver match once we have all the required versions
652657
if compare_ver and min_version and max_version:
653658
if semver_compatible(compare_ver, min_version, max_version):
654-
min_value = VersionInfo.parse(compare_ver, optional_minor_and_patch=True).compare(min_version)
655-
max_value = VersionInfo.parse(compare_ver, optional_minor_and_patch=True).compare(max_version)
659+
min_value = VersionInfo.parse(
660+
compare_ver, optional_minor_and_patch=True
661+
).compare(min_version)
662+
max_value = VersionInfo.parse(
663+
compare_ver, optional_minor_and_patch=True
664+
).compare(max_version)
656665
min_check = min_value > 0 if is_min_exclude else min_value >= 0
657666
max_check = max_value < 0 if is_max_exclude else max_value <= 0
658667
return min_check and max_check
@@ -1099,7 +1108,11 @@ def to_purl_vers(vendor: str, versions: list) -> str:
10991108
else:
11001109
vers_list.append(f">={version}")
11011110
if less_than and less_than != "*" and not less_than_or_equal:
1102-
vers_list.append(f"<{less_than}")
1111+
# Fix for #142
1112+
if version == "0.0.0" and check_hex(less_than):
1113+
vers_list = [f"<{less_than}"]
1114+
else:
1115+
vers_list.append(f"<{less_than}")
11031116
if not less_than and less_than_or_equal:
11041117
if less_than_or_equal == "*":
11051118
vers_list.append("*")
@@ -1152,9 +1165,10 @@ def url_to_purl(url: str) -> dict | None:
11521165
url_obj = urlparse(f"https://{git_repo_name}")
11531166
# Fix for #112
11541167
pkg_type = "generic"
1155-
hostname = url_obj.hostname
1156-
if url_obj.hostname in ("github.com", "gitlab.com"):
1157-
pkg_type = url_obj.hostname.removesuffix(".com")
1168+
# Fix for #143
1169+
hostname = url_obj.hostname.removeprefix("www.")
1170+
if hostname in ("github.com", "gitlab.com"):
1171+
pkg_type = hostname.removesuffix(".com")
11581172
git_repo_name = url_obj.path
11591173
hostname = None
11601174
# Filter repo names without a path

0 commit comments

Comments
 (0)