@@ -14,15 +14,6 @@ import (
14
14
"github.com/aquasecurity/trivy/pkg/types"
15
15
)
16
16
17
- const (
18
- AllReport = "all"
19
- SummaryReport = "summary"
20
-
21
- tableFormat = "table"
22
- jsonFormat = "json"
23
- cycloneDXFormat = "cyclonedx"
24
- )
25
-
26
17
var (
27
18
roleWithMisconfig = report.Resource {
28
19
Namespace : "default" ,
@@ -142,6 +133,44 @@ var (
142
133
},
143
134
},
144
135
}
136
+ deployOrionWithSingleMisconfig = report.Resource {
137
+ Namespace : "default" ,
138
+ Kind : "Deploy" ,
139
+ Name : "orion" ,
140
+ Results : types.Results {
141
+ {
142
+ Misconfigurations : []types.DetectedMisconfiguration {
143
+ {
144
+ ID : "ID100" ,
145
+ Status : types .MisconfStatusFailure ,
146
+ Severity : "LOW" ,
147
+ },
148
+ },
149
+ },
150
+ },
151
+ Report : types.Report {
152
+ Results : types.Results {
153
+ {
154
+ Class : types .ClassConfig ,
155
+ MisconfSummary : & types.MisconfSummary {
156
+ Successes : 0 ,
157
+ Failures : 1 ,
158
+ },
159
+ Misconfigurations : []types.DetectedMisconfiguration {
160
+ {
161
+ ID : "ID100" ,
162
+ Title : "Config file is bad" ,
163
+ Description : "Your config file is not good." ,
164
+ Message : "Oh no, a bad config." ,
165
+ PrimaryURL : "https://google.com/search?q=bad%20config" ,
166
+ Status : types .MisconfStatusFailure ,
167
+ Severity : "LOW" ,
168
+ },
169
+ },
170
+ },
171
+ },
172
+ },
173
+ }
145
174
deployOrionWithVulns = report.Resource {
146
175
Namespace : "default" ,
147
176
Kind : "Deploy" ,
@@ -181,9 +210,43 @@ var (
181
210
},
182
211
},
183
212
}
213
+
214
+ deployOrionWithSingleVuln = report.Resource {
215
+ Namespace : "default" ,
216
+ Kind : "Deploy" ,
217
+ Name : "orion" ,
218
+ Results : types.Results {
219
+ {
220
+ Vulnerabilities : []types.DetectedVulnerability {
221
+ {
222
+
223
+ VulnerabilityID : "CVE-2022-1111" ,
224
+ Vulnerability : dbTypes.Vulnerability {Severity : "LOW" },
225
+ },
226
+ },
227
+ },
228
+ },
229
+ Report : types.Report {
230
+ Results : types.Results {
231
+ {
232
+ Class : types .ClassLangPkg ,
233
+ Vulnerabilities : []types.DetectedVulnerability {
234
+ {
235
+ PkgName : "foo/bar" ,
236
+ VulnerabilityID : "CVE-2022-1111" ,
237
+ InstalledVersion : "v0.0.1" ,
238
+ FixedVersion : "v0.0.2" ,
239
+ PrimaryURL : "https://avd.aquasec.com/nvd/cve-2022-1111" ,
240
+ Vulnerability : dbTypes.Vulnerability {Severity : "LOW" },
241
+ },
242
+ },
243
+ },
244
+ },
245
+ },
246
+ }
184
247
)
185
248
186
- func TestReportWrite_Summary (t * testing.T ) {
249
+ func TestReportWrite_Table (t * testing.T ) {
187
250
allSeverities := []dbTypes.Severity {
188
251
dbTypes .SeverityUnknown ,
189
252
dbTypes .SeverityLow ,
@@ -198,6 +261,7 @@ func TestReportWrite_Summary(t *testing.T) {
198
261
opt report.Option
199
262
scanners types.Scanners
200
263
severities []dbTypes.Severity
264
+ reportType string
201
265
expectedOutput string
202
266
}{
203
267
{
@@ -208,6 +272,7 @@ func TestReportWrite_Summary(t *testing.T) {
208
272
},
209
273
scanners : types.Scanners {types .MisconfigScanner },
210
274
severities : allSeverities ,
275
+ reportType : report .SummaryReport ,
211
276
expectedOutput : `Summary Report for test
212
277
=======================
213
278
@@ -229,6 +294,29 @@ Infra Assessment
229
294
│ │ │ C │ H │ M │ L │ U │
230
295
└───────────┴──────────┴───┴───┴───┴───┴───┘
231
296
Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN` ,
297
+ },
298
+ {
299
+ name : "Single misconfig with `--report all`" ,
300
+ report : report.Report {
301
+ ClusterName : "test" ,
302
+ Resources : []report.Resource {deployOrionWithSingleMisconfig },
303
+ },
304
+ scanners : types.Scanners {types .MisconfigScanner },
305
+ severities : []dbTypes.Severity {
306
+ dbTypes .SeverityCritical ,
307
+ },
308
+ reportType : report .AllReport ,
309
+ expectedOutput : `namespace: default, deploy: orion ()
310
+ ====================================
311
+ Tests: 1 (SUCCESSES: 0, FAILURES: 1)
312
+ Failures: 0 (CRITICAL: 0)
313
+
314
+ (LOW): Oh no, a bad config.
315
+ ════════════════════════════════════════
316
+ Your config file is not good.
317
+
318
+ See https://google.com/search?q=bad%20config
319
+ ────────────────────────────────────────` ,
232
320
},
233
321
{
234
322
name : "Only vuln, all serverities" ,
@@ -238,6 +326,7 @@ Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN`,
238
326
},
239
327
scanners : types.Scanners {types .VulnerabilityScanner },
240
328
severities : allSeverities ,
329
+ reportType : report .SummaryReport ,
241
330
expectedOutput : `Summary Report for test
242
331
=======================
243
332
@@ -259,6 +348,27 @@ Infra Assessment
259
348
│ │ │ C │ H │ M │ L │ U │
260
349
└───────────┴──────────┴───┴───┴───┴───┴───┘
261
350
Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN` ,
351
+ },
352
+ {
353
+ name : "Single vuln with `--report all`" ,
354
+ report : report.Report {
355
+ ClusterName : "test" ,
356
+ Resources : []report.Resource {deployOrionWithSingleVuln },
357
+ },
358
+ scanners : types.Scanners {types .VulnerabilityScanner },
359
+ severities : []dbTypes.Severity {
360
+ dbTypes .SeverityLow ,
361
+ },
362
+ reportType : report .AllReport ,
363
+ expectedOutput : `namespace: default, deploy: orion ()
364
+ ====================================
365
+ Total: 1 (LOW: 1)
366
+
367
+ ┌─────────┬───────────────┬──────────┬─────────┬───────────────────┬───────────────┬───────────────────────────────────────────┐
368
+ │ Library │ Vulnerability │ Severity │ Status │ Installed Version │ Fixed Version │ Title │
369
+ ├─────────┼───────────────┼──────────┼─────────┼───────────────────┼───────────────┼───────────────────────────────────────────┤
370
+ │ foo/bar │ CVE-2022-1111 │ LOW │ unknown │ v0.0.1 │ v0.0.2 │ https://avd.aquasec.com/nvd/cve-2022-1111 │
371
+ └─────────┴───────────────┴──────────┴─────────┴───────────────────┴───────────────┴───────────────────────────────────────────┘` ,
262
372
},
263
373
{
264
374
name : "Only rbac, all serverities" ,
@@ -268,6 +378,7 @@ Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN`,
268
378
},
269
379
scanners : types.Scanners {types .RBACScanner },
270
380
severities : allSeverities ,
381
+ reportType : report .SummaryReport ,
271
382
expectedOutput : `Summary Report for test
272
383
=======================
273
384
@@ -289,6 +400,7 @@ Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN`,
289
400
},
290
401
scanners : types.Scanners {types .SecretScanner },
291
402
severities : allSeverities ,
403
+ reportType : report .SummaryReport ,
292
404
expectedOutput : `Summary Report for test
293
405
=======================
294
406
@@ -319,6 +431,7 @@ Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN`,
319
431
},
320
432
scanners : types.Scanners {types .MisconfigScanner },
321
433
severities : allSeverities ,
434
+ reportType : report .SummaryReport ,
322
435
expectedOutput : `Summary Report for test
323
436
=======================
324
437
@@ -353,6 +466,7 @@ Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN`,
353
466
types .SecretScanner ,
354
467
},
355
468
severities : allSeverities ,
469
+ reportType : report .SummaryReport ,
356
470
expectedOutput : `Summary Report for test
357
471
=======================
358
472
@@ -386,6 +500,7 @@ Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN`,
386
500
types .VulnerabilityScanner ,
387
501
},
388
502
severities : allSeverities ,
503
+ reportType : report .SummaryReport ,
389
504
expectedOutput : `Summary Report for test
390
505
=======================
391
506
@@ -412,19 +527,22 @@ Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN`,
412
527
413
528
for _ , tc := range tests {
414
529
t .Run (tc .name , func (t * testing.T ) {
530
+ t .Setenv ("TRIVY_DISABLE_VEX_NOTICE" , "true" )
415
531
output := bytes.Buffer {}
416
532
417
533
opt := report.Option {
418
534
Format : "table" ,
419
- Report : "summary" ,
535
+ Report : tc . reportType ,
420
536
Output : & output ,
421
537
Scanners : tc .scanners ,
422
538
Severities : tc .severities ,
423
539
}
424
540
425
541
err := Write (t .Context (), tc .report , opt )
426
542
require .NoError (t , err )
427
- assert .Equal (t , tc .expectedOutput , stripAnsi (output .String ()), tc .name )
543
+ got := stripAnsi (output .String ())
544
+ got = strings .ReplaceAll (got , "\r \n " , "\n " )
545
+ assert .Equal (t , tc .expectedOutput , got , tc .name )
428
546
})
429
547
}
430
548
}
0 commit comments