Common: Raise InvalidCredentialComponentError from Credentials
This commit is contained in:
parent
06fc4aaad6
commit
9ea0fb87ea
|
@ -77,7 +77,10 @@ class CredentialsSchema(Schema):
|
||||||
credential_component_type
|
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
|
@pre_dump
|
||||||
def _serialize_credentials(
|
def _serialize_credentials(
|
||||||
|
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from common.credentials import (
|
from common.credentials import (
|
||||||
Credentials,
|
Credentials,
|
||||||
|
InvalidCredentialComponentError,
|
||||||
InvalidCredentialsError,
|
InvalidCredentialsError,
|
||||||
LMHash,
|
LMHash,
|
||||||
NTHash,
|
NTHash,
|
||||||
|
@ -77,3 +78,12 @@ def test_credentials_deserialization__invalid_component_type():
|
||||||
invalid_data = {"secrets": [], "identities": [{"credential_type": "FAKE", "username": "user1"}]}
|
invalid_data = {"secrets": [], "identities": [{"credential_type": "FAKE", "username": "user1"}]}
|
||||||
with pytest.raises(InvalidCredentialsError):
|
with pytest.raises(InvalidCredentialsError):
|
||||||
Credentials.from_mapping(invalid_data)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue