Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(report): hide empty tables if all vulns has been filtered #6352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions pkg/report/table/vulnerability.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ func NewVulnerabilityRenderer(result types.Result, isTerminal, tree, suppressed
}

func (r *vulnerabilityRenderer) Render() string {
r.renderDetectedVulnerabilities()

if r.tree {
r.renderDependencyTree()
// There are 3 cases when we show the vulnerability table (or only target and `Total: 0...`):
// When Result contains vulnerabilities;
// When Result target is OS packages even if no vulnerabilities are found;
// When we show non-empty `Suppressed Vulnerabilities` table.
if len(r.result.Vulnerabilities) > 0 || r.result.Class == types.ClassOSPkg || (r.showSuppressed && len(r.result.ModifiedFindings) > 0) {
r.renderDetectedVulnerabilities()

if r.tree {
r.renderDependencyTree()
}
}

if r.showSuppressed {
Expand Down
105 changes: 105 additions & 0 deletions pkg/report/table/vulnerability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,111 @@ Suppressed Vulnerabilities (Total: 1)
├─────────┼───────────────┼──────────┼─────────┼─────────────────┼───────────────────┤
│ bar │ CVE-2020-0002 │ MEDIUM │ ignored │ Not exploitable │ .trivyignore.yaml │
└─────────┴───────────────┴──────────┴─────────┴─────────────────┴───────────────────┘
`,
},
{
name: "suppressed all OS package vulnerabilities without `showSuppressed` flag",
result: types.Result{
Target: "test",
Class: types.ClassOSPkg,
Type: ftypes.Alpine,
ModifiedFindings: []types.ModifiedFinding{
{
Type: types.FindingTypeVulnerability,
Status: types.FindingStatusIgnored,
Statement: "Not exploitable",
Source: ".trivyignore.yaml",
Finding: types.DetectedVulnerability{
VulnerabilityID: "CVE-2020-0001",
PkgName: "foo",
InstalledVersion: "1.2.3",
Status: dbTypes.StatusWillNotFix,
Vulnerability: dbTypes.Vulnerability{
Title: "title1",
Description: "desc1",
Severity: "MEDIUM",
},
},
},
},
},
showSuppressed: false,
want: `
test
====
Total: 0 (MEDIUM: 0, HIGH: 0)

`,
},
{
name: "suppressed all language package vulnerabilities without `showSuppressed` flag",
result: types.Result{
Target: "test",
Class: types.ClassLangPkg,
Type: ftypes.Jar,
ModifiedFindings: []types.ModifiedFinding{
{
Type: types.FindingTypeVulnerability,
Status: types.FindingStatusIgnored,
Statement: "Not exploitable",
Source: ".trivyignore.yaml",
Finding: types.DetectedVulnerability{
VulnerabilityID: "CVE-2020-0001",
PkgName: "foo",
InstalledVersion: "1.2.3",
Status: dbTypes.StatusWillNotFix,
Vulnerability: dbTypes.Vulnerability{
Title: "title1",
Description: "desc1",
Severity: "MEDIUM",
},
},
},
},
},
showSuppressed: false,
want: ``,
},
{
name: "suppressed all language package vulnerabilities with `showSuppressed` flag",
result: types.Result{
Target: "test",
Class: types.ClassLangPkg,
Type: ftypes.Jar,
ModifiedFindings: []types.ModifiedFinding{
{
Type: types.FindingTypeVulnerability,
Status: types.FindingStatusIgnored,
Statement: "Not exploitable",
Source: ".trivyignore.yaml",
Finding: types.DetectedVulnerability{
VulnerabilityID: "CVE-2020-0001",
PkgName: "foo",
InstalledVersion: "1.2.3",
Status: dbTypes.StatusWillNotFix,
Vulnerability: dbTypes.Vulnerability{
Title: "title1",
Description: "desc1",
Severity: "MEDIUM",
},
},
},
},
},
showSuppressed: true,
want: `
test (jar)
==========
Total: 0 (MEDIUM: 0, HIGH: 0)


Suppressed Vulnerabilities (Total: 1)
=====================================
┌─────────┬───────────────┬──────────┬─────────┬─────────────────┬───────────────────┐
│ Library │ Vulnerability │ Severity │ Status │ Statement │ Source │
├─────────┼───────────────┼──────────┼─────────┼─────────────────┼───────────────────┤
│ foo │ CVE-2020-0001 │ MEDIUM │ ignored │ Not exploitable │ .trivyignore.yaml │
└─────────┴───────────────┴──────────┴─────────┴─────────────────┴───────────────────┘
`,
},
}
Expand Down