Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the tests and test_case.py #192

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions precli/rules/go/stdlib/crypto/weak_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions precli/rules/go/stdlib/crypto/weak_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/rules/go/stdlib/crypto/test_weak_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/rules/go/stdlib/crypto/test_weak_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/rules/go/stdlib/crypto/test_weak_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/rules/python/M2Crypto/test_m2crypto_weak_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
48 changes: 24 additions & 24 deletions tests/unit/rules/python/PyYAML/test_yaml_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
44 changes: 22 additions & 22 deletions tests/unit/rules/python/aiohttp/test_no_certificate_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -37,7 +37,7 @@ def test_cryptography_weak_cipher_mode_rule_meta(self):

@parameterized.expand(
[
"modes_ecb",
"modes_ecb.py",
]
)
def test(self, filename):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Loading