1
0
mirror of https://github.com/securego/gosec.git synced 2025-07-03 00:27:05 +02:00

Ignore the issues from generated files when using the analysis framework (#1079)

Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
This commit is contained in:
Cosmin Cojocar
2023-11-30 17:42:44 +01:00
committed by GitHub
parent 43b7cbf661
commit eb256a7d70
2 changed files with 69 additions and 2 deletions

View File

@ -471,7 +471,7 @@ var _ = Describe("Analyzer", func() {
issues, _, _ := customAnalyzer.Report()
Expect(issues).Should(HaveLen(1))
})
It("should be able to scan generated files if NOT excluded", func() {
It("should be able to scan generated files if NOT excluded when using the rules", func() {
customAnalyzer := gosec.NewAnalyzer(nil, true, false, false, 1, logger)
customAnalyzer.LoadRules(rules.Generate(false).RulesInfo())
pkg := testutils.NewTestPackage()
@ -492,7 +492,7 @@ var _ = Describe("Analyzer", func() {
issues, _, _ := customAnalyzer.Report()
Expect(issues).Should(HaveLen(1))
})
It("should be able to skip generated files if excluded", func() {
It("should be able to skip generated files if excluded when using the rules", func() {
customAnalyzer := gosec.NewAnalyzer(nil, true, true, false, 1, logger)
customAnalyzer.LoadRules(rules.Generate(false).RulesInfo())
pkg := testutils.NewTestPackage()
@ -513,6 +513,50 @@ var _ = Describe("Analyzer", func() {
issues, _, _ := customAnalyzer.Report()
Expect(issues).Should(BeEmpty())
})
It("should be able to scan generated files if NOT excluded when using the analyzes", func() {
customAnalyzer := gosec.NewAnalyzer(nil, true, false, false, 1, logger)
customAnalyzer.LoadRules(rules.Generate(false).RulesInfo())
pkg := testutils.NewTestPackage()
defer pkg.Close()
pkg.AddFile("foo.go", `
package main
// Code generated some-generator DO NOT EDIT.
import (
"fmt"
)
func main() {
values := []string{}
fmt.Println(values[0])
}`)
err := pkg.Build()
Expect(err).ShouldNot(HaveOccurred())
err = customAnalyzer.Process(buildTags, pkg.Path)
Expect(err).ShouldNot(HaveOccurred())
issues, _, _ := customAnalyzer.Report()
Expect(issues).Should(HaveLen(1))
})
It("should be able to skip generated files if excluded when using the analyzes", func() {
customAnalyzer := gosec.NewAnalyzer(nil, true, true, false, 1, logger)
customAnalyzer.LoadRules(rules.Generate(false).RulesInfo())
pkg := testutils.NewTestPackage()
defer pkg.Close()
pkg.AddFile("foo.go", `
package main
// Code generated some-generator DO NOT EDIT.
import (
"fmt"
)
func main() {
values := []string{}
fmt.Println(values[0])
}`)
err := pkg.Build()
Expect(err).ShouldNot(HaveOccurred())
err = customAnalyzer.Process(buildTags, pkg.Path)
Expect(err).ShouldNot(HaveOccurred())
issues, _, _ := customAnalyzer.Report()
Expect(issues).Should(BeEmpty())
})
})
It("should be able to analyze Cgo files", func() {
analyzer.LoadRules(rules.Generate(false).RulesInfo())