Skip to content

Commit

Permalink
Merge pull request #1297 from snyk/fix/protect-shouldnt-fail-when-the…
Browse files Browse the repository at this point in the history
…res-nothing-to-do

fix: protect will not fail when there are not vulns to patch
  • Loading branch information
jasiskis committed Jul 29, 2020
2 parents 8f13109 + 7e31f59 commit 3fc09e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cli/commands/protect/index.ts
Expand Up @@ -98,7 +98,7 @@ async function patch(options: types.PolicyOptions & types.Options) {
analytics.add('success', true);
return 'Successfully applied Snyk patches';
} catch (e) {
if (e.code === 'ALREADY_PATCHED') {
if (e.strCode === 'ALREADY_PATCHED') {
analytics.add('success', true);
return e.message + ', nothing to do';
}
Expand Down
22 changes: 22 additions & 0 deletions test/acceptance/cli-protect-no-vulns-to-patch.test.ts
@@ -0,0 +1,22 @@
import { test } from 'tap';
import * as cli from '../../src/cli/commands';
import * as sinon from 'sinon';
import * as snyk from '../../src/lib';

test('`protect` with no vulns to patch', async (t) => {
t.plan(1);
const vulns = require('./fixtures/npm-package/test-graph-result.json');
vulns.vulnerabilities = undefined;
const testStub = sinon.stub(snyk, 'test').returns(vulns);

try {
const result = await cli.protect();
t.match(result, 'Code is already patched, nothing to do');
} catch (err) {
t.fail('should not fail');
} finally {
testStub.restore();
}

t.end();
});
1 change: 1 addition & 0 deletions test/acceptance/cli-protect.test.ts
Expand Up @@ -165,6 +165,7 @@ test('`protect` with no policy', async (t) => {
const req = server.popRequest();
const policySentToServer = req.body.policy;
t.equal(policySentToServer, projectPolicy, 'sends correct policy');

t.end();
});

Expand Down

0 comments on commit 3fc09e1

Please sign in to comment.