Repository navigation
Conversation
Split the integrity value on whitespace and test each SRI token, so a multi-hash string such as "sha512-… sha1-…" yields a supported hash (SHA-512 first, per the pre-sorted list) instead of throwing RangeError. This also fixes ExternalReferenceFactory.makeDist leaving hashes empty for such packages. Fixes CycloneDX#1544 Signed-off-by: Tariq Mahmood <t.ali1993@hotmail.com>
Add test cases for whitespace-separated multi-hash SRI strings: the SHA-512 digest is extracted whether it is the first or the second token, SHA-1 wins over SHA-256 per the pre-sorted list, and a string with no supported hash still throws RangeError. Signed-off-by: Tariq Mahmood <t.ali1993@hotmail.com>
The test file rewrite mistyped "my-own=registry" as "my-own-registry"; restore the original line so the diff only adds the new test cases. Signed-off-by: Tariq Mahmood <t.ali1993@hotmail.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
jkowalleck
left a comment
There was a problem hiding this comment.
Thanks for working on this.
While I like minimal non-breaking changes, I think this can be improved -see my comments.
|
Signed-off-by: Tariq Mahmood <t.ali1993@hotmail.com>
Signed-off-by: Tariq Mahmood <t.ali1993@hotmail.com>
Signed-off-by: Tariq Mahmood <t.ali1993@hotmail.com>
Signed-off-by: Tariq Mahmood <t.ali1993@hotmail.com>
Signed-off-by: Tariq Mahmood <t.ali1993@hotmail.com>
|
Thanks for the review, @jkowalleck — addressed in the two new commits:
I could not run the build or tests locally; please let CI verify. Ready for another look. |
| [[HashAlgorithm['SHA-384'], | ||
| 'a2a56e01f5d129aa7b7dd81c098e6eca433af91f46a90f0afeec72f6bc7b1cd42519897590fcd0868d70c7827063cc02']] | ||
| ], | ||
| ['sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg== sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=', |
There was a problem hiding this comment.
this is a bit hard to read.
could you reformat this like
['sha512-/... sha1-2Klr13/...', [
[HashAlgorithm['SHA-512'], '...'],
[HashAlgorithm['SHA-1'], '...'],
]]|
please sig of your commits - see https://github.com/CycloneDX/cyclonedx-javascript-library/blob/main/CONTRIBUTING.md#sign-off-your-commits see https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1545/checks?check_run_id=140319704043 on how to do this after the commits happened. |
Description
parsePackageIntegritycompared the whole integrity value against single-hash patterns anchored with^...$, so a whitespace-separated multi-hash SRI string (for examplesha512-… sha1-…frompackage-lock.json) threwRangeError: unparsable value.ExternalReferenceFactory.makeDistcaught that error, leaving the distribution reference's hashes empty.This PR splits the integrity value on whitespace and tests each token, returning the first supported hash in the pre-sorted list's order (SHA-512 first). A multi-hash string now yields the SHA-512 digest and
makeDistrecords it. A string with no supported hash still throwsRangeError. Added unit tests for multi-hash inputs and for a multi-hash string with no supported hash.I could not run the build or tests locally. Please let CI run the checks; happy to address any feedback.
Resolves or fixes issue: #1544
AI Tool Disclosure
Muse (browser agent, acting for the contributor via the GitHub web editor)Muse SparkFix issue #1544: make parsePackageIntegrity handle whitespace-separated multi-hash SRI strings and add unit test coverage for it.Affirmation