Skip to content

Commit

Permalink
Don't treat no checksum as a checksum match (#62146)
Browse files Browse the repository at this point in the history
Fixes #61978
* moar tests for get_url fetch behavior with existing file
* add changelog fragment
  • Loading branch information
sivel authored and samdoran committed Sep 13, 2019
1 parent 08279c7 commit 7d51cac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/61978-get-url-no-checksum.yml
@@ -0,0 +1,3 @@
bugfixes:
- get_url - Don't treat no checksum as a checksum match
(https://github.com/ansible/ansible/issues/61978)
2 changes: 1 addition & 1 deletion lib/ansible/modules/net_tools/basics/get_url.py
Expand Up @@ -540,7 +540,7 @@ def main():
checksum_mismatch = True

# Not forcing redownload, unless checksum does not match
if not force and not checksum_mismatch:
if not force and checksum and not checksum_mismatch:
# Not forcing redownload, unless checksum does not match
# allow file attribute changes
module.params['path'] = dest
Expand Down
36 changes: 30 additions & 6 deletions test/integration/targets/get_url/tasks/main.yml
Expand Up @@ -257,29 +257,53 @@
- result is changed
- "stat_result.stat.mode == '0775'"

- name: Get a file that already exists
- name: test checksum match in check mode
get_url:
url: 'https://{{ httpbin_host }}/get'
dest: '{{ remote_tmp_dir }}/test'
checksum: 'sha256:7036ede810fad2b5d2e7547ec703cae8da61edbba43c23f9d7203a0239b765c4.'
check_mode: True
register: result

- name: Assert that check mode was green
assert:
that:
- result is not changed

- name: Get a file that already exists with a checksum
get_url:
url: 'https://{{ httpbin_host }}/cache'
dest: '{{ remote_tmp_dir }}/test'
checksum: 'sha1:{{ stat_result.stat.checksum }}'
register: result

- name: Assert that the file was not downloaded
assert:
that:
- result.msg == 'file already exists'

- name: Get a file that already exists
get_url:
url: 'https://{{ httpbin_host }}/cache'
dest: '{{ remote_tmp_dir }}/test'
register: result

- name: Assert that we didn't re-download unnecessarily
assert:
that:
- result is not changed
- "'304' in result.msg"

- name: test checksum match in check mode
- name: get a file that doesn't respond to If-Modified-Since without checksum
get_url:
url: 'https://{{ httpbin_host }}/get'
dest: '{{ remote_tmp_dir }}/test'
checksum: 'sha256:7036ede810fad2b5d2e7547ec703cae8da61edbba43c23f9d7203a0239b765c4.'
check_mode: True
register: result

- name: Assert that check mode was green
- name: Assert that we downloaded the file
assert:
that:
- result is not changed
- result is changed

# https://github.com/ansible/ansible/issues/27617

Expand Down

0 comments on commit 7d51cac

Please sign in to comment.