1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

enforce dict for credential API input payloads

see: #6363
This commit is contained in:
Ryan Petrello 2017-05-30 13:08:44 -04:00
parent eb6e598f6c
commit 98fa654be2
2 changed files with 13 additions and 5 deletions

View File

@ -455,6 +455,11 @@ class CredentialInputField(JSONSchemaField):
def validate(self, value, model_instance):
# decrypt secret values so we can validate their contents (i.e.,
# ssh_key_data format)
if not isinstance(value, dict):
return super(CredentialInputField, self).validate(value,
model_instance)
decrypted_values = {}
for k, v in value.items():
if all([
@ -466,9 +471,8 @@ class CredentialInputField(JSONSchemaField):
else:
decrypted_values[k] = v
super(CredentialInputField, self).validate(
decrypted_values, model_instance
)
super(CredentialInputField, self).validate(decrypted_values,
model_instance)
errors = []
inputs = model_instance.credential_type.inputs

View File

@ -162,7 +162,11 @@ def test_credential_creation(organization_factory):
@pytest.mark.django_db
def test_credential_creation_validation_failure(organization_factory):
@pytest.mark.parametrize('inputs', [
['must-be-a-dict'],
{'user': 'wrong-key'},
])
def test_credential_creation_validation_failure(organization_factory, inputs):
org = organization_factory('test').organization
type_ = CredentialType(
kind='cloud',
@ -180,7 +184,7 @@ def test_credential_creation_validation_failure(organization_factory):
with pytest.raises(ValidationError):
cred = Credential(credential_type=type_, name="Bob's Credential",
inputs={'user': 'wrong-key'}, organization=org)
inputs=inputs, organization=org)
cred.save()
cred.full_clean()