mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
raise 400 instead of ignoring if fields mismatch v1/v2
This commit is contained in:
@@ -3015,12 +3015,12 @@ class JobTemplateLaunch(RetrieveAPIView):
|
|||||||
if fd not in modern_data and id_fd in modern_data:
|
if fd not in modern_data and id_fd in modern_data:
|
||||||
modern_data[fd] = modern_data[id_fd]
|
modern_data[fd] = modern_data[id_fd]
|
||||||
|
|
||||||
# This block causes `extra_credentials` to _always_ be ignored for
|
# This block causes `extra_credentials` to _always_ raise error if
|
||||||
# the launch endpoint if we're accessing `/api/v1/`
|
# the launch endpoint if we're accessing `/api/v1/`
|
||||||
if get_request_version(self.request) == 1 and 'extra_credentials' in modern_data:
|
if get_request_version(self.request) == 1 and 'extra_credentials' in modern_data:
|
||||||
extra_creds = modern_data.pop('extra_credentials', None)
|
raise ParseError({"extra_credentials": _(
|
||||||
if extra_creds is not None:
|
"Field is not allowed for use with v1 API."
|
||||||
ignored_fields['extra_credentials'] = extra_creds
|
)})
|
||||||
|
|
||||||
# Automatically convert legacy launch credential arguments into a list of `.credentials`
|
# Automatically convert legacy launch credential arguments into a list of `.credentials`
|
||||||
if 'credentials' in modern_data and (
|
if 'credentials' in modern_data and (
|
||||||
|
|||||||
@@ -567,16 +567,9 @@ def test_v1_launch_with_extra_credentials(get, post, organization_factory,
|
|||||||
credential=machine_credential.pk,
|
credential=machine_credential.pk,
|
||||||
extra_credentials=[credential.pk, net_credential.pk]
|
extra_credentials=[credential.pk, net_credential.pk]
|
||||||
),
|
),
|
||||||
objs.superusers.admin, expect=201
|
objs.superusers.admin, expect=400
|
||||||
)
|
)
|
||||||
job_pk = resp.data.get('id')
|
assert 'Field is not allowed for use with v1 API' in resp.data.get('extra_credentials')
|
||||||
assert resp.data.get('ignored_fields').keys() == ['extra_credentials']
|
|
||||||
|
|
||||||
resp = get(reverse('api:job_extra_credentials_list', kwargs={'pk': job_pk}), objs.superusers.admin)
|
|
||||||
assert resp.data.get('count') == 0
|
|
||||||
|
|
||||||
resp = get(reverse('api:job_template_extra_credentials_list', kwargs={'pk': jt.pk}), objs.superusers.admin)
|
|
||||||
assert resp.data.get('count') == 0
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
|||||||
Reference in New Issue
Block a user