Skip to content

Commit

Permalink
add tests for severity and confidence
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx authored and ldez committed Oct 27, 2021
1 parent de31a37 commit ddad317
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ linters-settings:
# Exclude generated files
exclude-generated: true
# Filter out the issues with a lower severity than the given value. Valid options are: low, medium, high.
severity: "high"
severity: "low"
# Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high.
confidence: "medium"
confidence: "low"
# To specify the configuration of rules.
# The configuration of rules is not fully documented by gosec:
# https://github.com/securego/gosec#configuration
Expand Down
6 changes: 3 additions & 3 deletions pkg/golinters/gosec.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func NewGosec(settings *config.GoSecSettings) *goanalysis.Linter {
}
severity, err := convertToScore(settings.Severity)
if err != nil {
lintCtx.Log.Warnf("The provided severity %q is invalid, use low instead. Valid options: low, medium, high", err)
lintCtx.Log.Warnf("The provided severity %v", err)
}

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

Expand Down
4 changes: 4 additions & 0 deletions test/testdata/configs/gosec_severity_confidence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters-settings:
gosec:
severity: "medium"
confidence: "medium"
31 changes: 31 additions & 0 deletions test/testdata/gosec_severity_confidence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//args: -Egosec
//config_path: testdata/configs/gosec_severity_confidence.yml
package testdata

import (
"fmt"
"io/ioutil"
"net/http"
)

var url string = "https://www.abcdefghijk.com"

func gosecVariableURL() {
resp, err := http.Get(url) // ERROR "G107: Potential HTTP request made with variable url"
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Printf("%s", body)
}

func gosecHardcodedCredentials() {
username := "admin"
var password = "f62e5bcda4fae4f82370da0c6f20697b8f8447ef"

fmt.Println("Doing something with: ", username, password)
}

0 comments on commit ddad317

Please sign in to comment.