Skip to content

Commit e72f54e

Browse files
authored
Fix HTML template and display the gosec version
1 parent c3f25b8 commit e72f54e

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

report/formatter_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ var _ = Describe("Formatter", func() {
304304
error := map[string][]gosec.Error{}
305305

306306
buf := new(bytes.Buffer)
307-
reportInfo := gosec.NewReportInfo([]*gosec.Issue{&issue}, &gosec.Metrics{NumFiles: 0, NumLines: 0, NumNosec: 0, NumFound: 0}, error)
307+
reportInfo := gosec.NewReportInfo([]*gosec.Issue{&issue}, &gosec.Metrics{NumFiles: 0, NumLines: 0, NumNosec: 0, NumFound: 0}, error).WithVersion("v2.7.0")
308308
err := CreateReport(buf, "xml", false, []string{}, reportInfo)
309309
Expect(err).ShouldNot(HaveOccurred())
310-
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"
310+
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"
311311
expect := fmt.Sprintf(pattern, rule, cwe.ID)
312312
Expect(buf.String()).To(Equal(expect))
313313
}

report/html/template.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const templateContent = `
1919
<html lang="en">
2020
<head>
2121
<meta charset="utf-8">
22-
<title>Go AST Scanner</title>
22+
<title>Golang Security Checker</title>
2323
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.2.1/css/bulma.min.css" integrity="sha256-DRcOKg8NK1KkSkcymcGmxOtS/lAn0lHWJXRa15gMHHk=" crossorigin="anonymous"/>
2424
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.min.js" integrity="sha256-cLWs9L+cjZg8CjGHMpJqUgKKouPlmoMP/0wIdPtaPGs=" crossorigin="anonymous"></script>
2525
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.min.js" integrity="sha256-JIW8lNqN2EtqC6ggNZYnAdKMJXRQfkPMvdRt+b0/Jxc=" crossorigin="anonymous"></script>
@@ -89,9 +89,7 @@ const templateContent = `
8989
</p>
9090
<figure className="highlight">
9191
<pre>
92-
<code className="golang hljs">
93-
{ this.props.data.code }
94-
</code>
92+
<code className="go">{ this.props.data.code }</code>
9593
</pre>
9694
</figure>
9795
</div>
@@ -103,7 +101,7 @@ const templateContent = `
103101
render: function() {
104102
return (
105103
<p className="help">
106-
Scanned { this.props.data.Stats.files.toLocaleString() } files
104+
Gosec {this.props.data.GosecVersion} scanned { this.props.data.Stats.files.toLocaleString() } files
107105
with { this.props.data.Stats.lines.toLocaleString() } lines of code.
108106
{ this.props.data.Stats.nosec ? '\n' + this.props.data.Stats.nosec.toLocaleString() + ' false positives (nosec) have been waived.' : ''}
109107
</p>
@@ -170,7 +168,6 @@ const templateContent = `
170168
);
171169
}
172170
});
173-
174171
var LevelSelector = React.createClass({
175172
handleChange: function(level) {
176173
return function(e) {
@@ -183,30 +180,34 @@ const templateContent = `
183180
}.bind(this);
184181
},
185182
render: function() {
186-
var highDisabled = !this.props.available.includes("HIGH");
187-
var mediumDisabled = !this.props.available.includes("MEDIUM");
188-
var lowDisabled = !this.props.available.includes("LOW");
189-
var on = "", off = "disabled";
190183
var HIGH = "HIGH", MEDIUM = "MEDIUM", LOW = "LOW";
184+
var highDisabled = !this.props.available.includes(HIGH);
185+
var mediumDisabled = !this.props.available.includes(MEDIUM);
186+
var lowDisabled = !this.props.available.includes(LOW);
187+
var on = "", off = "disabled";
188+
var baseClassName = "label checkbox ";
189+
var highClassName = baseClassName + (highDisabled ? off : on);
190+
var mediumClassName = baseClassName + (mediumDisabled ? off : on);
191+
var lowClassName = baseClassName + (lowDisabled ? off : on);
191192
return (
192193
<span>
193-
<label className="label checkbox { (highDisabled ? off : on )}">
194+
<label className={ highClassName }>
194195
<input
195196
type="checkbox"
196197
checked={ this.props.selected.includes(HIGH) }
197198
disabled={ highDisabled }
198199
onChange={ this.handleChange(HIGH) }/>
199200
High
200201
</label>
201-
<label className="label checkbox {( mediumDisabled ? off : on )}">
202+
<label className={mediumClassName}>
202203
<input
203204
type="checkbox"
204205
checked={ this.props.selected.includes(MEDIUM) }
205206
disabled={ mediumDisabled }
206207
onChange={ this.handleChange(MEDIUM) }/>
207208
Medium
208209
</label>
209-
<label className="label checkbox {( lowDisabled ? off : on )}">
210+
<label className={lowClassName}>
210211
<input
211212
type="checkbox"
212213
checked={ this.props.selected.includes(LOW) }
@@ -218,7 +219,6 @@ const templateContent = `
218219
);
219220
}
220221
});
221-
222222
var Navigation = React.createClass({
223223
updateSeverity: function(vals) {
224224
this.props.onSeverity(vals);
@@ -276,12 +276,14 @@ const templateContent = `
276276
</strong>
277277
</div>
278278
<div className="panel-block">
279-
<select onChange={ this.updateIssueType }>
280-
<option value="all" selected={ !this.props.issueType }>
281-
(all)
282-
</option>
283-
{ issueTypes }
284-
</select>
279+
<div className="select">
280+
<select onChange={ this.updateIssueType }>
281+
<option value="all" selected={ !this.props.issueType }>
282+
(all)
283+
</option>
284+
{ issueTypes }
285+
</select>
286+
</div>
285287
</div>
286288
</nav>
287289
);
@@ -353,11 +355,9 @@ const templateContent = `
353355
.filter(function(item, pos, ary) {
354356
return !pos || item != ary[pos - 1];
355357
});
356-
357358
if (this.state.issueType && !allTypes.includes(this.state.issueType)) {
358359
this.setState({issueType: null});
359360
}
360-
361361
this.setState({allIssueTypes: allTypes});
362362
},
363363
render: function() {

report/text/template.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ Golang errors in file: [{{ $filePath }}]:
1313
1414
{{ end }}
1515
{{ notice "Summary:" }}
16-
Files: {{.Stats.NumFiles}}
17-
Lines: {{.Stats.NumLines}}
18-
Nosec: {{.Stats.NumNosec}}
19-
Issues: {{ if eq .Stats.NumFound 0 }}
16+
Gosec : {{.GosecVersion}}
17+
Files : {{.Stats.NumFiles}}
18+
Lines : {{.Stats.NumLines}}
19+
Nosec : {{.Stats.NumNosec}}
20+
Issues : {{ if eq .Stats.NumFound 0 }}
2021
{{- success .Stats.NumFound }}
2122
{{- else }}
2223
{{- danger .Stats.NumFound }}

0 commit comments

Comments
 (0)