Common: Add LMHashSchema

This commit is contained in:
Mike Salvatore 2022-07-06 12:02:49 -04:00
parent 68e52eb512
commit def2381da6
2 changed files with 27 additions and 5 deletions

View File

@ -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)

View File

@ -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