diff --git a/awx/main/fields.py b/awx/main/fields.py index 89e1aae75d..8031d2e110 100644 --- a/awx/main/fields.py +++ b/awx/main/fields.py @@ -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 diff --git a/awx/main/tests/functional/test_credential.py b/awx/main/tests/functional/test_credential.py index 534bd2785f..95f36a98e6 100644 --- a/awx/main/tests/functional/test_credential.py +++ b/awx/main/tests/functional/test_credential.py @@ -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()