From f3d2d995a1660d48b5c6fac5ede44f50daab78b0 Mon Sep 17 00:00:00 2001 From: Mathieu Kniewallner Date: Fri, 8 Mar 2024 23:36:41 +0100 Subject: [PATCH] test(rules): add missing tests for S311 --- .../test/fixtures/flake8_bandit/S311.py | 21 ++++++ .../src/rules/flake8_bandit/mod.rs | 1 + ...s__flake8_bandit__tests__S311_S311.py.snap | 71 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 crates/ruff_linter/resources/test/fixtures/flake8_bandit/S311.py create mode 100644 crates/ruff_linter/src/rules/flake8_bandit/snapshots/ruff_linter__rules__flake8_bandit__tests__S311_S311.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_bandit/S311.py b/crates/ruff_linter/resources/test/fixtures/flake8_bandit/S311.py new file mode 100644 index 00000000000000..043158fbaebd90 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/flake8_bandit/S311.py @@ -0,0 +1,21 @@ +import os +import random + +import a_lib + +# OK +random.SystemRandom() + +# Errors +random.Random() +random.random() +random.randrange() +random.randint() +random.choice() +random.choices() +random.uniform() +random.triangular() + +# Unrelated +os.urandom() +a_lib.random() diff --git a/crates/ruff_linter/src/rules/flake8_bandit/mod.rs b/crates/ruff_linter/src/rules/flake8_bandit/mod.rs index ec2a462aafbbd8..cb4b1a670be526 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/mod.rs @@ -48,6 +48,7 @@ mod tests { #[test_case(Rule::SuspiciousEvalUsage, Path::new("S307.py"))] #[test_case(Rule::SuspiciousMarkSafeUsage, Path::new("S308.py"))] #[test_case(Rule::SuspiciousURLOpenUsage, Path::new("S310.py"))] + #[test_case(Rule::SuspiciousNonCryptographicRandomUsage, Path::new("S311.py"))] #[test_case(Rule::SuspiciousTelnetUsage, Path::new("S312.py"))] #[test_case(Rule::SuspiciousTelnetlibImport, Path::new("S401.py"))] #[test_case(Rule::SuspiciousFtplibImport, Path::new("S402.py"))] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/snapshots/ruff_linter__rules__flake8_bandit__tests__S311_S311.py.snap b/crates/ruff_linter/src/rules/flake8_bandit/snapshots/ruff_linter__rules__flake8_bandit__tests__S311_S311.py.snap new file mode 100644 index 00000000000000..81e321f53f5cf6 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_bandit/snapshots/ruff_linter__rules__flake8_bandit__tests__S311_S311.py.snap @@ -0,0 +1,71 @@ +--- +source: crates/ruff_linter/src/rules/flake8_bandit/mod.rs +--- +S311.py:11:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes + | + 9 | # Errors +10 | random.Random() +11 | random.random() + | ^^^^^^^^^^^^^^^ S311 +12 | random.randrange() +13 | random.randint() + | + +S311.py:12:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes + | +10 | random.Random() +11 | random.random() +12 | random.randrange() + | ^^^^^^^^^^^^^^^^^^ S311 +13 | random.randint() +14 | random.choice() + | + +S311.py:13:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes + | +11 | random.random() +12 | random.randrange() +13 | random.randint() + | ^^^^^^^^^^^^^^^^ S311 +14 | random.choice() +15 | random.choices() + | + +S311.py:14:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes + | +12 | random.randrange() +13 | random.randint() +14 | random.choice() + | ^^^^^^^^^^^^^^^ S311 +15 | random.choices() +16 | random.uniform() + | + +S311.py:15:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes + | +13 | random.randint() +14 | random.choice() +15 | random.choices() + | ^^^^^^^^^^^^^^^^ S311 +16 | random.uniform() +17 | random.triangular() + | + +S311.py:16:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes + | +14 | random.choice() +15 | random.choices() +16 | random.uniform() + | ^^^^^^^^^^^^^^^^ S311 +17 | random.triangular() + | + +S311.py:17:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes + | +15 | random.choices() +16 | random.uniform() +17 | random.triangular() + | ^^^^^^^^^^^^^^^^^^^ S311 +18 | +19 | # Unrelated + |