win_get_url - refactor tests to use httptester (#53765)

* win_get_url - refactor tests to use httptester

* Use the file lookup instead of slurp
This commit is contained in:
Jordan Borean 2019-03-14 08:04:49 +10:00 committed by GitHub
parent 42e6700a71
commit d3792145d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 215 additions and 272 deletions

View file

@ -381,13 +381,13 @@ $request_params = @{
} }
if ($checksum) { if ($checksum) {
$checksum = $checksum.Trim().toLower() $checksum = $checksum.Trim().ToLower()
} }
if ($checksum_algorithm) { if ($checksum_algorithm) {
$checksum_algorithm = $checksum_algorithm.Trim().toLower() $checksum_algorithm = $checksum_algorithm.Trim().ToLower()
} }
if ($checksum_url) { if ($checksum_url) {
$checksum_url = $checksum_url.Trim().toLower() $checksum_url = $checksum_url.Trim()
} }
# Check for case $checksum variable contain url. If yes, get file data from url and replace original value in $checksum # Check for case $checksum variable contain url. If yes, get file data from url and replace original value in $checksum

View file

@ -1 +1,3 @@
shippable/windows/group5 shippable/windows/group5
needs/httptester
skip/windows/2008 # httptester requires SSH which doesn't work with 2008

View file

@ -1,7 +0,0 @@
---
test_win_get_url_path: '{{win_output_dir}}\win_get_url'
test_win_get_url_host: www.redhat.com
test_win_get_url_env_var: WIN_GET_URL
remote_tmp_path: '{{win_output_dir}}\win_get_url_dest'
remote_http_path: '{{test_win_get_url_path}}\http'

View file

@ -0,0 +1,3 @@
a97e6837f60cec6da4491bab387296bbcd72bdba cHR1eA==
3911340502960ca33aece01129234460bfeb2791 not_target1.txt
1b4b6adf30992cedb0f6edefd6478ff0a593b2e4 not_target2.txt

View file

@ -0,0 +1,3 @@
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006 cHR1eA==
30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 not_target1.txt
d0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b not_target2.txt

View file

@ -0,0 +1,3 @@
b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006 ./cHR1eA==
30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 ./not_target1.txt
d0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b ./not_target2.txt

View file

@ -0,0 +1,3 @@
dependencies:
- setup_remote_tmp_dir
- prepare_http_tests

View file

@ -1,69 +1,39 @@
--- ---
- name: ensure testing folder is present
win_file:
path: '{{ item }}'
state: directory
loop:
- '{{ test_win_get_url_path }}'
- '{{ remote_http_path }}'
- '{{ remote_tmp_path }}'
- name: copy across testing files - name: copy across testing files
win_copy: win_copy:
src: files/ src: files/
dest: '{{test_win_get_url_path}}\' dest: '{{ remote_tmp_dir }}'
- name: download SlimFTPd binary - name: download SlimFTPd binary
win_get_url: win_get_url:
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/roles/test_win_get_url/SlimFTPd.exe url: https://s3.amazonaws.com/ansible-ci-files/test/integration/roles/test_win_get_url/SlimFTPd.exe
dest: '{{test_win_get_url_path}}\SlimFTPd.exe' dest: '{{ remote_tmp_dir }}\SlimFTPd.exe'
- name: template SlimFTPd configuration file - name: template SlimFTPd configuration file
win_template: win_template:
src: slimftpd.conf.tmpl src: slimftpd.conf.tmpl
dest: '{{test_win_get_url_path}}\slimftpd.conf' dest: '{{ remote_tmp_dir }}\slimftpd.conf'
- name: create SlimFTPd service - name: create SlimFTPd service
win_service: win_service:
name: SlimFTPd name: SlimFTPd
path: '"{{test_win_get_url_path}}\SlimFTPd.exe" -service' path: '"{{ remote_tmp_dir }}\SlimFTPd.exe" -service'
state: started state: started
dependencies: dependencies:
- tcpip - tcpip
- name: create env var for win_get_url tests
win_environment:
name: '{{test_win_get_url_env_var}}'
level: machine
value: '{{test_win_get_url_path}}'
state: present
- block: - block:
- name: run URL tests - name: run URL tests
include_tasks: tests_url.yml import_tasks: tests_url.yml
- name: run FTP tests - name: run FTP tests
include_tasks: tests_ftp.yml import_tasks: tests_ftp.yml
- name: run checksum tests - name: run checksum tests
include_tasks: tests_checksum.yml import_tasks: tests_checksum.yml
always: always:
- name: remove SlimFTPd service - name: remove SlimFTPd service
win_service: win_service:
name: SlimFTPd name: SlimFTPd
state: absent state: absent
- name: remove test env var for tests
win_environment:
name: '{{test_win_get_url_env_var}}'
level: machine
state: absent
- name: remove testing folders
win_file:
path: '{{ item }}'
state: absent
loop:
- '{{ test_win_get_url_path }}'
- '{{ remote_tmp_path }}'

