From db34336baa12eb97c5b0c92935b316ed73b40513 Mon Sep 17 00:00:00 2001 From: Or Sagie Date: Thu, 23 Jan 2020 18:36:31 +0200 Subject: [PATCH] feat: enable paket to be autodetected with --all-projects --- src/lib/detect.ts | 1 + .../cli-monitor.all-projects.spec.ts | 74 +++++++++++++++++-- .../cli-test/cli-test.all-projects.spec.ts | 31 +++++++- .../mono-repo-project/packages.config | 4 + .../mono-repo-project/paket.dependencies | 5 ++ .../workspaces/mono-repo-project/paket.lock | 10 +++ 6 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 test/acceptance/workspaces/mono-repo-project/packages.config create mode 100644 test/acceptance/workspaces/mono-repo-project/paket.dependencies create mode 100644 test/acceptance/workspaces/mono-repo-project/paket.lock diff --git a/src/lib/detect.ts b/src/lib/detect.ts index f8a03ec0a2..0fa7bb183b 100644 --- a/src/lib/detect.ts +++ b/src/lib/detect.ts @@ -39,6 +39,7 @@ export const AUTO_DETECTABLE_FILES: string[] = [ 'Gemfile.lock', 'pom.xml', 'packages.config', + 'paket.dependencies', 'project.json', 'project.assets.json', 'Podfile', diff --git a/test/acceptance/cli-monitor/cli-monitor.all-projects.spec.ts b/test/acceptance/cli-monitor/cli-monitor.all-projects.spec.ts index 890c77ca2f..a2c170b5db 100644 --- a/test/acceptance/cli-monitor/cli-monitor.all-projects.spec.ts +++ b/test/acceptance/cli-monitor/cli-monitor.all-projects.spec.ts @@ -26,6 +26,9 @@ export const AllProjectsTests: AcceptanceTests = { t.ok(spyPlugin.withArgs('rubygems').calledOnce, 'calls rubygems plugin'); t.ok(spyPlugin.withArgs('npm').calledOnce, 'calls npm plugin'); t.ok(spyPlugin.withArgs('maven').calledOnce, 'calls maven plugin'); + t.ok(spyPlugin.withArgs('nuget').calledOnce, 'calls nuget plugin'); + t.ok(spyPlugin.withArgs('paket').calledOnce, 'calls nuget plugin'); + // npm t.match( result, @@ -38,18 +41,39 @@ export const AllProjectsTests: AcceptanceTests = { 'rubygems/some/project-id', 'rubygems project was monitored', ); - + // nuget + t.match(result, 'nuget/some/project-id', 'nuget project was monitored'); + // paket + t.match(result, 'paket/some/project-id', 'paket project was monitored'); // maven t.match(result, 'maven/some/project-id', 'maven project was monitored '); // Pop all calls to server and filter out calls to `featureFlag` endpoint const requests = params.server - .popRequests(4) + .popRequests(6) .filter((req) => req.url.includes('/monitor/')); - t.equal(requests.length, 3, 'Correct amount of monitor requests'); + t.equal(requests.length, 5, 'Correct amount of monitor requests'); + + const pluginsWithoutTragetFilesInBody = [ + 'snyk-nodejs-lockfile-parser', + 'bundled:maven', + 'bundled:rubygems', + ]; requests.forEach((req) => { t.match(req.url, '/monitor/', 'puts at correct url'); - t.notOk(req.body.targetFile, "doesn't send the targetFile"); + if ( + pluginsWithoutTragetFilesInBody.includes(req.body.meta.pluginName) + ) { + t.notOk( + req.body.targetFile, + `doesn\'t send the targetFile for ${req.body.meta.pluginName}`, + ); + } else { + t.ok( + req.body.targetFile, + `does send the targetFile ${req.body.meta.pluginName}`, + ); + } t.equal(req.method, 'PUT', 'makes PUT request'); t.equal( req.headers['x-snyk-cli-version'], @@ -147,8 +171,22 @@ export const AllProjectsTests: AcceptanceTests = { detectionDepth: 1, }); // Pop all calls to server and filter out calls to `featureFlag` endpoint - const [rubyAll, npmAll, mavenAll] = params.server - .popRequests(4) + const [ + rubyAll, + npmAll, + nugetAll, + paketAll, + mavenAll, + ] = params.server + .popRequests(6) + .filter((req) => req.url.includes('/monitor/')); + + // nuget + await params.cli.monitor('mono-repo-project', { + file: 'packages.config', + }); + const [requestsNuget] = params.server + .popRequests(2) .filter((req) => req.url.includes('/monitor/')); // Ruby @@ -175,6 +213,14 @@ export const AllProjectsTests: AcceptanceTests = { .popRequests(2) .filter((req) => req.url.includes('/monitor/')); + // paket + await params.cli.monitor('mono-repo-project', { + file: 'paket.dependencies', + }); + const [requestsPaket] = params.server + .popRequests(2) + .filter((req) => req.url.includes('/monitor/')); + // Ruby project t.deepEqual( @@ -191,6 +237,14 @@ export const AllProjectsTests: AcceptanceTests = { 'Same body for --all-projects and --file=package-lock.json', ); + // NUGET project + + t.deepEqual( + nugetAll.body, + requestsNuget.body, + 'Same body for --all-projects and --file=packages.config', + ); + // Maven project t.deepEqual( @@ -198,6 +252,14 @@ export const AllProjectsTests: AcceptanceTests = { requestsMaven.body, 'Same body for --all-projects and --file=pom.xml', ); + + // Paket project + + t.deepEqual( + paketAll.body, + requestsPaket.body, + 'Same body for --all-projects and --file=paket.dependencies', + ); }, '`monitor mono-repo-project with lockfiles --all-projects --json`': ( params, diff --git a/test/acceptance/cli-test/cli-test.all-projects.spec.ts b/test/acceptance/cli-test/cli-test.all-projects.spec.ts index c15ca205d0..c2d1e5c8b8 100644 --- a/test/acceptance/cli-test/cli-test.all-projects.spec.ts +++ b/test/acceptance/cli-test/cli-test.all-projects.spec.ts @@ -21,8 +21,10 @@ export const AllProjectsTests: AcceptanceTests = { t.ok(spyPlugin.withArgs('rubygems').calledOnce, 'calls rubygems plugin'); t.ok(spyPlugin.withArgs('npm').calledOnce, 'calls npm plugin'); t.ok(spyPlugin.withArgs('maven').calledOnce, 'calls maven plugin'); + t.ok(spyPlugin.withArgs('nuget').calledOnce, 'calls nuget plugin'); + t.ok(spyPlugin.withArgs('paket').calledOnce, 'calls nuget plugin'); - params.server.popRequests(3).forEach((req) => { + params.server.popRequests(5).forEach((req) => { t.equal(req.method, 'POST', 'makes POST request'); t.equal( req.headers['x-snyk-cli-version'], @@ -33,7 +35,7 @@ export const AllProjectsTests: AcceptanceTests = { t.ok(req.body.depGraph, 'body contains depGraph'); t.match( req.body.depGraph.pkgManager.name, - /(npm|rubygems|maven)/, + /(npm|rubygems|maven|nuget|paket)/, 'depGraph has package manager', ); }); @@ -86,14 +88,26 @@ export const AllProjectsTests: AcceptanceTests = { const [ rubyAllProjectsBody, npmAllProjectsBody, + nugetAllProjectsBody, + paketAllProjectsBody, mavenAllProjectsBody, - ] = params.server.popRequests(3).map((req) => req.body); + ] = params.server.popRequests(5).map((req) => req.body); await params.cli.test('mono-repo-project', { file: 'Gemfile.lock', }); const { body: rubyFileBody } = params.server.popRequest(); + await params.cli.test('mono-repo-project', { + file: 'paket.dependencies', + }); + const { body: paketFileBody } = params.server.popRequest(); + + await params.cli.test('mono-repo-project', { + file: 'packages.config', + }); + const { body: nugetFileBody } = params.server.popRequest(); + await params.cli.test('mono-repo-project', { file: 'package-lock.json', }); @@ -116,6 +130,17 @@ export const AllProjectsTests: AcceptanceTests = { 'Same body for --all-projects and --file=package-lock.json', ); + t.same( + paketAllProjectsBody, + paketFileBody, + 'Same body for --all-projects and --file=package-lock.json', + ); + + t.same( + nugetAllProjectsBody, + nugetFileBody, + 'Same body for --all-projects and --file=package-lock.json', + ); t.same( mavenAllProjectsBody, mavenFileBody, diff --git a/test/acceptance/workspaces/mono-repo-project/packages.config b/test/acceptance/workspaces/mono-repo-project/packages.config new file mode 100644 index 0000000000..5264819b56 --- /dev/null +++ b/test/acceptance/workspaces/mono-repo-project/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/test/acceptance/workspaces/mono-repo-project/paket.dependencies b/test/acceptance/workspaces/mono-repo-project/paket.dependencies new file mode 100644 index 0000000000..21a28f61e1 --- /dev/null +++ b/test/acceptance/workspaces/mono-repo-project/paket.dependencies @@ -0,0 +1,5 @@ +redirects: on +source https://nuget.org/api/v2 + +nuget FSharp.Formatting +nuget FAKE diff --git a/test/acceptance/workspaces/mono-repo-project/paket.lock b/test/acceptance/workspaces/mono-repo-project/paket.lock new file mode 100644 index 0000000000..edd5b3f9b1 --- /dev/null +++ b/test/acceptance/workspaces/mono-repo-project/paket.lock @@ -0,0 +1,10 @@ +REDIRECTS: ON +NUGET + remote: https://www.nuget.org/api/v2 + FAKE (5.8.4) + FSharp.Compiler.Service (2.0.0.6) + FSharp.Formatting (2.14.4) + FSharp.Compiler.Service (2.0.0.6) + FSharpVSPowerTools.Core (>= 2.3 < 2.4) + FSharpVSPowerTools.Core (2.3) + FSharp.Compiler.Service (>= 2.0.0.3)