Skip to content

Commit 85aaf21

Browse files
committed
test: capture valid json output with policy
1 parent 8ef2e3e commit 85aaf21

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2+
version: v1.14.1
3+
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
4+
ignore:
5+
'SNYK-JS-CXCT-535487':
6+
- '*':
7+
reason: None given
8+
expires: '2100-03-01T19:48:49.699Z'

test/acceptance/workspaces/npm-package-single-ignored-vuln/package-lock.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "npm-package-single-ignored-vuln",
3+
"version": "1.0.0",
4+
"description": "application with annotated vulns",
5+
"dependencies": {
6+
"cxct": "0.0.1-security"
7+
},
8+
"devDependencies": {}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"result": {
3+
"affectedPkgs": {
4+
5+
"pkg": { "name": "cxct", "version": "0.0.1-security" },
6+
"issues": {
7+
"SNYK-JS-CXCT-535487": {
8+
"issueId": "SNYK-JS-CXCT-535487",
9+
"fixInfo": { "isPatchable": false, "upgradePaths": [] }
10+
}
11+
}
12+
}
13+
},
14+
"issuesData": {
15+
"SNYK-JS-CXCT-535487": {
16+
"CVSSv3": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
17+
"alternativeIds": [],
18+
"creationTime": "2019-11-24T13:10:43.888332Z",
19+
"credit": ["npm 󠅮󠅰󠅭security"],
20+
"cvssScore": 9.8,
21+
"description": "## Overview\n\n[cxct](https://www.npmjs.com/package/cxct) is a malicious package.\n\n\nThe package finds and exfiltrates cryptocurrency wallets.\n\n## Remediation\n\nAvoid using `cxct` altogether.\n\n\n## References\n\n- [NPM Security Advisory](https://www.npmjs.com/advisories/1344)\n",
22+
"disclosureTime": "2019-11-22T00:24:41Z",
23+
"exploit": "Not Defined",
24+
"fixedIn": [],
25+
"functions": [],
26+
"functions_new": [],
27+
"id": "SNYK-JS-CXCT-535487",
28+
"identifiers": { "CVE": [], "CWE": ["CWE-506"], "NSP": [1344] },
29+
"language": "js",
30+
"modificationTime": "2019-11-24T16:16:16.630345Z",
31+
"moduleName": "cxct",
32+
"packageManager": "npm",
33+
"packageName": "cxct",
34+
"patches": [],
35+
"publicationTime": "2019-11-24T13:11:04Z",
36+
"references": [
37+
{
38+
"title": "NPM Security Advisory",
39+
"url": "https://www.npmjs.com/advisories/1344"
40+
}
41+
],
42+
"semver": { "vulnerable": ["*"] },
43+
"severity": "high",
44+
"title": "Malicious 󠅮󠅰󠅭Package",
45+
"isPinnable": false
46+
}
47+
},
48+
"remediation": {
49+
"unresolved": [
50+
{
51+
"CVSSv3": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
52+
"alternativeIds": [],
53+
"creationTime": "2019-11-24T13:10:43.888332Z",
54+
"credit": ["npm 󠅮󠅰󠅭security"],
55+
"cvssScore": 9.8,
56+
"description": "## Overview\n\n[cxct](https://www.npmjs.com/package/cxct) is a malicious package.\n\n\nThe package finds and exfiltrates cryptocurrency wallets.\n\n## Remediation\n\nAvoid using `cxct` altogether.\n\n\n## References\n\n- [NPM Security Advisory](https://www.npmjs.com/advisories/1344)\n",
57+
"disclosureTime": "2019-11-22T00:24:41Z",
58+
"exploit": "Not Defined",
59+
"fixedIn": [],
60+
"functions": [],
61+
"functions_new": [],
62+
"id": "SNYK-JS-CXCT-535487",
63+
"identifiers": { "CVE": [], "CWE": ["CWE-506"], "NSP": [1344] },
64+
"language": "js",
65+
"modificationTime": "2019-11-24T16:16:16.630345Z",
66+
"moduleName": "cxct",
67+
"packageManager": "npm",
68+
"packageName": "cxct",
69+
"patches": [],
70+
"publicationTime": "2019-11-24T13:11:04Z",
71+
"references": [
72+
{
73+
"title": "NPM Security Advisory",
74+
"url": "https://www.npmjs.com/advisories/1344"
75+
}
76+
],
77+
"semver": { "vulnerable": ["*"] },
78+
"severity": "high",
79+
"title": "Malicious 󠅮󠅰󠅭Package",
80+
"isPinnable": false,
81+
82+
"upgradePath": [],
83+
"isUpgradable": false,
84+
"isPatchable": false,
85+
"name": "cxct",
86+
"version": "0.0.1-security"
87+
}
88+
],
89+
"upgrade": {},
90+
"patch": {},
91+
"ignore": {},
92+
"pin": {}
93+
}
94+
},
95+
"meta": {
96+
"isPrivate": true,
97+
"isLicensesEnabled": false,
98+
"licensesPolicy": { "severities": {}, "orgLicenseRules": {} },
99+
"policy": "# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.\nversion: v1.25.1\n# ignores vulnerabilities until expiry date; change duration by modifying expiry date\nignore:\n SNYK-JS-CXCT-535487:\n - '*':\n reason: None Given\n expires: 2100-12-13T14:20:21.158Z\n created: 2017-11-13T14:20:21.163Z\n source: cli\npatch: {}\n",
100+
"ignoreSettings": null,
101+
"org": "gitphill"
102+
},
103+
"filesystemPolicy": false
104+
}

test/jest/acceptance/cli-json-output.spec.ts

+28
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,33 @@ describe('test --json', () => {
164164
expect(code).toEqual(1);
165165
expect(server.getRequests().length).toBeGreaterThanOrEqual(1);
166166
});
167+
168+
it('returns well structured json', async () => {
169+
const project = await createProjectFromWorkspace(
170+
'npm-package-single-ignored-vuln',
171+
);
172+
server.setCustomResponse(
173+
await project.readJSON('test-graph-results.json'),
174+
);
175+
176+
const { code, stdout } = await runSnykCLI(
177+
`test -d --json --log-level=trace`,
178+
{
179+
cwd: project.path(),
180+
env,
181+
},
182+
);
183+
184+
try {
185+
const returnedJson = JSON.parse(stdout);
186+
187+
expect(returnedJson.vulnerabilities).toHaveLength(0);
188+
expect(code).toEqual(0);
189+
expect(server.getRequests().length).toBeGreaterThanOrEqual(1);
190+
} catch (err) {
191+
console.log(stdout);
192+
throw err;
193+
}
194+
});
167195
});
168196
});

0 commit comments

Comments
 (0)