Skip to content

Commit 358a63a

Browse files
committed
test(travis): Switch security audit checks from nsp-check to npm audit
1 parent 67c8380 commit 358a63a

File tree

4 files changed

+116
-24
lines changed

4 files changed

+116
-24
lines changed

.nsprc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{
2-
"exceptions": ["https://nodesecurity.io/advisories/566"]
2+
"exceptions": [
3+
"https://npmjs.com/advisories/118",
4+
"https://npmjs.com/advisories/577",
5+
"https://npmjs.com/advisories/612",
6+
"https://npmjs.com/advisories/678",
7+
"https://npmjs.com/advisories/720",
8+
"https://npmjs.com/advisories/725",
9+
"https://npmjs.com/advisories/745"
10+
]
311
}

.travis.yml

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,45 @@ os:
88
node_js:
99
- '6'
1010
- '8'
11+
- '10'
1112

1213
# Skip node_js 6 on travis windows workers (as it often fails because
1314
# travis fails to init the node_js 6 environment).
1415
matrix:
16+
fast_finish: true
1517
exclude:
1618
- node_js: '6'
1719
os: windows
20+
- node_js: '8'
21+
os: windows
1822

19-
before_script:
20-
# If this command fails and you can't fix it, file an issue and add an exception to .nsprc
21-
- if [[ "$TRAVIS_OS_NAME" != 'windows' ]]; then npm run nsp-check; fi
23+
jobs:
24+
include:
25+
- stage: npm audit and lint github PR title
26+
## Keep this in sync with the last version listed in the node_js property.
27+
node_js: '10'
28+
os: linux
29+
script:
30+
- npm run audit-deps
31+
- npm run travis-pr-title-lint
32+
- stage: deploy on npm
33+
## Keep this in sync with the last version listed in the node_js property.
34+
node_js: '10'
35+
os: linux
36+
script: echo "Deploying to npm..."
37+
## Make sure we have a production build.
38+
before_deploy: NODE_ENV=production npm run build
39+
deploy:
40+
provider: npm
41+
42+
# Note that cleanup runs *after* the before_deploy script.
43+
skip_cleanup: true
44+
# This is the API key for npm user 'addons-robot'
45+
api_key:
46+
secure: CVUpq7hp1/CvAD40vA0cm+5jI7Izlsb83mCNrAt7Qcjb4orFWTHUxE3Y0a5wGS2gAIr5l/hd/CruXdy4EfMVS6GyW5qhTeWxS0b36+t542z4Xlk9eY4UvB5DdKMJKH8RT+Sz8E/Sx6fhISgvQW48rGJCq3ePaH54mLkXLRJW7HqZxSnrAGc8XLiTJOUPKhOzo4AALXvLKDB+doTtHtSDFD+G+kpABMlJBw849V4mGVi/oUpK5Z/tnCjBBKIaU2Cw//2rE0Wo2mN4osq9eUHxNNTA4fTZoEONaDN/zeYhp3IjYc4cRVK611xnhITLW8CJwRSFJYaoPDB0S1sHOuIcl026SC36m01m7vb0RdxzxhTRBcdClSgo0VcqWHjGjZ5knR1s3ztUcOgVbkcuyQ7x03jp7DEe52sH86myzpWpymu6StRXQix4YjkDoGMFczhPmOP+fWYUex87VCsF1f3rdXJSQmtFuM4Tm11E4WoZGaLB5cgKTNZodJ5v6+UK5u3mop59fIJsIrFF+NKCJNnHvegchiLyGiOJb5wYWpnP4/O2XXNvDEtSPJBRGT/fcHVnYBr6hAl6ux/z4ND3xX77hKKnqQk+CrR28aQpURBNJMKFgtW2DcABAXTZ16ezhXsPlIp6/2GXu0VozTTnwPCRhvsl+s+dqqJu0faxSo+vB7s=
47+
on:
48+
tags: true
2249

23-
# Keep this in sync with appveyor.yml
2450
script:
2551
## run eslint, flow and the unit test suite.
2652
- COVERAGE=y NODE_ENV=production npm test
@@ -44,29 +70,12 @@ script:
4470
- npm config delete python
4571
- rm artifacts/production/package.json
4672

47-
## lint the github PR title.
48-
- if [[ "$TRAVIS_OS_NAME" != 'windows' ]]; then npm run travis-pr-title-lint; fi
49-
5073
after_script: npm run publish-coverage
5174

52-
before_deploy:
53-
## Make sure we have a production build.
54-
- NODE_ENV=production npm run build
5575

