Skip to content

Commit 9f94a01

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

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

Diff for: .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

Diff for: pkg/golinters/gosec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -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", str)
152152
}
153153
}
154154

Diff for: test/testdata/configs/gosec_severity_confidence.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
gosec:
3+
severity: "medium"
4+
confidence: "medium"

Diff for: test/testdata/gosec_severity_confidence.go

+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)