@@ -344,19 +344,22 @@ def test_check_ast_node_bad_type(self):
344
344
self .assertRaises (TypeError , b_utils .check_ast_node , "walk" )
345
345
346
346
def test_get_nosec (self ):
347
- # prepare the input data
348
- nosec_lines = {
349
- 3 : ' aws_access_key_id=\' key_goes_here\' ,\n ' ,
350
- 4 : ' aws_secret_access_key=\' secret_goes_here\' ,\n ' ,
351
- 5 : ' endpoint_url=\' s3.amazonaws.com\' ,\n ' ,
352
- 7 : '# nosec B108\n ' ,
353
- 8 : '# nosec B108\n '
354
- }
355
- context = {
356
- 'lineno' : 0 ,
357
- 'linerange' : [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
358
- }
359
- # execute the function being tested
360
- result = b_utils .get_nosec (nosec_lines , context )
361
- # assert that the expected result is returned
362
- self .assertEqual (result , "# nosec B106" )
347
+ # Test case 1: no #nosec comments
348
+ nosec_lines = {}
349
+ context = {"lineno" : 10 , "linerange" : [5 , 15 ]}
350
+ self .assertIsNone (b_utils .get_nosec (nosec_lines , context ))
351
+
352
+ # Test case 2: #nosec comment on lineno
353
+ nosec_lines = {10 : "B106" }
354
+ context = {"lineno" : 10 , "linerange" : [5 , 15 ]}
355
+ self .assertEqual (b_utils .get_nosec (nosec_lines , context ), "B106" )
356
+
357
+ # Test case 3: #nosec comment on a line within linerange
358
+ nosec_lines = {12 : "B106" }
359
+ context = {"lineno" : 10 , "linerange" : [5 , 15 ]}
360
+ self .assertEqual (b_utils .get_nosec (nosec_lines , context ), "B106" )
361
+
362
+ # Test case 4: #nosec comment outside linerange
363
+ nosec_lines = {3 : "B106" }
364
+ context = {"lineno" : 10 , "linerange" : [5 , 15 ]}
365
+ self .assertIsNone (b_utils .get_nosec (nosec_lines , context ))
0 commit comments