@@ -27,6 +27,66 @@ function tmock (t) {
2727 } )
2828}
2929
30+ const quickAuditResult = {
31+ actions : [ ] ,
32+ advisories : {
33+ '1316' : {
34+ findings : [
35+ {
36+ version : '1.0.0' ,
37+ paths : [
38+ 'baddep'
39+ ]
40+ }
41+ ] ,
42+ 'id' : 1316 ,
43+ 'created' : '2019-11-14T15:29:41.991Z' ,
44+ 'updated' : '2019-11-14T19:35:30.677Z' ,
45+ 'deleted' : null ,
46+ 'title' : 'Arbitrary Code Execution' ,
47+ 'found_by' : {
48+ 'link' : '' ,
49+ 'name' : 'François Lajeunesse-Robert' ,
50+ 'email' : ''
51+ } ,
52+ 'reported_by' : {
53+ 'link' : '' ,
54+ 'name' : 'François Lajeunesse-Robert' ,
55+ 'email' : ''
56+ } ,
57+ 'module_name' : 'baddep' ,
58+ 'cves' : [ ] ,
59+ 'vulnerable_versions' : '<4.5.2' ,
60+ 'patched_versions' : '>=4.5.2' ,
61+ 'overview' : 'a nice overview of the advisory' ,
62+ 'recommendation' : 'how you should fix it' ,
63+ 'references' : '' ,
64+ 'access' : 'public' ,
65+ 'severity' : 'high' ,
66+ 'cwe' : 'CWE-79' ,
67+ 'metadata' : {
68+ 'module_type' : '' ,
69+ 'exploitability' : 6 ,
70+ 'affected_components' : ''
71+ } ,
72+ 'url' : 'https://npmjs.com/advisories/1234542069'
73+ }
74+ } ,
75+ 'muted' : [ ] ,
76+ 'metadata' : {
77+ 'vulnerabilities' : {
78+ 'info' : 0 ,
79+ 'low' : 0 ,
80+ 'moderate' : 0 ,
81+ 'high' : 1 ,
82+ 'critical' : 0
83+ } ,
84+ 'dependencies' : 1 ,
85+ 'devDependencies' : 0 ,
86+ 'totalDependencies' : 1
87+ }
88+ }
89+
3090test ( 'exits with zero exit code for vulnerabilities below the `audit-level` flag' , t => {
3191 const fixture = new Tacks ( new Dir ( {
3292 'package.json' : new File ( {
@@ -40,7 +100,7 @@ test('exits with zero exit code for vulnerabilities below the `audit-level` flag
40100 fixture . create ( testDir )
41101 return tmock ( t ) . then ( srv => {
42102 srv . filteringRequestBody ( req => 'ok' )
43- srv . post ( '/-/npm/v1/security/audits/quick' , 'ok' ) . reply ( 200 , 'yeah' )
103+ srv . post ( '/-/npm/v1/security/audits/quick' , 'ok' ) . reply ( 200 , quickAuditResult )
44104 srv . get ( '/baddep' ) . twice ( ) . reply ( 200 , {
45105 name : 'baddep' ,
46106 'dist-tags' : {
@@ -75,6 +135,8 @@ test('exits with zero exit code for vulnerabilities below the `audit-level` flag
75135 '--registry' , common . registry ,
76136 '--cache' , path . join ( testDir , 'npm-cache' )
77137 ] , EXEC_OPTS ) . then ( ( [ code , stdout , stderr ] ) => {
138+ const result = JSON . parse ( stdout )
139+ t . same ( result . audit , quickAuditResult , 'printed quick audit result' )
78140 srv . filteringRequestBody ( req => 'ok' )
79141 srv . post ( '/-/npm/v1/security/audits' , 'ok' ) . reply ( 200 , {
80142 actions : [ {
@@ -102,6 +164,62 @@ test('exits with zero exit code for vulnerabilities below the `audit-level` flag
102164 } )
103165} )
104166
167+ test ( 'shows quick audit results summary for human' , t => {
168+ const fixture = new Tacks ( new Dir ( {
169+ 'package.json' : new File ( {
170+ name : 'foo' ,
171+ version : '1.0.0' ,
172+ dependencies : {
173+ baddep : '1.0.0'
174+ }
175+ } )
176+ } ) )
177+ fixture . create ( testDir )
178+ return tmock ( t ) . then ( srv => {
179+ srv . filteringRequestBody ( req => 'ok' )
180+ srv . post ( '/-/npm/v1/security/audits/quick' , 'ok' ) . reply ( 200 , quickAuditResult )
181+ srv . get ( '/baddep' ) . twice ( ) . reply ( 200 , {
182+ name : 'baddep' ,
183+ 'dist-tags' : {
184+ 'latest' : '1.2.3'
185+ } ,
186+ versions : {
187+ '1.0.0' : {
188+ name : 'baddep' ,
189+ version : '1.0.0' ,
190+ _hasShrinkwrap : false ,
191+ dist : {
192+ shasum : 'deadbeef' ,
193+ tarball : common . registry + '/idk/-/idk-1.0.0.tgz'
194+ }
195+ } ,
196+ '1.2.3' : {
197+ name : 'baddep' ,
198+ version : '1.2.3' ,
199+ _hasShrinkwrap : false ,
200+ dist : {
201+ shasum : 'deadbeef' ,
202+ tarball : common . registry + '/idk/-/idk-1.2.3.tgz'
203+ }
204+ }
205+ }
206+ } )
207+ return common . npm ( [
208+ 'install' ,
209+ '--audit' ,
210+ '--no-json' ,
211+ '--package-lock-only' ,
212+ '--registry' , common . registry ,
213+ '--cache' , path . join ( testDir , 'npm-cache' )
214+ ] , EXEC_OPTS ) . then ( ( [ code , stdout , stderr ] ) => {
215+ t . match ( stdout , new RegExp ( 'added 1 package and audited 1 package in .*\\n' +
216+ 'found 1 high severity vulnerability\\n' +
217+ ' run `npm audit fix` to fix them, or `npm audit` for details\\n' ) ,
218+ 'shows quick audit result' )
219+ } )
220+ } )
221+ } )
222+
105223test ( 'exits with non-zero exit code for vulnerabilities at the `audit-level` flag' , t => {
106224 const fixture = new Tacks ( new Dir ( {
107225 'package.json' : new File ( {
0 commit comments