|
| 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 |
0 commit comments