mirror of
https://github.com/ansible/awx.git
synced 2026-03-03 09:48:51 -03:30
@@ -1895,11 +1895,14 @@ class CredentialTypeSerializer(BaseSerializer):
|
|||||||
raise PermissionDenied(
|
raise PermissionDenied(
|
||||||
detail= _("Modifications to inputs are not allowed for credential types that are in use")
|
detail= _("Modifications to inputs are not allowed for credential types that are in use")
|
||||||
)
|
)
|
||||||
|
ret = super(CredentialTypeSerializer, self).validate(attrs)
|
||||||
|
|
||||||
fields = attrs.get('inputs', {}).get('fields', [])
|
fields = attrs.get('inputs', {}).get('fields', [])
|
||||||
for field in fields:
|
for field in fields:
|
||||||
if field.get('ask_at_runtime', False):
|
if field.get('ask_at_runtime', False):
|
||||||
raise serializers.ValidationError({"inputs": _("'ask_at_runtime' is not supported for custom credentials.")})
|
raise serializers.ValidationError({"inputs": _("'ask_at_runtime' is not supported for custom credentials.")})
|
||||||
return super(CredentialTypeSerializer, self).validate(attrs)
|
|
||||||
|
return ret
|
||||||
|
|
||||||
def get_related(self, obj):
|
def get_related(self, obj):
|
||||||
res = super(CredentialTypeSerializer, self).get_related(obj)
|
res = super(CredentialTypeSerializer, self).get_related(obj)
|
||||||
|
|||||||
@@ -167,15 +167,49 @@ def test_create_with_valid_inputs(get, post, admin):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_create_with_invalid_inputs_xfail(post, admin):
|
@pytest.mark.parametrize('inputs', [
|
||||||
|
True,
|
||||||
|
100,
|
||||||
|
[1, 2, 3, 4],
|
||||||
|
'malformed',
|
||||||
|
{'feelds': {}},
|
||||||
|
{'fields': [123, 234, 345]},
|
||||||
|
{'fields': [{'id':'one', 'label':'One'}, 234]},
|
||||||
|
{'feelds': {}, 'fields': [{'id':'one', 'label':'One'}, 234]}
|
||||||
|
])
|
||||||
|
def test_create_with_invalid_inputs_xfail(post, admin, inputs):
|
||||||
response = post(reverse('api:credential_type_list'), {
|
response = post(reverse('api:credential_type_list'), {
|
||||||
'kind': 'cloud',
|
'kind': 'cloud',
|
||||||
'name': 'MyCloud',
|
'name': 'MyCloud',
|
||||||
'inputs': {'feeelds': {},},
|
'inputs': inputs,
|
||||||
'injectors': {}
|
'injectors': {}
|
||||||
}, admin)
|
}, admin)
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert "'feeelds' was unexpected" in json.dumps(response.data)
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
@pytest.mark.parametrize('injectors', [
|
||||||
|
True,
|
||||||
|
100,
|
||||||
|
[1, 2, 3, 4],
|
||||||
|
'malformed',
|
||||||
|
{'mal': 'formed'},
|
||||||
|
{'env': {'ENV_VAR': 123}, 'mal': 'formed'},
|
||||||
|
{'env': True},
|
||||||
|
{'env': [1, 2, 3]},
|
||||||
|
{'file': True},
|
||||||
|
{'file': [1, 2, 3]},
|
||||||
|
{'extra_vars': True},
|
||||||
|
{'extra_vars': [1, 2, 3]},
|
||||||
|
])
|
||||||
|
def test_create_with_invalid_injectors_xfail(post, admin, injectors):
|
||||||
|
response = post(reverse('api:credential_type_list'), {
|
||||||
|
'kind': 'cloud',
|
||||||
|
'name': 'MyCloud',
|
||||||
|
'inputs': {},
|
||||||
|
'injectors': injectors,
|
||||||
|
}, admin)
|
||||||
|
assert response.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@@ -235,17 +269,6 @@ def test_create_with_valid_injectors(get, post, admin):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_create_with_invalid_injectors_xfail(post, admin):
|
|
||||||
response = post(reverse('api:credential_type_list'), {
|
|
||||||
'kind': 'cloud',
|
|
||||||
'name': 'MyCloud',
|
|
||||||
'inputs': {},
|
|
||||||
'injectors': {'nonsense': 123}
|
|
||||||
}, admin)
|
|
||||||
assert response.status_code == 400
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_create_with_undefined_template_variable_xfail(post, admin):
|
def test_create_with_undefined_template_variable_xfail(post, admin):
|
||||||
response = post(reverse('api:credential_type_list'), {
|
response = post(reverse('api:credential_type_list'), {
|
||||||
|
|||||||
Reference in New Issue
Block a user