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

More refactoring of tests #193

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
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// level: ERROR
// start_line: 24
// end_line: 24
// start_column: 25
// end_column: 50
package main

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// level: ERROR
// start_line: 14
// end_line: 14
// start_column: 9
// end_column: 16
package main

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// level: ERROR
// start_line: 14
// end_line: 14
// start_column: 9
// end_column: 22
package main

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 Secure Saurce LLC
import os

from parameterized import parameterized

from precli.core.level import Level
from precli.parsers import go
from precli.rules import Rule
from tests.unit.rules import test_case


class SshInsecureIgnoreHostkeyTests(test_case.TestCase):
def setUp(self):
super().setUp()
self.rule_id = "GO501"
self.parser = go.Go(enabled=[self.rule_id])
self.base_path = os.path.join(
"tests",
"unit",
"rules",
"go",
"golang_org_x_crypto",
"examples",
)

def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("improper_certificate_validation", rule.name)
self.assertEqual(
f"https://docs.securesauce.dev/rules/{self.rule_id}", rule.help_url
)
self.assertEqual(True, rule.default_config.enabled)
self.assertEqual(Level.WARNING, rule.default_config.level)
self.assertEqual(-1.0, rule.default_config.rank)
self.assertEqual("295", rule.cwe.cwe_id)

@parameterized.expand(
[
"ssh_insecure_ignore_hostkey.go",
]
)
def test(self, filename):
self.check(filename)
45 changes: 45 additions & 0 deletions tests/unit/rules/go/golang_org_x_crypto/test_weak_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2024 Secure Saurce LLC
import os

from parameterized import parameterized

from precli.core.level import Level
from precli.parsers import go
from precli.rules import Rule
from tests.unit.rules import test_case


class CryptoWeakHashTests(test_case.TestCase):
def setUp(self):
super().setUp()
self.rule_id = "GO502"
self.parser = go.Go(enabled=[self.rule_id])
self.base_path = os.path.join(
"tests",
"unit",
"rules",
"go",
"golang_org_x_crypto",
"examples",
)

def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("reversible_one_way_hash", rule.name)
self.assertEqual(
f"https://docs.securesauce.dev/rules/{self.rule_id}", rule.help_url
)
self.assertEqual(True, rule.default_config.enabled)
self.assertEqual(Level.WARNING, rule.default_config.level)
self.assertEqual(-1.0, rule.default_config.rank)
self.assertEqual("328", rule.cwe.cwe_id)

@parameterized.expand(
[
"weak_hash_md4.go",
"weak_hash_ripemd160.go",
]
)
def test(self, filename):
self.check(filename)
2 changes: 1 addition & 1 deletion tests/unit/rules/go/stdlib/crypto/test_weak_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
"examples",
)

def test_crypto_weak_cipher_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/rules/go/stdlib/crypto/test_weak_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tests.unit.rules import test_case


class CryptoWeakCipherTests(test_case.TestCase):
class CryptoWeakHashTests(test_case.TestCase):
def setUp(self):
super().setUp()
self.rule_id = "GO002"
Expand All @@ -24,7 +24,7 @@ def setUp(self):
"examples",
)

def test_crypto_weak_cipher_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("reversible_one_way_hash", rule.name)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/rules/go/stdlib/crypto/test_weak_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tests.unit.rules import test_case


class CryptoWeakCipherTests(test_case.TestCase):
class CryptoWeakKeyTests(test_case.TestCase):
def setUp(self):
super().setUp()
self.rule_id = "GO003"
Expand All @@ -24,7 +24,7 @@ def setUp(self):
"examples",
)

def test_crypto_weak_cipher_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("inadequate_encryption_strength", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_m2crypto_weak_key_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("inadequate_encryption_strength", rule.name)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/rules/python/PyYAML/test_yaml_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_yaml_load_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("deserialization_of_untrusted_data", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_no_certificate_verify_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("improper_certificate_validation", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_cryptography_weak_cipher_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_cryptography_weak_cipher_mode_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("use_of_risky_cryptographic_cipher_mode", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_cryptography_weak_hash_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("reversible_one_way_hash", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_cryptography_weak_key_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("inadequate_encryption_strength", rule.name)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/rules/python/dill/test_dill_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_dill_load_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("deserialization_of_untrusted_data", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_no_certificate_verify_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("improper_certificate_validation", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_jsonpickle_decode_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("deserialization_of_untrusted_data", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_pandas_read_pickle_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("deserialization_of_untrusted_data", rule.name)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/rules/python/paramiko/test_host_key_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_paramiko_no_host_key_verify_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("improper_certificate_validation", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_pycrypto_weak_cipher_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_pycrypto_weak_hash_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("reversible_one_way_hash", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_pycrypto_weak_key_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("inadequate_encryption_strength", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_pycryptodomex_weak_cipher_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_pycryptodomex_weak_hash_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("reversible_one_way_hash", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_pycryptodomex_weak_key_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("inadequate_encryption_strength", rule.name)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/rules/python/pyghmi/test_pyghmi_cleartext.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_pyghmi_cleartext_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("cleartext_transmission", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_pyopenssl_weak_key_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("inadequate_encryption_strength", rule.name)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/rules/python/pyopenssl/test_ssl_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_ssl_context_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("inadequate_encryption_strength", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"examples",
)

def test_no_certificate_verify_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("improper_certificate_validation", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
"examples",
)

def test_crypt_weak_hash_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("reversible_one_way_hash", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
"examples",
)

def test_ftp_cleartext_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("cleartext_transmission", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
"examples",
)

def test_hashlib_weak_hash_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("reversible_one_way_hash", rule.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
"examples",
)

def test_hmac_timing_attack_rule_meta(self):
def test_rule_meta(self):
rule = Rule.get_by_id(self.rule_id)
self.assertEqual(self.rule_id, rule.id)
self.assertEqual("observable_timing_discrepancy", rule.name)
Expand Down
Loading