Skip to content

Commit

Permalink
feat: add CocoaPods support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrackwitz committed Sep 30, 2019
1 parent 825666d commit 4bbcc3c
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"author": "snyk.io",
"license": "Apache-2.0",
"dependencies": {
"@snyk/cli-interface": "^2.0.3",
"@snyk/dep-graph": "1.12.0",
"@snyk/gemfile": "1.2.0",
"@types/agent-base": "^4.2.0",
Expand All @@ -69,6 +70,7 @@
"proxy-from-env": "^1.0.0",
"semver": "^6.0.0",
"snyk-config": "^2.2.1",
"@snyk/snyk-cocoapods-plugin": "1.0.2",
"snyk-docker-plugin": "1.29.1",
"snyk-go-plugin": "1.11.0",
"snyk-gradle-plugin": "^3.0.2",
Expand Down
4 changes: 4 additions & 0 deletions src/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const DETECTABLE_PACKAGE_MANAGERS: {
'project.json': 'nuget',
'paket.dependencies': 'paket',
'composer.lock': 'composer',
'Podfile.lock': 'cocoapods',
'CocoaPods.podfile.yaml': 'cocoapods',
'CocoaPods.podfile': 'cocoapods',
'Podfile': 'cocoapods',
};

export function isPathToPackageFile(path) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/package-managers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type SupportedPackageManagers = 'rubygems' | 'npm' | 'yarn' |
'maven' | 'pip' | 'sbt' | 'gradle' | 'golangdep' | 'govendor' | 'gomodules' |
'nuget' | 'paket' | 'composer';
'nuget' | 'paket' | 'composer' | 'cocoapods';

export const SUPPORTED_PACKAGE_MANAGER_NAME: {
readonly [packageManager in SupportedPackageManagers]: string;
Expand All @@ -18,6 +18,7 @@ export const SUPPORTED_PACKAGE_MANAGER_NAME: {
nuget: 'NuGet',
paket: 'Paket',
composer: 'Composer',
cocoapods: 'CocoaPods',
};

export const WIZARD_SUPPORTED_PACKAGE_MANAGERS: SupportedPackageManagers[]
Expand Down
4 changes: 4 additions & 0 deletions src/lib/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as goPlugin from 'snyk-go-plugin';
import * as nugetPlugin from 'snyk-nuget-plugin';
import * as phpPlugin from 'snyk-php-plugin';
import * as nodejsPlugin from './nodejs-plugin';
import * as cocoapodsPlugin from '@snyk/snyk-cocoapods-plugin';
import * as types from './types';
import {SupportedPackageManagers} from '../package-managers';
import { UnsupportedPackageManagerError } from '../errors';
Expand Down Expand Up @@ -54,6 +55,9 @@ export function loadPlugin(packageManager: SupportedPackageManagers,
case 'composer': {
return phpPlugin;
}
case 'cocoapods': {
return cocoapodsPlugin;
}
default: {
throw new UnsupportedPackageManagerError(packageManager);
}
Expand Down
55 changes: 55 additions & 0 deletions test/acceptance/cli.acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,59 @@ test('`monitor golang-app --file=vendor/vendor.json`', async (t) => {
}], 'calls golang plugin');
});

test('`monitor cocoapods-app`', async (t) => {
chdirWorkspaces();
try {
await cli.test('cocoapods-app');
t.fail('should have failed');
} catch (err) {
t.pass('throws err');
t.match(err.message, 'Could not detect supported target files in cocoapods-app.' +
'\nPlease see our documentation for supported' +
' languages and target files: ' +
'https://support.snyk.io/hc/en-us/articles/360000911957-Language-support' +
' and make sure you' +
' are in the right directory.');
}
});

test('`monitor cocoapods-app --file=Podfile`', async (t) => {
chdirWorkspaces();
const plugin = {
async inspect() {
return {
plugin: {
targetFile: 'Podfile',
name: 'snyk-cocoapods-plugin',
runtime: 'cocoapods',
},
package: {},
};
},
};
const spyPlugin = sinon.spy(plugin, 'inspect');

const loadPlugin = sinon.stub(plugins, 'loadPlugin');
t.teardown(loadPlugin.restore);
loadPlugin
.withArgs('cocoapods')
.returns(plugin);

await cli.monitor('cocoapods-app', {
file: 'Podfile',
});
const req = server.popRequest();
t.equal(req.method, 'PUT', 'makes PUT request');
t.equal(req.headers['x-snyk-cli-version'], versionNumber, 'sends version number');
t.match(req.url, '/monitor/cocoapods', 'puts at correct url');
t.equal(req.body.targetFile, 'Podfile', 'sends the targetFile');
t.same(spyPlugin.getCall(0).args,
['cocoapods-app', 'Podfile', {
args: null,
file: 'Podfile',
}], 'calls CocoaPods plugin');
});

test('`monitor composer-app ruby-app` works on multiple params', async (t) => {
chdirWorkspaces();
let results = await cli.monitor('composer-app', 'ruby-app', { json: true });
Expand Down Expand Up @@ -3127,6 +3180,7 @@ test('`wizard` for unsupported package managers', async (t) => {
{ file: 'golang-app/Gopkg.lock', type: 'dep (Go)' },
{ file: 'golang-app/vendor/vendor.json', type: 'govendor' },
{ file: 'composer-app/composer.lock', type: 'Composer' },
{ file: 'cocoapods-app/Podfile.lock', type: 'CocoaPods' },
];
const results = await Promise.all(cases.map(testUnsupported));
results.map((result, i) => {
Expand Down Expand Up @@ -3157,6 +3211,7 @@ test('`protect` for unsupported package managers', async (t) => {
{ file: 'golang-app/Gopkg.lock', type: 'dep (Go)' },
{ file: 'golang-app/vendor/vendor.json', type: 'govendor' },
{ file: 'composer-app/composer.lock', type: 'Composer' },
{ file: 'cocoapods-app/Podfile.lock', type: 'CocoaPods' },
];
const results = await Promise.all(cases.map(testUnsupported));
results.map((result, i) => {
Expand Down
4 changes: 4 additions & 0 deletions test/acceptance/workspaces/cocoapods-app/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target 'SampleApp' do
platform :ios, '6.0'
pod 'Reachability', '3.1.0'
end
14 changes: 14 additions & 0 deletions test/acceptance/workspaces/cocoapods-app/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
PODS:
- Reachability (3.1.0)

DEPENDENCIES:
- Reachability (= 3.1.0)

SPEC REPOS:
trunk:
- Reachability

SPEC CHECKSUMS:
Reachability: 3c8fe9643e52184d17f207e781cd84158da8c02b

PODFILE CHECKSUM: eef52b2296b88c87f94cf0f232f010176b9f11cd

0 comments on commit 4bbcc3c

Please sign in to comment.