5676
notifications:
5777
irc:
5878
channels:
5979
- irc.mozilla.org#amo-bots
6080
on_success: change
6181
on_failure: always
62-
deploy:
63-
provider: npm
64-
65-
# Note that cleanup runs *after* the before_deploy script.
66-
skip_cleanup: true
67-
# This is the API key for npm user 'addons-robot'
68-
api_key:
69-
secure: CVUpq7hp1/CvAD40vA0cm+5jI7Izlsb83mCNrAt7Qcjb4orFWTHUxE3Y0a5wGS2gAIr5l/hd/CruXdy4EfMVS6GyW5qhTeWxS0b36+t542z4Xlk9eY4UvB5DdKMJKH8RT+Sz8E/Sx6fhISgvQW48rGJCq3ePaH54mLkXLRJW7HqZxSnrAGc8XLiTJOUPKhOzo4AALXvLKDB+doTtHtSDFD+G+kpABMlJBw849V4mGVi/oUpK5Z/tnCjBBKIaU2Cw//2rE0Wo2mN4osq9eUHxNNTA4fTZoEONaDN/zeYhp3IjYc4cRVK611xnhITLW8CJwRSFJYaoPDB0S1sHOuIcl026SC36m01m7vb0RdxzxhTRBcdClSgo0VcqWHjGjZ5knR1s3ztUcOgVbkcuyQ7x03jp7DEe52sH86myzpWpymu6StRXQix4YjkDoGMFczhPmOP+fWYUex87VCsF1f3rdXJSQmtFuM4Tm11E4WoZGaLB5cgKTNZodJ5v6+UK5u3mop59fIJsIrFF+NKCJNnHvegchiLyGiOJb5wYWpnP4/O2XXNvDEtSPJBRGT/fcHVnYBr6hAl6ux/z4ND3xX77hKKnqQk+CrR28aQpURBNJMKFgtW2DcABAXTZ16ezhXsPlIp6/2GXu0VozTTnwPCRhvsl+s+dqqJu0faxSo+vB7s=
70-
on:
71-
tags: true
72-
condition: $TRAVIS_OS_NAME = 'linux'

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test:functional": "grunt test:functional:run",
2121
"copy-dist-files-to-artifacts-dir": "grunt copy-dist-files-to-artifacts-dir",
2222
"publish-coverage": "grunt coveralls",
23-
"nsp-check": "nsp check --reporter summary",
23+
"audit-deps": "node ./scripts/audit-deps",
2424
"changelog": "conventional-changelog -p angular -u",
2525
"changelog-lint": "conventional-changelog-lint --from master",
2626
"changelog-lint-from-stdin": "conventional-changelog-lint",
@@ -121,10 +121,10 @@
121121
"load-grunt-tasks": "4.0.0",
122122
"mocha": "5.2.0",
123123
"mocha-multi": "1.0.1",
124-
"nsp": "3.2.1",
125124
"object.entries": "1.0.4",
126125
"object.values": "1.0.4",
127126
"prettyjson": "1.2.1",
127+
"shelljs": "0.8.3",
128128
"sinon": "6.1.2",
129129
"webpack": "3.11.0",
130130
"webpack-dev-server": "2.11.1",

scripts/audit-deps

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env node
2+
3+
// This nodejs script loads the .nsprc's "exceptions" list (as `nsp check` used to support) and
4+
// and then filters the output of `npm audit --json` to check if any of the security advisories
5+
// detected should be a blocking issue and force the travis CI job to fail.
6+
//
7+
// We can remove this script if/once npm audit will support this feature natively
8+
// (See https://github.com/npm/npm/issues/20565).
9+
10+
const shell = require('shelljs');
11+
12+
const npmVersion = parseInt(shell.exec('npm --version', {silent: true}).stdout.split('.')[0], 10);
13+
const npmCmd = npmVersion >= 6 ? 'npm' : 'npx npm@latest';
14+
15+
if (npmCmd.startsWith('npx') && !shell.which('npx')) {
16+
shell.echo('Sorry, this script requires npm >= 6 or npx installed globally');
17+
shell.exit(1);
18+
}
19+
20+
if (!shell.test('-f', 'package-lock.json')) {
21+
console.log('audit-deps is generating the missing package-lock.json file');
22+
shell.exec(`${npmCmd} i --package-lock-only`);
23+
}
24+
25+
// Collect audit results and split them into blocking and ignored issues.
26+
27+
const auditRes = shell.exec(`${npmCmd} audit --json`, {silent: true});
28+
const blockingIssues = [];
29+
const ignoredIssues = [];
30+
31+
if (auditRes.code !== 0) {
32+
const exceptions = JSON.parse(shell.cat('.nsprc')).exceptions;
33+
const auditReport = JSON.parse(auditRes.stdout);
34+
35+
for (let advId of Object.keys(auditReport.advisories)) {
36+
const adv = auditReport.advisories[advId];
37+
38+
if (exceptions.includes(adv.url)) {
39+
ignoredIssues.push(adv)
40+
continue;
41+
}
42+
blockingIssues.push(adv);
43+
}
44+
}
45+
46+
// Reporting.
47+
48+
function formatFinding(desc) {
49+
const details = `(dev: ${desc.dev}, optional: ${desc.optional}, bundled: ${desc.bundled})`;
50+
return `${desc.version} ${details}\n ${desc.paths.join('\n ')}`;
51+
}
52+
53+
function formatAdvisory(adv) {
54+
const findings = adv.findings.map(formatFinding).map(msg => ` ${msg}`).join('\n');
55+
return `${adv.module_name} (${adv.url}):\n${findings}`;
56+
}
57+
58+
if (ignoredIssues.length > 0) {
59+
console.log('\n== audit-deps: ignored security issues (based on .nsprc exceptions)\n');
60+
61+
for (let adv of ignoredIssues) {
62+
console.log(formatAdvisory(adv));
63+
}
64+
}
65+
66+
if (blockingIssues.length > 0) {
67+
console.log('\n== audit-deps: blocking security issues\n');
68+
69+
for (let adv of blockingIssues) {
70+
console.log(formatAdvisory(adv));
71+
}
72+
73+
// Exit with error if blocking security issues has been found.
74+
process.exit(1);
75+
}

0 commit comments

Comments
 (0)