-
Notifications
You must be signed in to change notification settings - Fork 25
fix: CN-482 use correct falsy checks #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tyler-catlin
wants to merge
6
commits into
main
Choose a base branch
from
CN-482-use-correct-falsy-checks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+220
−12
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d75d16c
fix: correctly check for existence, add tests for that
tyler-catlin 6673b26
fix: order imports alphabetically
tyler-catlin a8ca96e
fix: linting
tyler-catlin ee5689a
fix: use correct url parsed strings to check for versions
tyler-catlin 43ccebf
fix: update dependent snapshots
tyler-catlin 9fbfdc9
fix: disable containerd when generating snapshots
tyler-catlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,8 +1,216 @@ | ||
| import { PackageInfo } from "@snyk/rpm-parser/lib/rpm/types"; | ||
| import * as fs from "fs"; | ||
| import * as path from "path"; | ||
| import { parseSourceRPM } from "../../../../lib/analyzer/package-managers/rpm"; | ||
| import { | ||
| analyze, | ||
| mapRpmSqlitePackages, | ||
| parseSourceRPM, | ||
| } from "../../../../lib/analyzer/package-managers/rpm"; | ||
| import { SourcePackage } from "../../../../lib/analyzer/types"; | ||
|
|
||
| describe("RPM Package Version and Epoch Handling", () => { | ||
| describe("formats version without epoch", () => { | ||
| it("should format version string correctly", () => { | ||
| const mappedResults = mapRpmSqlitePackages( | ||
| "test-image", | ||
| [ | ||
| { | ||
| name: "bash", | ||
| version: "5.1.16", | ||
| release: "4.el9", | ||
| size: 1024, | ||
| }, | ||
| ], | ||
| [], | ||
| ); | ||
|
|
||
| expect(mappedResults.Analysis).toHaveLength(1); | ||
| expect(mappedResults.Analysis[0].Name).toBe("bash"); | ||
| expect(mappedResults.Analysis[0].Version).toBe("5.1.16-4.el9"); | ||
| expect(mappedResults.Analysis[0].Purl).toBe("pkg:rpm/[email protected]"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("formats version with epoch == 0", () => { | ||
| it("should include epoch=0 in PURL qualifier (bug fix)", () => { | ||
| const mappedResults = mapRpmSqlitePackages( | ||
| "test-image", | ||
| [ | ||
| { | ||
| name: "libarchive", | ||
| version: "3.7.7", | ||
| release: "4.el10_0", | ||
| epoch: 0, | ||
| size: 2048, | ||
| }, | ||
| ], | ||
| [], | ||
| ); | ||
|
|
||
| expect(mappedResults.Analysis).toHaveLength(1); | ||
| expect(mappedResults.Analysis[0].Name).toBe("libarchive"); | ||
| expect(mappedResults.Analysis[0].Version).toBe("3.7.7-4.el10_0"); | ||
| // Critical: epoch=0 must be explicitly included in PURL | ||
| expect(mappedResults.Analysis[0].Purl).toBe( | ||
| "pkg:rpm/[email protected]_0?epoch=0", | ||
| ); | ||
| }); | ||
|
|
||
| it("should include epoch=0 with distro qualifier", () => { | ||
| const mappedResults = mapRpmSqlitePackages( | ||
| "test-image", | ||
| [ | ||
| { | ||
| name: "sqlite-libs", | ||
| version: "3.34.1", | ||
| release: "5.el8", | ||
| epoch: 0, | ||
| size: 1500, | ||
| }, | ||
| ], | ||
| [], | ||
| { name: "rhel", version: "8.5" }, | ||
| ); | ||
|
|
||
| expect(mappedResults.Analysis[0].Purl).toBe( | ||
| "pkg:rpm/rhel/[email protected]?distro=rhel-8.5&epoch=0", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("formats version with non-zero epoch", () => { | ||
| it("should format version with epoch=1", () => { | ||
| const mappedResults = mapRpmSqlitePackages( | ||
| "test-image", | ||
| [ | ||
| { | ||
| name: "findutils", | ||
| version: "4.5.11", | ||
| release: "6.amzn2", | ||
| epoch: 1, | ||
| size: 3000, | ||
| }, | ||
| ], | ||
| [], | ||
| ); | ||
|
|
||
| expect(mappedResults.Analysis[0].Name).toBe("findutils"); | ||
| expect(mappedResults.Analysis[0].Version).toBe("1:4.5.11-6.amzn2"); | ||
| expect(mappedResults.Analysis[0].Purl).toBe( | ||
| "pkg:rpm/findutils@1:4.5.11-6.amzn2?epoch=1", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("epoch consistency across functions", () => { | ||
| it("should handle epoch=0 consistently in analyze() function", async () => { | ||
| const pkgs: PackageInfo[] = [ | ||
| { | ||
| name: "openssl-libs", | ||
| version: "1.1.1", | ||
| release: "15.el8", | ||
| epoch: 0, | ||
| size: 6000, | ||
| }, | ||
| ]; | ||
|
|
||
| const result = await analyze("test-image", pkgs, [], { | ||
| name: "rhel", | ||
| version: "8.2", | ||
| }); | ||
|
|
||
| expect(result.Analysis[0].Purl).toBe( | ||
| "pkg:rpm/rhel/[email protected]?distro=rhel-8.2&epoch=0", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("multiple packages with different epochs", () => { | ||
| it("should correctly handle mixed epoch values", () => { | ||
| const packages: PackageInfo[] = [ | ||
| { | ||
| name: "pkg-no-epoch", | ||
| version: "1.0.0", | ||
| release: "1", | ||
| size: 100, | ||
| }, | ||
| { | ||
| name: "pkg-epoch-zero", | ||
| version: "2.0.0", | ||
| release: "1", | ||
| epoch: 0, | ||
| size: 200, | ||
| }, | ||
| { | ||
| name: "pkg-epoch-one", | ||
| version: "3.0.0", | ||
| release: "1", | ||
| epoch: 1, | ||
| size: 300, | ||
| }, | ||
| ]; | ||
|
|
||
| const result = mapRpmSqlitePackages("test-image", packages, []); | ||
|
|
||
| expect(result.Analysis[0].Purl).toBe("pkg:rpm/[email protected]"); | ||
| expect(result.Analysis[1].Purl).toBe( | ||
| "pkg:rpm/[email protected]?epoch=0", | ||
| ); | ||
| expect(result.Analysis[2].Purl).toBe( | ||
| "pkg:rpm/pkg-epoch-one@1:3.0.0-1?epoch=1", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("epoch with repositories and modules", () => { | ||
| it("should include epoch with other qualifiers", () => { | ||
| const result = mapRpmSqlitePackages( | ||
| "test-image", | ||
| [ | ||
| { | ||
| name: "nodejs", | ||
| version: "10.21.0", | ||
| release: "3.module+el8.2.0", | ||
| epoch: 1, | ||
| module: "nodejs:10", | ||
| size: 7000, | ||
| }, | ||
| ], | ||
| ["rhel-8-appstream"], | ||
| { name: "rhel", version: "8.2" }, | ||
| ); | ||
|
|
||
| const purl = result.Analysis[0].Purl; | ||
| expect(purl).toContain("?"); | ||
| expect(purl).toContain("epoch=1"); | ||
| expect(purl).toContain("module=nodejs%3A10"); // : is URL-encoded as %3A | ||
| expect(purl).toContain("repositories=rhel-8-appstream"); | ||
| expect(purl).toContain("distro=rhel-8.2"); | ||
| }); | ||
|
|
||
| it("should include epoch=0 with sourceRPM upstream qualifier", () => { | ||
| const result = mapRpmSqlitePackages( | ||
| "test-image", | ||
| [ | ||
| { | ||
| name: "libxml2", | ||
| version: "2.9.7", | ||
| release: "14.el8", | ||
| epoch: 0, | ||
| sourceRPM: "libxml2-2.9.7-14.el8.src.rpm", | ||
| size: 8000, | ||
| }, | ||
| ], | ||
| [], | ||
| ); | ||
|
|
||
| const purl = result.Analysis[0].Purl; | ||
| expect(purl).toContain("epoch=0"); | ||
| expect(purl).toContain("upstream=libxml2%402.9.7"); // @ is URL-encoded as %40 | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("parseSourceRPM", () => { | ||
| it("should correctly parse all valid source RPM strings from source_rpms.csv", () => { | ||
| const csvFilePath = path.join( | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2662,15 +2662,15 @@ Object { | |
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-CGI", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&upstream=perl%405.10.1", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&epoch=0&upstream=perl%405.10.1", | ||
| "version": "3.51-144.el6", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-ExtUtils-MakeMaker", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&upstream=perl%405.10.1", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&epoch=0&upstream=perl%405.10.1", | ||
| "version": "6.55-144.el6", | ||
| }, | ||
| }, | ||
|
|
@@ -2710,15 +2710,15 @@ Object { | |
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-Test-Harness", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&upstream=perl%405.10.1", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&epoch=0&upstream=perl%405.10.1", | ||
| "version": "3.17-144.el6", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-Test-Simple", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&upstream=perl%405.10.1", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&epoch=0&upstream=perl%405.10.1", | ||
| "version": "0.92-144.el6", | ||
| }, | ||
| }, | ||
|
|
@@ -5902,15 +5902,15 @@ Object { | |
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-CGI", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&upstream=perl%405.10.1", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&epoch=0&upstream=perl%405.10.1", | ||
| "version": "3.51-144.el6", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-ExtUtils-MakeMaker", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&upstream=perl%405.10.1", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&epoch=0&upstream=perl%405.10.1", | ||
| "version": "6.55-144.el6", | ||
| }, | ||
| }, | ||
|
|
@@ -5950,15 +5950,15 @@ Object { | |
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-Test-Harness", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&upstream=perl%405.10.1", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&epoch=0&upstream=perl%405.10.1", | ||
| "version": "3.17-144.el6", | ||
| }, | ||
| }, | ||
| Object { | ||
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-Test-Simple", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&upstream=perl%405.10.1", | ||
| "purl": "pkg:rpm/centos/[email protected]?distro=centos-6&epoch=0&upstream=perl%405.10.1", | ||
| "version": "0.92-144.el6", | ||
| }, | ||
| }, | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5110,7 +5110,7 @@ Object { | |
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-Errno", | ||
| "purl": "pkg:rpm/rhel/[email protected]?distro=rhel-8.2&repositories=rhel-8-for-x86_64-baseos-rpms%2Crhel-8-for-x86_64-appstream-rpms%2Crhel-8-for-x86_64-baseos-beta-rpms%2Crhel-8-for-x86_64-appstream-beta-rpms%2Crhel-8-for-x86_64-baseos-htb-rpms%2Crhel-8-for-x86_64-appstream-htb-rpms&upstream=perl%405.26.3", | ||
| "purl": "pkg:rpm/rhel/[email protected]?distro=rhel-8.2&epoch=0&repositories=rhel-8-for-x86_64-baseos-rpms%2Crhel-8-for-x86_64-appstream-rpms%2Crhel-8-for-x86_64-baseos-beta-rpms%2Crhel-8-for-x86_64-appstream-beta-rpms%2Crhel-8-for-x86_64-baseos-htb-rpms%2Crhel-8-for-x86_64-appstream-htb-rpms&upstream=perl%405.26.3", | ||
| "version": "1.28-416.el8", | ||
| }, | ||
| }, | ||
|
|
@@ -5174,7 +5174,7 @@ Object { | |
| "id": "[email protected]", | ||
| "info": Object { | ||
| "name": "perl-IO", | ||
| "purl": "pkg:rpm/rhel/[email protected]?distro=rhel-8.2&repositories=rhel-8-for-x86_64-baseos-rpms%2Crhel-8-for-x86_64-appstream-rpms%2Crhel-8-for-x86_64-baseos-beta-rpms%2Crhel-8-for-x86_64-appstream-beta-rpms%2Crhel-8-for-x86_64-baseos-htb-rpms%2Crhel-8-for-x86_64-appstream-htb-rpms&upstream=perl%405.26.3", | ||
| "purl": "pkg:rpm/rhel/[email protected]?distro=rhel-8.2&epoch=0&repositories=rhel-8-for-x86_64-baseos-rpms%2Crhel-8-for-x86_64-appstream-rpms%2Crhel-8-for-x86_64-baseos-beta-rpms%2Crhel-8-for-x86_64-appstream-beta-rpms%2Crhel-8-for-x86_64-baseos-htb-rpms%2Crhel-8-for-x86_64-appstream-htb-rpms&upstream=perl%405.26.3", | ||
| "version": "1.38-416.el8", | ||
| }, | ||
| }, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle
pkg.epoch = 0correctly? I'm not too familiar with thedumpster firewonderful joy that is true/false checks in JS, and I'm also not familiar with the pkg.epochThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disregard this, I need to learn to read the full PR message before looking at the code