From ce867964d867911c7c6a493e655ce7d785a2097f Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Tue, 2 Jan 2024 10:05:02 -0800 Subject: [PATCH] Refactor the tests and test_case.py Signed-off-by: Eric Brown --- precli/rules/go/stdlib/crypto/weak_cipher.py | 2 - precli/rules/go/stdlib/crypto/weak_key.py | 2 - .../go/stdlib/crypto/test_weak_cipher.py | 10 +- .../rules/go/stdlib/crypto/test_weak_hash.py | 16 +- .../rules/go/stdlib/crypto/test_weak_key.py | 16 +- .../python/M2Crypto/test_m2crypto_weak_key.py | 16 +- .../rules/python/PyYAML/test_yaml_load.py | 48 +++--- .../aiohttp/test_no_certificate_verify.py | 44 +++--- .../test_cryptography_weak_cipher.py | 2 +- .../test_cryptography_weak_cipher_mode.py | 4 +- .../test_cryptography_weak_hash.py | 6 +- .../test_cryptography_weak_key.py | 120 +++++++-------- .../unit/rules/python/dill/test_dill_load.py | 8 +- .../httpx/test_no_certificate_verify.py | 32 ++-- .../jsonpickle/test_jsonpickle_decode.py | 8 +- .../python/pandas/test_pandas_read_pickle.py | 4 +- .../python/paramiko/test_host_key_policy.py | 16 +- .../pycrypto/test_pycrypto_weak_cipher.py | 12 +- .../pycrypto/test_pycrypto_weak_hash.py | 12 +- .../python/pycrypto/test_pycrypto_weak_key.py | 14 +- .../test_pycryptodomex_weak_cipher.py | 12 +- .../test_pycryptodomex_weak_hash.py | 12 +- .../test_pycryptodomex_weak_key.py | 14 +- .../python/pyghmi/test_pyghmi_cleartext.py | 10 +- .../pyopenssl/test_pyopenssl_weak_key.py | 14 +- .../python/pyopenssl/test_ssl_context.py | 14 +- .../requests/test_no_certificate_verify.py | 42 +++--- .../stdlib/crypt/test_crypt_weak_hash.py | 28 ++-- .../stdlib/ftplib/test_ftp_cleartext.py | 18 ++- .../stdlib/hashlib/test_hashlib_weak_hash.py | 110 +++++++------- .../stdlib/hmac/test_hmac_timing_attack.py | 12 +- .../python/stdlib/hmac/test_hmac_weak_hash.py | 140 +++++++++--------- .../stdlib/imaplib/test_imap_cleartext.py | 18 ++- .../python/stdlib/json/test_json_load.py | 10 +- .../logging/test_insecure_listen_config.py | 18 ++- .../stdlib/marshal/test_marshal_load.py | 8 +- .../stdlib/nntplib/test_nntp_cleartext.py | 12 +- .../python/stdlib/pickle/test_pickle_load.py | 10 +- .../stdlib/poplib/test_pop_cleartext.py | 18 ++- .../python/stdlib/shelve/test_shelve_open.py | 10 +- .../stdlib/smtplib/test_smtp_cleartext.py | 14 +- .../stdlib/ssl/test_get_server_certificate.py | 16 +- .../python/stdlib/ssl/test_ssl_context.py | 16 +- .../stdlib/ssl/test_ssl_create_context.py | 8 +- .../python/stdlib/ssl/test_wrap_socket.py | 18 ++- .../telnetlib/test_telnetlib_cleartext.py | 10 +- .../tempfile/test_mktemp_race_condition.py | 18 ++- tests/unit/rules/python/test_case.py | 56 ------- tests/unit/rules/{go => }/test_case.py | 26 ++-- 49 files changed, 544 insertions(+), 560 deletions(-) delete mode 100644 tests/unit/rules/python/test_case.py rename tests/unit/rules/{go => }/test_case.py (67%) diff --git a/precli/rules/go/stdlib/crypto/weak_cipher.py b/precli/rules/go/stdlib/crypto/weak_cipher.py index 84a59f72..f73dc43c 100644 --- a/precli/rules/go/stdlib/crypto/weak_cipher.py +++ b/precli/rules/go/stdlib/crypto/weak_cipher.py @@ -123,7 +123,6 @@ .. versionadded:: 1.0.0 """ # noqa: E501 -from precli.core.config import Config from precli.core.level import Level from precli.core.location import Location from precli.core.result import Result @@ -141,7 +140,6 @@ def __init__(self, id: str): "known vulnerabilities and weaknesses.", targets=("call"), wildcards={}, - config=Config(enabled=False), ) def analyze(self, context: dict, **kwargs: dict) -> Result: diff --git a/precli/rules/go/stdlib/crypto/weak_key.py b/precli/rules/go/stdlib/crypto/weak_key.py index 60215219..99d8a3a9 100644 --- a/precli/rules/go/stdlib/crypto/weak_key.py +++ b/precli/rules/go/stdlib/crypto/weak_key.py @@ -90,7 +90,6 @@ .. versionadded:: 1.0.0 """ # noqa: E501 -from precli.core.config import Config from precli.core.level import Level from precli.core.location import Location from precli.core.result import Result @@ -108,7 +107,6 @@ def __init__(self, id: str): "vulnerable to attacks.", targets=("call"), wildcards={}, - config=Config(enabled=False), ) def analyze(self, context: dict, **kwargs: dict) -> Result: diff --git a/tests/unit/rules/go/stdlib/crypto/test_weak_cipher.py b/tests/unit/rules/go/stdlib/crypto/test_weak_cipher.py index 8ac2180f..bec05bf0 100644 --- a/tests/unit/rules/go/stdlib/crypto/test_weak_cipher.py +++ b/tests/unit/rules/go/stdlib/crypto/test_weak_cipher.py @@ -6,14 +6,14 @@ from precli.core.level import Level from precli.parsers import go from precli.rules import Rule -from tests.unit.rules.go import test_case +from tests.unit.rules import test_case class CryptoWeakCipherTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "GO001" - self.parser = go.Go(enabled=[self.rule_id]) + self.parser = go.Go() self.base_path = os.path.join( "tests", "unit", @@ -40,9 +40,9 @@ def test_crypto_weak_cipher_rule_meta(self): @parameterized.expand( [ - "weak_cipher_aes", - "weak_cipher_des", - "weak_cipher_rc4", + "weak_cipher_aes.go", + "weak_cipher_des.go", + "weak_cipher_rc4.go", ] ) def test(self, filename): diff --git a/tests/unit/rules/go/stdlib/crypto/test_weak_hash.py b/tests/unit/rules/go/stdlib/crypto/test_weak_hash.py index a172f5a4..fb3195dc 100644 --- a/tests/unit/rules/go/stdlib/crypto/test_weak_hash.py +++ b/tests/unit/rules/go/stdlib/crypto/test_weak_hash.py @@ -6,14 +6,14 @@ from precli.core.level import Level from precli.parsers import go from precli.rules import Rule -from tests.unit.rules.go import test_case +from tests.unit.rules import test_case class CryptoWeakCipherTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "GO002" - self.parser = go.Go(enabled=[self.rule_id]) + self.parser = go.Go() self.base_path = os.path.join( "tests", "unit", @@ -38,12 +38,12 @@ def test_crypto_weak_cipher_rule_meta(self): @parameterized.expand( [ - "weak_hash_md5_new", - "weak_hash_md5_sum", - "weak_hash_sha1_new", - "weak_hash_sha1_sum", - "weak_hash_sha256_new", - "weak_hash_sha256_sum", + "weak_hash_md5_new.go", + "weak_hash_md5_sum.go", + "weak_hash_sha1_new.go", + "weak_hash_sha1_sum.go", + "weak_hash_sha256_new.go", + "weak_hash_sha256_sum.go", ] ) def test(self, filename): diff --git a/tests/unit/rules/go/stdlib/crypto/test_weak_key.py b/tests/unit/rules/go/stdlib/crypto/test_weak_key.py index a3d06268..5af569e2 100644 --- a/tests/unit/rules/go/stdlib/crypto/test_weak_key.py +++ b/tests/unit/rules/go/stdlib/crypto/test_weak_key.py @@ -6,14 +6,14 @@ from precli.core.level import Level from precli.parsers import go from precli.rules import Rule -from tests.unit.rules.go import test_case +from tests.unit.rules import test_case class CryptoWeakCipherTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "GO003" - self.parser = go.Go(enabled=[self.rule_id]) + self.parser = go.Go() self.base_path = os.path.join( "tests", "unit", @@ -38,12 +38,12 @@ def test_crypto_weak_cipher_rule_meta(self): @parameterized.expand( [ - "weak_key_dsa_1024", - "weak_key_dsa_2048", - "weak_key_dsa_3072", - "weak_key_rsa_1024", - "weak_key_rsa_2048", - "weak_key_rsa_4096", + "weak_key_dsa_1024.go", + "weak_key_dsa_2048.go", + "weak_key_dsa_3072.go", + "weak_key_rsa_1024.go", + "weak_key_rsa_2048.go", + "weak_key_rsa_4096.go", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/M2Crypto/test_m2crypto_weak_key.py b/tests/unit/rules/python/M2Crypto/test_m2crypto_weak_key.py index 66602ed7..f86ccf48 100644 --- a/tests/unit/rules/python/M2Crypto/test_m2crypto_weak_key.py +++ b/tests/unit/rules/python/M2Crypto/test_m2crypto_weak_key.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class M2cryptoWeakKeyTests(test_case.TestCase): @@ -37,13 +37,13 @@ def test_m2crypto_weak_key_rule_meta(self): @parameterized.expand( [ - "dsa_gen_params_1024", - "dsa_gen_params_2048", - "dsa_gen_params_4096", - "ec_gen_params_nid_secp112r1", - "rsa_gen_key_1024", - "rsa_gen_key_2048", - "rsa_gen_key_4096", + "dsa_gen_params_1024.py", + "dsa_gen_params_2048.py", + "dsa_gen_params_4096.py", + "ec_gen_params_nid_secp112r1.py", + "rsa_gen_key_1024.py", + "rsa_gen_key_2048.py", + "rsa_gen_key_4096.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/PyYAML/test_yaml_load.py b/tests/unit/rules/python/PyYAML/test_yaml_load.py index e6558530..d6cb1ef4 100644 --- a/tests/unit/rules/python/PyYAML/test_yaml_load.py +++ b/tests/unit/rules/python/PyYAML/test_yaml_load.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class YamlLoadTests(test_case.TestCase): @@ -37,29 +37,29 @@ def test_yaml_load_rule_meta(self): @parameterized.expand( [ - "yaml_load", - "yaml_load_from_import", - "yaml_load_from_import_alias", - "yaml_load_from_import_wildcard", - "yaml_load_import_alias", - "yaml_load_import_in_async_func", - "yaml_load_import_in_class", - "yaml_load_import_in_func", - "yaml_load_import_in_loop", - "yaml_load_importlib", - "yaml_load_incomplete_import", - "yaml_load_invalid_import", - "yaml_load_kwarg_alias_loader", - "yaml_load_kwarg_csafeloader", - "yaml_load_kwarg_json_safeloader", - "yaml_load_kwarg_loader", - "yaml_load_kwarg_safeloader", - "yaml_load_loader_as_var", - "yaml_load_no_import", - "yaml_load_positional_csafeloader", - "yaml_load_positional_loader", - "yaml_load_positional_safeloader", - "yaml_load_yaml_as_identifier", + "yaml_load.py", + "yaml_load_from_import.py", + "yaml_load_from_import_alias.py", + "yaml_load_from_import_wildcard.py", + "yaml_load_import_alias.py", + "yaml_load_import_in_async_func.py", + "yaml_load_import_in_class.py", + "yaml_load_import_in_func.py", + "yaml_load_import_in_loop.py", + "yaml_load_importlib.py", + "yaml_load_incomplete_import.py", + "yaml_load_invalid_import.py", + "yaml_load_kwarg_alias_loader.py", + "yaml_load_kwarg_csafeloader.py", + "yaml_load_kwarg_json_safeloader.py", + "yaml_load_kwarg_loader.py", + "yaml_load_kwarg_safeloader.py", + "yaml_load_loader_as_var.py", + "yaml_load_no_import.py", + "yaml_load_positional_csafeloader.py", + "yaml_load_positional_loader.py", + "yaml_load_positional_safeloader.py", + "yaml_load_yaml_as_identifier.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/aiohttp/test_no_certificate_verify.py b/tests/unit/rules/python/aiohttp/test_no_certificate_verify.py index 03b3ae51..9a6fcd11 100644 --- a/tests/unit/rules/python/aiohttp/test_no_certificate_verify.py +++ b/tests/unit/rules/python/aiohttp/test_no_certificate_verify.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class NoCertificateVerifyTests(test_case.TestCase): @@ -37,27 +37,27 @@ def test_no_certificate_verify_rule_meta(self): @parameterized.expand( [ - "session_delete_ssl_false", - "session_delete_verify_ssl_false", - "session_get_ssl_false", - "session_get_ssl_true", - "session_get_ssl_unset", - "session_get_verify_ssl_false", - "session_get_verify_ssl_true", - "session_head_ssl_false", - "session_head_verify_ssl_false", - "session_options_ssl_false", - "session_options_verify_ssl_false", - "session_patch_ssl_false", - "session_patch_verify_ssl_false", - "session_post_ssl_false", - "session_post_verify_ssl_false", - "session_put_ssl_false", - "session_put_verify_ssl_false", - "session_request_ssl_false", - "session_request_verify_ssl_false", - "session_ws_connect_ssl_false", - "session_ws_connect_verify_ssl_false", + "session_delete_ssl_false.py", + "session_delete_verify_ssl_false.py", + "session_get_ssl_false.py", + "session_get_ssl_true.py", + "session_get_ssl_unset.py", + "session_get_verify_ssl_false.py", + "session_get_verify_ssl_true.py", + "session_head_ssl_false.py", + "session_head_verify_ssl_false.py", + "session_options_ssl_false.py", + "session_options_verify_ssl_false.py", + "session_patch_ssl_false.py", + "session_patch_verify_ssl_false.py", + "session_post_ssl_false.py", + "session_post_verify_ssl_false.py", + "session_put_ssl_false.py", + "session_put_verify_ssl_false.py", + "session_request_ssl_false.py", + "session_request_verify_ssl_false.py", + "session_ws_connect_ssl_false.py", + "session_ws_connect_verify_ssl_false.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/cryptography/test_cryptography_weak_cipher.py b/tests/unit/rules/python/cryptography/test_cryptography_weak_cipher.py index f9532be5..3d95f510 100644 --- a/tests/unit/rules/python/cryptography/test_cryptography_weak_cipher.py +++ b/tests/unit/rules/python/cryptography/test_cryptography_weak_cipher.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class CryptographyWeakCipherTests(test_case.TestCase): diff --git a/tests/unit/rules/python/cryptography/test_cryptography_weak_cipher_mode.py b/tests/unit/rules/python/cryptography/test_cryptography_weak_cipher_mode.py index a1ef492c..0bdbdb37 100644 --- a/tests/unit/rules/python/cryptography/test_cryptography_weak_cipher_mode.py +++ b/tests/unit/rules/python/cryptography/test_cryptography_weak_cipher_mode.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class CryptographyWeakCipherModeTests(test_case.TestCase): @@ -37,7 +37,7 @@ def test_cryptography_weak_cipher_mode_rule_meta(self): @parameterized.expand( [ - "modes_ecb", + "modes_ecb.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/cryptography/test_cryptography_weak_hash.py b/tests/unit/rules/python/cryptography/test_cryptography_weak_hash.py index 198628c8..df62c02a 100644 --- a/tests/unit/rules/python/cryptography/test_cryptography_weak_hash.py +++ b/tests/unit/rules/python/cryptography/test_cryptography_weak_hash.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class CryptographyWeakHashTests(test_case.TestCase): @@ -37,8 +37,8 @@ def test_cryptography_weak_hash_rule_meta(self): @parameterized.expand( [ - "hashes_md5", - "hashes_sha1", + "hashes_md5.py", + "hashes_sha1.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/cryptography/test_cryptography_weak_key.py b/tests/unit/rules/python/cryptography/test_cryptography_weak_key.py index 30733a11..079e550b 100644 --- a/tests/unit/rules/python/cryptography/test_cryptography_weak_key.py +++ b/tests/unit/rules/python/cryptography/test_cryptography_weak_key.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class CryptographyWeakKeyTests(test_case.TestCase): @@ -37,65 +37,65 @@ def test_cryptography_weak_key_rule_meta(self): @parameterized.expand( [ - "dsa_generate_parameters_1024", - "dsa_generate_parameters_2048", - "dsa_generate_parameters_4096", - "dsa_generate_parameters_kwarg_1024", - "dsa_generate_parameters_kwarg_2048", - "dsa_generate_parameters_kwarg_4096", - "dsa_generate_parameters_var_1024", - "dsa_generate_private_key_1024", - "dsa_generate_private_key_2048", - "dsa_generate_private_key_4096", - "dsa_generate_private_key_kwarg_1024", - "dsa_generate_private_key_kwarg_2048", - "dsa_generate_private_key_kwarg_4096", - "dsa_generate_private_key_var_1024", - "ec_derive_private_key_brainpoolp256r1", - "ec_derive_private_key_brainpoolp384r1", - "ec_derive_private_key_brainpoolp512r1", - "ec_derive_private_key_secp192r1", - "ec_derive_private_key_secp224r1", - "ec_derive_private_key_secp256k1", - "ec_derive_private_key_secp256r1", - "ec_derive_private_key_secp384r1", - "ec_derive_private_key_secp521r1", - "ec_derive_private_key_sect163k1", - "ec_derive_private_key_sect163r2", - "ec_derive_private_key_sect233k1", - "ec_derive_private_key_sect233r1", - "ec_derive_private_key_sect283k1", - "ec_derive_private_key_sect283r1", - "ec_derive_private_key_sect409k1", - "ec_derive_private_key_sect409r1", - "ec_derive_private_key_sect571k1", - "ec_derive_private_key_sect571r1", - "ec_generate_private_key_brainpoolp256r1", - "ec_generate_private_key_brainpoolp384r1", - "ec_generate_private_key_brainpoolp512r1", - "ec_generate_private_key_secp192r1", - "ec_generate_private_key_secp224r1", - "ec_generate_private_key_secp256k1", - "ec_generate_private_key_secp256r1", - "ec_generate_private_key_secp384r1", - "ec_generate_private_key_secp521r1", - "ec_generate_private_key_sect163k1", - "ec_generate_private_key_sect163r2", - "ec_generate_private_key_sect233k1", - "ec_generate_private_key_sect233r1", - "ec_generate_private_key_sect283k1", - "ec_generate_private_key_sect283r1", - "ec_generate_private_key_sect409k1", - "ec_generate_private_key_sect409r1", - "ec_generate_private_key_sect571k1", - "ec_generate_private_key_sect571r1", - "rsa_generate_private_key_1024", - "rsa_generate_private_key_2048", - "rsa_generate_private_key_4096", - "rsa_generate_private_key_kwarg_1024", - "rsa_generate_private_key_kwarg_2048", - "rsa_generate_private_key_kwarg_4096", - "rsa_generate_private_key_var_1024", + "dsa_generate_parameters_1024.py", + "dsa_generate_parameters_2048.py", + "dsa_generate_parameters_4096.py", + "dsa_generate_parameters_kwarg_1024.py", + "dsa_generate_parameters_kwarg_2048.py", + "dsa_generate_parameters_kwarg_4096.py", + "dsa_generate_parameters_var_1024.py", + "dsa_generate_private_key_1024.py", + "dsa_generate_private_key_2048.py", + "dsa_generate_private_key_4096.py", + "dsa_generate_private_key_kwarg_1024.py", + "dsa_generate_private_key_kwarg_2048.py", + "dsa_generate_private_key_kwarg_4096.py", + "dsa_generate_private_key_var_1024.py", + "ec_derive_private_key_brainpoolp256r1.py", + "ec_derive_private_key_brainpoolp384r1.py", + "ec_derive_private_key_brainpoolp512r1.py", + "ec_derive_private_key_secp192r1.py", + "ec_derive_private_key_secp224r1.py", + "ec_derive_private_key_secp256k1.py", + "ec_derive_private_key_secp256r1.py", + "ec_derive_private_key_secp384r1.py", + "ec_derive_private_key_secp521r1.py", + "ec_derive_private_key_sect163k1.py", + "ec_derive_private_key_sect163r2.py", + "ec_derive_private_key_sect233k1.py", + "ec_derive_private_key_sect233r1.py", + "ec_derive_private_key_sect283k1.py", + "ec_derive_private_key_sect283r1.py", + "ec_derive_private_key_sect409k1.py", + "ec_derive_private_key_sect409r1.py", + "ec_derive_private_key_sect571k1.py", + "ec_derive_private_key_sect571r1.py", + "ec_generate_private_key_brainpoolp256r1.py", + "ec_generate_private_key_brainpoolp384r1.py", + "ec_generate_private_key_brainpoolp512r1.py", + "ec_generate_private_key_secp192r1.py", + "ec_generate_private_key_secp224r1.py", + "ec_generate_private_key_secp256k1.py", + "ec_generate_private_key_secp256r1.py", + "ec_generate_private_key_secp384r1.py", + "ec_generate_private_key_secp521r1.py", + "ec_generate_private_key_sect163k1.py", + "ec_generate_private_key_sect163r2.py", + "ec_generate_private_key_sect233k1.py", + "ec_generate_private_key_sect233r1.py", + "ec_generate_private_key_sect283k1.py", + "ec_generate_private_key_sect283r1.py", + "ec_generate_private_key_sect409k1.py", + "ec_generate_private_key_sect409r1.py", + "ec_generate_private_key_sect571k1.py", + "ec_generate_private_key_sect571r1.py", + "rsa_generate_private_key_1024.py", + "rsa_generate_private_key_2048.py", + "rsa_generate_private_key_4096.py", + "rsa_generate_private_key_kwarg_1024.py", + "rsa_generate_private_key_kwarg_2048.py", + "rsa_generate_private_key_kwarg_4096.py", + "rsa_generate_private_key_var_1024.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/dill/test_dill_load.py b/tests/unit/rules/python/dill/test_dill_load.py index 53436ddb..669f14db 100644 --- a/tests/unit/rules/python/dill/test_dill_load.py +++ b/tests/unit/rules/python/dill/test_dill_load.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class DillLoadTests(test_case.TestCase): @@ -37,9 +37,9 @@ def test_dill_load_rule_meta(self): @parameterized.expand( [ - "dill_load", - "dill_loads", - "dill_unpickler", + "dill_load.py", + "dill_loads.py", + "dill_unpickler.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/httpx/test_no_certificate_verify.py b/tests/unit/rules/python/httpx/test_no_certificate_verify.py index d83fa3b3..c036babc 100644 --- a/tests/unit/rules/python/httpx/test_no_certificate_verify.py +++ b/tests/unit/rules/python/httpx/test_no_certificate_verify.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class NoCertificateVerifyTests(test_case.TestCase): @@ -37,21 +37,21 @@ def test_no_certificate_verify_rule_meta(self): @parameterized.expand( [ - "httpx_async_client_as_context_verify_false", - "httpx_async_client_verify_false", - "httpx_client_as_context_verify_false", - "httpx_client_verify_false", - "httpx_delete_verify_false", - "httpx_get_verify_false", - "httpx_get_verify_true", - "httpx_get_verify_unset", - "httpx_head_verify_false", - "httpx_options_verify_false", - "httpx_patch_verify_false", - "httpx_post_verify_false", - "httpx_put_verify_false", - "httpx_request_verify_false", - "httpx_stream_verify_false", + "httpx_async_client_as_context_verify_false.py", + "httpx_async_client_verify_false.py", + "httpx_client_as_context_verify_false.py", + "httpx_client_verify_false.py", + "httpx_delete_verify_false.py", + "httpx_get_verify_false.py", + "httpx_get_verify_true.py", + "httpx_get_verify_unset.py", + "httpx_head_verify_false.py", + "httpx_options_verify_false.py", + "httpx_patch_verify_false.py", + "httpx_post_verify_false.py", + "httpx_put_verify_false.py", + "httpx_request_verify_false.py", + "httpx_stream_verify_false.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/jsonpickle/test_jsonpickle_decode.py b/tests/unit/rules/python/jsonpickle/test_jsonpickle_decode.py index 95a8b8dc..7e758719 100644 --- a/tests/unit/rules/python/jsonpickle/test_jsonpickle_decode.py +++ b/tests/unit/rules/python/jsonpickle/test_jsonpickle_decode.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class JsonPickleDecodeTests(test_case.TestCase): @@ -37,9 +37,9 @@ def test_jsonpickle_decode_rule_meta(self): @parameterized.expand( [ - "jsonpickle_decode", - "jsonpickle_unpickler_decode", - "jsonpickle_unpickler_unpickler", + "jsonpickle_decode.py", + "jsonpickle_unpickler_decode.py", + "jsonpickle_unpickler_unpickler.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pandas/test_pandas_read_pickle.py b/tests/unit/rules/python/pandas/test_pandas_read_pickle.py index 4c7823e4..2f2ca975 100644 --- a/tests/unit/rules/python/pandas/test_pandas_read_pickle.py +++ b/tests/unit/rules/python/pandas/test_pandas_read_pickle.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PandasReadPickleTests(test_case.TestCase): @@ -37,7 +37,7 @@ def test_pandas_read_pickle_rule_meta(self): @parameterized.expand( [ - "pandas_read_pickle", + "pandas_read_pickle.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/paramiko/test_host_key_policy.py b/tests/unit/rules/python/paramiko/test_host_key_policy.py index a542a122..910dfae4 100644 --- a/tests/unit/rules/python/paramiko/test_host_key_policy.py +++ b/tests/unit/rules/python/paramiko/test_host_key_policy.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class HostKeyPolicyTests(test_case.TestCase): @@ -37,13 +37,13 @@ def test_paramiko_no_host_key_verify_rule_meta(self): @parameterized.expand( [ - "host_key_auto_add_policy", - "host_key_auto_add_policy_import_paramiko", - "host_key_auto_add_policy_in_func", - "host_key_auto_add_policy_kwarg", - "host_key_auto_add_policy_single_statement", - "host_key_auto_add_policy_walrus", - "host_key_warning_policy_single_statement", + "host_key_auto_add_policy.py", + "host_key_auto_add_policy_import_paramiko.py", + "host_key_auto_add_policy_in_func.py", + "host_key_auto_add_policy_kwarg.py", + "host_key_auto_add_policy_single_statement.py", + "host_key_auto_add_policy_walrus.py", + "host_key_warning_policy_single_statement.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pycrypto/test_pycrypto_weak_cipher.py b/tests/unit/rules/python/pycrypto/test_pycrypto_weak_cipher.py index ddd8d39c..f948c0ba 100644 --- a/tests/unit/rules/python/pycrypto/test_pycrypto_weak_cipher.py +++ b/tests/unit/rules/python/pycrypto/test_pycrypto_weak_cipher.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PycryptoWeakCipherTests(test_case.TestCase): @@ -39,11 +39,11 @@ def test_pycrypto_weak_cipher_rule_meta(self): @parameterized.expand( [ - "cipher_arc2", - "cipher_arc4", - "cipher_blowfish", - "cipher_des", - "cipher_xor", + "cipher_arc2.py", + "cipher_arc4.py", + "cipher_blowfish.py", + "cipher_des.py", + "cipher_xor.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pycrypto/test_pycrypto_weak_hash.py b/tests/unit/rules/python/pycrypto/test_pycrypto_weak_hash.py index 0ee00991..8cb2e718 100644 --- a/tests/unit/rules/python/pycrypto/test_pycrypto_weak_hash.py +++ b/tests/unit/rules/python/pycrypto/test_pycrypto_weak_hash.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PycryptoWeakCipherTests(test_case.TestCase): @@ -37,11 +37,11 @@ def test_pycrypto_weak_hash_rule_meta(self): @parameterized.expand( [ - "hash_md2", - "hash_md4", - "hash_md5", - "hash_ripemd", - "hash_sha", + "hash_md2.py", + "hash_md4.py", + "hash_md5.py", + "hash_ripemd.py", + "hash_sha.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pycrypto/test_pycrypto_weak_key.py b/tests/unit/rules/python/pycrypto/test_pycrypto_weak_key.py index 4865f6b3..417b757d 100644 --- a/tests/unit/rules/python/pycrypto/test_pycrypto_weak_key.py +++ b/tests/unit/rules/python/pycrypto/test_pycrypto_weak_key.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PycryptoWeakKeyTests(test_case.TestCase): @@ -37,12 +37,12 @@ def test_pycrypto_weak_key_rule_meta(self): @parameterized.expand( [ - "dsa_generate_1024", - "dsa_generate_2048", - "dsa_generate_4096", - "rsa_generate_1024", - "rsa_generate_2048", - "rsa_generate_4096", + "dsa_generate_1024.py", + "dsa_generate_2048.py", + "dsa_generate_4096.py", + "rsa_generate_1024.py", + "rsa_generate_2048.py", + "rsa_generate_4096.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_cipher.py b/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_cipher.py index 76f22fbf..a2754693 100644 --- a/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_cipher.py +++ b/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_cipher.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PycryptodomexWeakCipherTests(test_case.TestCase): @@ -39,11 +39,11 @@ def test_pycryptodomex_weak_cipher_rule_meta(self): @parameterized.expand( [ - "cipher_arc2", - "cipher_arc4", - "cipher_blowfish", - "cipher_des", - "cipher_xor", + "cipher_arc2.py", + "cipher_arc4.py", + "cipher_blowfish.py", + "cipher_des.py", + "cipher_xor.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_hash.py b/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_hash.py index fd44557f..2a2a6a9f 100644 --- a/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_hash.py +++ b/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_hash.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PycryptodomexWeakCipherTests(test_case.TestCase): @@ -37,11 +37,11 @@ def test_pycryptodomex_weak_hash_rule_meta(self): @parameterized.expand( [ - "hash_md2", - "hash_md4", - "hash_md5", - "hash_ripemd", - "hash_sha", + "hash_md2.py", + "hash_md4.py", + "hash_md5.py", + "hash_ripemd.py", + "hash_sha.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_key.py b/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_key.py index 5112c73e..40f4b205 100644 --- a/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_key.py +++ b/tests/unit/rules/python/pycryptodomex/test_pycryptodomex_weak_key.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PycryptodomexWeakKeyTests(test_case.TestCase): @@ -37,12 +37,12 @@ def test_pycryptodomex_weak_key_rule_meta(self): @parameterized.expand( [ - "dsa_generate_1024", - "dsa_generate_2048", - "dsa_generate_4096", - "rsa_generate_1024", - "rsa_generate_2048", - "rsa_generate_4096", + "dsa_generate_1024.py", + "dsa_generate_2048.py", + "dsa_generate_4096.py", + "rsa_generate_1024.py", + "rsa_generate_2048.py", + "rsa_generate_4096.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pyghmi/test_pyghmi_cleartext.py b/tests/unit/rules/python/pyghmi/test_pyghmi_cleartext.py index e973416d..115742d3 100644 --- a/tests/unit/rules/python/pyghmi/test_pyghmi_cleartext.py +++ b/tests/unit/rules/python/pyghmi/test_pyghmi_cleartext.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PyghmiCleartextTests(test_case.TestCase): @@ -37,10 +37,10 @@ def test_pyghmi_cleartext_rule_meta(self): @parameterized.expand( [ - "command_command", - "command_command_no_password", - "command_console", - "command_console_no_password", + "command_command.py", + "command_command_no_password.py", + "command_console.py", + "command_console_no_password.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pyopenssl/test_pyopenssl_weak_key.py b/tests/unit/rules/python/pyopenssl/test_pyopenssl_weak_key.py index 5b5425e9..a393c1f7 100644 --- a/tests/unit/rules/python/pyopenssl/test_pyopenssl_weak_key.py +++ b/tests/unit/rules/python/pyopenssl/test_pyopenssl_weak_key.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PyopensslWeakKeyTests(test_case.TestCase): @@ -37,12 +37,12 @@ def test_pyopenssl_weak_key_rule_meta(self): @parameterized.expand( [ - "generate_key_dsa_1024", - "generate_key_dsa_2048", - "generate_key_dsa_4096", - "generate_key_rsa_1024", - "generate_key_rsa_2048", - "generate_key_rsa_4096", + "generate_key_dsa_1024.py", + "generate_key_dsa_2048.py", + "generate_key_dsa_4096.py", + "generate_key_rsa_1024.py", + "generate_key_rsa_2048.py", + "generate_key_rsa_4096.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/pyopenssl/test_ssl_context.py b/tests/unit/rules/python/pyopenssl/test_ssl_context.py index a91d869a..5e10c871 100644 --- a/tests/unit/rules/python/pyopenssl/test_ssl_context.py +++ b/tests/unit/rules/python/pyopenssl/test_ssl_context.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class SslContextTests(test_case.TestCase): @@ -37,12 +37,12 @@ def test_ssl_context_rule_meta(self): @parameterized.expand( [ - "ssl_context_sslv2", - "ssl_context_sslv23", - "ssl_context_sslv3", - "ssl_context_tlsv1", - "ssl_context_tlsv11", - "ssl_context_tlsv12", + "ssl_context_sslv2.py", + "ssl_context_sslv23.py", + "ssl_context_sslv3.py", + "ssl_context_tlsv1.py", + "ssl_context_tlsv11.py", + "ssl_context_tlsv12.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/requests/test_no_certificate_verify.py b/tests/unit/rules/python/requests/test_no_certificate_verify.py index 0b44d6c9..7da86ab1 100644 --- a/tests/unit/rules/python/requests/test_no_certificate_verify.py +++ b/tests/unit/rules/python/requests/test_no_certificate_verify.py @@ -6,7 +6,7 @@ from precli.core.level import Level from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class NoCertificateVerifyTests(test_case.TestCase): @@ -37,26 +37,26 @@ def test_no_certificate_verify_rule_meta(self): @parameterized.expand( [ - "requests_delete_verify_false", - "requests_get_verify_as_var", - "requests_get_verify_false", - "requests_get_verify_true", - "requests_get_verify_unset", - "requests_head_verify_false", - "requests_options_verify_false", - "requests_patch_verify_false", - "requests_post_verify_false", - "requests_put_verify_false", - "requests_request_verify_false", - "requests_session_as_context_get_verify_false", - "requests_session_delete_verify_false", - "requests_session_get_verify_false", - "requests_session_head_verify_false", - "requests_session_options_verify_false", - "requests_session_patch_verify_false", - "requests_session_post_verify_false", - "requests_session_put_verify_false", - "requests_session_request_verify_false", + "requests_delete_verify_false.py", + "requests_get_verify_as_var.py", + "requests_get_verify_false.py", + "requests_get_verify_true.py", + "requests_get_verify_unset.py", + "requests_head_verify_false.py", + "requests_options_verify_false.py", + "requests_patch_verify_false.py", + "requests_post_verify_false.py", + "requests_put_verify_false.py", + "requests_request_verify_false.py", + "requests_session_as_context_get_verify_false.py", + "requests_session_delete_verify_false.py", + "requests_session_get_verify_false.py", + "requests_session_head_verify_false.py", + "requests_session_options_verify_false.py", + "requests_session_patch_verify_false.py", + "requests_session_post_verify_false.py", + "requests_session_put_verify_false.py", + "requests_session_request_verify_false.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/crypt/test_crypt_weak_hash.py b/tests/unit/rules/python/stdlib/crypt/test_crypt_weak_hash.py index e8c3d400..4b117e82 100644 --- a/tests/unit/rules/python/stdlib/crypt/test_crypt_weak_hash.py +++ b/tests/unit/rules/python/stdlib/crypt/test_crypt_weak_hash.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class CryptWeakHashTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY002" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,18 +38,18 @@ def test_crypt_weak_hash_rule_meta(self): @parameterized.expand( [ - "crypt_crypt", - "crypt_crypt_method_blowfish", - "crypt_crypt_method_crypt", - "crypt_crypt_method_md5", - "crypt_crypt_method_sha256", - "crypt_crypt_method_sha512", - "crypt_mksalt", - "crypt_mksalt_method_blowfish", - "crypt_mksalt_method_crypt", - "crypt_mksalt_method_md5", - "crypt_mksalt_method_sha256", - "crypt_mksalt_method_sha512", + "crypt_crypt.py", + "crypt_crypt_method_blowfish.py", + "crypt_crypt_method_crypt.py", + "crypt_crypt_method_md5.py", + "crypt_crypt_method_sha256.py", + "crypt_crypt_method_sha512.py", + "crypt_mksalt.py", + "crypt_mksalt_method_blowfish.py", + "crypt_mksalt_method_crypt.py", + "crypt_mksalt_method_md5.py", + "crypt_mksalt_method_sha256.py", + "crypt_mksalt_method_sha512.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/ftplib/test_ftp_cleartext.py b/tests/unit/rules/python/stdlib/ftplib/test_ftp_cleartext.py index 24799fe3..eaa3526c 100644 --- a/tests/unit/rules/python/stdlib/ftplib/test_ftp_cleartext.py +++ b/tests/unit/rules/python/stdlib/ftplib/test_ftp_cleartext.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class FtpCleartextTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY003" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,13 +38,13 @@ def test_ftp_cleartext_rule_meta(self): @parameterized.expand( [ - "ftp", - "ftp_tls", - "ftplib_ftp", - "ftplib_ftp_context_mgr", - "ftplib_ftp_tls", - "ftplib_ftp_user_password", - "ftplib_ftp_tls_user_password", + "ftp.py", + "ftp_tls.py", + "ftplib_ftp.py", + "ftplib_ftp_context_mgr.py", + "ftplib_ftp_tls.py", + "ftplib_ftp_user_password.py", + "ftplib_ftp_tls_user_password.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/hashlib/test_hashlib_weak_hash.py b/tests/unit/rules/python/stdlib/hashlib/test_hashlib_weak_hash.py index 83a9b551..2b35b36e 100644 --- a/tests/unit/rules/python/stdlib/hashlib/test_hashlib_weak_hash.py +++ b/tests/unit/rules/python/stdlib/hashlib/test_hashlib_weak_hash.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class HashlibWeakHashTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY004" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,59 +38,59 @@ def test_hashlib_weak_hash_rule_meta(self): @parameterized.expand( [ - "hashlib_blake2b", - "hashlib_blake2s", - "hashlib_md4", - "hashlib_md5", - "hashlib_md5_usedforsecurity_true", - "hashlib_new_blake2b", - "hashlib_new_blake2s", - "hashlib_new_md4", - "hashlib_new_md5", - "hashlib_new_md5_usedforsecurity_true", - "hashlib_new_name_sha", - "hashlib_new_ripemd160", - "hashlib_new_sha", - "hashlib_new_sha1", - "hashlib_new_sha224", - "hashlib_new_sha256", - "hashlib_new_sha384", - "hashlib_new_sha3_224", - "hashlib_new_sha3_256", - "hashlib_new_sha3_384", - "hashlib_new_sha3_512", - "hashlib_new_sha512", - "hashlib_new_sha_usedforsecurity_false", - "hashlib_new_shake_128", - "hashlib_new_shake_256", - "hashlib_pbkdf2_hmac_md4", - "hashlib_pbkdf2_hmac_md5", - "hashlib_pbkdf2_hmac_ripemd160", - "hashlib_pbkdf2_hmac_sha", - "hashlib_pbkdf2_hmac_sha1", - "hashlib_pbkdf2_hmac_sha224", - "hashlib_pbkdf2_hmac_sha256", - "hashlib_pbkdf2_hmac_sha384", - "hashlib_pbkdf2_hmac_sha3_224", - "hashlib_pbkdf2_hmac_sha3_256", - "hashlib_pbkdf2_hmac_sha3_384", - "hashlib_pbkdf2_hmac_sha3_512", - "hashlib_pbkdf2_hmac_shake_128", - "hashlib_pbkdf2_hmac_shake_256", - "hashlib_ripemd160", - "hashlib_sha", - "hashlib_sha1", - "hashlib_sha224", - "hashlib_sha256", - "hashlib_sha384", - "hashlib_sha3_224", - "hashlib_sha3_256", - "hashlib_sha3_384", - "hashlib_sha3_512", - "hashlib_sha512", - "hashlib_sha_usedforsecurity_false", - "hashlib_shake_128", - "hashlib_shake_256", + "hashlib_blake2b.py", + "hashlib_blake2s.py", + "hashlib_md4.py", + "hashlib_md5.py", + "hashlib_md5_usedforsecurity_true.py", + "hashlib_new_blake2b.py", + "hashlib_new_blake2s.py", + "hashlib_new_md4.py", + "hashlib_new_md5.py", + "hashlib_new_md5_usedforsecurity_true.py", + "hashlib_new_name_sha.py", + "hashlib_new_ripemd160.py", + "hashlib_new_sha.py", + "hashlib_new_sha1.py", + "hashlib_new_sha224.py", + "hashlib_new_sha256.py", + "hashlib_new_sha384.py", + "hashlib_new_sha3_224.py", + "hashlib_new_sha3_256.py", + "hashlib_new_sha3_384.py", + "hashlib_new_sha3_512.py", + "hashlib_new_sha512.py", + "hashlib_new_sha_usedforsecurity_false.py", + "hashlib_new_shake_128.py", + "hashlib_new_shake_256.py", + "hashlib_pbkdf2_hmac_md4.py", + "hashlib_pbkdf2_hmac_md5.py", + "hashlib_pbkdf2_hmac_ripemd160.py", + "hashlib_pbkdf2_hmac_sha.py", + "hashlib_pbkdf2_hmac_sha1.py", + "hashlib_pbkdf2_hmac_sha224.py", + "hashlib_pbkdf2_hmac_sha256.py", + "hashlib_pbkdf2_hmac_sha384.py", + "hashlib_pbkdf2_hmac_sha3_224.py", + "hashlib_pbkdf2_hmac_sha3_256.py", + "hashlib_pbkdf2_hmac_sha3_384.py", + "hashlib_pbkdf2_hmac_sha3_512.py", + "hashlib_pbkdf2_hmac_shake_128.py", + "hashlib_pbkdf2_hmac_shake_256.py", + "hashlib_ripemd160.py", + "hashlib_sha.py", + "hashlib_sha1.py", + "hashlib_sha224.py", + "hashlib_sha256.py", + "hashlib_sha384.py", + "hashlib_sha3_224.py", + "hashlib_sha3_256.py", + "hashlib_sha3_384.py", + "hashlib_sha3_512.py", + "hashlib_sha512.py", + "hashlib_sha_usedforsecurity_false.py", + "hashlib_shake_128.py", + "hashlib_shake_256.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/hmac/test_hmac_timing_attack.py b/tests/unit/rules/python/stdlib/hmac/test_hmac_timing_attack.py index cfaaa4e0..a02f0744 100644 --- a/tests/unit/rules/python/stdlib/hmac/test_hmac_timing_attack.py +++ b/tests/unit/rules/python/stdlib/hmac/test_hmac_timing_attack.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class HmacTimingAttackTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY005" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,10 +38,10 @@ def test_hmac_timing_attack_rule_meta(self): @parameterized.expand( [ - "hmac_timing_attack", - "hmac_timing_attack_class", - "hmac_timing_attack_class_hexdigest", - "hmac_timing_attack_compare_digest", + "hmac_timing_attack.py", + "hmac_timing_attack_class.py", + "hmac_timing_attack_class_hexdigest.py", + "hmac_timing_attack_compare_digest.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/hmac/test_hmac_weak_hash.py b/tests/unit/rules/python/stdlib/hmac/test_hmac_weak_hash.py index ff9591f9..302641b8 100644 --- a/tests/unit/rules/python/stdlib/hmac/test_hmac_weak_hash.py +++ b/tests/unit/rules/python/stdlib/hmac/test_hmac_weak_hash.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class HmacWeakHashTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY006" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,74 +38,74 @@ def test_hmac_weak_hash_rule_meta(self): @parameterized.expand( [ - "hmac_digest_blake2b", - "hmac_digest_blake2s", - "hmac_digest_hashlib_blake2b", - "hmac_digest_hashlib_blake2s", - "hmac_digest_hashlib_md4", - "hmac_digest_hashlib_md5", - "hmac_digest_hashlib_ripemd160", - "hmac_digest_hashlib_sha", - "hmac_digest_hashlib_sha1", - "hmac_digest_hashlib_sha224", - "hmac_digest_hashlib_sha256", - "hmac_digest_hashlib_sha384", - "hmac_digest_hashlib_sha3_224", - "hmac_digest_hashlib_sha3_256", - "hmac_digest_hashlib_sha3_384", - "hmac_digest_hashlib_sha3_512", - "hmac_digest_hashlib_sha512", - "hmac_digest_hashlib_shake_128", - "hmac_digest_hashlib_shake_256", - "hmac_digest_md4", - "hmac_digest_md5", - "hmac_digest_ripemd160", - "hmac_digest_sha", - "hmac_digest_sha1", - "hmac_digest_sha224", - "hmac_digest_sha256", - "hmac_digest_sha384", - "hmac_digest_sha3_224", - "hmac_digest_sha3_256", - "hmac_digest_sha3_384", - "hmac_digest_sha3_512", - "hmac_digest_sha512", - "hmac_digest_shake_128", - "hmac_digest_shake_256", - "hmac_new_digestmod_blake2b", - "hmac_new_digestmod_blake2s", - "hmac_new_digestmod_hashlib_blake2b", - "hmac_new_digestmod_hashlib_blake2s", - "hmac_new_digestmod_hashlib_md4", - "hmac_new_digestmod_hashlib_md5", - "hmac_new_digestmod_hashlib_ripemd160", - "hmac_new_digestmod_hashlib_sha", - "hmac_new_digestmod_hashlib_sha1", - "hmac_new_digestmod_hashlib_sha224", - "hmac_new_digestmod_hashlib_sha256", - "hmac_new_digestmod_hashlib_sha384", - "hmac_new_digestmod_hashlib_sha3_224", - "hmac_new_digestmod_hashlib_sha3_256", - "hmac_new_digestmod_hashlib_sha3_384", - "hmac_new_digestmod_hashlib_sha3_512", - "hmac_new_digestmod_hashlib_sha512", - "hmac_new_digestmod_hashlib_shake_128", - "hmac_new_digestmod_hashlib_shake_256", - "hmac_new_digestmod_md4", - "hmac_new_digestmod_md5", - "hmac_new_digestmod_ripemd160", - "hmac_new_digestmod_sha", - "hmac_new_digestmod_sha1", - "hmac_new_digestmod_sha224", - "hmac_new_digestmod_sha256", - "hmac_new_digestmod_sha384", - "hmac_new_digestmod_sha3_224", - "hmac_new_digestmod_sha3_256", - "hmac_new_digestmod_sha3_384", - "hmac_new_digestmod_sha3_512", - "hmac_new_digestmod_sha512", - "hmac_new_digestmod_shake_128", - "hmac_new_digestmod_shake_256", + "hmac_digest_blake2b.py", + "hmac_digest_blake2s.py", + "hmac_digest_hashlib_blake2b.py", + "hmac_digest_hashlib_blake2s.py", + "hmac_digest_hashlib_md4.py", + "hmac_digest_hashlib_md5.py", + "hmac_digest_hashlib_ripemd160.py", + "hmac_digest_hashlib_sha.py", + "hmac_digest_hashlib_sha1.py", + "hmac_digest_hashlib_sha224.py", + "hmac_digest_hashlib_sha256.py", + "hmac_digest_hashlib_sha384.py", + "hmac_digest_hashlib_sha3_224.py", + "hmac_digest_hashlib_sha3_256.py", + "hmac_digest_hashlib_sha3_384.py", + "hmac_digest_hashlib_sha3_512.py", + "hmac_digest_hashlib_sha512.py", + "hmac_digest_hashlib_shake_128.py", + "hmac_digest_hashlib_shake_256.py", + "hmac_digest_md4.py", + "hmac_digest_md5.py", + "hmac_digest_ripemd160.py", + "hmac_digest_sha.py", + "hmac_digest_sha1.py", + "hmac_digest_sha224.py", + "hmac_digest_sha256.py", + "hmac_digest_sha384.py", + "hmac_digest_sha3_224.py", + "hmac_digest_sha3_256.py", + "hmac_digest_sha3_384.py", + "hmac_digest_sha3_512.py", + "hmac_digest_sha512.py", + "hmac_digest_shake_128.py", + "hmac_digest_shake_256.py", + "hmac_new_digestmod_blake2b.py", + "hmac_new_digestmod_blake2s.py", + "hmac_new_digestmod_hashlib_blake2b.py", + "hmac_new_digestmod_hashlib_blake2s.py", + "hmac_new_digestmod_hashlib_md4.py", + "hmac_new_digestmod_hashlib_md5.py", + "hmac_new_digestmod_hashlib_ripemd160.py", + "hmac_new_digestmod_hashlib_sha.py", + "hmac_new_digestmod_hashlib_sha1.py", + "hmac_new_digestmod_hashlib_sha224.py", + "hmac_new_digestmod_hashlib_sha256.py", + "hmac_new_digestmod_hashlib_sha384.py", + "hmac_new_digestmod_hashlib_sha3_224.py", + "hmac_new_digestmod_hashlib_sha3_256.py", + "hmac_new_digestmod_hashlib_sha3_384.py", + "hmac_new_digestmod_hashlib_sha3_512.py", + "hmac_new_digestmod_hashlib_sha512.py", + "hmac_new_digestmod_hashlib_shake_128.py", + "hmac_new_digestmod_hashlib_shake_256.py", + "hmac_new_digestmod_md4.py", + "hmac_new_digestmod_md5.py", + "hmac_new_digestmod_ripemd160.py", + "hmac_new_digestmod_sha.py", + "hmac_new_digestmod_sha1.py", + "hmac_new_digestmod_sha224.py", + "hmac_new_digestmod_sha256.py", + "hmac_new_digestmod_sha384.py", + "hmac_new_digestmod_sha3_224.py", + "hmac_new_digestmod_sha3_256.py", + "hmac_new_digestmod_sha3_384.py", + "hmac_new_digestmod_sha3_512.py", + "hmac_new_digestmod_sha512.py", + "hmac_new_digestmod_shake_128.py", + "hmac_new_digestmod_shake_256.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/imaplib/test_imap_cleartext.py b/tests/unit/rules/python/stdlib/imaplib/test_imap_cleartext.py index 358df4ed..ff701c27 100644 --- a/tests/unit/rules/python/stdlib/imaplib/test_imap_cleartext.py +++ b/tests/unit/rules/python/stdlib/imaplib/test_imap_cleartext.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class ImapCleartextTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY007" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,13 +38,13 @@ def test_imap_cleartext_rule_meta(self): @parameterized.expand( [ - "imaplib_imap4_authenticate", - "imaplib_imap4_context_mgr", - "imaplib_imap4_login", - "imaplib_imap4_login_cram_md5", - "imaplib_imap4_ssl", - "imaplib_imap4_starttls", - "imaplib_imap4_stream", + "imaplib_imap4_authenticate.py", + "imaplib_imap4_context_mgr.py", + "imaplib_imap4_login.py", + "imaplib_imap4_login_cram_md5.py", + "imaplib_imap4_ssl.py", + "imaplib_imap4_starttls.py", + "imaplib_imap4_stream.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/json/test_json_load.py b/tests/unit/rules/python/stdlib/json/test_json_load.py index bd2c0eeb..1f9472c6 100644 --- a/tests/unit/rules/python/stdlib/json/test_json_load.py +++ b/tests/unit/rules/python/stdlib/json/test_json_load.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class JsonLoadTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY008" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,9 +38,9 @@ def test_json_load_rule_meta(self): @parameterized.expand( [ - "json_jsondecoder_decode", - "json_load", - "json_loads", + "json_jsondecoder_decode.py", + "json_load.py", + "json_loads.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/logging/test_insecure_listen_config.py b/tests/unit/rules/python/stdlib/logging/test_insecure_listen_config.py index f2643743..551338b2 100644 --- a/tests/unit/rules/python/stdlib/logging/test_insecure_listen_config.py +++ b/tests/unit/rules/python/stdlib/logging/test_insecure_listen_config.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class InsecureListenConfigTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY009" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,13 +38,13 @@ def test_insecure_listen_config_rule_meta(self): @parameterized.expand( [ - "insecure_listen_config_empty_args", - "insecure_listen_config_port", - "insecure_listen_config_port_verify_as_var", - "insecure_listen_config_port_verify_none", - "insecure_listen_config_verify_none", - "insecure_listen_config_verify_none_port", - "insecure_listen_config_verify_set", + "insecure_listen_config_empty_args.py", + "insecure_listen_config_port.py", + "insecure_listen_config_port_verify_as_var.py", + "insecure_listen_config_port_verify_none.py", + "insecure_listen_config_verify_none.py", + "insecure_listen_config_verify_none_port.py", + "insecure_listen_config_verify_set.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/marshal/test_marshal_load.py b/tests/unit/rules/python/stdlib/marshal/test_marshal_load.py index 9225a7dd..f8eb1a97 100644 --- a/tests/unit/rules/python/stdlib/marshal/test_marshal_load.py +++ b/tests/unit/rules/python/stdlib/marshal/test_marshal_load.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class MarshalLoadTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY010" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,8 +38,8 @@ def test_marshal_load_rule_meta(self): @parameterized.expand( [ - "marshal_load", - "marshal_loads", + "marshal_load.py", + "marshal_loads.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/nntplib/test_nntp_cleartext.py b/tests/unit/rules/python/stdlib/nntplib/test_nntp_cleartext.py index 8c35828c..22ba64e3 100644 --- a/tests/unit/rules/python/stdlib/nntplib/test_nntp_cleartext.py +++ b/tests/unit/rules/python/stdlib/nntplib/test_nntp_cleartext.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class NntpCleartextTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY011" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,10 +38,10 @@ def test_nntp_cleartext_rule_meta(self): @parameterized.expand( [ - "nntplib_nntp_context_mgr", - "nntplib_nntp_login", - "nntplib_nntp_ssl", - "nntplib_nntp_starttls", + "nntplib_nntp_context_mgr.py", + "nntplib_nntp_login.py", + "nntplib_nntp_ssl.py", + "nntplib_nntp_starttls.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/pickle/test_pickle_load.py b/tests/unit/rules/python/stdlib/pickle/test_pickle_load.py index 74295a1c..991de2e1 100644 --- a/tests/unit/rules/python/stdlib/pickle/test_pickle_load.py +++ b/tests/unit/rules/python/stdlib/pickle/test_pickle_load.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PickleLoadTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY012" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,9 +38,9 @@ def test_pickle_load_rule_meta(self): @parameterized.expand( [ - "pickle_load", - "pickle_loads", - "pickle_unpickler", + "pickle_load.py", + "pickle_loads.py", + "pickle_unpickler.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/poplib/test_pop_cleartext.py b/tests/unit/rules/python/stdlib/poplib/test_pop_cleartext.py index eee607d4..12a6a42a 100644 --- a/tests/unit/rules/python/stdlib/poplib/test_pop_cleartext.py +++ b/tests/unit/rules/python/stdlib/poplib/test_pop_cleartext.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class PopCleartextTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY013" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,13 +38,13 @@ def test_pop_cleartext_rule_meta(self): @parameterized.expand( [ - "poplib_pop3_apop", - "poplib_pop3_context_mgr", - "poplib_pop3_pass_", - "poplib_pop3_rpop", - "poplib_pop3_ssl", - "poplib_pop3_stls", - "poplib_pop3_user", + "poplib_pop3_apop.py", + "poplib_pop3_context_mgr.py", + "poplib_pop3_pass_.py", + "poplib_pop3_rpop.py", + "poplib_pop3_ssl.py", + "poplib_pop3_stls.py", + "poplib_pop3_user.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/shelve/test_shelve_open.py b/tests/unit/rules/python/stdlib/shelve/test_shelve_open.py index 40f7e618..9d330363 100644 --- a/tests/unit/rules/python/stdlib/shelve/test_shelve_open.py +++ b/tests/unit/rules/python/stdlib/shelve/test_shelve_open.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class ShelveOpenTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY014" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,9 +38,9 @@ def test_shelve_open_rule_meta(self): @parameterized.expand( [ - "shelve_dbfilenameshelf", - "shelve_open", - "shelve_open_context_mgr", + "shelve_dbfilenameshelf.py", + "shelve_open.py", + "shelve_open_context_mgr.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/smtplib/test_smtp_cleartext.py b/tests/unit/rules/python/stdlib/smtplib/test_smtp_cleartext.py index 5d0966cf..1f61f599 100644 --- a/tests/unit/rules/python/stdlib/smtplib/test_smtp_cleartext.py +++ b/tests/unit/rules/python/stdlib/smtplib/test_smtp_cleartext.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class SmtpCleartextTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY015" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,11 +38,11 @@ def test_smtp_cleartext_rule_meta(self): @parameterized.expand( [ - "smtplib_smtp_auth", - "smtplib_smtp_context_mgr", - "smtplib_smtp_login", - "smtplib_smtp_ssl", - "smtplib_smtp_starttls", + "smtplib_smtp_auth.py", + "smtplib_smtp_context_mgr.py", + "smtplib_smtp_login.py", + "smtplib_smtp_ssl.py", + "smtplib_smtp_starttls.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/ssl/test_get_server_certificate.py b/tests/unit/rules/python/stdlib/ssl/test_get_server_certificate.py index 2e8a6a58..02f282f1 100644 --- a/tests/unit/rules/python/stdlib/ssl/test_get_server_certificate.py +++ b/tests/unit/rules/python/stdlib/ssl/test_get_server_certificate.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class GetServerCertificateTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY017" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,12 +38,12 @@ def test_get_server_certificate_rule_meta(self): @parameterized.expand( [ - "get_server_certificate_sslv2", - "get_server_certificate_sslv23", - "get_server_certificate_sslv3", - "get_server_certificate_tlsv1", - "get_server_certificate_tlsv11", - "get_server_certificate_tlsv12", + "get_server_certificate_sslv2.py", + "get_server_certificate_sslv23.py", + "get_server_certificate_sslv3.py", + "get_server_certificate_tlsv1.py", + "get_server_certificate_tlsv11.py", + "get_server_certificate_tlsv12.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/ssl/test_ssl_context.py b/tests/unit/rules/python/stdlib/ssl/test_ssl_context.py index 2dee63a5..2f3d231b 100644 --- a/tests/unit/rules/python/stdlib/ssl/test_ssl_context.py +++ b/tests/unit/rules/python/stdlib/ssl/test_ssl_context.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class SslSocketTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY017" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,12 +38,12 @@ def test_ssl_context_rule_meta(self): @parameterized.expand( [ - "ssl_context_sslv2", - "ssl_context_sslv23", - "ssl_context_sslv3", - "ssl_context_tlsv1", - "ssl_context_tlsv11", - "ssl_context_tlsv12", + "ssl_context_sslv2.py", + "ssl_context_sslv23.py", + "ssl_context_sslv3.py", + "ssl_context_tlsv1.py", + "ssl_context_tlsv11.py", + "ssl_context_tlsv12.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/ssl/test_ssl_create_context.py b/tests/unit/rules/python/stdlib/ssl/test_ssl_create_context.py index 3ed35db3..ef698138 100644 --- a/tests/unit/rules/python/stdlib/ssl/test_ssl_create_context.py +++ b/tests/unit/rules/python/stdlib/ssl/test_ssl_create_context.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class SslCreateContextTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY016" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,8 +38,8 @@ def test_unverified_context_rule_meta(self): @parameterized.expand( [ - "create_default_context", - "create_unverified_context", + "create_default_context.py", + "create_unverified_context.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/ssl/test_wrap_socket.py b/tests/unit/rules/python/stdlib/ssl/test_wrap_socket.py index a2a82bdd..14ce08e7 100644 --- a/tests/unit/rules/python/stdlib/ssl/test_wrap_socket.py +++ b/tests/unit/rules/python/stdlib/ssl/test_wrap_socket.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class WrapSocketTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY017" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,13 +38,13 @@ def test_wrap_socket_rule_meta(self): @parameterized.expand( [ - "wrap_socket_sslv2", - "wrap_socket_sslv23", - "wrap_socket_sslv2_server_side_true", - "wrap_socket_sslv3", - "wrap_socket_tlsv1", - "wrap_socket_tlsv11", - "wrap_socket_tlsv12", + "wrap_socket_sslv2.py", + "wrap_socket_sslv23.py", + "wrap_socket_sslv2_server_side_true.py", + "wrap_socket_sslv3.py", + "wrap_socket_tlsv1.py", + "wrap_socket_tlsv11.py", + "wrap_socket_tlsv12.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/telnetlib/test_telnetlib_cleartext.py b/tests/unit/rules/python/stdlib/telnetlib/test_telnetlib_cleartext.py index a9716eb7..f802a0b1 100644 --- a/tests/unit/rules/python/stdlib/telnetlib/test_telnetlib_cleartext.py +++ b/tests/unit/rules/python/stdlib/telnetlib/test_telnetlib_cleartext.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class TelnetlibCleartextTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY018" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,9 +38,9 @@ def test_telnetlib_cleartext_rule_meta(self): @parameterized.expand( [ - "telnet", - "telnetlib_telnet", - "telnetlib_telnet_context_mgr", + "telnet.py", + "telnetlib_telnet.py", + "telnetlib_telnet_context_mgr.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/stdlib/tempfile/test_mktemp_race_condition.py b/tests/unit/rules/python/stdlib/tempfile/test_mktemp_race_condition.py index 7aa2235b..9e786064 100644 --- a/tests/unit/rules/python/stdlib/tempfile/test_mktemp_race_condition.py +++ b/tests/unit/rules/python/stdlib/tempfile/test_mktemp_race_condition.py @@ -4,14 +4,16 @@ from parameterized import parameterized from precli.core.level import Level +from precli.parsers import python from precli.rules import Rule -from tests.unit.rules.python import test_case +from tests.unit.rules import test_case class MktempRaceConditionTests(test_case.TestCase): def setUp(self): super().setUp() self.rule_id = "PY019" + self.parser = python.Python() self.base_path = os.path.join( "tests", "unit", @@ -36,13 +38,13 @@ def test_smtp_cleartext_rule_meta(self): @parameterized.expand( [ - "tempfile_mktemp", - "tempfile_mktemp_args_open", - "tempfile_mktemp_args_with_open_args", - "tempfile_mktemp_open", - "tempfile_mktemp_walrus_open", - "tempfile_mktemp_with_open", - "tempfile_mktemp_with_open_multiline", + "tempfile_mktemp.py", + "tempfile_mktemp_args_open.py", + "tempfile_mktemp_args_with_open_args.py", + "tempfile_mktemp_open.py", + "tempfile_mktemp_walrus_open.py", + "tempfile_mktemp_with_open.py", + "tempfile_mktemp_with_open_multiline.py", ] ) def test(self, filename): diff --git a/tests/unit/rules/python/test_case.py b/tests/unit/rules/python/test_case.py deleted file mode 100644 index c1aec5e9..00000000 --- a/tests/unit/rules/python/test_case.py +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright 2023 Secure Saurce LLC -import os - -import testtools - -from precli.core.level import Level -from precli.parsers import python - - -class TestCase(testtools.TestCase): - def setUp(self): - super().setUp() - self.parser = python.Python() - - def expected(self, filename): - with open(os.path.join(self.base_path, f"{filename}.py")) as f: - level = f.readline().strip() - level = level.removeprefix("# level: ") - level = getattr(Level, level) - if level != Level.NONE: - start_line = f.readline().strip() - start_line = int(start_line.removeprefix("# start_line: ")) - end_line = f.readline().strip() - end_line = int(end_line.removeprefix("# end_line: ")) - start_col = f.readline().strip() - start_col = int(start_col.removeprefix("# start_column: ")) - end_col = f.readline().strip() - end_col = int(end_col.removeprefix("# end_column: ")) - else: - start_line = end_line = start_col = end_col = -1 - - return (level, start_line, end_line, start_col, end_col) - - def check(self, filename): - ( - level, - start_line, - end_line, - start_column, - end_column, - ) = self.expected(filename) - results = self.parser.parse( - os.path.join(self.base_path, f"{filename}.py") - ) - if level == Level.NONE: - self.assertEqual(0, len(results)) - else: - self.assertEqual(1, len(results)) - result = results[0] - self.assertEqual(self.rule_id, result.rule_id) - self.assertEqual(start_line, result.location.start_line) - self.assertEqual(end_line, result.location.end_line) - self.assertEqual(start_column, result.location.start_column) - self.assertEqual(end_column, result.location.end_column) - self.assertEqual(level, result.level) - self.assertEqual(-1.0, result.rank) diff --git a/tests/unit/rules/go/test_case.py b/tests/unit/rules/test_case.py similarity index 67% rename from tests/unit/rules/go/test_case.py rename to tests/unit/rules/test_case.py index f8db855f..7b916af9 100644 --- a/tests/unit/rules/go/test_case.py +++ b/tests/unit/rules/test_case.py @@ -4,28 +4,34 @@ import testtools from precli.core.level import Level -from precli.parsers import go class TestCase(testtools.TestCase): def setUp(self): super().setUp() - self.parser = go.Go() def expected(self, filename): - with open(os.path.join(self.base_path, f"{filename}.go")) as f: + with open(os.path.join(self.base_path, filename)) as f: level = f.readline().strip() - level = level.removeprefix("// level: ") + level = level.lstrip("/# ").removeprefix("level: ") level = getattr(Level, level) if level != Level.NONE: start_line = f.readline().strip() - start_line = int(start_line.removeprefix("// start_line: ")) + start_line = int( + start_line.lstrip("/# ").removeprefix("start_line: ") + ) end_line = f.readline().strip() - end_line = int(end_line.removeprefix("// end_line: ")) + end_line = int( + end_line.lstrip("/# ").removeprefix("end_line: ") + ) start_col = f.readline().strip() - start_col = int(start_col.removeprefix("// start_column: ")) + start_col = int( + start_col.lstrip("/# ").removeprefix("start_column: ") + ) end_col = f.readline().strip() - end_col = int(end_col.removeprefix("// end_column: ")) + end_col = int( + end_col.lstrip("/# ").removeprefix("end_column: ") + ) else: start_line = end_line = start_col = end_col = -1 @@ -39,9 +45,7 @@ def check(self, filename): start_column, end_column, ) = self.expected(filename) - results = self.parser.parse( - os.path.join(self.base_path, f"{filename}.go") - ) + results = self.parser.parse(os.path.join(self.base_path, filename)) if level == Level.NONE: self.assertEqual(0, len(results)) else: