@@ -139,7 +139,7 @@ var _ = Describe("Analyzer", func() {
139
139
}
140
140
})
141
141
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 () {
143
143
sample := testutils .SampleCodeG401 [0 ]
144
144
source := sample .Code [0 ]
145
145
analyzer .LoadRules (rules .Generate (false , rules .NewRuleFilter (false , "G401" )).RulesInfo ())
@@ -156,6 +156,23 @@ var _ = Describe("Analyzer", func() {
156
156
Expect (nosecIssues ).Should (BeEmpty ())
157
157
})
158
158
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
+
159
176
It ("should not report errors when an exclude comment is present for the correct rule" , func () {
160
177
// Rule for MD5 weak crypto usage
161
178
sample := testutils .SampleCodeG401 [0 ]
0 commit comments