diff --git a/monkey/common/credentials/lm_hash.py b/monkey/common/credentials/lm_hash.py index 818999244..4a1b59f80 100644 --- a/monkey/common/credentials/lm_hash.py +++ b/monkey/common/credentials/lm_hash.py @@ -1,6 +1,15 @@ from dataclasses import dataclass, field +from marshmallow import fields + from . import CredentialComponentType, ICredentialComponent +from .credential_component_schema import CredentialComponentSchema, CredentialTypeField +from .validators import ntlm_hash_validator + + +class LMHashSchema(CredentialComponentSchema): + credential_type = CredentialTypeField(CredentialComponentType.LM_HASH) + lm_hash = fields.Str(validate=ntlm_hash_validator) @dataclass(frozen=True) diff --git a/monkey/tests/unit_tests/common/credentials/test_single_value_credential_components.py b/monkey/tests/unit_tests/common/credentials/test_single_value_credential_components.py index 51d02ae04..1b61dc329 100644 --- a/monkey/tests/unit_tests/common/credentials/test_single_value_credential_components.py +++ b/monkey/tests/unit_tests/common/credentials/test_single_value_credential_components.py @@ -1,7 +1,8 @@ import pytest from marshmallow.exceptions import ValidationError -from common.credentials import CredentialComponentType, Password, Username +from common.credentials import CredentialComponentType, LMHash, Password, Username +from common.credentials.lm_hash import LMHashSchema from common.credentials.password import PasswordSchema from common.credentials.username import UsernameSchema @@ -12,16 +13,29 @@ PARAMETRIZED_PARAMETER_NAMES = ( PARAMETRIZED_PARAMETER_VALUES = [ (Password, PasswordSchema, CredentialComponentType.PASSWORD, "password", "123456"), (Username, UsernameSchema, CredentialComponentType.USERNAME, "username", "test_user"), + ( + LMHash, + LMHashSchema, + CredentialComponentType.LM_HASH, + "lm_hash", + "E52CAC67419A9A224A3B108F3FA6CB6D", + ), ] - - INVALID_VALUES = { CredentialComponentType.USERNAME: (None, 1, 2.0), CredentialComponentType.PASSWORD: (None, 1, 2.0), + CredentialComponentType.LM_HASH: ( + None, + 1, + 2.0, + "0123456789012345678901234568901", + "E52GAC67419A9A224A3B108F3FA6CB6D", + ), } + def build_component_dict(credential_component_type: CredentialComponentType, key: str, value: str): return {"credential_type": credential_component_type.name, key: value} @@ -31,9 +45,7 @@ def test_credential_component_serialize( credential_component_class, schema_class, credential_component_type, key, value ): schema = schema_class() - print(type(schema)) constructed_object = credential_component_class(value) - print(type(constructed_object)) serialized_object = schema.dump(constructed_object) @@ -80,6 +92,7 @@ def test_encorrect_credential_type( with pytest.raises(ValidationError): credential_component_class(**schema.load(incorrect_component_dict)) + @pytest.mark.parametrize(PARAMETRIZED_PARAMETER_NAMES, PARAMETRIZED_PARAMETER_VALUES) def test_invalid_values( credential_component_class, schema_class, credential_component_type, key, value