1
0
mirror of https://github.com/securego/gosec.git synced 2025-11-27 22:28:20 +02:00

rand: resolve math/rand package

This commit is contained in:
Tommy Murphy
2016-11-01 22:10:20 -04:00
parent 068e8a85ad
commit 75e0e1aa42
2 changed files with 90 additions and 10 deletions

View File

@@ -55,3 +55,26 @@ func TestRandBad(t *testing.T) {
checkTestResults(t, issues, 1, "Use of weak random number generator (math/rand instead of crypto/rand)")
}
func TestRandRenamed(t *testing.T) {
config := map[string]interface{}{"ignoreNosec": false}
analyzer := gas.NewAnalyzer(config, nil)
analyzer.AddRule(NewWeakRandCheck(config))
issues := gasTestRunner(
`
package samples
import (
"crypto/rand"
mrand "math/rand"
)
func main() {
good, err := rand.Read(nil)
i := mrand.Int()
}`, analyzer)
checkTestResults(t, issues, 0, "Not expected to match")
}