| 1 |
# test code for the uri module |
| 2 |
# (c) 2014, Leonid Evdokimov <[email protected]> |
| 3 |
|
| 4 |
# This file is part of Ansible |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
- name: set role facts |
| 20 |
set_fact: |
| 21 |
http_port: 15260 |
| 22 |
files_dir: '{{ remote_tmp_dir|expanduser }}/files' |
| 23 |
checkout_dir: '{{ remote_tmp_dir }}/git' |
| 24 |
|
| 25 |
- name: create a directory to serve files from |
| 26 |
file: |
| 27 |
dest: "{{ files_dir }}" |
| 28 |
state: directory |
| 29 |
|
| 30 |
- copy: |
| 31 |
src: "{{ item }}" |
| 32 |
dest: "{{files_dir}}/{{ item }}" |
| 33 |
with_sequence: start=0 end=4 format=pass%d.json |
| 34 |
|
| 35 |
- copy: |
| 36 |
src: "{{ item }}" |
| 37 |
dest: "{{files_dir}}/{{ item }}" |
| 38 |
with_sequence: start=0 end=30 format=fail%d.json |
| 39 |
|
| 40 |
- copy: |
| 41 |
src: "testserver.py" |
| 42 |
dest: "{{ remote_tmp_dir }}/testserver.py" |
| 43 |
|
| 44 |
- name: start SimpleHTTPServer |
| 45 |
shell: cd {{ files_dir }} && {{ ansible_python.executable }} {{ remote_tmp_dir}}/testserver.py {{ http_port }} |
| 46 |
async: 180 # this test is slower on remotes like FreeBSD, and running split slows it down further |
| 47 |
poll: 0 |
| 48 |
|
| 49 |
- wait_for: port={{ http_port }} |
| 50 |
|
| 51 |
|
| 52 |
- name: checksum pass_json |
| 53 |
stat: path={{ files_dir }}/{{ item }}.json get_checksum=yes |
| 54 |
register: pass_checksum |
| 55 |
with_sequence: start=0 end=4 format=pass%d |
| 56 |
|
| 57 |
|
| 58 |
- name: test basic auth with urlencoded |
| 59 |
register: result |
| 60 |
uri: |
| 61 |
url: 'https://foo%40example.com:test%40@{{ httpbin_host }}/basic-auth/foo%40example.com/test%40' |
| 62 |
|
| 63 |
- name: Ensure basic auth credentials where URL-decoded |
| 64 |
assert: |
| 65 |
that: |
| 66 |
- result.json.authenticated |
| 67 |
- result.json.user == '[email protected]' |
| 68 |
|
| 69 |
- name: fetch pass_json |
| 70 |
uri: return_content=yes url=http://localhost:{{ http_port }}/{{ item }}.json |
| 71 |
register: fetch_pass_json |
| 72 |
with_sequence: start=0 end=4 format=pass%d |
| 73 |
|
| 74 |
- name: check pass_json |
| 75 |
assert: |
| 76 |
that: |
| 77 |
- '"json" in item.1' |
| 78 |
- item.0.stat.checksum == item.1.content | checksum |
| 79 |
with_together: |
| 80 |
- "{{pass_checksum.results}}" |
| 81 |
- "{{fetch_pass_json.results}}" |
| 82 |
|
| 83 |
|
| 84 |
- name: checksum fail_json |
| 85 |
stat: path={{ files_dir }}/{{ item }}.json get_checksum=yes |
| 86 |
register: fail_checksum |
| 87 |
with_sequence: start=0 end=30 format=fail%d |
| 88 |
|
| 89 |
- name: fetch fail_json |
| 90 |
uri: return_content=yes url=http://localhost:{{ http_port }}/{{ item }}.json |
| 91 |
register: fail |
| 92 |
with_sequence: start=0 end=30 format=fail%d |
| 93 |
|
| 94 |
- name: check fail_json |
| 95 |
assert: |
| 96 |
that: |
| 97 |
- item.0.stat.checksum == item.1.content | checksum |
| 98 |
- '"json" not in item.1' |
| 99 |
with_together: |
| 100 |
- "{{fail_checksum.results}}" |
| 101 |
- "{{fail.results}}" |
| 102 |
|
| 103 |
- name: Request IncompleteRead from localhost |
| 104 |
uri: |
| 105 |
return_content: yes |
| 106 |
url: http://localhost:{{ http_port }}/chunked |
| 107 |
register: r |
| 108 |
ignore_errors: true |
| 109 |
|
| 110 |
- name: Check if IncompleteRead raises error |
| 111 |
assert: |
| 112 |
that: |
| 113 |
- r.failed |
| 114 |
- "'HTTP Error while fetching' in r.msg" |
| 115 |
|
| 116 |
- name: test https fetch to a site with mismatched hostname and certificate |
| 117 |
uri: |
| 118 |
url: "https://{{ badssl_host }}/" |
| 119 |
dest: "{{ remote_tmp_dir }}/shouldnotexist.html" |
| 120 |
ignore_errors: True |
| 121 |
register: result |
| 122 |
|
| 123 |
- stat: |
| 124 |
path: "{{ remote_tmp_dir }}/shouldnotexist.html" |
| 125 |
register: stat_result |
| 126 |
|
| 127 |
- name: Assert that the file was not downloaded |
| 128 |
assert: |
| 129 |
that: |
| 130 |
- result.failed == true |
| 131 |
- "'Failed to validate the SSL certificate' in result.msg or 'Hostname mismatch' in result.msg or (result.msg is match('hostname .* doesn.t match .*'))" |
| 132 |
- stat_result.stat.exists == false |
| 133 |
- result.status is defined |
| 134 |
- result.status == -1 |
| 135 |
- result.url == 'https://' ~ badssl_host ~ '/' |
| 136 |
|
| 137 |
- name: Clean up any cruft from the results directory |
| 138 |
file: |
| 139 |
name: "{{ remote_tmp_dir }}/kreitz.html" |
| 140 |
state: absent |
| 141 |
|
| 142 |
- name: test https fetch to a site with mismatched hostname and certificate and validate_certs=no |
| 143 |
uri: |
| 144 |
url: "https://{{ badssl_host }}/" |
| 145 |
dest: "{{ remote_tmp_dir }}/kreitz.html" |
| 146 |
validate_certs: no |
| 147 |
register: result |
| 148 |
|
| 149 |
- stat: |
| 150 |
path: "{{ remote_tmp_dir }}/kreitz.html" |
| 151 |
register: stat_result |
| 152 |
|
| 153 |
- name: Assert that the file was downloaded |
| 154 |
assert: |
| 155 |
that: |
| 156 |
- "stat_result.stat.exists == true" |
| 157 |
- "result.changed == true" |
| 158 |
|
| 159 |
- name: "get ca certificate {{ self_signed_host }}" |
| 160 |
uri: |
| 161 |
url: "http://{{ httpbin_host }}/ca2cert.pem" |
| 162 |
dest: "{{ remote_tmp_dir }}/ca2cert.pem" |
| 163 |
|
| 164 |
- name: test https fetch to a site with self signed certificate using ca_path |
| 165 |
uri: |
| 166 |
url: "https://{{ self_signed_host }}:444/" |
| 167 |
dest: "{{ remote_tmp_dir }}/self-signed_using_ca_path.html" |
| 168 |
ca_path: "{{ remote_tmp_dir }}/ca2cert.pem" |
| 169 |
validate_certs: yes |
| 170 |
register: result |
| 171 |
|
| 172 |
- stat: |
| 173 |
path: "{{ remote_tmp_dir }}/self-signed_using_ca_path.html" |
| 174 |
register: stat_result |
| 175 |
|
| 176 |
- name: Assert that the file was downloaded |
| 177 |
assert: |
| 178 |
that: |
| 179 |
- "stat_result.stat.exists == true" |
| 180 |
- "result.changed == true" |
| 181 |
|
| 182 |
- name: test https fetch to a site with self signed certificate without using ca_path |
| 183 |
uri: |
| 184 |
url: "https://{{ self_signed_host }}:444/" |
| 185 |
dest: "{{ remote_tmp_dir }}/self-signed-without_using_ca_path.html" |
| 186 |
validate_certs: yes |
| 187 |
register: result |
| 188 |
ignore_errors: true |
| 189 |
|
| 190 |
- stat: |
| 191 |
path: "{{ remote_tmp_dir }}/self-signed-without_using_ca_path.html" |
| 192 |
register: stat_result |
| 193 |
|
| 194 |
- name: Assure that https access to a host with self-signed certificate without providing ca_path fails |
| 195 |
assert: |
| 196 |
that: |
| 197 |
- "stat_result.stat.exists == false" |
| 198 |
- result is failed |
| 199 |
- "'certificate verify failed' in result.msg" |
| 200 |
|
| 201 |
- name: Locate ca-bundle |
| 202 |
stat: |
| 203 |
path: '{{ item }}' |
| 204 |
loop: |
| 205 |
- '{{ cafile_path.stdout_lines|default(["/_i_dont_exist_ca.pem"])|first }}' |
| 206 |
- /etc/ssl/certs/ca-bundle.crt |
| 207 |
- /etc/ssl/certs/ca-certificates.crt |
| 208 |
- /var/lib/ca-certificates/ca-bundle.pem |
| 209 |
- /usr/local/share/certs/ca-root-nss.crt |
| 210 |
- /etc/ssl/cert.pem |
| 211 |
register: ca_bundle_candidates |
| 212 |
|
| 213 |
- name: Test that ca_path can be a full bundle |
| 214 |
uri: |
| 215 |
url: "https://{{ httpbin_host }}/get" |
| 216 |
ca_path: '{{ ca_bundle }}' |
| 217 |
vars: |
| 218 |
ca_bundle: '{{ ca_bundle_candidates.results|selectattr("stat.exists")|map(attribute="item")|first }}' |
| 219 |
|
| 220 |
- name: test redirect without follow_redirects |
| 221 |
uri: |
| 222 |
url: 'https://{{ httpbin_host }}/redirect/2' |
| 223 |
follow_redirects: 'none' |
| 224 |
status_code: 302 |
| 225 |
register: result |
| 226 |
|
| 227 |
- name: Assert location header |
| 228 |
assert: |
| 229 |
that: |
| 230 |
- 'result.location|default("") == "https://" + httpbin_host + "/relative-redirect/1"' |
| 231 |
|
| 232 |
- name: Check SSL with redirect |
| 233 |
uri: |
| 234 |
url: 'https://{{ httpbin_host }}/redirect/2' |
| 235 |
register: result |
| 236 |
|
| 237 |
- name: Assert SSL with redirect |
| 238 |
assert: |
| 239 |
that: |
| 240 |
- 'result.url|default("") == "https://" + httpbin_host + "/get"' |
| 241 |
|
| 242 |
- name: redirect to bad SSL site |
| 243 |
uri: |
| 244 |
url: 'http://{{ badssl_host }}' |
| 245 |
register: result |
| 246 |
ignore_errors: true |
| 247 |
|
| 248 |
- name: Ensure bad SSL site redirect fails |
| 249 |
assert: |
| 250 |
that: |
| 251 |
- result is failed |
| 252 |
- 'badssl_host in result.msg' |
| 253 |
|
| 254 |
- name: test basic auth |
| 255 |
uri: |
| 256 |
url: 'https://{{ httpbin_host }}/basic-auth/user/passwd' |
| 257 |
user: user |
| 258 |
password: passwd |
| 259 |
|
| 260 |
- name: test basic forced auth |
| 261 |
uri: |
| 262 |
url: 'https://{{ httpbin_host }}/hidden-basic-auth/user/passwd' |
| 263 |
force_basic_auth: true |
| 264 |
user: user |
| 265 |
password: passwd |
| 266 |
|
| 267 |
- name: test digest auth |
| 268 |
uri: |
| 269 |
url: 'https://{{ httpbin_host }}/digest-auth/auth/user/passwd' |
| 270 |
user: user |
| 271 |
password: passwd |
| 272 |
headers: |
| 273 |
Cookie: "fake=fake_value" |
| 274 |
|
| 275 |
- name: test digest auth failure |
| 276 |
uri: |
| 277 |
url: 'https://{{ httpbin_host }}/digest-auth/auth/user/passwd' |
| 278 |
user: user |
| 279 |
password: wrong |
| 280 |
headers: |
| 281 |
Cookie: "fake=fake_value" |
| 282 |
register: result |
| 283 |
failed_when: result.status != 401 |
| 284 |
|
| 285 |
- name: test unredirected_headers |
| 286 |
uri: |
| 287 |
url: 'https://{{ httpbin_host }}/redirect-to?status_code=301&url=/basic-auth/user/passwd' |
| 288 |
user: user |
| 289 |
password: passwd |
| 290 |
force_basic_auth: true |
| 291 |
unredirected_headers: |
| 292 |
- authorization |
| 293 |
ignore_errors: true |
| 294 |
register: unredirected_headers |
| 295 |
|
| 296 |
- name: test omitting unredirected headers |
| 297 |
uri: |
| 298 |
url: 'https://{{ httpbin_host }}/redirect-to?status_code=301&url=/basic-auth/user/passwd' |
| 299 |
user: user |
| 300 |
password: passwd |
| 301 |
force_basic_auth: true |
| 302 |
register: redirected_headers |
| 303 |
|
| 304 |
- name: ensure unredirected_headers caused auth to fail |
| 305 |
assert: |
| 306 |
that: |
| 307 |
- unredirected_headers is failed |
| 308 |
- unredirected_headers.status == 401 |
| 309 |
- redirected_headers is successful |
| 310 |
- redirected_headers.status == 200 |
| 311 |
|
| 312 |
- name: test PUT |
| 313 |
uri: |
| 314 |
url: 'https://{{ httpbin_host }}/put' |
| 315 |
method: PUT |
| 316 |
body: 'foo=bar' |
| 317 |
|
| 318 |
- name: test OPTIONS |
| 319 |
uri: |
| 320 |
url: 'https://{{ httpbin_host }}/' |
| 321 |
method: OPTIONS |
| 322 |
register: result |
| 323 |
|
| 324 |
- name: Assert we got an allow header |
| 325 |
assert: |
| 326 |
that: |
| 327 |
- 'result.allow.split(", ")|sort == ["GET", "HEAD", "OPTIONS"]' |
| 328 |
|
| 329 |
- name: Testing support of https_proxy (with failure expected) |
| 330 |
environment: |
| 331 |
https_proxy: 'https://localhost:3456' |
| 332 |
uri: |
| 333 |
url: 'https://{{ httpbin_host }}/get' |
| 334 |
register: result |
| 335 |
ignore_errors: true |
| 336 |
|
| 337 |
- assert: |
| 338 |
that: |
| 339 |
- result is failed |
| 340 |
- result.status == -1 |
| 341 |
|
| 342 |
- name: Testing use_proxy=no is honored |
| 343 |
environment: |
| 344 |
https_proxy: 'https://localhost:3456' |
| 345 |
uri: |
| 346 |
url: 'https://{{ httpbin_host }}/get' |
| 347 |
use_proxy: no |
| 348 |
|
| 349 |
- name: Test that SNI succeeds on python versions that have SNI |
| 350 |
uri: |
| 351 |
url: 'https://{{ sni_host }}/' |
| 352 |
return_content: true |
| 353 |
when: ansible_python.has_sslcontext |
| 354 |
register: result |
| 355 |
|
| 356 |
- name: Assert SNI verification succeeds on new python |
| 357 |
assert: |
| 358 |
that: |
| 359 |
- result is successful |
| 360 |
- 'sni_host in result.content' |
| 361 |
when: ansible_python.has_sslcontext |
| 362 |
|
| 363 |
- name: validate the status_codes are correct |
| 364 |
uri: |
| 365 |
url: "https://{{ httpbin_host }}/status/202" |
| 366 |
status_code: 202 |
| 367 |
method: POST |
| 368 |
body: foo |
| 369 |
|
| 370 |
- name: Validate body_format json does not override content-type in 2.3 or newer |
| 371 |
uri: |
| 372 |
url: "https://{{ httpbin_host }}/post" |
| 373 |
method: POST |
| 374 |
body: |
| 375 |
foo: bar |
| 376 |
body_format: json |
| 377 |
headers: |
| 378 |
'Content-Type': 'text/json' |
| 379 |
return_content: true |
| 380 |
register: result |
| 381 |
failed_when: result.json.headers['Content-Type'] != 'text/json' |
| 382 |
|
| 383 |
- name: Validate body_format form-urlencoded using dicts works |
| 384 |
uri: |
| 385 |
url: https://{{ httpbin_host }}/post |
| 386 |
method: POST |
| 387 |
body: |
| 388 |
user: foo |
| 389 |
password: bar!#@ |&82$M |
| 390 |
submit: Sign in |
| 391 |
body_format: form-urlencoded |
| 392 |
return_content: yes |
| 393 |
register: result |
| 394 |
|
| 395 |
- name: Assert form-urlencoded dict input |
| 396 |
assert: |
| 397 |
that: |
| 398 |
- result is successful |
| 399 |
- result.json.headers['Content-Type'] == 'application/x-www-form-urlencoded' |
| 400 |
- result.json.form.password == 'bar!#@ |&82$M' |
| 401 |
|
| 402 |
- name: Validate body_format form-urlencoded using lists works |
| 403 |
uri: |
| 404 |
url: https://{{ httpbin_host }}/post |
| 405 |
method: POST |
| 406 |
body: |
| 407 |
- [ user, foo ] |
| 408 |
- [ password, bar!#@ |&82$M ] |
| 409 |
- [ submit, Sign in ] |
| 410 |
body_format: form-urlencoded |
| 411 |
return_content: yes |
| 412 |
register: result |
| 413 |
|
| 414 |
- name: Assert form-urlencoded list input |
| 415 |
assert: |
| 416 |
that: |
| 417 |
- result is successful |
| 418 |
- result.json.headers['Content-Type'] == 'application/x-www-form-urlencoded' |
| 419 |
- result.json.form.password == 'bar!#@ |&82$M' |
| 420 |
|
| 421 |
- name: Validate body_format form-urlencoded of invalid input fails |
| 422 |
uri: |
| 423 |
url: https://{{ httpbin_host }}/post |
| 424 |
method: POST |
| 425 |
body: |
| 426 |
- foo |
| 427 |
- bar: baz |
| 428 |
body_format: form-urlencoded |
| 429 |
return_content: yes |
| 430 |
register: result |
| 431 |
ignore_errors: yes |
| 432 |
|
| 433 |
- name: Assert invalid input fails |
| 434 |
assert: |
| 435 |
that: |
| 436 |
- result is failure |
| 437 |
- "'failed to parse body as form_urlencoded: too many values to unpack' in result.msg" |
| 438 |
|
| 439 |
- name: multipart/form-data |
| 440 |
uri: |
| 441 |
url: https://{{ httpbin_host }}/post |
| 442 |
method: POST |
| 443 |
body_format: form-multipart |
| 444 |
body: |
| 445 |
file1: |
| 446 |
filename: formdata.txt |
| 447 |
multipart_encoding: base64 |
| 448 |
file2: |
| 449 |
content: text based file content |
| 450 |
filename: fake.txt |
| 451 |
mime_type: text/plain |
| 452 |
file3: |
| 453 |
filename: formdata.txt |
| 454 |
multipart_encoding: '7or8bit' |
| 455 |
file4: |
| 456 |
filename: formdata.txt |
| 457 |
text_form_field1: value1 |
| 458 |
text_form_field2: |
| 459 |
content: value2 |
| 460 |
mime_type: text/plain |
| 461 |
register: multipart |
| 462 |
|
| 463 |
- name: Assert multipart/form-data |
| 464 |
assert: |
| 465 |
that: |
| 466 |
- multipart.json.files.file1 | b64decode == '_multipart/form-data_\n' |
| 467 |
- multipart.json.files.file2 == 'text based file content' |
| 468 |
- multipart.json.files.file3 == '_multipart/form-data_\n' |
| 469 |
- multipart.json.files.file4 == '_multipart/form-data_\n' |
| 470 |
- multipart.json.form.text_form_field1 == 'value1' |
| 471 |
- multipart.json.form.text_form_field2 == 'value2' |
| 472 |
|
| 473 |
# https://github.com/ansible/ansible/issues/74276 - verifies we don't have a traceback |
| 474 |
- name: multipart/form-data with invalid value |
| 475 |
uri: |
| 476 |
url: https://{{ httpbin_host }}/post |
| 477 |
method: POST |
| 478 |
body_format: form-multipart |
| 479 |
body: |
| 480 |
integer_value: 1 |
| 481 |
register: multipart_invalid |
| 482 |
failed_when: '"failed to parse body as form-multipart: value must be a string, or mapping, cannot be type" not in multipart_invalid.msg' |
| 483 |
|
| 484 |
- name: multipart/form-data with file and retry |
| 485 |
uri: |
| 486 |
url: https://{{ httpbin_host }}/post |
| 487 |
method: POST |
| 488 |
body_format: form-multipart |
| 489 |
body: |
| 490 |
file: |
| 491 |
filename: formdata.txt |
| 492 |
retries: 1 |
| 493 |
delay: 0.01 |
| 494 |
register: result |
| 495 |
failed_when: result is failed or result.attempts == 1 |
| 496 |
|
| 497 |
- name: Assert multipart/form-data with file and retry |
| 498 |
assert: |
| 499 |
that: |
| 500 |
- result.json.files.file == '_multipart/form-data_\n' |
| 501 |
- result.attempts == 2 |
| 502 |
|
| 503 |
- name: Validate invalid method |
| 504 |
uri: |
| 505 |
url: https://{{ httpbin_host }}/anything |
| 506 |
method: UNKNOWN |
| 507 |
register: result |
| 508 |
ignore_errors: yes |
| 509 |
|
| 510 |
- name: Assert invalid method fails |
| 511 |
assert: |
| 512 |
that: |
| 513 |
- result is failure |
| 514 |
- result.status == 405 |
| 515 |
- "'METHOD NOT ALLOWED' in result.msg" |
| 516 |
|
| 517 |
- name: Test client cert auth, no certs |
| 518 |
uri: |
| 519 |
url: "https://ansible.http.tests/ssl_client_verify" |
| 520 |
status_code: 200 |
| 521 |
return_content: true |
| 522 |
register: result |
| 523 |
failed_when: result.content != "ansible.http.tests:NONE" |
| 524 |
when: has_httptester |
| 525 |
|
| 526 |
- name: Test client cert auth, with certs |
| 527 |
uri: |
| 528 |
url: "https://ansible.http.tests/ssl_client_verify" |
| 529 |
client_cert: "{{ remote_tmp_dir }}/client.pem" |
| 530 |
client_key: "{{ remote_tmp_dir }}/client.key" |
| 531 |
return_content: true |
| 532 |
register: result |
| 533 |
failed_when: result.content != "ansible.http.tests:SUCCESS" |
| 534 |
when: has_httptester |
| 535 |
|
| 536 |
- name: Test client cert auth, with no validation |
| 537 |
uri: |
| 538 |
url: "https://fail.ansible.http.tests/ssl_client_verify" |
| 539 |
client_cert: "{{ remote_tmp_dir }}/client.pem" |
| 540 |
client_key: "{{ remote_tmp_dir }}/client.key" |
| 541 |
return_content: true |
| 542 |
validate_certs: no |
| 543 |
register: result |
| 544 |
failed_when: result.content != "ansible.http.tests:SUCCESS" |
| 545 |
when: has_httptester |
| 546 |
|
| 547 |
- name: Test client cert auth, with validation and ssl mismatch |
| 548 |
uri: |
| 549 |
url: "https://fail.ansible.http.tests/ssl_client_verify" |
| 550 |
client_cert: "{{ remote_tmp_dir }}/client.pem" |
| 551 |
client_key: "{{ remote_tmp_dir }}/client.key" |
| 552 |
return_content: true |
| 553 |
validate_certs: yes |
| 554 |
register: result |
| 555 |
failed_when: result is not failed |
| 556 |
when: has_httptester |
| 557 |
|
| 558 |
- uri: |
| 559 |
url: https://{{ httpbin_host }}/response-headers?Set-Cookie=Foo%3Dbar&Set-Cookie=Baz%3Dqux |
| 560 |
register: result |
| 561 |
|
| 562 |
- assert: |
| 563 |
that: |
| 564 |
- result['set_cookie'] == 'Foo=bar, Baz=qux' |
| 565 |
# Python 3.10 and earlier sorts cookies in order of most specific (ie. longest) path first |
| 566 |
# items with the same path are reversed from response order |
| 567 |
- result['cookies_string'] == 'Baz=qux; Foo=bar' |
| 568 |
when: ansible_python_version is version('3.11', '<') |
| 569 |
|
| 570 |
- assert: |
| 571 |
that: |
| 572 |
- result['set_cookie'] == 'Foo=bar, Baz=qux' |
| 573 |
# Python 3.11 no longer sorts cookies. |
| 574 |
# See: https://github.com/python/cpython/issues/86232 |
| 575 |
- result['cookies_string'] == 'Foo=bar; Baz=qux' |
| 576 |
when: ansible_python_version is version('3.11', '>=') |
| 577 |
|
| 578 |
- name: Write out netrc template |
| 579 |
template: |
| 580 |
src: netrc.j2 |
| 581 |
dest: "{{ remote_tmp_dir }}/netrc" |
| 582 |
|
| 583 |
- name: Test netrc with port |
| 584 |
uri: |
| 585 |
url: "https://{{ httpbin_host }}:443/basic-auth/user/passwd" |
| 586 |
environment: |
| 587 |
NETRC: "{{ remote_tmp_dir }}/netrc" |
| 588 |
|
| 589 |
- name: Test JSON POST with src |
| 590 |
uri: |
| 591 |
url: "https://{{ httpbin_host}}/post" |
| 592 |
src: pass0.json |
| 593 |
method: POST |
| 594 |
return_content: true |
| 595 |
body_format: json |
| 596 |
register: result |
| 597 |
|
| 598 |
- name: Validate POST with src works |
| 599 |
assert: |
| 600 |
that: |
| 601 |
- result.json.json[0] == 'JSON Test Pattern pass1' |
| 602 |
|
| 603 |
- name: Copy file pass0.json to remote |
| 604 |
copy: |
| 605 |
src: "{{ role_path }}/files/pass0.json" |
| 606 |
dest: "{{ remote_tmp_dir }}/pass0.json" |
| 607 |
|
| 608 |
- name: Test JSON POST with src and remote_src=True |
| 609 |
uri: |
| 610 |
url: "https://{{ httpbin_host}}/post" |
| 611 |
src: "{{ remote_tmp_dir }}/pass0.json" |
| 612 |
remote_src: true |
| 613 |
method: POST |
| 614 |
return_content: true |
| 615 |
body_format: json |
| 616 |
register: result |
| 617 |
|
| 618 |
- name: Validate POST with src and remote_src=True works |
| 619 |
assert: |
| 620 |
that: |
| 621 |
- result.json.json[0] == 'JSON Test Pattern pass1' |
| 622 |
|
| 623 |
- name: Test find JSON as subtype |
| 624 |
uri: |
| 625 |
url: "https://{{ httpbin_host }}/response-headers?content-type=application/ld%2Bjson" |
| 626 |
method: POST |
| 627 |
return_content: true |
| 628 |
register: result |
| 629 |
|
| 630 |
- name: Validate JSON as subtype |
| 631 |
assert: |
| 632 |
that: |
| 633 |
- result.json is defined |
| 634 |
|
| 635 |
- name: Make request that includes password in JSON keys |
| 636 |
uri: |
| 637 |
url: "https://{{ httpbin_host}}/get?key-password=value-password" |
| 638 |
user: admin |
| 639 |
password: password |
| 640 |
register: sanitize_keys |
| 641 |
|
| 642 |
- name: assert that keys are still accessible in result |
| 643 |
assert: |
| 644 |
that: |
| 645 |
- sanitize_keys.json.args['key-password'] == 'value-password' |
| 646 |
|
| 647 |
- name: Test gzip encoding |
| 648 |
uri: |
| 649 |
url: "https://{{ httpbin_host }}/gzip" |
| 650 |
register: result |
| 651 |
|
| 652 |
- name: Validate gzip decoding |
| 653 |
assert: |
| 654 |
that: |
| 655 |
- result.json.gzipped |
| 656 |
|
| 657 |
- name: test gzip encoding no auto decompress |
| 658 |
uri: |
| 659 |
url: "https://{{ httpbin_host }}/gzip" |
| 660 |
decompress: false |
| 661 |
register: result |
| 662 |
|
| 663 |
- name: Assert gzip wasn't decompressed |
| 664 |
assert: |
| 665 |
that: |
| 666 |
- result.json is undefined |
| 667 |
|
| 668 |
- name: Create a testing file |
| 669 |
copy: |
| 670 |
content: "content" |
| 671 |
dest: "{{ remote_tmp_dir }}/output" |
| 672 |
|
| 673 |
- name: Download a file from non existing location |
| 674 |
uri: |
| 675 |
url: http://does/not/exist |
| 676 |
dest: "{{ remote_tmp_dir }}/output" |
| 677 |
ignore_errors: yes |
| 678 |
|
| 679 |
- name: Save testing file's output |
| 680 |
command: "cat {{ remote_tmp_dir }}/output" |
| 681 |
register: file_out |
| 682 |
|
| 683 |
- name: Test the testing file was not overwritten |
| 684 |
assert: |
| 685 |
that: |
| 686 |
- "'content' in file_out.stdout" |
| 687 |
|
| 688 |
- name: Test downloading cached file |
| 689 |
uri: |
| 690 |
url: "https://{{ httpbin_host }}/cache" |
| 691 |
|
| 692 |
- name: Test downloading cached file to existing file results in "304 Not Modified" |
| 693 |
uri: |
| 694 |
url: "https://{{ httpbin_host }}/cache" |
| 695 |
dest: "{{ remote_tmp_dir }}/output" |
| 696 |
status_code: [304] |
| 697 |
|
| 698 |
- name: Test downloading cached file to existing file with "force" |
| 699 |
uri: |
| 700 |
url: "https://{{ httpbin_host }}/cache" |
| 701 |
dest: "{{ remote_tmp_dir }}/output" |
| 702 |
force: true |
| 703 |
|
| 704 |
- name: Clean up |
| 705 |
file: |
| 706 |
dest: "{{ remote_tmp_dir }}/output" |
| 707 |
state: absent |
| 708 |
|
| 709 |
- name: Test download root to dir without content-disposition |
| 710 |
uri: |
| 711 |
url: "https://{{ httpbin_host }}/" |
| 712 |
dest: "{{ remote_tmp_dir }}" |
| 713 |
register: get_root_no_filename |
| 714 |
|
| 715 |
- name: Test downloading to dir without content-disposition |
| 716 |
uri: |
| 717 |
url: "https://{{ httpbin_host }}/response-headers" |
| 718 |
dest: "{{ remote_tmp_dir }}" |
| 719 |
register: get_dir_no_filename |
| 720 |
|
| 721 |
- name: Test downloading to dir with content-disposition |
| 722 |
uri: |
| 723 |
url: 'https://{{ httpbin_host }}/response-headers?Content-Disposition=attachment%3B%20filename%3D%22filename.json%22' |
| 724 |
dest: "{{ remote_tmp_dir }}" |
| 725 |
register: get_dir_filename |
| 726 |
|
| 727 |
- assert: |
| 728 |
that: |
| 729 |
- get_root_no_filename.path == remote_tmp_dir ~ "/index.html" |
| 730 |
- get_dir_no_filename.path == remote_tmp_dir ~ "/response-headers" |
| 731 |
- get_dir_filename.path == remote_tmp_dir ~ "/filename.json" |
| 732 |
|
| 733 |
- name: Test follow_redirects=none |
| 734 |
import_tasks: redirect-none.yml |
| 735 |
|
| 736 |
- name: Test follow_redirects=safe |
| 737 |
import_tasks: redirect-safe.yml |
| 738 |
|
| 739 |
- name: Test follow_redirects=urllib2 |
| 740 |
import_tasks: redirect-urllib2.yml |
| 741 |
|
| 742 |
- name: Test follow_redirects=all |
| 743 |
import_tasks: redirect-all.yml |
| 744 |
|
| 745 |
- name: Check unexpected failures |
| 746 |
import_tasks: unexpected-failures.yml |
| 747 |
|
| 748 |
- name: Check return-content |
| 749 |
import_tasks: return-content.yml |
| 750 |
|
| 751 |
- name: Test use_gssapi=True |
| 752 |
include_tasks: |
| 753 |
file: use_gssapi.yml |
| 754 |
apply: |
| 755 |
environment: |
| 756 |
KRB5_CONFIG: '{{ krb5_config }}' |
| 757 |
KRB5CCNAME: FILE:{{ remote_tmp_dir }}/krb5.cc |
| 758 |
OPENSSL_CONF: '{{ krb5_openssl_conf }}' |
| 759 |
when: krb5_config is defined |
| 760 |
|
| 761 |
- name: Test ciphers |
| 762 |
import_tasks: ciphers.yml |
| 763 |
when: false # skipped until we have a way to disable TLS 1.3 on the client or server, since cipher suite selection won't break TLS 1.3 |
| 764 |
|
| 765 |
- name: Test use_netrc.yml |
| 766 |
import_tasks: use_netrc.yml |
| 767 |
|
| 768 |
- name: Test unix socket |
| 769 |
import_tasks: install-socat-and-test-unix-socket.yml |
| 770 |
|
| 771 |
- name: ensure skip action |
| 772 |
uri: |
| 773 |
url: http://example.com |
| 774 |
check_mode: True |
| 775 |
register: uri_check |
| 776 |
|
| 777 |
- name: check that we skipped at action |
| 778 |
assert: |
| 779 |
that: |
| 780 |
- uri_check.msg == "This action (uri) does not support check mode." |
| 781 |
|
| 782 |
- name: Test auth fail downloading to dir |
| 783 |
uri: |
| 784 |
url: 'https://secretuser:secretpassword@{{ httpbin_host }}/nonexistant' |
| 785 |
dest: "{{ remote_tmp_dir }}" |
| 786 |
ignore_errors: true |
| 787 |
register: auth_error |
| 788 |
|
| 789 |
- name: Ensure secret is not visible |
| 790 |
assert: |
| 791 |
that: |
| 792 |
- "'secret' not in auth_error|to_json" |