From 58fcc3761ce6011dde8cd6db7f865e50d7394679 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 6 Jul 2022 12:07:44 -0400 Subject: [PATCH] UT: Add NTHashSchema --- monkey/common/credentials/nt_hash.py | 9 +++++++++ .../test_single_value_credential_components.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/monkey/common/credentials/nt_hash.py b/monkey/common/credentials/nt_hash.py index 67246f695..838ec4596 100644 --- a/monkey/common/credentials/nt_hash.py +++ b/monkey/common/credentials/nt_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 NTHashSchema(CredentialComponentSchema): + credential_type = CredentialTypeField(CredentialComponentType.NT_HASH) + nt_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 1b61dc329..0004b38ee 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,8 +1,9 @@ import pytest from marshmallow.exceptions import ValidationError -from common.credentials import CredentialComponentType, LMHash, Password, Username +from common.credentials import CredentialComponentType, LMHash, NTHash, Password, Username from common.credentials.lm_hash import LMHashSchema +from common.credentials.nt_hash import NTHashSchema from common.credentials.password import PasswordSchema from common.credentials.username import UsernameSchema @@ -20,6 +21,13 @@ PARAMETRIZED_PARAMETER_VALUES = [ "lm_hash", "E52CAC67419A9A224A3B108F3FA6CB6D", ), + ( + NTHash, + NTHashSchema, + CredentialComponentType.NT_HASH, + "nt_hash", + "E52CAC67419A9A224A3B108F3FA6CB6D", + ), ] @@ -33,6 +41,13 @@ INVALID_VALUES = { "0123456789012345678901234568901", "E52GAC67419A9A224A3B108F3FA6CB6D", ), + CredentialComponentType.NT_HASH: ( + None, + 1, + 2.0, + "0123456789012345678901234568901", + "E52GAC67419A9A224A3B108F3FA6CB6D", + ), }