mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 00:38:45 -03:30
@@ -455,6 +455,11 @@ class CredentialInputField(JSONSchemaField):
|
|||||||
def validate(self, value, model_instance):
|
def validate(self, value, model_instance):
|
||||||
# decrypt secret values so we can validate their contents (i.e.,
|
# decrypt secret values so we can validate their contents (i.e.,
|
||||||
# ssh_key_data format)
|
# ssh_key_data format)
|
||||||
|
|
||||||
|
if not isinstance(value, dict):
|
||||||
|
return super(CredentialInputField, self).validate(value,
|
||||||
|
model_instance)
|
||||||
|
|
||||||
decrypted_values = {}
|
decrypted_values = {}
|
||||||
for k, v in value.items():
|
for k, v in value.items():
|
||||||
if all([
|
if all([
|
||||||
@@ -466,9 +471,8 @@ class CredentialInputField(JSONSchemaField):
|
|||||||
else:
|
else:
|
||||||
decrypted_values[k] = v
|
decrypted_values[k] = v
|
||||||
|
|
||||||
super(CredentialInputField, self).validate(
|
super(CredentialInputField, self).validate(decrypted_values,
|
||||||
decrypted_values, model_instance
|
model_instance)
|
||||||
)
|
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
inputs = model_instance.credential_type.inputs
|
inputs = model_instance.credential_type.inputs
|
||||||
|
|||||||
@@ -162,7 +162,11 @@ def test_credential_creation(organization_factory):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@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
|
org = organization_factory('test').organization
|
||||||
type_ = CredentialType(
|
type_ = CredentialType(
|
||||||
kind='cloud',
|
kind='cloud',
|
||||||
@@ -180,7 +184,7 @@ def test_credential_creation_validation_failure(organization_factory):
|
|||||||
|
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
cred = Credential(credential_type=type_, name="Bob's Credential",
|
cred = Credential(credential_type=type_, name="Bob's Credential",
|
||||||
inputs={'user': 'wrong-key'}, organization=org)
|
inputs=inputs, organization=org)
|
||||||
cred.save()
|
cred.save()
|
||||||
cred.full_clean()
|
cred.full_clean()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user