1
1
const { expect } = require ( "chai" ) ;
2
- const path = require ( "path" ) ;
3
2
const { audit, report } = require ( "../lib/npm-auditer" ) ;
4
3
const Allowlist = require ( "../lib/allowlist" ) ;
5
- const { summaryWithDefault } = require ( "./common" ) ;
4
+ const { summaryWithDefault, config , testDir } = require ( "./common" ) ;
6
5
7
6
const reportNpmCritical = require ( "./npm-critical/npm7-output.json" ) ;
8
- const reportNpmHigh = require ( "./npm-high/npm7-output.json" ) ;
9
- const reportNpmModerate = require ( "./npm-moderate/npm7-output.json" ) ;
10
- const reportNpmAllowlisted = require ( "./npm-allowlisted-path/npm7-output.json" ) ;
11
- const reportNpmNone = require ( "./npm-none/npm7-output.json" ) ;
7
+ const reportNpmHighSeverity = require ( "./npm-high/npm7-output.json" ) ;
8
+ const reportNpmModerateSeverity = require ( "./npm-moderate/npm7-output.json" ) ;
9
+ const reportNpmAllowlistedPath = require ( "./npm-allowlisted-path/npm7-output.json" ) ;
12
10
const reportNpmLow = require ( "./npm-low/npm7-output.json" ) ;
13
-
14
- function config ( additions ) {
15
- const defaultConfig = {
16
- levels : {
17
- low : false ,
18
- moderate : false ,
19
- high : false ,
20
- critical : false ,
21
- } ,
22
- "report-type" : "important" ,
23
- allowlist : new Allowlist ( ) ,
24
- "show-not-found" : false ,
25
- "retry-count" : 5 ,
26
- directory : "./" ,
27
- registry : undefined ,
28
- "pass-enoaudit" : false ,
29
- } ;
30
- return { ...defaultConfig , ...additions } ;
31
- }
32
-
33
- function testDir ( s ) {
34
- return path . resolve ( __dirname , s ) ;
35
- }
11
+ const reportNpmNone = require ( "./npm-none/npm7-output.json" ) ;
36
12
37
13
describe ( "npm7-auditer" , function testNpm7Auditer ( ) {
38
14
it ( "prints full report with critical severity" , ( ) => {
@@ -65,7 +41,7 @@ describe("npm7-auditer", function testNpm7Auditer() {
65
41
} ) ;
66
42
it ( "reports summary with high severity" , ( ) => {
67
43
const summary = report (
68
- reportNpmHigh ,
44
+ reportNpmHighSeverity ,
69
45
config ( {
70
46
directory : testDir ( "npm-high" ) ,
71
47
levels : { high : true } ,
@@ -82,7 +58,7 @@ describe("npm7-auditer", function testNpm7Auditer() {
82
58
} ) ;
83
59
it ( "reports important info with moderate severity" , ( ) => {
84
60
const summary = report (
85
- reportNpmModerate ,
61
+ reportNpmModerateSeverity ,
86
62
config ( {
87
63
directory : testDir ( "npm-moderate" ) ,
88
64
levels : { moderate : true } ,
@@ -99,7 +75,7 @@ describe("npm7-auditer", function testNpm7Auditer() {
99
75
} ) ;
100
76
it ( "does not report moderate severity if it set to false" , ( ) => {
101
77
const summary = report (
102
- reportNpmModerate ,
78
+ reportNpmModerateSeverity ,
103
79
config ( {
104
80
directory : testDir ( "npm-moderate" ) ,
105
81
levels : { moderate : false } ,
@@ -110,7 +86,7 @@ describe("npm7-auditer", function testNpm7Auditer() {
110
86
} ) ;
111
87
it ( "[DEPRECATED - advisories] ignores an advisory if it is whitelisted" , ( ) => {
112
88
const summary = report (
113
- reportNpmModerate ,
89
+ reportNpmModerateSeverity ,
114
90
config ( {
115
91
directory : testDir ( "npm-moderate" ) ,
116
92
levels : { moderate : true } ,
@@ -126,7 +102,7 @@ describe("npm7-auditer", function testNpm7Auditer() {
126
102
} ) ;
127
103
it ( "ignores an advisory if it is allowlisted" , ( ) => {
128
104
const summary = report (
129
- reportNpmModerate ,
105
+ reportNpmModerateSeverity ,
130
106
config ( {
131
107
directory : testDir ( "npm-moderate" ) ,
132
108
levels : { moderate : true } ,
@@ -142,7 +118,7 @@ describe("npm7-auditer", function testNpm7Auditer() {
142
118
} ) ;
143
119
it ( "[DEPRECATED - advisories] does not ignore an advisory that is not whitelisted" , ( ) => {
144
120
const summary = report (
145
- reportNpmModerate ,
121
+ reportNpmModerateSeverity ,
146
122
config ( {
147
123
directory : testDir ( "npm-moderate" ) ,
148
124
levels : { moderate : true } ,
@@ -160,7 +136,7 @@ describe("npm7-auditer", function testNpm7Auditer() {
160
136
} ) ;
161
137
it ( "does not ignore an advisory that is not allowlisted" , ( ) => {
162
138
const summary = report (
163
- reportNpmModerate ,
139
+ reportNpmModerateSeverity ,
164
140
config ( {
165
141
directory : testDir ( "npm-moderate" ) ,
166
142
levels : { moderate : true } ,
@@ -178,39 +154,73 @@ describe("npm7-auditer", function testNpm7Auditer() {
178
154
} ) ;
179
155
it ( "[DEPRECATED - path-whitelist] reports only vulnerabilities with a not whitelisted path" , ( ) => {
180
156
const summary = report (
181
- reportNpmAllowlisted ,
157
+ reportNpmAllowlistedPath ,
182
158
config ( {
183
159
directory : testDir ( "npm-allowlisted-path" ) ,
184
160
levels : { moderate : true } ,
185
161
allowlist : Allowlist . mapConfigToAllowlist ( {
186
- "path-whitelist" : [ "axios |github-build" ] ,
162
+ "path-whitelist" : [ "880 |github-build>axios " ] ,
187
163
} ) ,
188
164
} ) ,
189
165
( _summary ) => _summary
190
166
) ;
191
167
expect ( summary ) . to . eql (
192
168
summaryWithDefault ( {
193
- allowlistedPathsFound : [ "axios |github-build" ] ,
169
+ allowlistedPathsFound : [ "880 |github-build>axios " ] ,
194
170
failedLevelsFound : [ "moderate" ] ,
195
- advisoriesFound : [ "axios" ] ,
171
+ advisoriesFound : [ 880 ] ,
196
172
} )
197
173
) ;
198
174
} ) ;
199
175
it ( "reports only vulnerabilities with a not allowlisted path" , ( ) => {
200
176
const summary = report (
201
- reportNpmAllowlisted ,
177
+ reportNpmAllowlistedPath ,
202
178
config ( {
203
179
directory : testDir ( "npm-allowlisted-path" ) ,
204
180
levels : { moderate : true } ,
205
- allowlist : new Allowlist ( [ "axios |github-build" ] ) ,
181
+ allowlist : new Allowlist ( [ "880 |github-build>axios " ] ) ,
206
182
} ) ,
207
183
( _summary ) => _summary
208
184
) ;
209
185
expect ( summary ) . to . eql (
210
186
summaryWithDefault ( {
211
- allowlistedPathsFound : [ "axios |github-build" ] ,
187
+ allowlistedPathsFound : [ "880 |github-build>axios " ] ,
212
188
failedLevelsFound : [ "moderate" ] ,
213
- advisoriesFound : [ "axios" ] ,
189
+ advisoriesFound : [ 880 ] ,
190
+ } )
191
+ ) ;
192
+ } ) ;
193
+ it ( "[DEPRECATED - path-whitelist] whitelist all vulnerabilities with a whitelisted path" , ( ) => {
194
+ const summary = report (
195
+ reportNpmAllowlistedPath ,
196
+ config ( {
197
+ directory : testDir ( "npm-allowlisted-path" ) ,
198
+ levels : { moderate : true } ,
199
+ allowlist : Allowlist . mapConfigToAllowlist ( {
200
+ "path-whitelist" : [ "880|axios" , "880|github-build>axios" ] ,
201
+ } ) ,
202
+ } ) ,
203
+ ( _summary ) => _summary
204
+ ) ;
205
+ expect ( summary ) . to . eql (
206
+ summaryWithDefault ( {
207
+ allowlistedPathsFound : [ "880|axios" , "880|github-build>axios" ] ,
208
+ } )
209
+ ) ;
210
+ } ) ;
211
+ it ( "allowlist all vulnerabilities with a allowlisted path" , ( ) => {
212
+ const summary = report (
213
+ reportNpmAllowlistedPath ,
214
+ config ( {
215
+ directory : testDir ( "npm-allowlisted-path" ) ,
216
+ levels : { moderate : true } ,
217
+ allowlist : new Allowlist ( [ "880|axios" , "880|github-build>axios" ] ) ,
218
+ } ) ,
219
+ ( _summary ) => _summary
220
+ ) ;
221
+ expect ( summary ) . to . eql (
222
+ summaryWithDefault ( {
223
+ allowlistedPathsFound : [ "880|axios" , "880|github-build>axios" ] ,
214
224
} )
215
225
) ;
216
226
} ) ;
@@ -226,7 +236,7 @@ describe("npm7-auditer", function testNpm7Auditer() {
226
236
expect ( summary ) . to . eql (
227
237
summaryWithDefault ( {
228
238
failedLevelsFound : [ "low" ] ,
229
- advisoriesFound : [ 786 , "braces" ] ,
239
+ advisoriesFound : [ 786 ] ,
230
240
} )
231
241
) ;
232
242
} ) ;
0 commit comments