-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor parse_purl and update intergration test
- Loading branch information
Showing
7 changed files
with
271 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,37 +15,12 @@ | |
|
||
import unittest | ||
|
||
from server import _match_purl | ||
from server import should_skip_bucket | ||
from packageurl import PackageURL | ||
|
||
|
||
class ServerTest(unittest.TestCase): | ||
"""Server tests.""" | ||
|
||
def test_match_purl(self): | ||
"""Test PURL generation for PyPI.""" | ||
|
||
test_cases = [ | ||
# Version diffs are ignored | ||
('pkg:pypi/django', 'pkg:pypi/[email protected]', True), | ||
('pkg:deb/debian/[email protected]+deb10u3', | ||
'pkg:deb/debian/[email protected]+deb10u4', True), | ||
# Different packages do not match | ||
('pkg:deb/debian/[email protected]+deb10u3', | ||
'pkg:deb/debian/[email protected]+deb10u3', False), | ||
('pkg:deb/debian/[email protected]+deb10u3?arch=amd64', | ||
'pkg:deb/debian/[email protected]?arch=source', True), | ||
('pkg:deb/debian/[email protected]+deb10u3?distro=debian-10', | ||
'pkg:deb/debian/[email protected]?arch=source', True), | ||
] | ||
|
||
for a, b, expected in test_cases: | ||
self.assertEqual( | ||
expected, | ||
_match_purl(PackageURL.from_string(a), PackageURL.from_string(b)), | ||
a + ' == ' + b) | ||
|
||
def test_should_skip_bucket(self): | ||
"""Test should_skip_bucket.""" | ||
test_cases = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,91 @@ def test_swift(self): | |
purl_helpers.package_to_purl('SwiftURL', | ||
'github.com/Alamofire/Alamofire')) | ||
|
||
def test_parse_purl(self): | ||
"""Test parse purl""" | ||
self.assertEqual( | ||
('Alpine', 'postgresql14', None), | ||
purl_helpers.parse_purl('pkg:apk/alpine/postgresql14?arch=source')) | ||
|
||
self.assertEqual(('Bitnami', 'moodl', None), | ||
purl_helpers.parse_purl('pkg:bitnami/moodl')) | ||
|
||
self.assertEqual(('Chainguard', 'solr', None), | ||
purl_helpers.parse_purl('pkg:apk/chainguard/solr')) | ||
|
||
self.assertEqual(('crates.io', 'surrealdb', '2.1.0'), | ||
purl_helpers.parse_purl('pkg:cargo/[email protected]')) | ||
|
||
self.assertEqual(('Debian', 'mpg123', '1.26.4-1+deb11u1'), | ||
purl_helpers.parse_purl( | ||
'pkg:deb/debian/[email protected]+deb11u1?arch=source')) | ||
|
||
self.assertEqual(('Go', 'github.com/treeverse/lakefs', '1.33.0'), | ||
purl_helpers.parse_purl( | ||
'pkg:golang/github.com/treeverse/[email protected]')) | ||
|
||
self.assertEqual(('Hackage', 'process', None), | ||
purl_helpers.parse_purl('pkg:hackage/process')) | ||
|
||
self.assertEqual(('Hex', 'test-package', None), | ||
purl_helpers.parse_purl('pkg:hex/test-package')) | ||
|
||
self.assertEqual( | ||
('Maven', 'test-package', '1.0.0'), | ||
purl_helpers.parse_purl('pkg:maven/com.example/[email protected]')) | ||
|
||
self.assertEqual(('npm', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:npm/[email protected]')) | ||
|
||
self.assertEqual(('NuGet', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:nuget/[email protected]')) | ||
|
||
self.assertEqual( | ||
('openSUSE', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:rpm/opensuse/[email protected]')) | ||
|
||
self.assertEqual(('OSS-Fuzz', 'test-package', None), | ||
purl_helpers.parse_purl('pkg:generic/test-package')) | ||
|
||
self.assertEqual(('Packagist', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:composer/[email protected]')) | ||
|
||
self.assertEqual(('Pub', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:pub/[email protected]')) | ||
|
||
self.assertEqual(('PyPI', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:pypi/[email protected]')) | ||
|
||
self.assertEqual( | ||
('Red Hat', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:rpm/redhat/[email protected]')) | ||
|
||
self.assertEqual( | ||
('Rocky Linux', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:rpm/rocky-linux/[email protected]')) | ||
|
||
self.assertEqual(('RubyGems', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:gem/[email protected]')) | ||
|
||
self.assertEqual(('SUSE', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:rpm/suse/[email protected]')) | ||
|
||
self.assertEqual(('SwiftURL', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:swift/[email protected]')) | ||
|
||
self.assertEqual(('Ubuntu', 'pygments', '2.11.2+dfsg-2ubuntu0.1'), | ||
purl_helpers.parse_purl( | ||
'pkg:deb/ubuntu/[email protected]+dfsg-2ubuntu0.1')) | ||
|
||
self.assertEqual( | ||
('Wolfi', 'test-package', '1.2.3'), | ||
purl_helpers.parse_purl('pkg:apk/wolfi/[email protected]')) | ||
|
||
self.assertEqual(None, purl_helpers.parse_purl('pkg:bad/ubuntu/pygments')) | ||
|
||
self.assertEqual( | ||
None, purl_helpers.parse_purl('purl:apk/wolfi/[email protected]')) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |