From e72f54ed40931d60e2fb765ed205dc573cca96fe Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Fri, 21 May 2021 11:14:43 +0200 Subject: [PATCH] Fix HTML template and display the gosec version --- report/formatter_test.go | 4 ++-- report/html/template.go | 44 ++++++++++++++++++++-------------------- report/text/template.go | 9 ++++---- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/report/formatter_test.go b/report/formatter_test.go index 21a71e8..2db39f1 100644 --- a/report/formatter_test.go +++ b/report/formatter_test.go @@ -304,10 +304,10 @@ var _ = Describe("Formatter", func() { error := map[string][]gosec.Error{} buf := new(bytes.Buffer) - reportInfo := gosec.NewReportInfo([]*gosec.Issue{&issue}, &gosec.Metrics{NumFiles: 0, NumLines: 0, NumNosec: 0, NumFound: 0}, error) + reportInfo := gosec.NewReportInfo([]*gosec.Issue{&issue}, &gosec.Metrics{NumFiles: 0, NumLines: 0, NumNosec: 0, NumFound: 0}, error).WithVersion("v2.7.0") err := CreateReport(buf, "xml", false, []string{}, reportInfo) Expect(err).ShouldNot(HaveOccurred()) - pattern := "Results:\n\n\n[/home/src/project/test.go:1] - %s (CWE-%s): test (Confidence: HIGH, Severity: HIGH)\n > 1: testcode\n\n\n\nSummary:\n Files: 0\n Lines: 0\n Nosec: 0\n Issues: 0\n\n" + pattern := "Results:\n\n\n[/home/src/project/test.go:1] - %s (CWE-%s): test (Confidence: HIGH, Severity: HIGH)\n > 1: testcode\n\n\n\nSummary:\n Gosec : v2.7.0\n Files : 0\n Lines : 0\n Nosec : 0\n Issues : 0\n\n" expect := fmt.Sprintf(pattern, rule, cwe.ID) Expect(buf.String()).To(Equal(expect)) } diff --git a/report/html/template.go b/report/html/template.go index a6be2f1..d628468 100644 --- a/report/html/template.go +++ b/report/html/template.go @@ -19,7 +19,7 @@ const templateContent = ` - Go AST Scanner + Golang Security Checker @@ -89,9 +89,7 @@ const templateContent = `

-                
-                  { this.props.data.code }
-                
+                { this.props.data.code }
               
@@ -103,7 +101,7 @@ const templateContent = ` render: function() { return (

- Scanned { this.props.data.Stats.files.toLocaleString() } files + Gosec {this.props.data.GosecVersion} scanned { this.props.data.Stats.files.toLocaleString() } files with { this.props.data.Stats.lines.toLocaleString() } lines of code. { this.props.data.Stats.nosec ? '\n' + this.props.data.Stats.nosec.toLocaleString() + ' false positives (nosec) have been waived.' : ''}

@@ -170,7 +168,6 @@ const templateContent = ` ); } }); - var LevelSelector = React.createClass({ handleChange: function(level) { return function(e) { @@ -183,14 +180,18 @@ const templateContent = ` }.bind(this); }, render: function() { - var highDisabled = !this.props.available.includes("HIGH"); - var mediumDisabled = !this.props.available.includes("MEDIUM"); - var lowDisabled = !this.props.available.includes("LOW"); - var on = "", off = "disabled"; var HIGH = "HIGH", MEDIUM = "MEDIUM", LOW = "LOW"; + var highDisabled = !this.props.available.includes(HIGH); + var mediumDisabled = !this.props.available.includes(MEDIUM); + var lowDisabled = !this.props.available.includes(LOW); + var on = "", off = "disabled"; + var baseClassName = "label checkbox "; + var highClassName = baseClassName + (highDisabled ? off : on); + var mediumClassName = baseClassName + (mediumDisabled ? off : on); + var lowClassName = baseClassName + (lowDisabled ? off : on); return ( -