From cdb6de4fd8ff9e4d989070b290ce4d9713b60ce9 Mon Sep 17 00:00:00 2001 From: Liliana Kastilio Date: Mon, 27 Jan 2020 15:28:33 +0000 Subject: [PATCH] feat: enable composer.lock for --all-projects Auto detect and scan Composer (Php) projects when `snyk test` or `snyk monitor` is run with `--all-projects` --- src/lib/detect.ts | 1 + .../cli-monitor.all-projects.spec.ts | 29 +++++++++++++++++ .../cli-test/cli-test.all-projects.spec.ts | 31 +++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/src/lib/detect.ts b/src/lib/detect.ts index f8a03ec0a2..b7ecbc0db4 100644 --- a/src/lib/detect.ts +++ b/src/lib/detect.ts @@ -43,6 +43,7 @@ export const AUTO_DETECTABLE_FILES: string[] = [ 'project.assets.json', 'Podfile', 'Podfile.lock', + 'composer.lock', ]; // when file is specified with --file, we look it up here 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..ffe357a0ad 100644 --- a/test/acceptance/cli-monitor/cli-monitor.all-projects.spec.ts +++ b/test/acceptance/cli-monitor/cli-monitor.all-projects.spec.ts @@ -199,6 +199,35 @@ export const AllProjectsTests: AcceptanceTests = { 'Same body for --all-projects and --file=pom.xml', ); }, + '`monitor composer-app with --all-projects and without same meta`': ( + params, + utils, + ) => async (t) => { + utils.chdirWorkspaces(); + const spyPlugin = sinon.spy(params.plugins, 'loadPlugin'); + t.teardown(spyPlugin.restore); + + await params.cli.monitor('composer-app', { + allProjects: true, + }); + // Pop all calls to server and filter out calls to `featureFlag` endpoint + const [composerAll] = params.server + .popRequests(2) + .filter((req) => req.url.includes('/monitor/')); + + await params.cli.monitor('composer-app', { + file: 'composer.lock', + }); + const [requestsComposer] = params.server + .popRequests(2) + .filter((req) => req.url.includes('/monitor/')); + + t.deepEqual( + composerAll.body, + requestsComposer.body, + 'Same body for --all-projects and --file=composer.lock', + ); + }, '`monitor mono-repo-project with lockfiles --all-projects --json`': ( params, utils, 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..3761b16555 100644 --- a/test/acceptance/cli-test/cli-test.all-projects.spec.ts +++ b/test/acceptance/cli-test/cli-test.all-projects.spec.ts @@ -440,5 +440,36 @@ export const AllProjectsTests: AcceptanceTests = { t.fail('expected to pass'); } }, + '`test composer-app --all-projects`': (params, utils) => async (t) => { + utils.chdirWorkspaces(); + const spyPlugin = sinon.spy(params.plugins, 'loadPlugin'); + t.teardown(spyPlugin.restore); + + const result = await params.cli.test('composer-app', { + allProjects: true, + }); + + t.ok(spyPlugin.withArgs('composer').calledOnce, 'calls composer plugin'); + + params.server.popRequests(2).forEach((req) => { + t.equal(req.method, 'POST', 'makes POST request'); + t.equal( + req.headers['x-snyk-cli-version'], + params.versionNumber, + 'sends version number', + ); + t.match(req.url, '/api/v1/test', 'posts to correct url'); + }); + t.match( + result, + 'Package manager: composer', + 'contains package manager composer', + ); + t.match( + result, + 'Target file: composer.lock', + 'contains target file composer.lock', + ); + }, }, };