Skip to content

Commit 240f623

Browse files
authored
Merge pull request #947 from snyk/fix/wizard-adding-snyk-dependency
fix: snyk always being added as dependency when running wizard
2 parents ab83ab8 + 49b0cd3 commit 240f623

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

src/cli/commands/protect/wizard.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,13 @@ function processAnswers(answers, policy, options) {
469469
let lbl = 'Updating package.json...';
470470
const addSnykToDependencies =
471471
answers['misc-add-test'] || answers['misc-add-protect'];
472-
let updateSnykFunc = () =>
473-
protect.install(packageManager, ['snyk'], live);
472+
let updateSnykFunc = () => {
473+
return;
474+
}; // noop
474475

476+
if (addSnykToDependencies) {
477+
updateSnykFunc = () => protect.install(packageManager, ['snyk'], live);
478+
}
475479
if (addSnykToDependencies) {
476480
debug('updating %s', packageFile);
477481

test/fixtures/basic-npm/answers.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"npm:minimatch:20160620-u4": {
3+
"vuln": {
4+
"title": "Regular Expression Denial of Service",
5+
"creationTime": "2016-06-20T16:00:06.484Z",
6+
"modificationTime": "2016-06-20T16:00:06.484Z",
7+
"publicationTime": "2016-06-20T15:52:52.000Z",
8+
"disclosureTime": "2016-06-20T15:52:52.000Z",
9+
"semver": {
10+
"vulnerable": "<=3.0.1",
11+
"unaffected": ">=3.0.2"
12+
},
13+
"CVSSv3": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
14+
"severity": "high",
15+
"identifiers": {
16+
"CWE": [
17+
"CWE-400"
18+
],
19+
"CVE": [],
20+
"NSP": 118
21+
},
22+
"patches": [
23+
{
24+
"urls": [
25+
"https://snyk-patches.s3.amazonaws.com/npm/minimatch/20160620/minimatch_20160620_0_0_6944abf9e0694bd22fd9dad293faa40c2bc8a955.patch"
26+
],
27+
"version": "<=3.0.1 >2.0.5",
28+
"modificationTime": "2016-06-20T16:00:06.484Z",
29+
"comments": [],
30+
"id": "patch:npm:minimatch:20160620:0"
31+
}
32+
],
33+
"moduleName": "minimatch",
34+
"id": "npm:minimatch:20160620",
35+
"from": [
36+
37+
],
38+
"upgradePath": [
39+
false,
40+
41+
],
42+
"version": "3.0.0",
43+
"name": "minimatch",
44+
"isUpgradable": true,
45+
"isPatchable": true,
46+
"__filename": "/Users/oakfang/dev/SC-1472/node_modules/minimatch/package.json",
47+
"parentDepType": "dev",
48+
"grouped": {
49+
"affected": {
50+
"name": "tap",
51+
"version": "3.1.2",
52+
53+
},
54+
"main": true,
55+
"id": "npm:minimatch:20160620-4",
56+
"count": 3,
57+
"upgrades": [
58+
59+
]
60+
}
61+
},
62+
"choice": "update"
63+
},
64+
"misc-add-test": false,
65+
"misc-add-protect": false,
66+
"misc-test-no-monitor": true
67+
}

test/fixtures/basic-npm/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "package-file-basic",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"author": "",
7+
"license": "ISC",
8+
"dependencies": {
9+
"debug": "^1.0.0",
10+
"minimatch": "3.0.0"
11+
}
12+
}

test/wizard-process-answers.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,25 @@ test('wizard updates vulns and retains indentation', async function(t) {
311311
process.chdir(old);
312312
t.end();
313313
});
314+
315+
test('wizard updates vulns but does not install snyk', async function(t) {
316+
const old = process.cwd();
317+
const dir = path.resolve(__dirname, 'fixtures', 'basic-npm');
318+
const answersPath = path.resolve(dir, 'answers.json');
319+
320+
const answers = JSON.parse(fs.readFileSync(answersPath, 'utf-8'));
321+
322+
const installCommands = [
323+
['uninstall', ['minimatch'], true, undefined, undefined],
324+
['install', ['[email protected]'], true, null, ['--save-dev']],
325+
];
326+
327+
process.chdir(dir);
328+
329+
await wizard.processAnswers(answers, mockPolicy);
330+
331+
t.deepEqual(execSpy.args, installCommands, 'snyk not installed');
332+
333+
process.chdir(old);
334+
t.end();
335+
});

0 commit comments

Comments
 (0)