Add tests for excludes with comments

This commit is contained in:
Jon McClintock 2017-10-05 21:43:54 +00:00
parent 37cada13f3
commit 2b2999b48d

View file

@ -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")
}