Don't treat no checksum as a checksum match (#62146)

Fixes #61978
* moar tests for get_url fetch behavior with existing file
* add changelog fragment
pull/62297/head
Matt Martz 5 years ago committed by Sam Doran
parent 08279c7d54
commit 7d51cac330

@ -0,0 +1,3 @@
bugfixes:
- get_url - Don't treat no checksum as a checksum match
(https://github.com/ansible/ansible/issues/61978)

@ -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

@ -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

Loading…
Cancel
Save