From f018b85f561eb5f5c3c86d9d1d9c8e858f454a44 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Thu, 1 Sep 2022 13:59:08 +0300 Subject: [PATCH] UT: Add nt/lm hash unit test and data --- .../unit_tests/common/credentials/conftest.py | 20 ++++++++++++++ .../common/credentials/test_nt_hash.py | 14 ++++++++++ .../common/credentials/test_ntlm_hash.py | 26 ------------------- 3 files changed, 34 insertions(+), 26 deletions(-) create mode 100644 monkey/tests/unit_tests/common/credentials/conftest.py create mode 100644 monkey/tests/unit_tests/common/credentials/test_nt_hash.py delete mode 100644 monkey/tests/unit_tests/common/credentials/test_ntlm_hash.py diff --git a/monkey/tests/unit_tests/common/credentials/conftest.py b/monkey/tests/unit_tests/common/credentials/conftest.py new file mode 100644 index 000000000..b6e60289c --- /dev/null +++ b/monkey/tests/unit_tests/common/credentials/conftest.py @@ -0,0 +1,20 @@ +from typing import List + +import pytest + + +@pytest.fixture(scope="session") +def valid_ntlm_hash() -> str: + return "E520AC67419A9A224A3B108F3FA6CB6D" + + +@pytest.fixture(scope="session") +def invalid_ntlm_hashes() -> List[str]: + return [ + 0, + 1, + 2.0, + "invalid", + "0123456789012345678901234568901", + "E52GAC67419A9A224A3B108F3FA6CB6D", + ] diff --git a/monkey/tests/unit_tests/common/credentials/test_nt_hash.py b/monkey/tests/unit_tests/common/credentials/test_nt_hash.py new file mode 100644 index 000000000..1c60f4fca --- /dev/null +++ b/monkey/tests/unit_tests/common/credentials/test_nt_hash.py @@ -0,0 +1,14 @@ +import pytest + +from common.credentials import NTHash + + +def test_construct_valid_nt_hash(valid_ntlm_hash): + # This test will fail if an exception is raised + NTHash(nt_hash=valid_ntlm_hash) + + +def test_construct_invalid_nt_hash(invalid_ntlm_hashes): + for invalid_hash in invalid_ntlm_hashes: + with pytest.raises(ValueError): + NTHash(nt_hash=invalid_hash) diff --git a/monkey/tests/unit_tests/common/credentials/test_ntlm_hash.py b/monkey/tests/unit_tests/common/credentials/test_ntlm_hash.py deleted file mode 100644 index 5f50110e8..000000000 --- a/monkey/tests/unit_tests/common/credentials/test_ntlm_hash.py +++ /dev/null @@ -1,26 +0,0 @@ -import pytest - -from common.credentials import InvalidCredentialComponentError, LMHash, NTHash - -VALID_HASH = "E520AC67419A9A224A3B108F3FA6CB6D" -INVALID_HASHES = ( - 0, - 1, - 2.0, - "invalid", - "0123456789012345678901234568901", - "E52GAC67419A9A224A3B108F3FA6CB6D", -) - - -@pytest.mark.parametrize("ntlm_hash_class", (LMHash, NTHash)) -def test_construct_valid_ntlm_hash(ntlm_hash_class): - # This test will fail if an exception is raised - ntlm_hash_class(VALID_HASH) - - -@pytest.mark.parametrize("ntlm_hash_class", (LMHash, NTHash)) -def test_construct_invalid_ntlm_hash(ntlm_hash_class): - for invalid_hash in INVALID_HASHES: - with pytest.raises(InvalidCredentialComponentError): - ntlm_hash_class(invalid_hash)