summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2018-09-12 12:05:25 -0300
committerToshio Kuratomi <a.badger@gmail.com>2018-09-12 08:05:25 -0700
commitc41681b888bd50218866f211b313c7c1e1c199cc (patch)
tree90c40628483ba5da0b2d20dcffd1b5635acb01e1
parent99171a9c6f6029716f93eee92a149b5afe622cf1 (diff)
downloadansible-c41681b888bd50218866f211b313c7c1e1c199cc.tar.gz
[backport-2.7] Fix remote checksums when paths have leading dots (#45287) (#45501)
* Fix remote checksums when paths have leading dots (#45287) * Fix remote checksums with paths have leading dots * Fix result recorded from the wrong file * Add changelog fragment (cherry picked from commit 600c7ac108e32232d7734fca62c61e6591f450b9)
-rw-r--r--changelogs/fragments/45501-get_url-better_checksums.yaml2
-rw-r--r--lib/ansible/modules/net_tools/basics/get_url.py2
-rw-r--r--test/integration/targets/get_url/tasks/main.yml26
3 files changed, 29 insertions, 1 deletions
diff --git a/changelogs/fragments/45501-get_url-better_checksums.yaml b/changelogs/fragments/45501-get_url-better_checksums.yaml
new file mode 100644
index 0000000000..d61a8251d0
--- /dev/null
+++ b/changelogs/fragments/45501-get_url-better_checksums.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+- get_url - support remote checksum files with paths specified with leading dots (`./path/to/file`)
diff --git a/lib/ansible/modules/net_tools/basics/get_url.py b/lib/ansible/modules/net_tools/basics/get_url.py
index b8afb83ee1..eb63a5791f 100644
--- a/lib/ansible/modules/net_tools/basics/get_url.py
+++ b/lib/ansible/modules/net_tools/basics/get_url.py
@@ -449,7 +449,7 @@ def main():
os.remove(checksum_tmpsrc)
lines = dict(s.split(None, 1) for s in lines)
filename = url_filename(url)
- [checksum] = (k for (k, v) in lines.items() if v == filename)
+ [checksum] = (k for (k, v) in lines.items() if v.strip('./') == filename)
# Remove any non-alphanumeric characters, including the infamous
# Unicode zero-width space
checksum = re.sub(r'\W+', '', checksum).lower()
diff --git a/test/integration/targets/get_url/tasks/main.yml b/test/integration/targets/get_url/tasks/main.yml
index 0c3df2fbaf..170b080713 100644
--- a/test/integration/targets/get_url/tasks/main.yml
+++ b/test/integration/targets/get_url/tasks/main.yml
@@ -311,6 +311,19 @@
- '30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 not_target1.txt'
- 'd0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b not_target2.txt'
+- name: create sha256 checksum file of src with a dot leading path
+ copy:
+ dest: '{{ files_dir }}/sha256sum_with_dot.txt'
+ content: "b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. ./27617.txt"
+
+- name: add sha256 checksums with dot leading path not going to be downloaded
+ lineinfile:
+ dest: "{{ files_dir }}/sha256sum_with_dot.txt"
+ line: "{{ item }}"
+ loop:
+ - '30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 ./not_target1.txt'
+ - 'd0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b ./not_target2.txt'
+
- copy:
src: "testserver.py"
dest: "{{ output_dir }}/testserver.py"
@@ -342,13 +355,26 @@
path: "{{ output_dir }}/27617.txt"
register: stat_result_sha256
+- name: download src with sha256 checksum url with dot leading paths
+ get_url:
+ url: 'http://localhost:{{ http_port }}/27617.txt'
+ dest: '{{ output_dir }}/27617sha256_with_dot.txt'
+ checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_dot.txt'
+ register: result_sha256_with_dot
+
+- stat:
+ path: "{{ output_dir }}/27617sha256_with_dot.txt"
+ register: stat_result_sha256_with_dot
+
- name: Assert that the file was downloaded
assert:
that:
- result_sha1 is changed
- result_sha256 is changed
+ - result_sha256_with_dot is changed
- "stat_result_sha1.stat.exists == true"
- "stat_result_sha256.stat.exists == true"
+ - "stat_result_sha256_with_dot.stat.exists == true"
#https://github.com/ansible/ansible/issues/16191
- name: Test url split with no filename