uri - fix traceback on multipart-form int value (#74302)

pull/74317/head
Jordan Borean 4 years ago committed by GitHub
parent fdee5ca16d
commit 019452dda7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- uri - Fix traceback and provide error message when trying to use non-string or mapping for ``form-multipart`` body - https://github.com/ansible/ansible/issues/74276

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible.module_utils.six import binary_type, text_type from ansible.module_utils.six import binary_type, text_type
from ansible.module_utils.common._collections_compat import Hashable, Mapping, Sequence from ansible.module_utils.common._collections_compat import Hashable, Mapping, MutableMapping, Sequence
class ImmutableDict(Hashable, Mapping): class ImmutableDict(Hashable, Mapping):

@ -11,7 +11,7 @@ import os
from ansible.errors import AnsibleError, AnsibleAction, _AnsibleActionDone, AnsibleActionFail from ansible.errors import AnsibleError, AnsibleAction, _AnsibleActionDone, AnsibleActionFail
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
from ansible.module_utils.common.collections import Mapping from ansible.module_utils.common.collections import Mapping, MutableMapping
from ansible.module_utils.parsing.convert_bool import boolean from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils.six import text_type from ansible.module_utils.six import text_type
from ansible.plugins.action import ActionBase from ansible.plugins.action import ActionBase
@ -61,7 +61,7 @@ class ActionModule(ActionBase):
'body must be mapping, cannot be type %s' % body.__class__.__name__ 'body must be mapping, cannot be type %s' % body.__class__.__name__
) )
for field, value in body.items(): for field, value in body.items():
if isinstance(value, text_type): if not isinstance(value, MutableMapping):
continue continue
content = value.get('content') content = value.get('content')
filename = value.get('filename') filename = value.get('filename')

@ -474,6 +474,16 @@
- multipart.json.form.text_form_field1 == 'value1' - multipart.json.form.text_form_field1 == 'value1'
- multipart.json.form.text_form_field2 == 'value2' - multipart.json.form.text_form_field2 == 'value2'
# https://github.com/ansible/ansible/issues/74276 - verifies we don't have a traceback
- name: multipart/form-data with invalid value
uri:
url: https://{{ httpbin_host }}/post
method: POST
body_format: form-multipart
body:
integer_value: 1
register: multipart_invalid
failed_when: 'multipart_invalid.msg != "failed to parse body as form-multipart: value must be a string, or mapping, cannot be type int"'
- name: Validate invalid method - name: Validate invalid method
uri: uri:

Loading…
Cancel
Save