Skip to content

Commit 83147b8

Browse files
authored
fix(cli): HTML generation of vuln assessment (#1204)
* fix(cli): HTML generation of vuln assessment Since #1025 the generation of static HTML output has been broken, this change fixes it so that it renders like it was before. Signed-off-by: Salim Afiune Maya <[email protected]> * test(cli): vulContainerImageLayersToHTML() function Signed-off-by: Salim Afiune Maya <[email protected]> --------- Signed-off-by: Salim Afiune Maya <[email protected]>
1 parent cc90a5b commit 83147b8

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

api/v2_vulnerabilities.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (r VulnerabilitiesContainersResponse) VulnFixableCount(severity string) int
217217
func (r VulnerabilitiesContainersResponse) TotalVulnerabilities() int {
218218
count := 0
219219
for _, vuln := range r.Data {
220-
if vuln.EvalCtx.ImageInfo.Status == "VULNERABLE" {
220+
if vuln.Status == "VULNERABLE" {
221221
count = count + 1
222222
}
223223
}

cli/cmd/vuln_html.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -328,32 +328,31 @@ func vulContainerImageLayersToHTML(image []api.VulnerabilityContainer) []htmlVul
328328
var vulns = []htmlVuln{}
329329
for _, i := range image {
330330
space := regexp.MustCompile(`\s+`)
331-
// Todo(v2): CreatedBy does not exist in v2
332-
layerCreatedBy := space.ReplaceAllString("", " ")
331+
layerCreatedBy := space.ReplaceAllString(i.FeatureProps.IntroducedIn, " ")
333332

334333
newHtmlVuln := htmlVuln{
335334
CVE: i.VulnID,
336335
Severity: cases.Title(language.English).String(i.Severity),
337-
SeverityHTMLClass: i.Severity,
336+
SeverityHTMLClass: strings.ToLower(i.Severity),
338337
PkgName: i.FeatureKey.Name,
339338
PkgVersion: i.FeatureKey.Version,
340339
PkgFixed: i.FixInfo.FixedVersion,
341340
Layer: layerCreatedBy,
342341
}
343342

344343
// Todo(v2): CVSSv3Score does not exist in v2 container response
345-
//if score := vul.CVSSv3Score(); score != 0 {
346-
// // CVSSv3
347-
// newHtmlVuln.V3Score = score
348-
// newHtmlVuln.UseV3Score = true
349-
//} else if score = vul.CVSSv2Score(); score != 0 {
350-
// // CVSSv2
351-
// newHtmlVuln.V2Score = score
352-
// newHtmlVuln.UseV2Score = true
353-
//} else {
354-
// // N/A
355-
// newHtmlVuln.UseNoScore = true
356-
//}
344+
// if score := vul.CVSSv3Score(); score != 0 {
345+
// // CVSSv3
346+
// newHtmlVuln.V3Score = score
347+
// newHtmlVuln.UseV3Score = true
348+
// } else if score = vul.CVSSv2Score(); score != 0 {
349+
// // CVSSv2
350+
// newHtmlVuln.V2Score = score
351+
// newHtmlVuln.UseV2Score = true
352+
// } else {
353+
// // N/A
354+
newHtmlVuln.UseNoScore = true
355+
// }
357356

358357
vulns = append(vulns, newHtmlVuln)
359358
}

cli/cmd/vuln_html_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Author:: Salim Afiune Maya (<[email protected]>)
3+
// Copyright:: Copyright 2023, Lacework Inc.
4+
// License:: Apache License, Version 2.0
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
19+
package cmd
20+
21+
import (
22+
"testing"
23+
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
func TestVulContainerImageLayersToHTML(t *testing.T) {
28+
var (
29+
expectedVulnIDs = []string{"CVE-2021-24215", "CVE-2020-24215"}
30+
resp = mockVulnerabilityAssessment()
31+
subject = vulContainerImageLayersToHTML(resp.Data)
32+
)
33+
if assert.Equal(t, 2, len(subject), "wrong number of vulnerabilities") {
34+
for _, vuln := range subject {
35+
assert.NotEmpty(t, vuln.Layer, "the layer should not be empty, did response change?")
36+
assert.True(t, vuln.UseNoScore, "do we have CVSS scores? update, please")
37+
assert.Contains(t, expectedVulnIDs, vuln.CVE,
38+
"missing CVE, check HTML output")
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)