View file

@ -1,202 +1,91 @@
--- ---
- name: create src file # These files are pre formatted and we want to get the base64 value so we can use it for httpbin
win_copy: # dynamic content in checksum_url
dest: '{{ remote_http_path }}\27617.txt' - name: set base64 values for checksum files
content: 'ptux' set_fact:
sha1sum: '{{ lookup("file", "ftp/anon/sha1sum.txt") | b64encode }}'
sha256sum: '{{ lookup("file", "ftp/anon/sha256sum.txt") | b64encode }}'
sha256sum_dot: '{{ lookup("file", "ftp/anon/sha256sum_with_dot.txt") | b64encode }}'
- name: create sha1 checksum file of src - name: download file with sha1 checksum url
win_copy:
dest: '{{ remote_http_path }}\sha1sum.txt'
content: 'a97e6837f60cec6da4491bab387296bbcd72bdba 27617.txt'
- name: add sha1 checksum not going to be downloaded
win_lineinfile:
dest: '{{ remote_http_path }}\sha1sum.txt'
line: '{{ item }}'
loop:
- '3911340502960ca33aece01129234460bfeb2791 not_target1.txt'
- '1b4b6adf30992cedb0f6edefd6478ff0a593b2e4 not_target2.txt'
- name: create sha256 checksum file of src
win_copy:
dest: '{{ remote_http_path }}\sha256sum.txt'
content: 'b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. 27617.txt'
- name: add sha256 checksum not going to be downloaded
win_lineinfile:
dest: '{{ remote_http_path }}\sha256sum.txt'
line: '{{ item }}'
loop:
- '30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 not_target1.txt'
- 'd0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b not_target2.txt'
- name: create sha256 checksum file of src with a dot leading path
win_copy:
dest: '{{ remote_http_path }}\sha256sum_with_dot.txt'
content: 'b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. ./27617.txt'
- name: add sha256 checksums with dot leading path not going to be downloaded
win_lineinfile:
dest: '{{ remote_http_path }}\sha256sum_with_dot.txt'
line: '{{ item }}'
loop:
- '30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 ./not_target1.txt'
- 'd0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b ./not_target2.txt'
- name: copy files to ftp
win_copy:
src: '{{ remote_http_path }}\'
dest: '{{ test_win_get_url_path }}\ftp\{{ item }}\'
remote_src: yes
loop: '{{ dest_folders }}'
vars:
dest_folders:
- anon
- user
- user-pass
- name: download src with sha1 checksum url
win_get_url: win_get_url:
url: 'ftp://localhost/anon/27617.txt' url: https://{{ httpbin_host }}/base64/cHR1eA==
dest: '{{ remote_tmp_path }}' dest: '{{ remote_tmp_dir }}\sha1.txt'
checksum_url: 'ftp://localhost/anon/sha1sum.txt' checksum_url: https://{{ httpbin_host }}/base64/{{ sha1sum }}
force: True force: True
register: result_sha1 register: download_sha1_url
- name: download src with sha1 checksum value - name: download file with sha1 checksum value
win_get_url: win_get_url:
url: 'ftp://localhost/anon/27617.txt' url: https://{{ httpbin_host }}/base64/cHR1eA==
dest: '{{ remote_tmp_path }}' dest: '{{ remote_tmp_dir }}\sha1.txt'
checksum: 'a97e6837f60cec6da4491bab387296bbcd72bdba' checksum: a97e6837f60cec6da4491bab387296bbcd72bdba
force: True force: True
register: result_sha1_alt register: download_sha1_value
- win_stat: - name: assert download file with sha1 checksum
path: '{{ remote_tmp_path }}\27617.txt'
register: stat_result_sha1
- name: download src with sha256 checksum url
win_get_url:
url: 'ftp://localhost/anon/27617.txt'
dest: '{{ remote_tmp_path }}\27617sha256.txt'
checksum_url: 'ftp://localhost/anon/sha256sum.txt'
checksum_algorithm: sha256
force: True
register: result_sha256
- win_stat:
path: '{{ remote_tmp_path }}\27617.txt'
register: stat_result_sha256
- name: download src with sha256 checksum url with dot leading paths
win_get_url:
url: 'ftp://localhost/anon/27617.txt'
dest: '{{ remote_tmp_path }}\27617sha256_with_dot.txt'
checksum_url: 'ftp://localhost/anon/sha256sum_with_dot.txt'
checksum_algorithm: sha256
force: True
register: result_sha256_with_dot
- win_stat:
path: '{{ remote_tmp_path }}\27617sha256_with_dot.txt'
register: stat_result_sha256_with_dot
- name: Assert that the file was downloaded
assert: assert:
that: that:
- result_sha1 is changed - download_sha1_url is changed
- result_sha1.checksum_dest == 'a97e6837f60cec6da4491bab387296bbcd72bdba' - download_sha1_url.status_code == 200
- result_sha1_alt is succeeded - download_sha1_url.checksum_dest == 'a97e6837f60cec6da4491bab387296bbcd72bdba'
- not result_sha1_alt is changed - not download_sha1_value is changed
- result_sha1_alt.checksum_dest == 'a97e6837f60cec6da4491bab387296bbcd72bdba' - download_sha1_value.status_code == 200
- result_sha256 is changed - download_sha1_value.checksum_dest == 'a97e6837f60cec6da4491bab387296bbcd72bdba'
- result_sha256_with_dot is changed
- stat_result_sha1.stat.exists | bool
- stat_result_sha256.stat.exists | bool
- stat_result_sha256_with_dot.stat.exists | bool
# Check download with force: False - name: download file with sha256 checksum ftp
- name: download src with sha1 checksum url
win_get_url: win_get_url:
url: 'ftp://localhost/anon/27617.txt' url: https://{{ httpbin_host }}/base64/cHR1eA==
dest: '{{ remote_tmp_path }}' dest: '{{ remote_tmp_dir }}\sha256.txt'
checksum_url: 'ftp://localhost/anon/sha1sum.txt' checksum_url: ftp://localhost/anon/sha256sum.txt # tests that a checksum can be from an FTP URI
checksum_algorithm: sha1
force: False
register: result_sha1_no_force
- name: download src with sha256 checksum url
win_get_url:
url: 'ftp://localhost/anon/27617.txt'
dest: '{{ remote_tmp_path }}/27617sha256.txt'
checksum_url: 'ftp://localhost/anon/sha256sum.txt'
checksum_algorithm: sha256 checksum_algorithm: sha256
force: False force: True
register: result_sha256_no_force register: download_sha256_ftp
- name: assert download single file with force no - name: download file with sha256 checksum dot leading source as file
win_get_url:
url: https://{{ httpbin_host }}/base64/cHR1eA==
dest: '{{ remote_tmp_dir }}\sha256.txt'
checksum_url: '{{ remote_tmp_dir }}\ftp\anon\sha256sum_with_dot.txt'
checksum_algorithm: sha256
force: True
register: download_sha256_file
- name: download file with sha256 checksum value
win_get_url:
url: https://{{ httpbin_host }}/base64/cHR1eA==
dest: '{{ remote_tmp_dir }}\sha256.txt'
checksum: b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006
checksum_algorithm: sha256
register: download_sha256_value
- name: assert download file with sha256 checksum
assert: assert:
that: that:
- result_sha1_no_force is not changed - download_sha256_ftp is changed
- result_sha256_no_force is not changed - download_sha256_ftp.status_code == 200
- download_sha256_ftp.checksum_dest == 'b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006'
- not download_sha256_file is changed
- download_sha256_file.status_code == 200
- download_sha256_file.checksum_dest == 'b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006'
- not download_sha256_value is changed
- download_sha256_value.status_code == 200
- download_sha256_value.checksum_dest == 'b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006'
# Check download with check_mode: True - name: fail download with invalid checksum and force=no
- name: download src with sha1 checksum url | checkmode
win_get_url: win_get_url:
url: 'ftp://localhost/anon/27617.txt' url: https://{{ httpbin_host }}/base64/cHR1eA==
dest: '{{ remote_tmp_path }}' dest: '{{ remote_tmp_dir }}\fail.txt'
checksum_url: 'ftp://localhost/anon/sha1sum.txt' checksum: invalid
checksum_algorithm: sha1 force: no
check_mode: True register: fail_checksum_force_no
register: result_sha1_check_mode failed_when: fail_checksum_force_no.msg != "The checksum for https://" + httpbin_host + "/base64/cHR1eA== did not match 'invalid', it was 'a97e6837f60cec6da4491bab387296bbcd72bdba'"
- name: download src with sha256 checksum url | checkmode - name: fail download with invalid checksum and force=yes
win_get_url: win_get_url:
url: 'ftp://localhost/anon/27617.txt' url: https://{{ httpbin_host }}/base64/cHR1eA==
dest: '{{ remote_tmp_path }}\27617sha256.txt' dest: '{{ remote_tmp_dir }}\fail.txt'
checksum_url: 'ftp://localhost/anon/sha256sum.txt' checksum: invalid
checksum_algorithm: sha256 force: yes
check_mode: True register: fail_checksum_force_yes
register: result_sha256_check_mode failed_when: fail_checksum_force_yes.msg != "The checksum for https://" + httpbin_host + "/base64/cHR1eA== did not match 'invalid', it was 'a97e6837f60cec6da4491bab387296bbcd72bdba'"
- name: assert download single file with force no
assert:
that:
- result_sha1_check_mode.checksum_dest == 'a97e6837f60cec6da4491bab387296bbcd72bdba'
- result_sha256_check_mode.checksum_dest == 'b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006'
- result_sha1_check_mode.checksum_src | length
- result_sha256_check_mode.checksum_src | length
# Check download with wrong checksum
- name: download src with sha1 checksum value | fail
win_get_url:
url: 'ftp://localhost/anon/27617.txt'
dest: '{{ remote_tmp_path }}'
checksum: 'redacted'
checksum_algorithm: sha1
failed_when:
- '"did not match" not in result_sha1_failed.msg'
- '"The checksum" not in result_sha1_failed.msg'
- '"Unknown error downloading" not in result_sha1_failed.msg'
register: result_sha1_failed
- name: download src with sha256 checksum value | fail
win_get_url:
url: 'ftp://localhost/anon/27617.txt'
dest: '{{ remote_tmp_path }}\27617sha256.txt'
checksum: 'redacted'
checksum_algorithm: sha256
failed_when:
- '"did not match" not in result_sha256_failed.msg'
- '"The checksum" not in result_sha256_failed.msg'
- '"Unknown error downloading" not in result_sha256_failed.msg'
register: result_sha256_failed
- name: assert failed downloads
assert:
that:
- result_sha1_failed is succeeded
- result_sha256_failed is succeeded

