mirror of
https://github.com/securego/gosec.git
synced 2024-11-05 19:45:51 +00:00
Add tests for excludes with comments
This commit is contained in:
parent
37cada13f3
commit
2b2999b48d
1 changed files with 46 additions and 0 deletions
|
@ -168,6 +168,29 @@ func TestNosecBlockExcludeOne(t *testing.T) {
|
||||||
checkTestResults(t, issues, 0, "None")
|
checkTestResults(t, issues, 0, "None")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNosecBlockExcludeOneWithComment(t *testing.T) {
|
||||||
|
config := map[string]interface{}{"ignoreNosec": false}
|
||||||
|
analyzer := gas.NewAnalyzer(config, nil)
|
||||||
|
analyzer.AddRule(NewSubproc("G001", config))
|
||||||
|
|
||||||
|
issues := gasTestRunner(
|
||||||
|
`package main
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// #exclude !G001(This rule is bogus)
|
||||||
|
if true {
|
||||||
|
cmd := exec.Command("sh", "-c", os.Getenv("BLAH"))
|
||||||
|
cmd.Run()
|
||||||
|
}
|
||||||
|
}`, analyzer)
|
||||||
|
|
||||||
|
checkTestResults(t, issues, 0, "None")
|
||||||
|
}
|
||||||
|
|
||||||
func TestNosecBlockExcludeOneNoMatch(t *testing.T) {
|
func TestNosecBlockExcludeOneNoMatch(t *testing.T) {
|
||||||
config := map[string]interface{}{"ignoreNosec": false}
|
config := map[string]interface{}{"ignoreNosec": false}
|
||||||
analyzer := gas.NewAnalyzer(config, nil)
|
analyzer := gas.NewAnalyzer(config, nil)
|
||||||
|
@ -256,3 +279,26 @@ func TestNosecExcludeTwoBothMatch(t *testing.T) {
|
||||||
|
|
||||||
checkTestResults(t, issues, 0, "No issues")
|
checkTestResults(t, issues, 0, "No issues")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNosecExcludeTwoWithComments(t *testing.T) {
|
||||||
|
config := map[string]interface{}{"ignoreNosec": false}
|
||||||
|
analyzer := gas.NewAnalyzer(config, nil)
|
||||||
|
analyzer.AddRule(NewSubproc("G001", config))
|
||||||
|
analyzer.AddRule(NewWeakRandCheck("G002", config))
|
||||||
|
|
||||||
|
issues := gasTestRunner(
|
||||||
|
`package main
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// #exclude !G001(The env var is trusted) !G002(Unimportant random number)
|
||||||
|
cmd := exec.Command("sh", "-c", os.Getenv("BLAH"), string(rand.Int()))
|
||||||
|
cmd.Run()
|
||||||
|
}`, analyzer)
|
||||||
|
|
||||||
|
checkTestResults(t, issues, 0, "No issues")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue