@@ -168,6 +168,29 @@ func TestNosecBlockExcludeOne(t *testing.T) {
168
168
checkTestResults (t , issues , 0 , "None" )
169
169
}
170
170
171
+ func TestNosecBlockExcludeOneWithComment (t * testing.T ) {
172
+ config := map [string ]interface {}{"ignoreNosec" : false }
173
+ analyzer := gas .NewAnalyzer (config , nil )
174
+ analyzer .AddRule (NewSubproc ("G001" , config ))
175
+
176
+ issues := gasTestRunner (
177
+ `package main
178
+ import (
179
+ "os"
180
+ "os/exec"
181
+ )
182
+
183
+ func main() {
184
+ // #exclude !G001(This rule is bogus)
185
+ if true {
186
+ cmd := exec.Command("sh", "-c", os.Getenv("BLAH"))
187
+ cmd.Run()
188
+ }
189
+ }` , analyzer )
190
+
191
+ checkTestResults (t , issues , 0 , "None" )
192
+ }
193
+
171
194
func TestNosecBlockExcludeOneNoMatch (t * testing.T ) {
172
195
config := map [string ]interface {}{"ignoreNosec" : false }
173
196
analyzer := gas .NewAnalyzer (config , nil )
@@ -256,3 +279,26 @@ func TestNosecExcludeTwoBothMatch(t *testing.T) {
256
279
257
280
checkTestResults (t , issues , 0 , "No issues" )
258
281
}
282
+
283
+ func TestNosecExcludeTwoWithComments (t * testing.T ) {
284
+ config := map [string ]interface {}{"ignoreNosec" : false }
285
+ analyzer := gas .NewAnalyzer (config , nil )
286
+ analyzer .AddRule (NewSubproc ("G001" , config ))
287
+ analyzer .AddRule (NewWeakRandCheck ("G002" , config ))
288
+
289
+ issues := gasTestRunner (
290
+ `package main
291
+ import (
292
+ "math/rand"
293
+ "os"
294
+ "os/exec"
295
+ )
296
+
297
+ func main() {
298
+ // #exclude !G001(The env var is trusted) !G002(Unimportant random number)
299
+ cmd := exec.Command("sh", "-c", os.Getenv("BLAH"), string(rand.Int()))
300
+ cmd.Run()
301
+ }` , analyzer )
302
+
303
+ checkTestResults (t , issues , 0 , "No issues" )
304
+ }
0 commit comments