@@ -3,6 +3,7 @@ import { unlinkSync, writeFileSync } from 'fs';
3
3
import { Vulnerability , TrivyOption } from '../src/interface' ;
4
4
5
5
const downloader = new Downloader ( ) ;
6
+ const trivy = new Trivy ( ) ;
6
7
7
8
function removeTrivyCmd ( path : string ) {
8
9
path = path . replace ( / \/ t r i v y $ / , '' ) ;
@@ -54,7 +55,7 @@ describe('getDownloadUrl', () => {
54
55
await expect (
55
56
downloader [ 'getDownloadUrl' ] ( version , os )
56
57
) . rejects . toThrowError (
57
- 'The Trivy version that you specified does not exist .'
58
+ 'Cloud not be found a Trivy asset that you specified.'
58
59
) ;
59
60
} ) ;
60
61
@@ -64,7 +65,7 @@ describe('getDownloadUrl', () => {
64
65
await expect (
65
66
downloader [ 'getDownloadUrl' ] ( version , os )
66
67
) . rejects . toThrowError (
67
- 'Cloud not be found Trivy asset that You specified.'
68
+ 'Cloud not be found a Trivy asset that you specified.'
68
69
) ;
69
70
} ) ;
70
71
} ) ;
@@ -109,7 +110,7 @@ describe('Trivy command', () => {
109
110
} ) ;
110
111
} ) ;
111
112
112
- describe ( 'Scan ' , ( ) => {
113
+ describe ( 'Trivy scan ' , ( ) => {
113
114
let trivyPath : string ;
114
115
const image : string = 'alpine:3.10' ;
115
116
@@ -123,49 +124,49 @@ describe('Scan', () => {
123
124
removeTrivyCmd ( trivyPath ) ;
124
125
} ) ;
125
126
126
- test ( 'with valid options ' , ( ) => {
127
- const options : TrivyOption = {
127
+ test ( 'with valid option ' , ( ) => {
128
+ const option : TrivyOption = {
128
129
severity : 'HIGH,CRITICAL' ,
129
130
vulnType : 'os,library' ,
130
131
ignoreUnfixed : true ,
131
132
format : 'json' ,
132
133
} ;
133
- const result : Vulnerability [ ] | string = Trivy . scan (
134
+ const result : Vulnerability [ ] | string = trivy . scan (
134
135
trivyPath ,
135
136
image ,
136
- options
137
+ option
137
138
) ;
138
139
expect ( result . length ) . toBeGreaterThanOrEqual ( 1 ) ;
139
140
expect ( result ) . toBeInstanceOf ( Object ) ;
140
141
} ) ;
141
142
142
143
test ( 'without ignoreUnfixed' , ( ) => {
143
- const options : TrivyOption = {
144
+ const option : TrivyOption = {
144
145
severity : 'HIGH,CRITICAL' ,
145
146
vulnType : 'os,library' ,
146
147
ignoreUnfixed : false ,
147
148
format : 'json' ,
148
149
} ;
149
- const result : Vulnerability [ ] | string = Trivy . scan (
150
+ const result : Vulnerability [ ] | string = trivy . scan (
150
151
trivyPath ,
151
152
image ,
152
- options
153
+ option
153
154
) ;
154
155
expect ( result . length ) . toBeGreaterThanOrEqual ( 1 ) ;
155
156
expect ( result ) . toBeInstanceOf ( Object ) ;
156
157
} ) ;
157
158
158
159
test ( 'with table format' , ( ) => {
159
- const options : TrivyOption = {
160
+ const option : TrivyOption = {
160
161
severity : 'HIGH,CRITICAL' ,
161
162
vulnType : 'os,library' ,
162
163
ignoreUnfixed : false ,
163
164
format : 'table' ,
164
165
} ;
165
- const result : Vulnerability [ ] | string = Trivy . scan (
166
+ const result : Vulnerability [ ] | string = trivy . scan (
166
167
trivyPath ,
167
168
image ,
168
- options
169
+ option
169
170
) ;
170
171
expect ( result . length ) . toBeGreaterThanOrEqual ( 1 ) ;
171
172
expect ( result ) . toMatch ( / a l p i n e : 3 \. 1 0 / ) ;
@@ -179,8 +180,8 @@ describe('Scan', () => {
179
180
format : 'json' ,
180
181
} ;
181
182
expect ( ( ) => {
182
- Trivy . scan ( trivyPath , image , invalidOption ) ;
183
- } ) . toThrowError ( 'severity option error: INVALID is unknown severity' ) ;
183
+ trivy . scan ( trivyPath , image , invalidOption ) ;
184
+ } ) . toThrowError ( 'Trivy option error: INVALID is unknown severity' ) ;
184
185
} ) ;
185
186
186
187
test ( 'with invalid vulnType' , ( ) => {
@@ -191,8 +192,8 @@ describe('Scan', () => {
191
192
format : 'json' ,
192
193
} ;
193
194
expect ( ( ) => {
194
- Trivy . scan ( trivyPath , image , invalidOption ) ;
195
- } ) . toThrowError ( 'vuln-type option error: INVALID is unknown vuln-type' ) ;
195
+ trivy . scan ( trivyPath , image , invalidOption ) ;
196
+ } ) . toThrowError ( 'Trivy option error: INVALID is unknown vuln-type' ) ;
196
197
} ) ;
197
198
} ) ;
198
199
@@ -204,7 +205,7 @@ describe('Parse', () => {
204
205
Vulnerabilities : null ,
205
206
} ,
206
207
] ;
207
- const result = Trivy . parse ( vulnerabilities ) ;
208
+ const result = trivy . parse ( vulnerabilities ) ;
208
209
expect ( result ) . toBe ( '' ) ;
209
210
} ) ;
210
211
@@ -247,9 +248,77 @@ describe('Parse', () => {
247
248
] ,
248
249
} ,
249
250
] ;
250
- const result = Trivy . parse ( vulnerabilities ) ;
251
+ const result = trivy . parse ( vulnerabilities ) ;
251
252
expect ( result ) . toMatch (
252
253
/ \| T i t l e \| S e v e r i t y \| C V E \| P a c k a g e N a m e \| I n s t a l l e d V e r s i o n \| F i x e d V e r s i o n \| R e f e r e n c e s \| /
253
254
) ;
254
255
} ) ;
255
256
} ) ;
257
+
258
+ describe ( 'Validate trivy option' , ( ) => {
259
+ test ( 'with a valid severity' , ( ) => {
260
+ const options : string [ ] = [ 'HIGH' ] ;
261
+ const result = trivy [ 'validateSeverity' ] ( options ) ;
262
+ expect ( result ) . toBeTruthy ( ) ;
263
+ } ) ;
264
+
265
+ test ( 'with two valid severities' , ( ) => {
266
+ const options : string [ ] = [ 'HIGH' , 'CRITICAL' ] ;
267
+ const result = trivy [ 'validateSeverity' ] ( options ) ;
268
+ expect ( result ) . toBeTruthy ( ) ;
269
+ } ) ;
270
+
271
+ test ( 'with an invalid severity' , ( ) => {
272
+ const options : string [ ] = [ 'INVALID' ] ;
273
+ expect ( ( ) => {
274
+ trivy [ 'validateSeverity' ] ( options ) ;
275
+ } ) . toThrowError ( 'Trivy option error: INVALID is unknown severity' ) ;
276
+ } ) ;
277
+
278
+ test ( 'with two invalid severities' , ( ) => {
279
+ const options : string [ ] = [ 'INVALID' , 'ERROR' ] ;
280
+ expect ( ( ) => {
281
+ trivy [ 'validateSeverity' ] ( options ) ;
282
+ } ) . toThrowError ( 'Trivy option error: INVALID,ERROR is unknown severity' ) ;
283
+ } ) ;
284
+
285
+ test ( 'with an invalid and a valid severities' , ( ) => {
286
+ const options : string [ ] = [ 'INVALID' , 'HIGH' ] ;
287
+ expect ( ( ) => {
288
+ trivy [ 'validateSeverity' ] ( options ) ;
289
+ } ) . toThrowError ( 'Trivy option error: INVALID,HIGH is unknown severity' ) ;
290
+ } ) ;
291
+
292
+ test ( 'with a valid vuln-type' , ( ) => {
293
+ const options : string [ ] = [ 'os' ] ;
294
+ const result = trivy [ 'validateVulnType' ] ( options ) ;
295
+ expect ( result ) . toBeTruthy ( ) ;
296
+ } ) ;
297
+
298
+ test ( 'with two valid vuln-types' , ( ) => {
299
+ const options : string [ ] = [ 'os' , 'library' ] ;
300
+ const result = trivy [ 'validateVulnType' ] ( options ) ;
301
+ expect ( result ) . toBeTruthy ( ) ;
302
+ } ) ;
303
+
304
+ test ( 'with an invalid vuln-type' , ( ) => {
305
+ const options : string [ ] = [ 'INVALID' ] ;
306
+ expect ( ( ) => {
307
+ trivy [ 'validateVulnType' ] ( options ) ;
308
+ } ) . toThrowError ( 'Trivy option error: INVALID is unknown vuln-type' ) ;
309
+ } ) ;
310
+
311
+ test ( 'with two invalid vuln-types' , ( ) => {
312
+ const options : string [ ] = [ 'INVALID' , 'ERROR' ] ;
313
+ expect ( ( ) => {
314
+ trivy [ 'validateVulnType' ] ( options ) ;
315
+ } ) . toThrowError ( 'Trivy option error: INVALID,ERROR is unknown vuln-type' ) ;
316
+ } ) ;
317
+
318
+ test ( 'with a valid and an invalid vuln-types' , ( ) => {
319
+ const options : string [ ] = [ 'INVALID' , 'os' ] ;
320
+ expect ( ( ) => {
321
+ trivy [ 'validateVulnType' ] ( options ) ;
322
+ } ) . toThrowError ( 'Trivy option error: INVALID,os is unknown vuln-type' ) ;
323
+ } ) ;
324
+ } ) ;
0 commit comments