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

Split the G401 rule into two separate ones

Now the G401 rule is split into hashing and encryption algorithms.

G401 is responsible for checking the usage of MD5 and SHA1, with corresponding CWE of 328.
And G405(New rule) is responsible for checking the usege of DES and RC4, with corresponding CWE of 327.
This commit is contained in:
Dimitar Banchev
2024-06-20 13:02:59 +02:00
committed by Cosmin Cojocar
parent 2e71f37efd
commit 58e4fccc13
11 changed files with 480 additions and 14 deletions

View File

@@ -94,6 +94,32 @@ var _ = Describe("Call List", func() {
Expect(matched).Should(Equal(1))
})
It("should match a package call expression", func() {
// Create file to be scanned
pkg := testutils.NewTestPackage()
defer pkg.Close()
pkg.AddFile("cipher.go", testutils.SampleCodeG405[0].Code[0])
ctx := pkg.CreateContext("cipher.go")
// Search for des.NewCipher()
calls.Add("crypto/des", "NewCipher")
// Stub out visitor and count number of matched call expr
matched := 0
v := testutils.NewMockVisitor()
v.Context = ctx
v.Callback = func(n ast.Node, ctx *gosec.Context) bool {
if _, ok := n.(*ast.CallExpr); ok && calls.ContainsPkgCallExpr(n, ctx, false) != nil {
matched++
}
return true
}
ast.Walk(v, ctx.Root)
Expect(matched).Should(Equal(1))
})
It("should match a call expression", func() {
// Create file to be scanned
pkg := testutils.NewTestPackage()