1
0
mirror of https://github.com/securego/gosec.git synced 2025-11-23 22:15:04 +02:00

Detect the unhandled errors even though they are explicitly ignored if the 'audit: enabled' setting is defined in the global configuration (#274)

* Define more explicit the global options in the configuration

* Detect in audit mode the unhandled errors even thought they are explicitly ignored
This commit is contained in:
Cosmin Cojocar
2019-01-14 12:37:40 +01:00
committed by Grant Murphy
parent 14ed63d558
commit f87af5fa72
8 changed files with 128 additions and 17 deletions

View File

@@ -12,13 +12,18 @@ import (
"github.com/securego/gosec/testutils"
)
type option struct {
name gosec.GlobalOption
value string
}
var _ = Describe("gosec rules", func() {
var (
logger *log.Logger
config gosec.Config
analyzer *gosec.Analyzer
runner func(string, []testutils.CodeSample)
runner func(string, []testutils.CodeSample, ...option)
buildTags []string
)
@@ -26,7 +31,10 @@ var _ = Describe("gosec rules", func() {
logger, _ = testutils.NewLogger()
config = gosec.NewConfig()
analyzer = gosec.NewAnalyzer(config, logger)
runner = func(rule string, samples []testutils.CodeSample) {
runner = func(rule string, samples []testutils.CodeSample, options ...option) {
for _, o := range options {
config.SetGlobal(o.name, o.value)
}
analyzer.LoadRules(rules.Generate(rules.NewRuleFilter(false, rule)).Builders())
for n, sample := range samples {
analyzer.Reset()
@@ -61,10 +69,14 @@ var _ = Describe("gosec rules", func() {
runner("G103", testutils.SampleCodeG103)
})
It("should errors not being checked", func() {
It("should detect errors not being checked", func() {
runner("G104", testutils.SampleCodeG104)
})
It("should detect errors not being checked in audit mode", func() {
runner("G104", testutils.SampleCodeG104Audit, option{name: gosec.Audit, value: "enabled"})
})
It("should detect of big.Exp function", func() {
runner("G105", testutils.SampleCodeG105)
})