View file

@ -2,13 +2,13 @@
- name: download file from FTP source (check) - name: download file from FTP source (check)
win_get_url: win_get_url:
url: ftp://localhost/anon/file.txt url: ftp://localhost/anon/file.txt
dest: '{{test_win_get_url_path}}\ftp-anon.txt' dest: '{{ remote_tmp_dir }}\ftp-anon.txt'
check_mode: yes check_mode: yes
register: ftp_anon_check register: ftp_anon_check
- name: get results of download file from FTP source (check) - name: get results of download file from FTP source (check)
win_stat: win_stat:
path: '{{test_win_get_url_path}}\ftp-anon.txt' path: '{{ remote_tmp_dir }}\ftp-anon.txt'
register: ftp_anon_result_check register: ftp_anon_result_check
- name: assert download file from FTP source (check) - name: assert download file from FTP source (check)
@ -20,12 +20,12 @@
- name: download file from FTP source - name: download file from FTP source
win_get_url: win_get_url:
url: ftp://localhost/anon/file.txt url: ftp://localhost/anon/file.txt
dest: '{{test_win_get_url_path}}\ftp-anon.txt' dest: '{{ remote_tmp_dir }}\ftp-anon.txt'
register: ftp_anon register: ftp_anon
- name: get results of download file from FTP source - name: get results of download file from FTP source
win_stat: win_stat:
path: '{{test_win_get_url_path}}\ftp-anon.txt' path: '{{ remote_tmp_dir }}\ftp-anon.txt'
register: ftp_anon_result register: ftp_anon_result
- name: assert download file from FTP source - name: assert download file from FTP source
@ -35,12 +35,21 @@
- ftp_anon_result.stat.exists - ftp_anon_result.stat.exists
- ftp_anon_result.stat.checksum == '67e0de92f29645cc30d8d147b767cceb81756651' - ftp_anon_result.stat.checksum == '67e0de92f29645cc30d8d147b767cceb81756651'
# TODO: Add check for idempotent with force: yes once tmp download and checksum verify are in - name: download file from FTP source (idempotent)
win_get_url:
url: ftp://localhost/anon/file.txt
dest: '{{ remote_tmp_dir }}\ftp-anon.txt'
register: ftp_anon_again
- name: assert download file from FTP source (idempotent)
assert:
that:
- not ftp_anon_again is changed
- name: download file from FTP source with force no (check) - name: download file from FTP source with force no (check)
win_get_url: win_get_url:
url: ftp://localhost/anon/file.txt url: ftp://localhost/anon/file.txt
dest: '{{test_win_get_url_path}}\ftp-anon.txt' dest: '{{ remote_tmp_dir }}\ftp-anon.txt'
force: no force: no
check_mode: yes check_mode: yes
register: ftp_anon_force_no_check register: ftp_anon_force_no_check
@ -53,7 +62,7 @@
- name: download file from FTP source with force no - name: download file from FTP source with force no
win_get_url: win_get_url:
url: ftp://localhost/anon/file.txt url: ftp://localhost/anon/file.txt
dest: '{{test_win_get_url_path}}\ftp-anon.txt' dest: '{{ remote_tmp_dir }}\ftp-anon.txt'
force: no force: no
register: ftp_anon_force_no register: ftp_anon_force_no
@ -63,19 +72,19 @@
- ftp_anon_force_no is not changed - ftp_anon_force_no is not changed
- name: set last modified time on FTP source to newer datetime - name: set last modified time on FTP source to newer datetime
win_shell: (Get-Item -Path '{{test_win_get_url_path}}\ftp\anon\file2.txt').LastWriteTime = (Get-Date).AddHours(24) win_shell: (Get-Item -Path '{{ remote_tmp_dir }}\ftp\anon\file2.txt').LastWriteTime = (Get-Date).AddHours(24)
- name: download newer file from FTP source to same dest (check) - name: download newer file from FTP source to same dest (check)
win_get_url: win_get_url:
url: ftp://localhost/anon/file2.txt url: ftp://localhost/anon/file2.txt
dest: '{{test_win_get_url_path}}\ftp-anon.txt' dest: '{{ remote_tmp_dir }}\ftp-anon.txt'
force: no force: no
check_mode: yes check_mode: yes
register: ftp_anon_force_no_different_check register: ftp_anon_force_no_different_check
- name: get result of download newer file from FTP source to same dest (check) - name: get result of download newer file from FTP source to same dest (check)
win_stat: win_stat:
path: '{{test_win_get_url_path}}\ftp-anon.txt' path: '{{ remote_tmp_dir }}\ftp-anon.txt'
register: ftp_anon_force_no_different_result_check register: ftp_anon_force_no_different_result_check
- name: assert download newer file from FTP source to same dest (check) - name: assert download newer file from FTP source to same dest (check)
@ -87,13 +96,13 @@
- name: download newer file from FTP source to same dest - name: download newer file from FTP source to same dest
win_get_url: win_get_url:
url: ftp://localhost/anon/file2.txt url: ftp://localhost/anon/file2.txt
dest: '{{test_win_get_url_path}}\ftp-anon.txt' dest: '{{ remote_tmp_dir }}\ftp-anon.txt'
force: no force: no
register: ftp_anon_force_no_different register: ftp_anon_force_no_different
- name: get result of download newer file from FTP source to same dest - name: get result of download newer file from FTP source to same dest
win_stat: win_stat:
path: '{{test_win_get_url_path}}\ftp-anon.txt' path: '{{ remote_tmp_dir }}\ftp-anon.txt'
register: ftp_anon_force_no_different_result register: ftp_anon_force_no_different_result
- name: assert download newer file from FTP source to same dest (check) - name: assert download newer file from FTP source to same dest (check)
@ -105,7 +114,7 @@
- name: fail to download file from ftp protected by username - name: fail to download file from ftp protected by username
win_get_url: win_get_url:
url: ftp://localhost/user/file.txt url: ftp://localhost/user/file.txt
dest: '{{test_win_get_url_path}}\ftp-user.txt' dest: '{{ remote_tmp_dir }}\ftp-user.txt'
register: fail_ftp_no_user register: fail_ftp_no_user
ignore_errors: yes ignore_errors: yes
@ -120,13 +129,13 @@
- name: download FTP file protected by username - name: download FTP file protected by username
win_get_url: win_get_url:
url: ftp://localhost/user/file.txt url: ftp://localhost/user/file.txt
dest: '{{test_win_get_url_path}}\ftp-user.txt' dest: '{{ remote_tmp_dir }}\ftp-user.txt'
url_username: username url_username: username
register: ftp_user_file register: ftp_user_file
- name: get result of download FTP file protected by username - name: get result of download FTP file protected by username
win_stat: win_stat:
path: '{{test_win_get_url_path}}\ftp-user.txt' path: '{{ remote_tmp_dir }}\ftp-user.txt'
register: ftp_user_file_result register: ftp_user_file_result
- name: assert download FTP file protected by username - name: assert download FTP file protected by username
@ -139,14 +148,14 @@
- name: download FTP file protected by username and password - name: download FTP file protected by username and password
win_get_url: win_get_url:
url: ftp://localhost/user-pass/file.txt url: ftp://localhost/user-pass/file.txt
dest: '{{test_win_get_url_path}}\ftp-user-pass.txt' dest: '{{ remote_tmp_dir }}\ftp-user-pass.txt'
url_username: userpass url_username: userpass
url_password: password url_password: password
register: ftp_user_pass_file register: ftp_user_pass_file
- name: get result of download FTP file protected by username and password - name: get result of download FTP file protected by username and password
win_stat: win_stat:
path: '{{test_win_get_url_path}}\ftp-user-pass.txt' path: '{{ remote_tmp_dir }}\ftp-user-pass.txt'
register: ftp_user_pass_file_result register: ftp_user_pass_file_result
- name: assert download FTP file protected by username and password - name: assert download FTP file protected by username and password

