Common: Raise InvalidCredentialComponentError from Credentials

This commit is contained in:
Mike Salvatore 2022-07-07 08:52:33 -04:00
parent 06fc4aaad6
commit 9ea0fb87ea
2 changed files with 14 additions and 1 deletions

View File

@ -77,7 +77,10 @@ class CredentialsSchema(Schema):
credential_component_type
]
return credential_component_class(**credential_component_schema.load(data))
try:
return credential_component_class(**credential_component_schema.load(data))
except MarshmallowError as err:
raise InvalidCredentialComponentError(credential_component_class, str(err))
@pre_dump
def _serialize_credentials(

View File

@ -4,6 +4,7 @@ import pytest
from common.credentials import (
Credentials,
InvalidCredentialComponentError,
InvalidCredentialsError,
LMHash,
NTHash,
@ -77,3 +78,12 @@ def test_credentials_deserialization__invalid_component_type():
invalid_data = {"secrets": [], "identities": [{"credential_type": "FAKE", "username": "user1"}]}
with pytest.raises(InvalidCredentialsError):
Credentials.from_mapping(invalid_data)
def test_credentials_deserialization__invalid_component():
invalid_data = {
"secrets": [],
"identities": [{"credential_type": "USERNAME", "unknown_field": "user1"}],
}
with pytest.raises(InvalidCredentialComponentError):
Credentials.from_mapping(invalid_data)