Skip to content

Commit f69c71b

Browse files
committed
add tests for severity and confidence
Signed-off-by: Ryan Leung <[email protected]>
1 parent 221d30d commit f69c71b

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

.golangci.example.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ linters-settings:
372372
# Exclude generated files
373373
exclude-generated: true
374374
# Filter out the issues with a lower severity than the given value. Valid options are: low, medium, high.
375-
severity: "high"
375+
severity: "low"
376376
# Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high.
377-
confidence: "medium"
377+
confidence: "low"
378378
# To specify the configuration of rules.
379379
# The configuration of rules is not fully documented by gosec:
380380
# https://github.com/securego/gosec#configuration

pkg/golinters/gosec.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ func NewGosec(settings *config.GoSecSettings) *goanalysis.Linter {
7171
}
7272
severity, err := convertToScore(settings.Severity)
7373
if err != nil {
74-
lintCtx.Log.Warnf("The provided severity %q is invalid, use low instead. Valid options: low, medium, high", err)
74+
lintCtx.Log.Warnf("The provided severity %v", err)
7575
}
7676

7777
confidence, err := convertToScore(settings.Confidence)
7878
if err != nil {
79-
lintCtx.Log.Warnf("The provided confidence %q is invalid, use low instead. Valid options: low, medium, high", err)
79+
lintCtx.Log.Warnf("The provided confidence %v", err)
8080
}
8181
issues = filterIssues(issues, severity, confidence)
8282
res := make([]goanalysis.Issue, 0, len(issues))
@@ -148,7 +148,7 @@ func convertToScore(str string) (gosec.Score, error) {
148148
case "high":
149149
return gosec.High, nil
150150
default:
151-
return gosec.Low, errors.Errorf("'%s' not valid", str)
151+
return gosec.Low, errors.Errorf("'%s' is invalid, use low instead. Valid options: low, medium, high", str)
152152
}
153153
}
154154

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
gosec:
3+
severity: "medium"
4+
confidence: "medium"
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//args: -Egosec
2+
//config_path: testdata/configs/gosec_severity_confidence.yml
3+
package testdata
4+
5+
import (
6+
"fmt"
7+
"io/ioutil"
8+
"net/http"
9+
)
10+
11+
var url string = "https://www.abcdefghijk.com"
12+
13+
func gosecVariableURL() {
14+
resp, err := http.Get(url) // ERROR "G107: Potential HTTP request made with variable url"
15+
if err != nil {
16+
panic(err)
17+
}
18+
defer resp.Body.Close()
19+
body, err := ioutil.ReadAll(resp.Body)
20+
if err != nil {
21+
panic(err)
22+
}
23+
fmt.Printf("%s", body)
24+
}
25+
26+
func gosecHardcodedCredentials() {
27+
username := "admin"
28+
var password = "f62e5bcda4fae4f82370da0c6f20697b8f8447ef"
29+
30+
fmt.Println("Doing something with: ", username, password)
31+
}

0 commit comments

Comments
 (0)