From ca56c695e65f11b44b0c50f93b892a0e03aea97a Mon Sep 17 00:00:00 2001 From: Jacky Cheung Date: Fri, 13 Sep 2024 18:11:34 +0100 Subject: [PATCH] feat: enable cocoapods to send graphs for cli monitor --- src/lib/package-managers.ts | 1 + test/tap/cli-monitor.acceptance.test.ts | 56 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/lib/package-managers.ts b/src/lib/package-managers.ts index a42080a7c2..514eb473b7 100644 --- a/src/lib/package-managers.ts +++ b/src/lib/package-managers.ts @@ -85,6 +85,7 @@ export const GRAPH_SUPPORTED_PACKAGE_MANAGERS: SupportedPackageManagers[] = [ 'yarn', 'rubygems', 'poetry', + 'cocoapods', ]; // For ecosystems with a flat set of libraries (e.g. Python, JVM), one can // "pin" a transitive dependency diff --git a/test/tap/cli-monitor.acceptance.test.ts b/test/tap/cli-monitor.acceptance.test.ts index 57ba729297..4fb8e9b0d0 100644 --- a/test/tap/cli-monitor.acceptance.test.ts +++ b/test/tap/cli-monitor.acceptance.test.ts @@ -1475,6 +1475,62 @@ if (!isWindows) { ); }); + test('`monitor cocoapods-app with just Podfile.lock`', async (t) => { + chdirWorkspaces('cocoapods-app'); + const plugin = { + async inspect() { + return { + plugin: { + targetFile: 'Podfile.lock', + name: 'snyk-cocoapods-plugin', + runtime: 'cocoapods', + }, + package: {}, + }; + }, + }; + console.log(plugin); + const spyPlugin = sinon.spy(plugin, 'inspect'); + + const loadPlugin = sinon.stub(plugins, 'loadPlugin'); + t.teardown(loadPlugin.restore); + loadPlugin.withArgs('cocoapods').returns(plugin); + + await cli.monitor('./', { + file: 'Podfile.lock', + }); + const req = server.popRequest(); + t.equal(req.method, 'PUT', 'makes PUT request'); + t.equal( + req.headers['x-snyk-cli-version'], + versionNumber, + 'sends version number', + ); + const depGraphJSON = req.body.depGraphJSON; + t.ok(depGraphJSON); + t.match(req.url, '/monitor/cocoapods/graph', 'puts at correct url'); + t.equal( + req.body.targetFile, + 'Podfile.lock', + 'sends the targetFile (Podfile.lock)', + ); + t.same( + spyPlugin.getCall(0).args, + [ + './', + 'Podfile.lock', + { + args: null, + file: 'Podfile.lock', + packageManager: 'cocoapods', + path: './', + }, + snykHttpClient, + ], + 'calls CocoaPods plugin', + ); + }); + test('`monitor large-mono-repo --file=bundler-app/Gemfile` suggest to use --all-projects', async (t) => { chdirWorkspaces('large-mono-repo'); const res = await cli.monitor({ file: 'bundler-app/Gemfile' });