File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ const {
21
21
* @return boolean
22
22
*/
23
23
function checkSampleContent ( lockfile , isYarnBerry ) {
24
+ if ( Object . entries ( lockfile ) . length < ( isYarnBerry ? 2 : 1 ) ) {
25
+ return false
26
+ }
24
27
const [ sampleKey , sampleValue ] = Object . entries ( lockfile ) [ isYarnBerry ? 1 : 0 ]
25
28
return (
26
29
sampleKey . match ( / .* @ .* / ) &&
Original file line number Diff line number Diff line change @@ -164,6 +164,48 @@ describe('Main CLI logic', () => {
164
164
expect ( result . validatorCount ) . toEqual ( 1 )
165
165
expect ( result . validatorSuccesses ) . toEqual ( 1 )
166
166
} )
167
+
168
+ test ( 'should fail with an empty npm lock file' , ( ) => {
169
+ const lockfilePath = path . join ( __dirname , '/fixtures/empty.json' )
170
+ const lockfileType = 'npm'
171
+ const validators = [
172
+ {
173
+ name : 'validateHosts' ,
174
+ values : [ 'npm' ]
175
+ }
176
+ ]
177
+
178
+ expect ( ( ) =>
179
+ main
180
+ . runValidators ( {
181
+ path : lockfilePath ,
182
+ type : lockfileType ,
183
+ validators
184
+ } )
185
+ . toThrow ( 'Lockfile does not seem to contain a valid dependency list' )
186
+ )
187
+ } )
188
+
189
+ test ( 'should fail with an empty yarn lock file' , ( ) => {
190
+ const lockfilePath = path . join ( __dirname , '/fixtures/empty.json' )
191
+ const lockfileType = 'yarn'
192
+ const validators = [
193
+ {
194
+ name : 'validateHosts' ,
195
+ values : [ 'yarn' ]
196
+ }
197
+ ]
198
+
199
+ expect ( ( ) =>
200
+ main
201
+ . runValidators ( {
202
+ path : lockfilePath ,
203
+ type : lockfileType ,
204
+ validators
205
+ } )
206
+ . toThrow ( 'Lockfile does not seem to contain a valid dependency list' )
207
+ )
208
+ } )
167
209
} )
168
210
169
211
describe ( 'validateSchemes' , ( ) => {
You can’t perform that action at this time.
0 commit comments