Skip to content

Commit 662ddcb

Browse files
committed
Add tests for purl hash
Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent d139fc7 commit 662ddcb

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

aboutcode/hashid/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_vcid_yml_file_path(vcid: str):
7272
return Path(VULNERABILITY_REPO_NAME) / vulnerability_yml_path(vcid)
7373

7474

75-
# This cuxstom 32 characters alphabet is designed to avoid visually easily confusable characters:
75+
# This custom 32 characters alphabet is designed to avoid visually easily confusable characters:
7676
# i and l
7777
# 0 and o
7878
_base32_alphabet = b"abcdefghjkmnpqrstuvwxyz123456789"
@@ -164,7 +164,7 @@ def get_package_vulnerabilities_yml_file_path(purl: Union[PackageURL, str]):
164164

165165
# We use a 4-tier system for storing package metadata.
166166
# The tiers are as follows:
167-
# 1. Super Large Ecosystem (~5M packages): 2^10 = 1,028 git repositories
167+
# 1. Super Large Ecosystem (~5M packages): 2^10 = 1,024 git repositories
168168
# 2. Large Ecosystem (~500K packages): 2^7 = 128 git repositories
169169
# 3. Medium Ecosystem (~50K packages): 2^5 = 32 git repositories
170170
# 4. Small Ecosystem (~2K packages): 2^0 = 1 git repository
@@ -188,6 +188,7 @@ def get_package_vulnerabilities_yml_file_path(purl: Union[PackageURL, str]):
188188
"composer": 5,
189189
"deb": 5,
190190
"docker": 5,
191+
"gem": 5,
191192
"generic": 5,
192193
"huggingface": 5,
193194
"mlflow": 5,
@@ -200,7 +201,6 @@ def get_package_vulnerabilities_yml_file_path(purl: Union[PackageURL, str]):
200201
"conda": 0,
201202
"cpan": 0,
202203
"cran": 0,
203-
"gem": 0,
204204
"hackage": 0,
205205
"hex": 0,
206206
"luarocks": 0,

aboutcode/hashid/tests/test_hashid.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# Portions Copyright (c) The Python Software Foundation
4+
# VulnerableCode is a trademark of nexB Inc.
5+
# SPDX-License-Identifier: Apache-2.0 and Python-2.0
6+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
7+
# See https://github.com/nexB/vulnerablecode for support or download.
8+
# See https://aboutcode.org for more information about nexB OSS projects.
9+
#
10+
11+
import pytest
12+
13+
from aboutcode.hashid import package_path_elements
14+
15+
16+
@pytest.mark.parametrize(
17+
"purl, purl_hash",
18+
[
19+
("pkg:maven/org.apache.commons/io", "4f"),
20+
("pkg:GOLANG/google.golang.org/genproto@abcdedf#/googleapis/api/annotations/", "4a"),
21+
("pkg:golang/github.com/nats-io/nats-server/v2/[email protected]", "22"),
22+
("pkg:bitbucket/birKenfeld/pyGments-main@244fd47e07d1014f0aed9c", "03"),
23+
("pkg:github/Package-url/purl-Spec@244fd47e07d1004f0aed9c", "095"),
24+
("pkg:deb/debian/[email protected]?arch=i386&distro=jessie", "19"),
25+
(
26+
"pkg:docker/customer/dockerimage@sha256:244fd47e07d1004f0aed9c?repository_url=gcr.io",
27+
"10",
28+
),
29+
("pkg:gem/[email protected]?Platform=java", "1e"),
30+
(
31+
"pkg:Maven/org.apache.xmlgraphics/[email protected]?repositorY_url=repo.spring.io/release&classifier=sources",
32+
"28",
33+
),
34+
(
35+
"pkg:Maven/org.apache.xmlgraphics/[email protected]?repositorY_url=repo.spring.io/release&extension=pom",
36+
"28",
37+
),
38+
("pkg:Maven/net.sf.jacob-project/[email protected]?type=dll&classifier=x86", "17"),
39+
("pkg:npm/%40angular/[email protected]", "323"),
40+
("pkg:Nuget/[email protected]", "63"),
41+
("pkg:PYPI/[email protected]", "00"),
42+
("pkg:composer/guzzlehttp/[email protected]", "1d"),
43+
("pkg:Rpm/fedora/[email protected]?Arch=i386&Distro=fedora-25", "16"),
44+
("pkg:maven/HTTPClient/[email protected]", "4d"),
45+
("pkg:maven/mygroup/[email protected]%20Final?mykey=my%20value", "6f"),
46+
("pkg:npm/@babel/core#/googleapis/api/annotations/", "0dc"),
47+
("pkg:npm/@babel/[email protected]#/googleapis/api/annotations/", "0dc"),
48+
("pkg:npm/[email protected]#/googleapis/api/annotations/", "23b"),
49+
("pkg:npm/core#/googleapis/api/annotations/", "23b"),
50+
],
51+
)
52+
def test_purl_hash(purl, purl_hash):
53+
result_hash, *_ = package_path_elements(purl)
54+
assert result_hash == purl_hash

pyproject-aboutcode.hashid.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ excludes = [
6666
"**/*.bak",
6767
"**/.ipynb_checkpoints",
6868
"aboutcode/hashid/python.LICENSE",
69+
"aboutcode/hashid/tests/**/*",
6970
]
7071

7172
metadata_files = ["apache-2.0.LICENSE", "NOTICE", "aboutcode/hashid/python.LICENSE"]

0 commit comments

Comments
 (0)