@@ -139,7 +139,7 @@ var _ = Describe("Analyzer", func() {
139139 }
140140 })
141141
142- It ("should not report errors when a nosec comment is present" , func () {
142+ It ("should not report errors when a nosec line comment is present" , func () {
143143 sample := testutils .SampleCodeG401 [0 ]
144144 source := sample .Code [0 ]
145145 analyzer .LoadRules (rules .Generate (false , rules .NewRuleFilter (false , "G401" )).RulesInfo ())
@@ -156,6 +156,23 @@ var _ = Describe("Analyzer", func() {
156156 Expect (nosecIssues ).Should (BeEmpty ())
157157 })
158158
159+ It ("should not report errors when a nosec block comment is present" , func () {
160+ sample := testutils .SampleCodeG401 [0 ]
161+ source := sample .Code [0 ]
162+ analyzer .LoadRules (rules .Generate (false , rules .NewRuleFilter (false , "G401" )).RulesInfo ())
163+
164+ nosecPackage := testutils .NewTestPackage ()
165+ defer nosecPackage .Close ()
166+ nosecSource := strings .Replace (source , "h := md5.New()" , "h := md5.New() /* #nosec */" , 1 )
167+ nosecPackage .AddFile ("md5.go" , nosecSource )
168+ err := nosecPackage .Build ()
169+ Expect (err ).ShouldNot (HaveOccurred ())
170+ err = analyzer .Process (buildTags , nosecPackage .Path )
171+ Expect (err ).ShouldNot (HaveOccurred ())
172+ nosecIssues , _ , _ := analyzer .Report ()
173+ Expect (nosecIssues ).Should (BeEmpty ())
174+ })
175+
159176 It ("should not report errors when an exclude comment is present for the correct rule" , func () {
160177 // Rule for MD5 weak crypto usage
161178 sample := testutils .SampleCodeG401 [0 ]
0 commit comments