View file

@ -1,13 +1,13 @@
- name: download single file (check) - name: download single file (check)
win_get_url: win_get_url:
url: https://{{test_win_get_url_host}} url: https://{{ httpbin_host }}/base64/SG93IG5vdyBicm93biBjb3c=
dest: '{{test_win_get_url_path}}\web.html' dest: '{{ remote_tmp_dir }}\output.txt'
check_mode: yes check_mode: yes
register: http_download_check register: http_download_check
- name: get result of download single file (check) - name: get result of download single file (check)
win_stat: win_stat:
path: '{{test_win_get_url_path}}\web.html' path: '{{ remote_tmp_dir }}\output.txt'
register: http_download_result_check register: http_download_result_check
- name: assert download single file (check) - name: assert download single file (check)
@ -21,13 +21,13 @@
- name: download single file - name: download single file
win_get_url: win_get_url:
url: https://{{test_win_get_url_host}} url: https://{{ httpbin_host }}/base64/SG93IG5vdyBicm93biBjb3c=
dest: '{{test_win_get_url_path}}\web.html' dest: '{{ remote_tmp_dir }}\output.txt'
register: http_download register: http_download
- name: get result of download single file - name: get result of download single file
win_stat: win_stat:
path: '{{test_win_get_url_path}}\web.html' path: '{{ remote_tmp_dir }}\output.txt'
register: http_download_result register: http_download_result
- name: assert download single file - name: assert download single file
@ -41,8 +41,8 @@
- name: download single file (idempotent) - name: download single file (idempotent)
win_get_url: win_get_url:
url: https://{{test_win_get_url_host}} url: https://{{ httpbin_host }}/base64/SG93IG5vdyBicm93biBjb3c=
dest: '{{test_win_get_url_path}}\web.html' dest: '{{ remote_tmp_dir }}\output.txt'
register: http_download_again register: http_download_again
- name: assert download single file (idempotent) - name: assert download single file (idempotent)
@ -50,10 +50,16 @@
that: that:
- not http_download_again is changed - not http_download_again is changed
# Cannot use httpbin as the Last-Modified date is generated dynamically
- name: download file for force=no tests
win_get_url:
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/roles/test_win_get_url/SlimFTPd.exe
dest: '{{ remote_tmp_dir }}\output'
- name: download single file with force no - name: download single file with force no
win_get_url: win_get_url:
url: https://{{test_win_get_url_host}} url: https://s3.amazonaws.com/ansible-ci-files/test/integration/roles/test_win_get_url/SlimFTPd.exe
dest: '{{test_win_get_url_path}}\web.html' dest: '{{ remote_tmp_dir }}\output'
force: no force: no
register: http_download_no_force register: http_download_no_force
@ -64,13 +70,14 @@
- name: manually change the content and last modified time on FTP source to older datetime - name: manually change the content and last modified time on FTP source to older datetime
win_shell: | win_shell: |
Set-Content -Path '{{test_win_get_url_path}}\web.html' -Value 'abc' $path = '{{ remote_tmp_dir }}\output'
(Get-Item -Path '{{test_win_get_url_path}}\web.html').LastWriteTime = (Get-Date -Date "01/01/1970") Set-Content -Path $path -Value 'abc'
(Get-Item -Path $path).LastWriteTime = (Get-Date -Date "01/01/1970")
- name: download newer file with force no - name: download newer file with force no
win_get_url: win_get_url:
url: https://{{test_win_get_url_host}} url: https://s3.amazonaws.com/ansible-ci-files/test/integration/roles/test_win_get_url/SlimFTPd.exe
dest: '{{test_win_get_url_path}}\web.html' dest: '{{ remote_tmp_dir }}\output'
force: no force: no
register: http_download_newer_no_force register: http_download_newer_no_force
@ -81,13 +88,13 @@
- name: download file to directory - name: download file to directory
win_get_url: win_get_url:
url: https://{{test_win_get_url_host}} url: https://{{ httpbin_host }}/image/png
dest: '{{test_win_get_url_path}}' dest: '{{ remote_tmp_dir }}'
register: http_download_to_directory register: http_download_to_directory
- name: get result of download to directory - name: get result of download to directory
win_stat: win_stat:
path: '{{test_win_get_url_path}}\{{test_win_get_url_host}}' path: '{{ remote_tmp_dir }}\png'
register: http_download_to_directory_result register: http_download_to_directory_result
- name: assert download file to directory - name: assert download file to directory
@ -98,13 +105,15 @@
- name: download to path with env var - name: download to path with env var
win_get_url: win_get_url:
url: https://{{test_win_get_url_host}} url: https://{{ httpbin_host }}/image/jpeg
dest: '%{{test_win_get_url_env_var}}%\http-env.html' dest: '%TEST_WIN_GET_URL%\jpeg.jpg'
register: http_download_with_env register: http_download_with_env
environment:
TEST_WIN_GET_URL: '{{ remote_tmp_dir }}'
- name: get result of download to path with env var - name: get result of download to path with env var
win_stat: win_stat:
path: '{{test_win_get_url_path}}\http-env.html' path: '{{ remote_tmp_dir }}\jpeg.jpg'
register: http_download_with_env_result register: http_download_with_env_result
- name: assert download to path with env var - name: assert download to path with env var
@ -115,8 +124,8 @@
- name: fail when link returns 404 - name: fail when link returns 404
win_get_url: win_get_url:
url: https://{{test_win_get_url_host}}/skynet_module.html url: https://{{ httpbin_host }}/status/404
dest: '{{test_win_get_url_path}}\skynet_module.html' dest: '{{ remote_tmp_dir }}\skynet_module.html'
ignore_errors: yes ignore_errors: yes
register: fail_download_404 register: fail_download_404
@ -129,7 +138,66 @@
- name: fail when dest is an invalid path - name: fail when dest is an invalid path
win_get_url: win_get_url:
url: https://{{test_win_get_url_host}} url: https://{{ httpbin_host }}/base64/YQ==
dest: Q:\Filez\Cyberdyne.html dest: Q:\Filez\Cyberdyne.html
register: fail_invalid_path register: fail_invalid_path
failed_when: '"The path ''Q:\Filez'' does not exist for destination ''Q:\Filez\Cyberdyne.html''" not in fail_invalid_path.msg' failed_when: '"The path ''Q:\Filez'' does not exist for destination ''Q:\Filez\Cyberdyne.html''" not in fail_invalid_path.msg'
- name: test basic authentication
win_get_url:
url: http://{{ httpbin_host }}/basic-auth/username/password
dest: '{{ remote_tmp_dir }}\basic.txt'
url_username: username
url_password: password
register: basic_auth
- name: assert test basic authentication
assert:
that:
- basic_auth is changed
- basic_auth.status_code == 200
# httpbin hidden-basic-auth returns 404 not found on auth failure which stops the automatic auth handler from working.
# Setting force_basic_auth=yes means the Basic auth header is sent in the original request not after a 401 response
- name: test force basic authentication
win_get_url:
url: http://{{ httpbin_host }}/hidden-basic-auth/username/password
dest: '{{ remote_tmp_dir }}\force-basic.txt'
url_username: username
url_password: password
force_basic_auth: yes
register: force_basic_auth
- name: assert test force basic auth
assert:
that:
- force_basic_auth is changed
- force_basic_auth.status_code == 200
- name: timeout request
win_get_url:
url: https://{{ httpbin_host }}/delay/7
dest: '{{ remote_tmp_dir }}\timeout.txt'
timeout: 3
register: timeout_req
failed_when: timeout_req.msg != "Error requesting 'https://" + httpbin_host + "/delay/7'. The operation has timed out"
- name: send request with headers
win_get_url:
url: https://{{ httpbin_host }}/headers
dest: '{{ remote_tmp_dir }}\headers.txt'
headers:
testing: 123
register: headers
- name: get result of send request with headers
slurp:
path: '{{ remote_tmp_dir }}\headers.txt'
register: headers_actual
- name: assert send request with headers
assert:
that:
- headers is changed
- headers.status_code == 200
- (headers_actual.content | b64decode | from_json).headers.Testing == '123'

View file

@ -8,14 +8,14 @@ LookupHosts On
<User "anonymous"> <User "anonymous">
Password "" Password ""
Mount / {{test_win_get_url_path}}\ftp Mount / "{{ remote_tmp_dir | replace('\\', '\\\\') }}\\ftp"
Allow /anon All Allow /anon All
Deny /user All Deny /user All
Deny /user-pass All Deny /user-pass All
</User> </User>
<User "username"> <User "username">
Mount / {{test_win_get_url_path}}\ftp Mount / "{{ remote_tmp_dir | replace('\\', '\\\\') }}\\ftp"
Allow /anon All Allow /anon All
Allow /user All Allow /user All
Deny /user-pass All Deny /user-pass All
@ -23,6 +23,6 @@ LookupHosts On
<User "userpass"> <User "userpass">
Password "password" Password "password"
Mount / {{test_win_get_url_path}}\ftp Mount / "{{ remote_tmp_dir | replace('\\', '\\\\') }}\\ftp"
Allow / All Allow / All
</User> </User>