| 1 |
# Test code for the get_url module |
| 2 |
# (c) 2014, Richard Isaacson <[email protected]> |
| 3 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
|
| 5 |
- name: Determine if python looks like it will support modern ssl features like SNI |
| 6 |
command: "{{ ansible_python.executable }} -c 'from ssl import SSLContext'" |
| 7 |
ignore_errors: True |
| 8 |
register: python_test |
| 9 |
|
| 10 |
- name: Set python_has_sslcontext if we have it |
| 11 |
set_fact: |
| 12 |
python_has_ssl_context: True |
| 13 |
when: python_test.rc == 0 |
| 14 |
|
| 15 |
- name: Set python_has_sslcontext False if we don't have it |
| 16 |
set_fact: |
| 17 |
python_has_ssl_context: False |
| 18 |
when: python_test.rc != 0 |
| 19 |
|
| 20 |
- name: Define test files for file schema |
| 21 |
set_fact: |
| 22 |
geturl_srcfile: "{{ remote_tmp_dir }}/aurlfile.txt" |
| 23 |
geturl_dstfile: "{{ remote_tmp_dir }}/aurlfile_copy.txt" |
| 24 |
|
| 25 |
- name: Create source file |
| 26 |
copy: |
| 27 |
dest: "{{ geturl_srcfile }}" |
| 28 |
content: "foobar" |
| 29 |
register: source_file_copied |
| 30 |
|
| 31 |
- name: test file fetch |
| 32 |
get_url: |
| 33 |
url: "file://{{ source_file_copied.dest }}" |
| 34 |
dest: "{{ geturl_dstfile }}" |
| 35 |
register: result |
| 36 |
|
| 37 |
- name: assert success and change |
| 38 |
assert: |
| 39 |
that: |
| 40 |
- result is changed |
| 41 |
- '"OK" in result.msg' |
| 42 |
|
| 43 |
- name: test nonexisting file fetch |
| 44 |
get_url: |
| 45 |
url: "file://{{ source_file_copied.dest }}NOFILE" |
| 46 |
dest: "{{ geturl_dstfile }}NOFILE" |
| 47 |
register: result |
| 48 |
ignore_errors: True |
| 49 |
|
| 50 |
- name: assert success and change |
| 51 |
assert: |
| 52 |
that: |
| 53 |
- result is failed |
| 54 |
|
| 55 |
- name: test HTTP HEAD request for file in check mode |
| 56 |
get_url: |
| 57 |
url: "https://{{ httpbin_host }}/get" |
| 58 |
dest: "{{ remote_tmp_dir }}/get_url_check.txt" |
| 59 |
force: yes |
| 60 |
check_mode: True |
| 61 |
register: result |
| 62 |
|
| 63 |
- name: assert that the HEAD request was successful in check mode |
| 64 |
assert: |
| 65 |
that: |
| 66 |
- result is changed |
| 67 |
- '"OK" in result.msg' |
| 68 |
|
| 69 |
- name: test HTTP HEAD for nonexistent URL in check mode |
| 70 |
get_url: |
| 71 |
url: "https://{{ httpbin_host }}/DOESNOTEXIST" |
| 72 |
dest: "{{ remote_tmp_dir }}/shouldnotexist.html" |
| 73 |
force: yes |
| 74 |
check_mode: True |
| 75 |
register: result |
| 76 |
ignore_errors: True |
| 77 |
|
| 78 |
- name: assert that HEAD request for nonexistent URL failed |
| 79 |
assert: |
| 80 |
that: |
| 81 |
- result is failed |
| 82 |
|
| 83 |
- name: test https fetch |
| 84 |
get_url: url="https://{{ httpbin_host }}/get" dest={{remote_tmp_dir}}/get_url.txt force=yes |
| 85 |
register: result |
| 86 |
|
| 87 |
- name: assert the get_url call was successful |
| 88 |
assert: |
| 89 |
that: |
| 90 |
- result is changed |
| 91 |
- '"OK" in result.msg' |
| 92 |
|
| 93 |
- name: test https fetch to a site with mismatched hostname and certificate |
| 94 |
get_url: |
| 95 |
url: "https://{{ badssl_host }}/" |
| 96 |
dest: "{{ remote_tmp_dir }}/shouldnotexist.html" |
| 97 |
ignore_errors: True |
| 98 |
register: result |
| 99 |
|
| 100 |
- stat: |
| 101 |
path: "{{ remote_tmp_dir }}/shouldnotexist.html" |
| 102 |
register: stat_result |
| 103 |
|
| 104 |
- name: Assert that the file was not downloaded |
| 105 |
assert: |
| 106 |
that: |
| 107 |
- "result is failed" |
| 108 |
- "'Failed to validate the SSL certificate' in result.msg or 'Hostname mismatch' in result.msg or ( result.msg is match('hostname .* doesn.t match .*'))" |
| 109 |
- "stat_result.stat.exists == false" |
| 110 |
|
| 111 |
- name: test https fetch to a site with mismatched hostname and certificate and validate_certs=no |
| 112 |
get_url: |
| 113 |
url: "https://{{ badssl_host }}/" |
| 114 |
dest: "{{ remote_tmp_dir }}/get_url_no_validate.html" |
| 115 |
validate_certs: no |
| 116 |
register: result |
| 117 |
|
| 118 |
- stat: |
| 119 |
path: "{{ remote_tmp_dir }}/get_url_no_validate.html" |
| 120 |
register: stat_result |
| 121 |
|
| 122 |
- name: Assert that the file was downloaded |
| 123 |
assert: |
| 124 |
that: |
| 125 |
- result is changed |
| 126 |
- "stat_result.stat.exists == true" |
| 127 |
|
| 128 |
# SNI Tests |
| 129 |
# SNI is only built into the stdlib from python-2.7.9 onwards |
| 130 |
- name: Test that SNI works |
| 131 |
get_url: |
| 132 |
url: 'https://{{ sni_host }}/' |
| 133 |
dest: "{{ remote_tmp_dir }}/sni.html" |
| 134 |
register: get_url_result |
| 135 |
ignore_errors: True |
| 136 |
|
| 137 |
- command: "grep '{{ sni_host }}' {{ remote_tmp_dir}}/sni.html" |
| 138 |
register: data_result |
| 139 |
when: python_has_ssl_context |
| 140 |
|
| 141 |
- debug: |
| 142 |
var: get_url_result |
| 143 |
|
| 144 |
- name: Assert that SNI works with this python version |
| 145 |
assert: |
| 146 |
that: |
| 147 |
- 'data_result.rc == 0' |
| 148 |
when: python_has_ssl_context |
| 149 |
|
| 150 |
# If the client doesn't support SNI then get_url should have failed with a certificate mismatch |
| 151 |
- name: Assert that hostname verification failed because SNI is not supported on this version of python |
| 152 |
assert: |
| 153 |
that: |
| 154 |
- 'get_url_result is failed' |
| 155 |
when: not python_has_ssl_context |
| 156 |
|
| 157 |
# These tests are just side effects of how the site is hosted. It's not |
| 158 |
# specifically a test site. So the tests may break due to the hosting changing |
| 159 |
- name: Test that SNI works |
| 160 |
get_url: |
| 161 |
url: 'https://{{ sni_host }}/' |
| 162 |
dest: "{{ remote_tmp_dir }}/sni.html" |
| 163 |
register: get_url_result |
| 164 |
ignore_errors: True |
| 165 |
|
| 166 |
- command: "grep '{{ sni_host }}' {{ remote_tmp_dir}}/sni.html" |
| 167 |
register: data_result |
| 168 |
when: python_has_ssl_context |
| 169 |
|
| 170 |
- debug: |
| 171 |
var: get_url_result |
| 172 |
|
| 173 |
- name: Assert that SNI works with this python version |
| 174 |
assert: |
| 175 |
that: |
| 176 |
- 'data_result.rc == 0' |
| 177 |
- 'get_url_result is not failed' |
| 178 |
when: python_has_ssl_context |
| 179 |
|
| 180 |
# If the client doesn't support SNI then get_url should have failed with a certificate mismatch |
| 181 |
- name: Assert that hostname verification failed because SNI is not supported on this version of python |
| 182 |
assert: |
| 183 |
that: |
| 184 |
- 'get_url_result is failed' |
| 185 |
when: not python_has_ssl_context |
| 186 |
# End hacky SNI test section |
| 187 |
|
| 188 |
- name: Test get_url with redirect |
| 189 |
get_url: |
| 190 |
url: 'https://{{ httpbin_host }}/redirect/6' |
| 191 |
dest: "{{ remote_tmp_dir }}/redirect.json" |
| 192 |
|
| 193 |
- name: Test that setting file modes work |
| 194 |
get_url: |
| 195 |
url: 'https://{{ httpbin_host }}/' |
| 196 |
dest: '{{ remote_tmp_dir }}/test' |
| 197 |
mode: '0707' |
| 198 |
register: result |
| 199 |
|
| 200 |
- stat: |
| 201 |
path: "{{ remote_tmp_dir }}/test" |
| 202 |
register: stat_result |
| 203 |
|
| 204 |
- name: Assert that the file has the right permissions |
| 205 |
assert: |
| 206 |
that: |
| 207 |
- result is changed |
| 208 |
- "stat_result.stat.mode == '0707'" |
| 209 |
|
| 210 |
- name: Test that setting file modes on an already downloaded file work |
| 211 |
get_url: |
| 212 |
url: 'https://{{ httpbin_host }}/' |
| 213 |
dest: '{{ remote_tmp_dir }}/test' |
| 214 |
mode: '0070' |
| 215 |
register: result |
| 216 |
|
| 217 |
- stat: |
| 218 |
path: "{{ remote_tmp_dir }}/test" |
| 219 |
register: stat_result |
| 220 |
|
| 221 |
- name: Assert that the file has the right permissions |
| 222 |
assert: |
| 223 |
that: |
| 224 |
- result is changed |
| 225 |
- "stat_result.stat.mode == '0070'" |
| 226 |
|
| 227 |
# https://github.com/ansible/ansible/pull/65307/ |
| 228 |
- name: Test that on http status 304, we get a status_code field. |
| 229 |
get_url: |
| 230 |
url: 'https://{{ httpbin_host }}/status/304' |
| 231 |
dest: '{{ remote_tmp_dir }}/test' |
| 232 |
register: result |
| 233 |
|
| 234 |
- name: Assert that we get the appropriate status_code |
| 235 |
assert: |
| 236 |
that: |
| 237 |
- "'status_code' in result" |
| 238 |
- "result.status_code == 304" |
| 239 |
|
| 240 |
# https://github.com/ansible/ansible/issues/29614 |
| 241 |
- name: Change mode on an already downloaded file and specify checksum |
| 242 |
get_url: |
| 243 |
url: 'https://{{ httpbin_host }}/base64/cHR1eA==' |
| 244 |
dest: '{{ remote_tmp_dir }}/test' |
| 245 |
checksum: 'sha256:b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006.' |
| 246 |
mode: '0775' |
| 247 |
register: result |
| 248 |
|
| 249 |
- stat: |
| 250 |
path: "{{ remote_tmp_dir }}/test" |
| 251 |
register: stat_result |
| 252 |
|
| 253 |
- name: Assert that file permissions on already downloaded file were changed |
| 254 |
assert: |
| 255 |
that: |
| 256 |
- result is changed |
| 257 |
- "stat_result.stat.mode == '0775'" |
| 258 |
|
| 259 |
- name: test checksum match in check mode |
| 260 |
get_url: |
| 261 |
url: 'https://{{ httpbin_host }}/base64/cHR1eA==' |
| 262 |
dest: '{{ remote_tmp_dir }}/test' |
| 263 |
checksum: 'sha256:b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006.' |
| 264 |
check_mode: True |
| 265 |
register: result |
| 266 |
|
| 267 |
- name: Assert that check mode was green |
| 268 |
assert: |
| 269 |
that: |
| 270 |
- result is not changed |
| 271 |
|
| 272 |
- name: Get a file that already exists with a checksum |
| 273 |
get_url: |
| 274 |
url: 'https://{{ httpbin_host }}/cache' |
| 275 |
dest: '{{ remote_tmp_dir }}/test' |
| 276 |
checksum: 'sha1:{{ stat_result.stat.checksum }}' |
| 277 |
register: result |
| 278 |
|
| 279 |
- name: Assert that the file was not downloaded |
| 280 |
assert: |
| 281 |
that: |
| 282 |
- result.msg == 'file already exists' |
| 283 |
|
| 284 |
- name: Get a file that already exists |
| 285 |
get_url: |
| 286 |
url: 'https://{{ httpbin_host }}/cache' |
| 287 |
dest: '{{ remote_tmp_dir }}/test' |
| 288 |
register: result |
| 289 |
|
| 290 |
- name: Assert that we didn't re-download unnecessarily |
| 291 |
assert: |
| 292 |
that: |
| 293 |
- result is not changed |
| 294 |
- "'304' in result.msg" |
| 295 |
|
| 296 |
- name: get a file that doesn't respond to If-Modified-Since without checksum |
| 297 |
get_url: |
| 298 |
url: 'https://{{ httpbin_host }}/get' |
| 299 |
dest: '{{ remote_tmp_dir }}/test' |
| 300 |
register: result |
| 301 |
|
| 302 |
- name: Assert that we downloaded the file |
| 303 |
assert: |
| 304 |
that: |
| 305 |
- result is changed |
| 306 |
|
| 307 |
# https://github.com/ansible/ansible/issues/27617 |
| 308 |
|
| 309 |
- name: set role facts |
| 310 |
set_fact: |
| 311 |
http_port: 27617 |
| 312 |
files_dir: '{{ remote_tmp_dir }}/files' |
| 313 |
|
| 314 |
- name: create files_dir |
| 315 |
file: |
| 316 |
dest: "{{ files_dir }}" |
| 317 |
state: directory |
| 318 |
|
| 319 |
- name: create src file |
| 320 |
copy: |
| 321 |
dest: '{{ files_dir }}/{{ item }}.txt' |
| 322 |
content: "ptux" |
| 323 |
loop: |
| 324 |
- 27617 |
| 325 |
- 71420 |
| 326 |
- 86132 |
| 327 |
- 86132_single_space |
| 328 |
|
| 329 |
- name: create sha1 checksum file of src |
| 330 |
copy: |
| 331 |
dest: '{{ files_dir }}/sha1sum.txt' |
| 332 |
content: | |
| 333 |
a97e6837f60cec6da4491bab387296bbcd72bdba 27617.txt |
| 334 |
a97e6837f60cec6da4491bab387296bbcd72bdba 71420.txt |
| 335 |
a97e6837f60cec6da4491bab387296bbcd72bdba 86132.txt |
| 336 |
a97e6837f60cec6da4491bab387296bbcd72bdba 86132_single_space.txt |
| 337 |
3911340502960ca33aece01129234460bfeb2791 not_target1.txt |
| 338 |
1b4b6adf30992cedb0f6edefd6478ff0a593b2e4 not_target2.txt |
| 339 |
|
| 340 |
- name: create sha256 checksum file of src |
| 341 |
copy: |
| 342 |
dest: '{{ files_dir }}/sha256sum.txt' |
| 343 |
content: | |
| 344 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. 27617.txt |
| 345 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. 71420.txt |
| 346 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. 86132.txt |
| 347 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. 86132_single_space.txt |
| 348 |
30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 not_target1.txt |
| 349 |
d0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b not_target2.txt |
| 350 |
|
| 351 |
- name: create sha256 checksum file of src with a dot leading path |
| 352 |
copy: |
| 353 |
dest: '{{ files_dir }}/sha256sum_with_dot.txt' |
| 354 |
content: | |
| 355 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. ./27617.txt |
| 356 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. ./71420.txt |
| 357 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. ./86132.txt |
| 358 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. ./86132_single_space.txt |
| 359 |
30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 ./not_target1.txt |
| 360 |
d0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b ./not_target2.txt |
| 361 |
|
| 362 |
- name: create sha256 checksum file of src with a * leading path |
| 363 |
copy: |
| 364 |
dest: '{{ files_dir }}/sha256sum_with_asterisk.txt' |
| 365 |
content: | |
| 366 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. *27617.txt |
| 367 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. *71420.txt |
| 368 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. *86132.txt |
| 369 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. *86132_single_space.txt |
| 370 |
30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 *not_target1.txt |
| 371 |
d0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b *not_target2.txt |
| 372 |
|
| 373 |
- name: create sha256 checksum file of src in BSD-style checksum (--tag) |
| 374 |
copy: |
| 375 |
dest: '{{ files_dir }}/sha256sum_bsd_style.txt' |
| 376 |
content: | |
| 377 |
SHA256 (27617.txt) = b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. |
| 378 |
SHA256 (71420.txt) = b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. |
| 379 |
SHA256 (not_target1.txt) = 30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 |
| 380 |
SHA256 (not_target2.txt) = d0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b |
| 381 |
|
| 382 |
# completing 27617 with bug 54390 |
| 383 |
- name: create sha256 checksum only with no filename inside |
| 384 |
copy: |
| 385 |
dest: '{{ files_dir }}/sha256sum_checksum_only.txt' |
| 386 |
content: | |
| 387 |
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006 |
| 388 |
|
| 389 |
- copy: |
| 390 |
src: "testserver.py" |
| 391 |
dest: "{{ remote_tmp_dir }}/testserver.py" |
| 392 |
|
| 393 |
# NOTE: This http test server will live for only the timeout specified in "async", so all uses |
| 394 |
# of it must be grouped relatively close together. |
| 395 |
- name: start SimpleHTTPServer for issues 27617 |
| 396 |
shell: cd {{ files_dir }} && {{ ansible_python.executable }} {{ remote_tmp_dir}}/testserver.py {{ http_port }} |
| 397 |
async: 90 |
| 398 |
poll: 0 |
| 399 |
|
| 400 |
- name: Wait for SimpleHTTPServer to come up online |
| 401 |
wait_for: |
| 402 |
host: 'localhost' |
| 403 |
port: '{{ http_port }}' |
| 404 |
state: started |
| 405 |
|
| 406 |
- include_tasks: hashlib.yml |
| 407 |
|
| 408 |
- name: download src with sha1 checksum url in check mode |
| 409 |
get_url: |
| 410 |
url: 'http://localhost:{{ http_port }}/27617.txt' |
| 411 |
dest: '{{ remote_tmp_dir }}' |
| 412 |
checksum: 'sha1:http://localhost:{{ http_port }}/sha1sum.txt' |
| 413 |
register: result_sha1_check_mode |
| 414 |
check_mode: True |
| 415 |
|
| 416 |
- name: download src with sha1 checksum url |
| 417 |
get_url: |
| 418 |
url: 'http://localhost:{{ http_port }}/27617.txt' |
| 419 |
dest: '{{ remote_tmp_dir }}' |
| 420 |
checksum: 'sha1:http://localhost:{{ http_port }}/sha1sum.txt' |
| 421 |
register: result_sha1 |
| 422 |
|
| 423 |
- stat: |
| 424 |
path: "{{ remote_tmp_dir }}/27617.txt" |
| 425 |
register: stat_result_sha1 |
| 426 |
|
| 427 |
- name: download src with sha256 checksum url |
| 428 |
get_url: |
| 429 |
url: 'http://localhost:{{ http_port }}/27617.txt' |
| 430 |
dest: '{{ remote_tmp_dir }}/27617sha256.txt' |
| 431 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum.txt' |
| 432 |
register: result_sha256 |
| 433 |
|
| 434 |
- stat: |
| 435 |
path: "{{ remote_tmp_dir }}/27617.txt" |
| 436 |
register: stat_result_sha256 |
| 437 |
|
| 438 |
- name: download src with sha256 checksum url with dot leading paths |
| 439 |
get_url: |
| 440 |
url: 'http://localhost:{{ http_port }}/27617.txt' |
| 441 |
dest: '{{ remote_tmp_dir }}/27617sha256_with_dot.txt' |
| 442 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_dot.txt' |
| 443 |
register: result_sha256_with_dot |
| 444 |
|
| 445 |
- stat: |
| 446 |
path: "{{ remote_tmp_dir }}/27617sha256_with_dot.txt" |
| 447 |
register: stat_result_sha256_with_dot |
| 448 |
|
| 449 |
- name: download src with sha256 checksum url with asterisk leading paths |
| 450 |
get_url: |
| 451 |
url: 'http://localhost:{{ http_port }}/27617.txt' |
| 452 |
dest: '{{ remote_tmp_dir }}/27617sha256_with_asterisk.txt' |
| 453 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_asterisk.txt' |
| 454 |
register: result_sha256_with_asterisk |
| 455 |
|
| 456 |
- stat: |
| 457 |
path: "{{ remote_tmp_dir }}/27617sha256_with_asterisk.txt" |
| 458 |
register: stat_result_sha256_with_asterisk |
| 459 |
|
| 460 |
- name: download src with sha256 checksum url with file scheme |
| 461 |
get_url: |
| 462 |
url: 'http://localhost:{{ http_port }}/27617.txt' |
| 463 |
dest: '{{ remote_tmp_dir }}/27617sha256_with_file_scheme.txt' |
| 464 |
checksum: 'sha256:file://{{ files_dir }}/sha256sum.txt' |
| 465 |
register: result_sha256_with_file_scheme |
| 466 |
|
| 467 |
- stat: |
| 468 |
path: "{{ remote_tmp_dir }}/27617sha256_with_dot.txt" |
| 469 |
register: stat_result_sha256_with_file_scheme |
| 470 |
|
| 471 |
- name: download src with sha256 checksum url with BSD style checksum |
| 472 |
get_url: |
| 473 |
url: 'http://localhost:{{ http_port }}/27617.txt' |
| 474 |
dest: '{{ remote_tmp_dir }}/27617sha256_with_bsd_style.txt' |
| 475 |
checksum: 'sha256:file://{{ files_dir }}/sha256sum_bsd_style.txt' |
| 476 |
register: result_sha256_with_bsd_style |
| 477 |
|
| 478 |
- stat: |
| 479 |
path: "{{ remote_tmp_dir }}/27617sha256_with_bsd_style.txt" |
| 480 |
register: stat_result_sha256_with_bsd_style |
| 481 |
|
| 482 |
- name: download 71420.txt with sha1 checksum url |
| 483 |
get_url: |
| 484 |
url: 'http://localhost:{{ http_port }}/71420.txt' |
| 485 |
dest: '{{ remote_tmp_dir }}' |
| 486 |
checksum: 'sha1:http://localhost:{{ http_port }}/sha1sum.txt' |
| 487 |
register: result_sha1_71420 |
| 488 |
|
| 489 |
- stat: |
| 490 |
path: "{{ remote_tmp_dir }}/71420.txt" |
| 491 |
register: stat_result_sha1_71420 |
| 492 |
|
| 493 |
- name: download 71420.txt with sha256 checksum url |
| 494 |
get_url: |
| 495 |
url: 'http://localhost:{{ http_port }}/71420.txt' |
| 496 |
dest: '{{ remote_tmp_dir }}/71420sha256.txt' |
| 497 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum.txt' |
| 498 |
register: result_sha256_71420 |
| 499 |
|
| 500 |
- stat: |
| 501 |
path: "{{ remote_tmp_dir }}/71420.txt" |
| 502 |
register: stat_result_sha256_71420 |
| 503 |
|
| 504 |
- name: download 71420.txt with sha256 checksum url with dot leading paths |
| 505 |
get_url: |
| 506 |
url: 'http://localhost:{{ http_port }}/71420.txt' |
| 507 |
dest: '{{ remote_tmp_dir }}/71420sha256_with_dot.txt' |
| 508 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_dot.txt' |
| 509 |
register: result_sha256_with_dot_71420 |
| 510 |
|
| 511 |
- stat: |
| 512 |
path: "{{ remote_tmp_dir }}/71420sha256_with_dot.txt" |
| 513 |
register: stat_result_sha256_with_dot_71420 |
| 514 |
|
| 515 |
- name: download 71420.txt with sha256 checksum url with asterisk leading paths |
| 516 |
get_url: |
| 517 |
url: 'http://localhost:{{ http_port }}/71420.txt' |
| 518 |
dest: '{{ remote_tmp_dir }}/71420sha256_with_asterisk.txt' |
| 519 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_asterisk.txt' |
| 520 |
register: result_sha256_with_asterisk_71420 |
| 521 |
|
| 522 |
- stat: |
| 523 |
path: "{{ remote_tmp_dir }}/71420sha256_with_asterisk.txt" |
| 524 |
register: stat_result_sha256_with_asterisk_71420 |
| 525 |
|
| 526 |
- name: download 71420.txt with sha256 checksum url with file scheme |
| 527 |
get_url: |
| 528 |
url: 'http://localhost:{{ http_port }}/71420.txt' |
| 529 |
dest: '{{ remote_tmp_dir }}/71420sha256_with_file_scheme.txt' |
| 530 |
checksum: 'sha256:file://{{ files_dir }}/sha256sum.txt' |
| 531 |
register: result_sha256_with_file_scheme_71420 |
| 532 |
|
| 533 |
- stat: |
| 534 |
path: "{{ remote_tmp_dir }}/71420sha256_with_dot.txt" |
| 535 |
register: stat_result_sha256_with_file_scheme_71420 |
| 536 |
|
| 537 |
- name: download src with sha256 checksum url with no filename |
| 538 |
get_url: |
| 539 |
url: 'http://localhost:{{ http_port }}/27617.txt' |
| 540 |
dest: '{{ remote_tmp_dir }}/27617sha256_with_no_filename.txt' |
| 541 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_checksum_only.txt' |
| 542 |
register: result_sha256_checksum_only |
| 543 |
|
| 544 |
- stat: |
| 545 |
path: "{{ remote_tmp_dir }}/27617.txt" |
| 546 |
register: stat_result_sha256_checksum_only |
| 547 |
|
| 548 |
- name: download 86132.txt with sha1 checksum url |
| 549 |
get_url: |
| 550 |
url: 'http://localhost:{{ http_port }}/86132.txt' |
| 551 |
dest: '{{ remote_tmp_dir }}' |
| 552 |
checksum: 'sha1:http://localhost:{{ http_port }}/sha1sum.txt' |
| 553 |
register: result_sha1_86132 |
| 554 |
|
| 555 |
- stat: |
| 556 |
path: "{{ remote_tmp_dir }}/86132.txt" |
| 557 |
register: stat_result_sha1_86132 |
| 558 |
|
| 559 |
- name: download 86132.txt with sha256 checksum url |
| 560 |
get_url: |
| 561 |
url: 'http://localhost:{{ http_port }}/86132.txt' |
| 562 |
dest: '{{ remote_tmp_dir }}/86132sha256.txt' |
| 563 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum.txt' |
| 564 |
register: result_sha256_86132 |
| 565 |
|
| 566 |
- stat: |
| 567 |
path: "{{ remote_tmp_dir }}/86132.txt" |
| 568 |
register: stat_result_sha256_86132 |
| 569 |
|
| 570 |
- name: download 86132.txt with sha256 checksum url with dot leading paths |
| 571 |
get_url: |
| 572 |
url: 'http://localhost:{{ http_port }}/86132.txt' |
| 573 |
dest: '{{ remote_tmp_dir }}/86132sha256_with_dot.txt' |
| 574 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_dot.txt' |
| 575 |
register: result_sha256_with_dot_86132 |
| 576 |
|
| 577 |
- stat: |
| 578 |
path: "{{ remote_tmp_dir }}/86132sha256_with_dot.txt" |
| 579 |
register: stat_result_sha256_with_dot_86132 |
| 580 |
|
| 581 |
- name: download 86132.txt with sha256 checksum url with asterisk leading paths |
| 582 |
get_url: |
| 583 |
url: 'http://localhost:{{ http_port }}/86132.txt' |
| 584 |
dest: '{{ remote_tmp_dir }}/86132sha256_with_asterisk.txt' |
| 585 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_asterisk.txt' |
| 586 |
register: result_sha256_with_asterisk_86132 |
| 587 |
|
| 588 |
- stat: |
| 589 |
path: "{{ remote_tmp_dir }}/86132sha256_with_asterisk.txt" |
| 590 |
register: stat_result_sha256_with_asterisk_86132 |
| 591 |
|
| 592 |
- name: download 86132_single_space.txt with sha256 checksum url |
| 593 |
get_url: |
| 594 |
url: 'http://localhost:{{ http_port }}/86132_single_space.txt' |
| 595 |
dest: '{{ remote_tmp_dir }}/86132_single_space.txt' |
| 596 |
checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum.txt' |
| 597 |
register: result_sha256_86132_single_space |
| 598 |
|
| 599 |
- stat: |
| 600 |
path: "{{ remote_tmp_dir }}/86132_single_space.txt" |
| 601 |
register: stat_result_sha256_86132_single_space |
| 602 |
|
| 603 |
- name: Assert that the file was downloaded |
| 604 |
assert: |
| 605 |
that: |
| 606 |
- result_sha1 is changed |
| 607 |
- result_sha1_check_mode is changed |
| 608 |
- result_sha256 is changed |
| 609 |
- result_sha256_with_dot is changed |
| 610 |
- result_sha256_with_asterisk is changed |
| 611 |
- result_sha256_with_file_scheme is changed |
| 612 |
- result_sha256_with_bsd_style is changed |
| 613 |
- "stat_result_sha1.stat.exists == true" |
| 614 |
- "stat_result_sha256.stat.exists == true" |
| 615 |
- "stat_result_sha256_with_dot.stat.exists == true" |
| 616 |
- "stat_result_sha256_with_asterisk.stat.exists == true" |
| 617 |
- "stat_result_sha256_with_file_scheme.stat.exists == true" |
| 618 |
- stat_result_sha256_with_bsd_style.stat.exists |
| 619 |
- result_sha1_71420 is changed |
| 620 |
- result_sha256_71420 is changed |
| 621 |
- result_sha256_with_dot_71420 is changed |
| 622 |
- result_sha256_with_asterisk_71420 is changed |
| 623 |
- result_sha256_checksum_only is changed |
| 624 |
- result_sha256_with_file_scheme_71420 is changed |
| 625 |
- "stat_result_sha1_71420.stat.exists == true" |
| 626 |
- "stat_result_sha256_71420.stat.exists == true" |
| 627 |
- "stat_result_sha256_with_dot_71420.stat.exists == true" |
| 628 |
- "stat_result_sha256_with_asterisk_71420.stat.exists == true" |
| 629 |
- "stat_result_sha256_with_file_scheme_71420.stat.exists == true" |
| 630 |
- "stat_result_sha256_checksum_only.stat.exists == true" |
| 631 |
- result_sha1_86132 is changed |
| 632 |
- result_sha256_86132 is changed |
| 633 |
- result_sha256_with_dot_86132 is changed |
| 634 |
- result_sha256_with_asterisk_86132 is changed |
| 635 |
- "stat_result_sha1_86132.stat.exists == true" |
| 636 |
- "stat_result_sha256_86132.stat.exists == true" |
| 637 |
- "stat_result_sha256_with_dot_86132.stat.exists == true" |
| 638 |
- "stat_result_sha256_with_asterisk_86132.stat.exists == true" |
| 639 |
- result_sha256_86132_single_space is changed |
| 640 |
- "stat_result_sha256_86132_single_space.stat.exists == true" |
| 641 |
|
| 642 |
- name: Test for incomplete data read (issue 85164) |
| 643 |
get_url: |
| 644 |
url: 'http://localhost:{{ http_port }}/incompleteRead' |
| 645 |
dest: '{{ remote_tmp_dir }}/85164.txt' |
| 646 |
ignore_errors: true |
| 647 |
register: result |
| 648 |
|
| 649 |
- name: Assert we have an incomplete read failure |
| 650 |
assert: |
| 651 |
that: |
| 652 |
- result is failed |
| 653 |
- '"Incomplete read" in result.msg' |
| 654 |
|
| 655 |
#https://github.com/ansible/ansible/issues/16191 |
| 656 |
- name: Test url split with no filename |
| 657 |
get_url: |
| 658 |
url: https://{{ httpbin_host }} |
| 659 |
dest: "{{ remote_tmp_dir }}" |
| 660 |
|
| 661 |
- name: Test headers dict |
| 662 |
get_url: |
| 663 |
url: https://{{ httpbin_host }}/headers |
| 664 |
headers: |
| 665 |
Foo: bar |
| 666 |
Baz: qux |
| 667 |
dest: "{{ remote_tmp_dir }}/headers_dict.json" |
| 668 |
|
| 669 |
- name: Get downloaded file |
| 670 |
slurp: |
| 671 |
src: "{{ remote_tmp_dir }}/headers_dict.json" |
| 672 |
register: result |
| 673 |
|
| 674 |
- name: Test headers dict |
| 675 |
assert: |
| 676 |
that: |
| 677 |
- (result.content | b64decode | from_json).headers.get('Foo') == 'bar' |
| 678 |
- (result.content | b64decode | from_json).headers.get('Baz') == 'qux' |
| 679 |
|
| 680 |
- name: Test gzip decompression |
| 681 |
get_url: |
| 682 |
url: https://{{ httpbin_host }}/gzip |
| 683 |
dest: "{{ remote_tmp_dir }}/gzip.json" |
| 684 |
|
| 685 |
- name: Get gzip file contents |
| 686 |
slurp: |
| 687 |
path: "{{ remote_tmp_dir }}/gzip.json" |
| 688 |
register: gzip_json |
| 689 |
|
| 690 |
- name: validate gzip decompression |
| 691 |
assert: |
| 692 |
that: |
| 693 |
- (gzip_json.content|b64decode|from_json).gzipped |
| 694 |
|
| 695 |
- name: Test gzip no decompression |
| 696 |
get_url: |
| 697 |
url: https://{{ httpbin_host }}/gzip |
| 698 |
dest: "{{ remote_tmp_dir }}/gzip.json.gz" |
| 699 |
decompress: no |
| 700 |
|
| 701 |
- name: Get gzip file contents |
| 702 |
command: 'gunzip -c {{ remote_tmp_dir }}/gzip.json.gz' |
| 703 |
register: gzip_json |
| 704 |
|
| 705 |
- name: validate gzip no decompression |
| 706 |
assert: |
| 707 |
that: |
| 708 |
- (gzip_json.stdout|from_json).gzipped |
| 709 |
|
| 710 |
- name: Test client cert auth, with certs |
| 711 |
get_url: |
| 712 |
url: "https://ansible.http.tests/ssl_client_verify" |
| 713 |
client_cert: "{{ remote_tmp_dir }}/client.pem" |
| 714 |
client_key: "{{ remote_tmp_dir }}/client.key" |
| 715 |
dest: "{{ remote_tmp_dir }}/ssl_client_verify" |
| 716 |
when: has_httptester |
| 717 |
|
| 718 |
- name: Get downloaded file |
| 719 |
slurp: |
| 720 |
src: "{{ remote_tmp_dir }}/ssl_client_verify" |
| 721 |
register: result |
| 722 |
when: has_httptester |
| 723 |
|
| 724 |
- name: Assert that the ssl_client_verify file contains the correct content |
| 725 |
assert: |
| 726 |
that: |
| 727 |
- '(result.content | b64decode) == "ansible.http.tests:SUCCESS"' |
| 728 |
when: has_httptester |
| 729 |
|
| 730 |
- name: test unredirected_headers |
| 731 |
get_url: |
| 732 |
url: 'https://{{ httpbin_host }}/redirect-to?status_code=301&url=/basic-auth/user/passwd' |
| 733 |
username: user |
| 734 |
password: passwd |
| 735 |
force_basic_auth: true |
| 736 |
unredirected_headers: |
| 737 |
- authorization |
| 738 |
dest: "{{ remote_tmp_dir }}/doesnt_matter" |
| 739 |
ignore_errors: true |
| 740 |
register: unredirected_headers |
| 741 |
|
| 742 |
- name: test unredirected_headers |
| 743 |
get_url: |
| 744 |
url: 'https://{{ httpbin_host }}/redirect-to?status_code=301&url=/basic-auth/user/passwd' |
| 745 |
username: user |
| 746 |
password: passwd |
| 747 |
force_basic_auth: true |
| 748 |
dest: "{{ remote_tmp_dir }}/doesnt_matter" |
| 749 |
register: redirected_headers |
| 750 |
|
| 751 |
- name: ensure unredirected_headers caused auth to fail |
| 752 |
assert: |
| 753 |
that: |
| 754 |
- unredirected_headers is failed |
| 755 |
- unredirected_headers.status_code == 401 |
| 756 |
- redirected_headers is successful |
| 757 |
- redirected_headers.status_code == 200 |
| 758 |
|
| 759 |
- name: Test use_gssapi=True |
| 760 |
include_tasks: |
| 761 |
file: use_gssapi.yml |
| 762 |
apply: |
| 763 |
environment: |
| 764 |
KRB5_CONFIG: '{{ krb5_config }}' |
| 765 |
KRB5CCNAME: FILE:{{ remote_tmp_dir }}/krb5.cc |
| 766 |
OPENSSL_CONF: '{{ krb5_openssl_conf }}' |
| 767 |
when: krb5_config is defined |
| 768 |
|
| 769 |
- name: Test ciphers |
| 770 |
import_tasks: ciphers.yml |
| 771 |
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 |
| 772 |
|
| 773 |
- name: Test use_netrc=False |
| 774 |
import_tasks: use_netrc.yml |
| 775 |
|
| 776 |
# https://github.com/ansible/ansible/pull/64092 |
| 777 |
# Calling get_url with bad checksum should not delete the target file |
| 778 |
- name: Define test files for checksum verification |
| 779 |
set_fact: |
| 780 |
checksum_verify_dstfile: "{{ remote_tmp_dir }}/checksum-verify-test.txt" |
| 781 |
|
| 782 |
- name: Download file |
| 783 |
get_url: |
| 784 |
url: https://{{ httpbin_host }}/get |
| 785 |
dest: "{{ checksum_verify_dstfile}}" |
| 786 |
register: result |
| 787 |
|
| 788 |
- stat: |
| 789 |
path: "{{ checksum_verify_dstfile }}" |
| 790 |
register: stat_result_checksum_verify |
| 791 |
|
| 792 |
- name: Assert success |
| 793 |
assert: |
| 794 |
that: |
| 795 |
- result is changed |
| 796 |
- '"OK" in result.msg' |
| 797 |
- stat_result_checksum_verify.stat.exists |
| 798 |
|
| 799 |
- name: Download file again, with wrong checksum |
| 800 |
get_url: |
| 801 |
url: https://{{ httpbin_host }}/get |
| 802 |
dest: "{{ checksum_verify_dstfile}}" |
| 803 |
checksum: "sha256:18b2a70b53c350ad49e4eafb69560bf77ba2ef4f3c93376b65f18b753c912809" |
| 804 |
register: result |
| 805 |
failed_when: |
| 806 |
- result is successful |
| 807 |
|
| 808 |
- stat: |
| 809 |
path: "{{ checksum_verify_dstfile }}" |
| 810 |
register: stat_result_checksum_verify |
| 811 |
|
| 812 |
- name: Assert destination file was not removed |
| 813 |
assert: |
| 814 |
that: |
| 815 |
- result is not changed |
| 816 |
- '"did not match" in result.msg' |
| 817 |
- stat_result_checksum_verify.stat.exists |
| 818 |
|
| 819 |
- name: Test downloading to dir with content-disposition attachment |
| 820 |
get_url: |
| 821 |
url: 'https://{{ httpbin_host }}/response-headers?Content-Disposition=attachment%3B%20filename%3D%22filename.json%22' |
| 822 |
dest: "{{ remote_tmp_dir }}" |
| 823 |
register: get_dir_filename |
| 824 |
|
| 825 |
- assert: |
| 826 |
that: |
| 827 |
- get_dir_filename.dest == remote_tmp_dir ~ "/filename.json" |
| 828 |
|
| 829 |
- name: Test downloading to dir with content-disposition inline |
| 830 |
get_url: |
| 831 |
url: 'https://{{ httpbin_host }}/response-headers?Content-Disposition=inline%3B%20filename%3D%22filename.json%22' |
| 832 |
dest: "{{ remote_tmp_dir }}" |
| 833 |
register: get_dir_filename |
| 834 |
|
| 835 |
- assert: |
| 836 |
that: |
| 837 |
- get_dir_filename.dest == remote_tmp_dir ~ "/filename.json" |
| 838 |
|
| 839 |
- name: Test auth fail downloading to dir |
| 840 |
get_url: |
| 841 |
url: 'https://secretuser:secretpassword@{{ httpbin_host }}/nonexistant' |
| 842 |
dest: "{{ remote_tmp_dir }}" |
| 843 |
ignore_errors: true |
| 844 |
register: auth_error |
| 845 |
|
| 846 |
- name: Ensure secret is not visible |
| 847 |
assert: |
| 848 |
that: |
| 849 |
- "'secret' not in auth_error|to_json" |