Skip to content

Commit

Permalink
Fix secure-random to ignore random.SystemRandom
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Jan 31, 2024
1 parent 26b7379 commit fe92398
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core_codemods/secure_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def rule(cls):
rules:
- patterns:
- pattern: random.$F(...)
- pattern-not: random.SystemRandom()
- pattern-inside: |
import random
...
Expand Down
24 changes: 24 additions & 0 deletions tests/codemods/test_secure_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,27 @@ def test_random_multifunctions(self, tmpdir):
"""

self.run_and_assert(tmpdir, input_code, expected_output)

def test_random_systemrandom(self, tmpdir):
input_code = """
import random
rand = random.SystemRandom()
"""
self.run_and_assert(tmpdir, input_code, input_code)

def test_random_systemrandom_importfrom(self, tmpdir):
input_code = """
from random import SystemRandom
rand = SystemRandom()
"""
self.run_and_assert(tmpdir, input_code, input_code)

def test_random_systemrandom_import_alias(self, tmpdir):
input_code = """
import random as domran
rand = domran.SystemRandom()
"""
self.run_and_assert(tmpdir, input_code, input_code)

0 comments on commit fe92398

Please sign in to comment.