-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(RELEASE-1345): avoid failing on invalid purl string
The sboms can contain invalid non-rpm purl strings and we would fail on parsing them using the packageurl module. Avoid these failures by parsing the purl type in our own function and only pass it to packageurl if it's an rpm purl. Otherwise skip it. Signed-off-by: Martin Malina <[email protected]>
- Loading branch information
Showing
4 changed files
with
108 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
update_container_content_sets, | ||
load_sbom_packages, | ||
construct_rpm_items_and_content_sets, | ||
get_purl_type, | ||
) | ||
|
||
GRAPHQL_API = "myapiurl" | ||
|
@@ -458,3 +459,25 @@ def test_construct_rpm_items_and_content_sets__no_packages_result_in_empty_list( | |
|
||
assert rpms == [] | ||
assert content_sets == [] | ||
|
||
|
||
def test_get_purl_type__rpm(): | ||
purl = ( | ||
"pkg:rpm/rhel/[email protected]?arch=x86_64&upstream=acl-2.3.1-4.el9.src.rpm" | ||
"&distro=rhel-9.4&repository_id=myrepo3" | ||
) | ||
|
||
type = get_purl_type(purl) | ||
|
||
assert type == "rpm" | ||
|
||
|
||
def test_get_purl_type__invalid_docker(): | ||
"""This is an invalid purl that packageurl.PackageURL.from_string() would fail on, | ||
but we can still get the type successfully. | ||
""" | ||
purl = "pkg:github/docker:/#docker.mirror.hashicorp.services/rhysd/actionlint:latest" | ||
|
||
type = get_purl_type(purl) | ||
|
||
assert type == "github" |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
load_sbom_components, | ||
check_bom_ref_duplicates, | ||
construct_rpm_items_and_content_sets, | ||
get_purl_type, | ||
) | ||
|
||
GRAPHQL_API = "myapiurl" | ||
|
@@ -435,3 +436,25 @@ def test_construct_rpm_items_and_content_sets__no_components_result_in_empty_lis | |
|
||
assert rpms == [] | ||
assert content_sets == [] | ||
|
||
|
||
def test_get_purl_type__rpm(): | ||
purl = ( | ||
"pkg:rpm/rhel/[email protected]?arch=x86_64&upstream=acl-2.3.1-4.el9.src.rpm" | ||
"&distro=rhel-9.4&repository_id=myrepo3" | ||
) | ||
|
||
type = get_purl_type(purl) | ||
|
||
assert type == "rpm" | ||
|
||
|
||
def test_get_purl_type__invalid_docker(): | ||
"""This is an invalid purl that packageurl.PackageURL.from_string() would fail on, | ||
but we can still get the type successfully. | ||
""" | ||
purl = "pkg:github/docker:/#docker.mirror.hashicorp.services/rhysd/actionlint:latest" | ||
|
||
type = get_purl_type(purl) | ||
|
||
assert type == "github" |
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