From 06099bd1160baa5ee8e6a6d940be22d94a753e33 Mon Sep 17 00:00:00 2001 From: Andrea Scarpino Date: Wed, 12 Dec 2018 05:06:54 +0100 Subject: [PATCH] win_uri: fix body with one item in list (#49484) --- .../fragments/win_uri-oneitem-list.yaml | 2 ++ lib/ansible/modules/windows/win_uri.ps1 | 2 +- .../targets/win_uri/tasks/test.yml | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/win_uri-oneitem-list.yaml diff --git a/changelogs/fragments/win_uri-oneitem-list.yaml b/changelogs/fragments/win_uri-oneitem-list.yaml new file mode 100644 index 00000000000..4e984eb36ec --- /dev/null +++ b/changelogs/fragments/win_uri-oneitem-list.yaml @@ -0,0 +1,2 @@ +bugfixes: +- win_uri - allow to send a JSON array with just one item into - https://github.com/ansible/ansible/issues/49483 diff --git a/lib/ansible/modules/windows/win_uri.ps1 b/lib/ansible/modules/windows/win_uri.ps1 index b78a6b1bbee..09dd55ba9ba 100644 --- a/lib/ansible/modules/windows/win_uri.ps1 +++ b/lib/ansible/modules/windows/win_uri.ps1 @@ -179,7 +179,7 @@ if ($user -and $password) { } if ($null -ne $body) { - if ($body -is [Hashtable]) { + if ($body -is [System.Collections.IDictionary] -or $body -is [System.Collections.IList]) { $body_string = ConvertTo-Json -InputObject $body -Compress } elseif ($body -isnot [String]) { $body_string = $body.ToString() diff --git a/test/integration/targets/win_uri/tasks/test.yml b/test/integration/targets/win_uri/tasks/test.yml index 9275a62e88a..ebeda5e8b94 100644 --- a/test/integration/targets/win_uri/tasks/test.yml +++ b/test/integration/targets/win_uri/tasks/test.yml @@ -296,6 +296,29 @@ - json_as_dict.json.json == json_as_dict_value - json_as_dict.status_code == 200 +- name: send JSON body with 1 item in list + win_uri: + url: https://{{httpbin_host}}/post + method: POST + body: + - foo: bar + headers: + 'Content-Type': 'text/json' + return_content: yes + register: json_as_oneitemlist + +- name: set fact of expected json 1 item list + set_fact: + json_as_oneitemlist_value: + - foo: bar + +- name: assert send JSON body with 1 item in list + assert: + that: + - not json_as_oneitemlist.changed + - json_as_oneitemlist.json.json == json_as_oneitemlist_value + - json_as_oneitemlist.status_code == 200 + - name: get request with custom headers win_uri: url: https://{{httpbin_host}}/get