Skip to content

Commit

Permalink
feat: npm without lockfiles integration test UNIFY-68
Browse files Browse the repository at this point in the history
  • Loading branch information
adrobuta committed Apr 23, 2024
1 parent f18cbce commit 6dee227
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cliv2/go.mod
Expand Up @@ -88,7 +88,7 @@ require (
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.0 // indirect
github.com/hashicorp/go-getter v1.7.4 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cliv2/go.sum
Expand Up @@ -513,8 +513,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-getter v1.7.0 h1:bzrYP+qu/gMrL1au7/aDvkoOVGUJpeKBgbqRHACAFDY=
github.com/hashicorp/go-getter v1.7.0/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-getter v1.7.4 h1:3yQjWuxICvSpYwqSayAdKRFcvBl1y/vogCxczWSmix0=
github.com/hashicorp/go-getter v1.7.4/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
Expand Down
28 changes: 13 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -116,7 +116,7 @@
"semver": "^6.0.0",
"snyk-config": "^5.0.0",
"snyk-cpp-plugin": "2.24.0",
"snyk-docker-plugin": "6.10.4",
"snyk-docker-plugin": "github:snyk/snyk-docker-plugin#feat/npm-scan-without-lockfiles",
"snyk-go-plugin": "1.23.0",
"snyk-gradle-plugin": "4.1.0",
"snyk-module": "3.1.0",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 36 additions & 0 deletions test/jest/acceptance/snyk-container/container.spec.ts
Expand Up @@ -112,6 +112,42 @@ describe('snyk container', () => {
await expect(cli).toDisplay(`yum @ 4.9.0`, { timeout: 60 * 1000 });
});

it('npm depGraph is generated in an npm image with lockfiles', async () => {
const { code, stdout, stderr } = await runSnykCLIWithDebug(
`container test docker-archive:test/fixtures/container-projects/npm7-with-package-lock-file.tar --print-deps`,
);

assertCliExitCode(code, 1, stderr);
expect(stdout).toContain('Package manager: npm');
});

it('npm depGraph is generated in an npm image without package-lock.json file', async () => {
const { code, stdout, stderr } = await runSnykCLIWithDebug(
`container test docker-archive:test/fixtures/container-projects/npm7-without-package-lock-file.tar --print-deps`,
);

assertCliExitCode(code, 1, stderr);
expect(stdout).toContain('Package manager: npm');
});

it('npm depGraph is generated in an npm image without package-lock.json and package.json file', async () => {
const { code, stdout, stderr } = await runSnykCLIWithDebug(
`container test docker-archive:test/fixtures/container-projects/npm7-without-package-and-lock-file.tar --print-deps`,
);

assertCliExitCode(code, 1, stderr);
expect(stdout).toContain('Package manager: npm');
});

it('npm depGraph is generated in an npm image with lockfiles image', async () => {
const { code, stdout, stderr } = await runSnykCLIWithDebug(
`container test docker-archive:test/fixtures/container-projects/npm7-without-package-lock-file.tar --print-deps`,
);

assertCliExitCode(code, 1, stderr);
expect(stdout).toContain('Package manager: npm');
});

it('finds dependencies in oci image (library/ubuntu)', async () => {
cli = await startSnykCLI(
'container test library/ubuntu@sha256:7a57c69fe1e9d5b97c5fe649849e79f2cfc3bf11d10bbd5218b4eb61716aebe6 --print-deps',
Expand Down
Expand Up @@ -44,12 +44,29 @@ describe('container test projects behavior with --app-vulns, --file and --exclud
);
const jsonOutput = JSON.parse(stdout);
expect(Array.isArray(jsonOutput)).toBeFalsy();
expect(jsonOutput.applications).toBeUndefined();
expect(jsonOutput.ok).toEqual(false);
expect(jsonOutput.uniqueCount).toBeGreaterThan(0);
expect(code).toEqual(1);
}, 30000);

it('should find vulns on an npm project application image without package-lock.json file', async () => {
const { code, stdout } = await runSnykCLI(
`container test docker-archive:test/fixtures/container-projects/npm7-without-package-lock-file.tar --json --app-vulns`,
);
const jsonOutput = JSON.parse(stdout);
expect(Array.isArray(jsonOutput)).toBeFalsy();
expect(jsonOutput.uniqueCount).toBeGreaterThan(0);
expect(code).toEqual(1);
}, 60000);

it('should find vulns on an npm project application image without package.json and package-lock.json file', async () => {
const { code, stdout } = await runSnykCLI(
`container test docker-archive:test/fixtures/container-projects/npm7-without-package-and-lock-file.tar --print-deps --app-vulns`,
);
expect(code).toEqual(1);
expect(stdout).toContain('Package manager: npm');
}, 60000);

it('should show app vulns tip when available', async () => {
const { stdout } = await runSnykCLI(
`container test docker-archive:test/fixtures/container-projects/os-packages-and-app-vulns.tar`,
Expand Down

0 comments on commit 6dee227

Please sign in to comment.