From 8a754e0858d922e955e71b253c139e071ecec432 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 18:04:21 +0200 Subject: Adding upstream version 2.14.3. Signed-off-by: Daniel Baumann --- test/integration/targets/unarchive/aliases | 3 + test/integration/targets/unarchive/files/foo.txt | 1 + ...217\343\202\211\343\201\250\343\201\277.tar.gz" | Bin 0 -> 4947 bytes .../targets/unarchive/handlers/main.yml | 3 + test/integration/targets/unarchive/meta/main.yml | 4 + test/integration/targets/unarchive/tasks/main.yml | 22 +++ .../targets/unarchive/tasks/prepare_tests.yml | 115 +++++++++++++++ .../tasks/test_different_language_var.yml | 41 ++++++ .../targets/unarchive/tasks/test_download.yml | 44 ++++++ .../targets/unarchive/tasks/test_exclude.yml | 54 +++++++ .../targets/unarchive/tasks/test_include.yml | 81 ++++++++++ .../unarchive/tasks/test_invalid_options.yml | 27 ++++ .../unarchive/tasks/test_missing_binaries.yml | 87 +++++++++++ .../targets/unarchive/tasks/test_missing_files.yml | 47 ++++++ .../targets/unarchive/tasks/test_mode.yml | 151 +++++++++++++++++++ .../unarchive/tasks/test_non_ascii_filename.yml | 66 +++++++++ .../targets/unarchive/tasks/test_owner_group.yml | 164 +++++++++++++++++++++ .../unarchive/tasks/test_ownership_top_folder.yml | 50 +++++++ .../unarchive/tasks/test_parent_not_writeable.yml | 32 ++++ .../unarchive/tasks/test_quotable_characters.yml | 38 +++++ .../targets/unarchive/tasks/test_symlink.yml | 64 ++++++++ .../targets/unarchive/tasks/test_tar.yml | 33 +++++ .../targets/unarchive/tasks/test_tar_gz.yml | 35 +++++ .../unarchive/tasks/test_tar_gz_creates.yml | 53 +++++++ .../unarchive/tasks/test_tar_gz_keep_newer.yml | 57 +++++++ .../unarchive/tasks/test_tar_gz_owner_group.yml | 50 +++++++ .../targets/unarchive/tasks/test_tar_zst.yml | 40 +++++ .../unarchive/tasks/test_unprivileged_user.yml | 63 ++++++++ .../targets/unarchive/tasks/test_zip.yml | 57 +++++++ test/integration/targets/unarchive/vars/Darwin.yml | 1 + .../integration/targets/unarchive/vars/FreeBSD.yml | 4 + test/integration/targets/unarchive/vars/Linux.yml | 4 + 32 files changed, 1491 insertions(+) create mode 100644 test/integration/targets/unarchive/aliases create mode 100644 test/integration/targets/unarchive/files/foo.txt create mode 100644 "test/integration/targets/unarchive/files/test-unarchive-nonascii-\343\201\217\343\202\211\343\201\250\343\201\277.tar.gz" create mode 100644 test/integration/targets/unarchive/handlers/main.yml create mode 100644 test/integration/targets/unarchive/meta/main.yml create mode 100644 test/integration/targets/unarchive/tasks/main.yml create mode 100644 test/integration/targets/unarchive/tasks/prepare_tests.yml create mode 100644 test/integration/targets/unarchive/tasks/test_different_language_var.yml create mode 100644 test/integration/targets/unarchive/tasks/test_download.yml create mode 100644 test/integration/targets/unarchive/tasks/test_exclude.yml create mode 100644 test/integration/targets/unarchive/tasks/test_include.yml create mode 100644 test/integration/targets/unarchive/tasks/test_invalid_options.yml create mode 100644 test/integration/targets/unarchive/tasks/test_missing_binaries.yml create mode 100644 test/integration/targets/unarchive/tasks/test_missing_files.yml create mode 100644 test/integration/targets/unarchive/tasks/test_mode.yml create mode 100644 test/integration/targets/unarchive/tasks/test_non_ascii_filename.yml create mode 100644 test/integration/targets/unarchive/tasks/test_owner_group.yml create mode 100644 test/integration/targets/unarchive/tasks/test_ownership_top_folder.yml create mode 100644 test/integration/targets/unarchive/tasks/test_parent_not_writeable.yml create mode 100644 test/integration/targets/unarchive/tasks/test_quotable_characters.yml create mode 100644 test/integration/targets/unarchive/tasks/test_symlink.yml create mode 100644 test/integration/targets/unarchive/tasks/test_tar.yml create mode 100644 test/integration/targets/unarchive/tasks/test_tar_gz.yml create mode 100644 test/integration/targets/unarchive/tasks/test_tar_gz_creates.yml create mode 100644 test/integration/targets/unarchive/tasks/test_tar_gz_keep_newer.yml create mode 100644 test/integration/targets/unarchive/tasks/test_tar_gz_owner_group.yml create mode 100644 test/integration/targets/unarchive/tasks/test_tar_zst.yml create mode 100644 test/integration/targets/unarchive/tasks/test_unprivileged_user.yml create mode 100644 test/integration/targets/unarchive/tasks/test_zip.yml create mode 100644 test/integration/targets/unarchive/vars/Darwin.yml create mode 100644 test/integration/targets/unarchive/vars/FreeBSD.yml create mode 100644 test/integration/targets/unarchive/vars/Linux.yml (limited to 'test/integration/targets/unarchive') diff --git a/test/integration/targets/unarchive/aliases b/test/integration/targets/unarchive/aliases new file mode 100644 index 0000000..961b205 --- /dev/null +++ b/test/integration/targets/unarchive/aliases @@ -0,0 +1,3 @@ +needs/root +shippable/posix/group2 +destructive diff --git a/test/integration/targets/unarchive/files/foo.txt b/test/integration/targets/unarchive/files/foo.txt new file mode 100644 index 0000000..7c6ded1 --- /dev/null +++ b/test/integration/targets/unarchive/files/foo.txt @@ -0,0 +1 @@ +foo.txt diff --git "a/test/integration/targets/unarchive/files/test-unarchive-nonascii-\343\201\217\343\202\211\343\201\250\343\201\277.tar.gz" "b/test/integration/targets/unarchive/files/test-unarchive-nonascii-\343\201\217\343\202\211\343\201\250\343\201\277.tar.gz" new file mode 100644 index 0000000..4882b92 Binary files /dev/null and "b/test/integration/targets/unarchive/files/test-unarchive-nonascii-\343\201\217\343\202\211\343\201\250\343\201\277.tar.gz" differ diff --git a/test/integration/targets/unarchive/handlers/main.yml b/test/integration/targets/unarchive/handlers/main.yml new file mode 100644 index 0000000..cb8b671 --- /dev/null +++ b/test/integration/targets/unarchive/handlers/main.yml @@ -0,0 +1,3 @@ +- name: restore packages + package: + name: "{{ unarchive_packages }}" diff --git a/test/integration/targets/unarchive/meta/main.yml b/test/integration/targets/unarchive/meta/main.yml new file mode 100644 index 0000000..ae54a4e --- /dev/null +++ b/test/integration/targets/unarchive/meta/main.yml @@ -0,0 +1,4 @@ +dependencies: + - setup_remote_tmp_dir + - setup_gnutar + - setup_test_user diff --git a/test/integration/targets/unarchive/tasks/main.yml b/test/integration/targets/unarchive/tasks/main.yml new file mode 100644 index 0000000..148e583 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/main.yml @@ -0,0 +1,22 @@ +- import_tasks: prepare_tests.yml +- import_tasks: test_missing_binaries.yml +- import_tasks: test_tar.yml +- import_tasks: test_tar_gz.yml +- import_tasks: test_tar_gz_creates.yml +- import_tasks: test_tar_gz_owner_group.yml +- import_tasks: test_tar_gz_keep_newer.yml +- import_tasks: test_tar_zst.yml +- import_tasks: test_zip.yml +- import_tasks: test_exclude.yml +- import_tasks: test_include.yml +- import_tasks: test_parent_not_writeable.yml +- import_tasks: test_mode.yml +- import_tasks: test_quotable_characters.yml +- import_tasks: test_non_ascii_filename.yml +- import_tasks: test_missing_files.yml +- import_tasks: test_symlink.yml +- import_tasks: test_download.yml +- import_tasks: test_unprivileged_user.yml +- import_tasks: test_different_language_var.yml +- import_tasks: test_invalid_options.yml +- import_tasks: test_ownership_top_folder.yml diff --git a/test/integration/targets/unarchive/tasks/prepare_tests.yml b/test/integration/targets/unarchive/tasks/prepare_tests.yml new file mode 100644 index 0000000..98a8ba1 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/prepare_tests.yml @@ -0,0 +1,115 @@ +- name: Include system specific variables + include_vars: "{{ ansible_facts.system }}.yml" + +# Need unzip for unarchive module, and zip for archive creation. +- name: Ensure required binaries are present + package: + name: "{{ unarchive_packages }}" + when: ansible_pkg_mgr in ('yum', 'dnf', 'apt', 'pkgng') + +- name: prep our file + copy: + src: foo.txt + dest: "{{remote_tmp_dir}}/foo-unarchive.txt" + mode: preserve + +- name: prep a tar file + shell: tar cvf test-unarchive.tar foo-unarchive.txt chdir={{remote_tmp_dir}} + +- name: prep a tar.gz file + shell: tar czvf test-unarchive.tar.gz foo-unarchive.txt chdir={{remote_tmp_dir}} + +- name: see if we have the zstd executable + ignore_errors: true + shell: zstd --version + register: zstd_available + +- when: zstd_available.rc == 0 + block: + - name: find gnu tar + shell: | + #!/bin/sh + which gtar 2>/dev/null + if test $? -ne 0; then + if test -z "`tar --version | grep bsdtar`"; then + which tar + fi + fi + register: gnu_tar + + - name: prep a tar.zst file + shell: "{{ gnu_tar.stdout }} --use-compress-program=zstd -cvf test-unarchive.tar.zst foo-unarchive.txt chdir={{remote_tmp_dir}}" + when: gnu_tar.stdout != "" + +- name: prep a chmodded file for zip + copy: + src: foo.txt + dest: '{{remote_tmp_dir}}/foo-unarchive-777.txt' + mode: '0777' + +- name: prep a windows permission file for our zip + copy: + src: foo.txt + dest: '{{remote_tmp_dir}}/FOO-UNAR.TXT' + mode: preserve + +# This gets around an unzip timestamp bug in some distributions +# Recent unzip on Ubuntu and BSD will randomly round some timestamps up. +# But that doesn't seem to happen when the timestamp has an even second. +- name: Bug work around + command: touch -t "201705111530.00" {{remote_tmp_dir}}/foo-unarchive.txt {{remote_tmp_dir}}/foo-unarchive-777.txt {{remote_tmp_dir}}/FOO-UNAR.TXT +# See Ubuntu bug 1691636: https://bugs.launchpad.net/ubuntu/+source/unzip/+bug/1691636 +# When these are fixed, this code should be removed. + +- name: prep a zip file + shell: zip test-unarchive.zip foo-unarchive.txt foo-unarchive-777.txt chdir={{remote_tmp_dir}} + +- name: Prepare - Create test dirs + file: + path: "{{remote_tmp_dir}}/{{item}}" + state: directory + with_items: + - created/include + - created/exclude + - created/other + +- name: Prepare - Create test files + file: + path: "{{remote_tmp_dir}}/created/{{item}}" + state: touch + with_items: + - include/include-1.txt + - include/include-2.txt + - include/include-3.txt + - exclude/exclude-1.txt + - exclude/exclude-2.txt + - exclude/exclude-3.txt + - other/include-1.ext + - other/include-2.ext + - other/exclude-1.ext + - other/exclude-2.ext + - other/other-1.ext + - other/other-2.ext + +- name: Prepare - zip file + shell: zip -r {{remote_tmp_dir}}/unarchive-00.zip * chdir={{remote_tmp_dir}}/created/ + +- name: Prepare - tar file + shell: tar czvf {{remote_tmp_dir}}/unarchive-00.tar * chdir={{remote_tmp_dir}}/created/ + +- name: add a file with Windows permissions to zip file + shell: zip -k test-unarchive.zip FOO-UNAR.TXT chdir={{remote_tmp_dir}} + +- name: prep a subdirectory + file: + path: '{{remote_tmp_dir}}/unarchive-dir' + state: directory + +- name: prep our file + copy: + src: foo.txt + dest: '{{remote_tmp_dir}}/unarchive-dir/foo-unarchive.txt' + mode: preserve + +- name: prep a tar.gz file with directory + shell: tar czvf test-unarchive-dir.tar.gz unarchive-dir chdir={{remote_tmp_dir}} diff --git a/test/integration/targets/unarchive/tasks/test_different_language_var.yml b/test/integration/targets/unarchive/tasks/test_different_language_var.yml new file mode 100644 index 0000000..9eec658 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_different_language_var.yml @@ -0,0 +1,41 @@ +- name: test non-ascii with different LANGUAGE + when: ansible_os_family == 'Debian' + block: + - name: install fr language pack + apt: + name: language-pack-fr + state: present + + - name: create our unarchive destination + file: + path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" + state: directory + + - name: test that unarchive works with an archive that contains non-ascii filenames + unarchive: + # Both the filename of the tarball and the filename inside the tarball have + # nonascii chars + src: "test-unarchive-nonascii-くらとみ.tar.gz" + dest: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" + mode: "u+rwX,go+rX" + remote_src: no + register: nonascii_result0 + + - name: Check that file is really there + stat: + path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz/storage/àâæçéèïîôœ(copy)!@#$%^&-().jpg" + register: nonascii_stat0 + + - name: Assert that nonascii tests succeeded + assert: + that: + - "nonascii_result0.changed == true" + - "nonascii_stat0.stat.exists == true" + + - name: remove nonascii test + file: + path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" + state: absent + + environment: + LANGUAGE: fr_FR:fr diff --git a/test/integration/targets/unarchive/tasks/test_download.yml b/test/integration/targets/unarchive/tasks/test_download.yml new file mode 100644 index 0000000..241f11b --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_download.yml @@ -0,0 +1,44 @@ +# Test downloading a file before unarchiving it +- name: create our unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + state: directory + +- name: Test TLS download + block: + - name: Install packages to make TLS connections work on CentOS 6 + pip: + name: + - urllib3==1.10.2 + - ndg_httpsclient==0.4.4 + - pyOpenSSL==16.2.0 + state: present + when: + - ansible_facts.distribution == 'CentOS' + - not ansible_facts.python.has_sslcontext + - name: unarchive a tar from an URL + unarchive: + src: "https://releases.ansible.com/ansible/ansible-latest.tar.gz" + dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + mode: "0700" + remote_src: yes + register: unarchive13 + - name: Test that unarchive succeeded + assert: + that: + - "unarchive13.changed == true" + always: + - name: Uninstall CentOS 6 TLS connections packages + pip: + name: + - urllib3 + - ndg_httpsclient + - pyOpenSSL + state: absent + when: + - ansible_facts.distribution == 'CentOS' + - not ansible_facts.python.has_sslcontext + - name: remove our tar.gz unarchive destination + file: + path: '{{ remote_tmp_dir }}/test-unarchive-tar-gz' + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_exclude.yml b/test/integration/targets/unarchive/tasks/test_exclude.yml new file mode 100644 index 0000000..8d3183c --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_exclude.yml @@ -0,0 +1,54 @@ +- name: "Create {{ remote_tmp_dir }}/exclude directory" + file: + state: directory + path: "{{ remote_tmp_dir }}/exclude-{{item}}" + with_items: + - zip + - tar + +- name: Unpack archive file excluding regular and glob files. + unarchive: + src: "{{ remote_tmp_dir }}/unarchive-00.{{item}}" + dest: "{{ remote_tmp_dir }}/exclude-{{item}}" + remote_src: yes + list_files: yes + exclude: + - "exclude/exclude-*.txt" + - "other/exclude-1.ext" + register: result_of_unarchive + with_items: + - zip + - tar + +- name: Make sure unarchive module reported back extracted files + assert: + that: + - "'include/include-1.txt' in item.files" + - "'include/include-2.txt' in item.files" + - "'include/include-3.txt' in item.files" + - "'other/include-1.ext' in item.files" + - "'other/include-2.ext' in item.files" + - "'other/exclude-2.ext' in item.files" + - "'other/other-1.ext' in item.files" + - "'other/other-2.ext' in item.files" + loop: "{{ result_of_unarchive.results }}" + +- name: verify that the file was unarchived + shell: find {{ remote_tmp_dir }}/exclude-{{item}} chdir={{ remote_tmp_dir }} + register: unarchive00 + with_items: + - zip + - tar + +- name: verify that archive extraction excluded the files + assert: + that: + - "'exclude/exclude-1.txt' not in item.stdout" + - "'other/exclude-1.ext' not in item.stdout" + with_items: + - "{{ unarchive00.results }}" + +- name: remove our zip unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-zip' + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_include.yml b/test/integration/targets/unarchive/tasks/test_include.yml new file mode 100644 index 0000000..ea3a01c --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_include.yml @@ -0,0 +1,81 @@ +- name: Create a tar file with multiple files + shell: tar cvf test-unarchive-multi.tar foo-unarchive-777.txt foo-unarchive.txt + args: + chdir: "{{ remote_tmp_dir }}" + +- name: Create include test directories + file: + state: directory + path: "{{ remote_tmp_dir }}/{{ item }}" + loop: + - include-zip + - include-tar + +- name: Unpack zip file include one file + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.zip" + dest: "{{ remote_tmp_dir }}/include-zip" + remote_src: yes + include: + - FOO-UNAR.TXT + +- name: Verify that single file was unarchived + find: + paths: "{{ remote_tmp_dir }}/include-zip" + register: unarchive_dir02 + +- name: Verify that zip extraction included only one file + assert: + that: + - file_names == ['FOO-UNAR.TXT'] + vars: + file_names: "{{ unarchive_dir02.files | map(attribute='path') | map('basename') }}" + +- name: Unpack tar file include one file + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive-multi.tar" + dest: "{{ remote_tmp_dir }}/include-tar" + remote_src: yes + include: + - foo-unarchive-777.txt + +- name: verify that single file was unarchived from tar + find: + paths: "{{ remote_tmp_dir }}/include-tar" + register: unarchive_dir03 + +- name: Verify that tar extraction included only one file + assert: + that: + - file_names == ['foo-unarchive-777.txt'] + vars: + file_names: "{{ unarchive_dir03.files | map(attribute='path') | map('basename') }}" + when: + - "ansible_facts.os_family == 'RedHat'" + - ansible_facts.distribution_major_version is version('7', '>=') + +- name: Check mutually exclusive parameters + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive-multi.tar" + dest: "{{ remote_tmp_dir }}/include-tar" + remote_src: yes + include: + - foo-unarchive-777.txt + exclude: + - foo + ignore_errors: yes + register: unarchive_mutually_exclusive_check + +- name: Check mutually exclusive parameters + assert: + that: + - unarchive_mutually_exclusive_check is failed + - "'mutually exclusive' in unarchive_mutually_exclusive_check.msg" + +- name: "Remove include feature tests directory" + file: + state: absent + path: "{{ remote_tmp_dir }}/{{ item }}" + loop: + - 'include-zip' + - 'include-tar' diff --git a/test/integration/targets/unarchive/tasks/test_invalid_options.yml b/test/integration/targets/unarchive/tasks/test_invalid_options.yml new file mode 100644 index 0000000..68a0621 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_invalid_options.yml @@ -0,0 +1,27 @@ +- name: create our tar unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar' + state: directory + +- name: unarchive a tar file with an invalid option + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.tar' + dest: '{{remote_tmp_dir}}/test-unarchive-tar' + remote_src: yes + extra_opts: + - "--invalid-éxtra-optら" + ignore_errors: yes + register: unarchive + +- name: verify that the invalid option is in the error message + assert: + that: + - "unarchive is failed" + - "unarchive['msg'] is search(msg)" + vars: + msg: "Unable to list files in the archive: /.*/(tar|gtar): unrecognized option '--invalid-éxtra-optら'" + +- name: remove our tar unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar' + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_missing_binaries.yml b/test/integration/targets/unarchive/tasks/test_missing_binaries.yml new file mode 100644 index 0000000..58d38f4 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_missing_binaries.yml @@ -0,0 +1,87 @@ +- name: Test missing binaries + when: ansible_pkg_mgr in ('yum', 'dnf', 'apt', 'pkgng') + block: + - name: Remove zip binaries + package: + state: absent + name: + - zip + - unzip + notify: restore packages + + - name: create unarchive destinations + file: + path: '{{ remote_tmp_dir }}/test-unarchive-{{ item }}' + state: directory + loop: + - zip + - tar + + # With the zip binaries absent and tar still present, this task should work + - name: unarchive a tar file + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.tar' + dest: '{{remote_tmp_dir}}/test-unarchive-tar' + remote_src: yes + register: tar + + - name: unarchive a zip file + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.zip' + dest: '{{remote_tmp_dir}}/test-unarchive-zip' + list_files: True + remote_src: yes + register: zip_fail + ignore_errors: yes + # FreeBSD does not have zipinfo, but does have a bootstrapped unzip in /usr/bin + # which alone is sufficient to run unarchive. + # Exclude /usr/bin from the PATH to test having no binary available. + environment: + PATH: "{{ ENV_PATH }}" + vars: + ENV_PATH: "{{ lookup('env', 'PATH') | regex_replace(re, '') }}" + re: "[^A-Za-z](\/usr\/bin:?)" + + - name: Ensure tasks worked as expected + assert: + that: + - tar is success + - zip_fail is failed + - zip_fail.msg is search('Unable to find required') + + - name: unarchive a zip file using unzip without zipinfo + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.zip' + dest: '{{remote_tmp_dir}}/test-unarchive-zip' + list_files: True + remote_src: yes + register: zip_success + # FreeBSD does not have zipinfo, but does have a bootstrapped unzip in /usr/bin + # which alone is sufficient to run unarchive. + when: ansible_pkg_mgr == 'pkgng' + + - assert: + that: + - zip_success is success + - zip_success.changed + # Verify that file list is generated + - "'files' in zip_success" + - "{{zip_success['files']| length}} == 3" + - "'foo-unarchive.txt' in zip_success['files']" + - "'foo-unarchive-777.txt' in zip_success['files']" + - "'FOO-UNAR.TXT' in zip_success['files']" + when: ansible_pkg_mgr == 'pkgng' + + - name: Remove unarchive destinations + file: + path: '{{ remote_tmp_dir }}/test-unarchive-{{ item }}' + state: absent + loop: + - zip + - tar + + - name: Reinsntall zip binaries + package: + name: + - zip + - unzip diff --git a/test/integration/targets/unarchive/tasks/test_missing_files.yml b/test/integration/targets/unarchive/tasks/test_missing_files.yml new file mode 100644 index 0000000..4f57e18 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_missing_files.yml @@ -0,0 +1,47 @@ +# Test that unarchiving is performed if files are missing +# https://github.com/ansible/ansible-modules-core/issues/1064 +- name: create our unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + state: directory + +- name: unarchive a tar that has directories + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive-dir.tar.gz" + dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + mode: "0700" + remote_src: yes + register: unarchive10 + +- name: Test that unarchive succeeded + assert: + that: + - "unarchive10.changed == true" + +- name: Change the mode of the toplevel dir + file: + path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/unarchive-dir" + mode: "0701" + +- name: Remove a file from the extraction point + file: + path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/unarchive-dir/foo-unarchive.txt" + state: absent + +- name: unarchive a tar that has directories + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive-dir.tar.gz" + dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + mode: "0700" + remote_src: yes + register: unarchive10_1 + +- name: Test that unarchive succeeded + assert: + that: + - "unarchive10_1.changed == true" + +- name: remove our tar.gz unarchive destination + file: + path: '{{ remote_tmp_dir }}/test-unarchive-tar-gz' + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_mode.yml b/test/integration/targets/unarchive/tasks/test_mode.yml new file mode 100644 index 0000000..c69e3bd --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_mode.yml @@ -0,0 +1,151 @@ +- name: create our unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + state: directory + +- name: unarchive and set mode to 0600, directories 0700 + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz" + dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + remote_src: yes + mode: "u+rwX,g-rwx,o-rwx" + list_files: True + register: unarchive06 + +- name: Test that the file modes were changed + stat: + path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/foo-unarchive.txt" + register: unarchive06_stat + +- name: Test that the file modes were changed + assert: + that: + - "unarchive06.changed == true" + - "unarchive06_stat.stat.mode == '0600'" + # Verify that file list is generated + - "'files' in unarchive06" + - "{{unarchive06['files']| length}} == 1" + - "'foo-unarchive.txt' in unarchive06['files']" + +- name: remove our tar.gz unarchive destination + file: + path: '{{ remote_tmp_dir }}/test-unarchive-tar-gz' + state: absent + +- name: create our unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + state: directory + +- name: unarchive over existing extraction and set mode to 0644 + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz" + dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + remote_src: yes + mode: "u+rwX,g-wx,o-wx,g+r,o+r" + register: unarchive06_2 + +- name: Test that the file modes were changed + stat: + path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/foo-unarchive.txt" + register: unarchive06_2_stat + +- debug: + var: unarchive06_2_stat.stat.mode + +- name: Test that the files were changed + assert: + that: + - "unarchive06_2.changed == true" + - "unarchive06_2_stat.stat.mode == '0644'" + +- name: Repeat the last request to verify no changes + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz" + dest: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + remote_src: yes + mode: "u+rwX-x,g-wx,o-wx,g+r,o+r" + list_files: True + register: unarchive07 + +- name: Test that the files were not changed + assert: + that: + - "unarchive07.changed == false" + # Verify that file list is generated + - "'files' in unarchive07" + - "{{unarchive07['files']| length}} == 1" + - "'foo-unarchive.txt' in unarchive07['files']" + +- name: remove our tar.gz unarchive destination + file: + path: '{{ remote_tmp_dir }}/test-unarchive-tar-gz' + state: absent + +- name: create our unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-zip' + state: directory + +- name: unarchive and set mode to 0601, directories 0700 + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.zip" + dest: "{{ remote_tmp_dir }}/test-unarchive-zip" + remote_src: yes + mode: "u+rwX-x,g-rwx,o=x" + list_files: True + register: unarchive08 + +- name: Test that the file modes were changed + stat: + path: "{{ remote_tmp_dir }}/test-unarchive-zip/foo-unarchive.txt" + register: unarchive08_stat + +- name: Test that the file modes were changed + assert: + that: + - "unarchive08.changed == true" + - "unarchive08_stat.stat.mode == '0601'" + # Verify that file list is generated + - "'files' in unarchive08" + - "{{unarchive08['files']| length}} == 3" + - "'foo-unarchive.txt' in unarchive08['files']" + - "'foo-unarchive-777.txt' in unarchive08['files']" + - "'FOO-UNAR.TXT' in unarchive08['files']" + +- name: unarchive zipfile a second time and set mode to 0601, directories 0700 + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.zip" + dest: "{{ remote_tmp_dir }}/test-unarchive-zip" + remote_src: yes + mode: "u+rwX-x,g-rwx,o=x" + list_files: True + register: unarchive08 + +- name: Test that the file modes were not changed + stat: + path: "{{ remote_tmp_dir }}/test-unarchive-zip/foo-unarchive.txt" + register: unarchive08_stat + +- debug: + var: unarchive08 + +- debug: + var: unarchive08_stat + +- name: Test that the files did not change + assert: + that: + - "unarchive08.changed == false" + - "unarchive08_stat.stat.mode == '0601'" + # Verify that file list is generated + - "'files' in unarchive08" + - "{{unarchive08['files']| length}} == 3" + - "'foo-unarchive.txt' in unarchive08['files']" + - "'foo-unarchive-777.txt' in unarchive08['files']" + - "'FOO-UNAR.TXT' in unarchive08['files']" + +- name: remove our zip unarchive destination + file: + path: '{{ remote_tmp_dir }}/test-unarchive-zip' + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_non_ascii_filename.yml b/test/integration/targets/unarchive/tasks/test_non_ascii_filename.yml new file mode 100644 index 0000000..c884f49 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_non_ascii_filename.yml @@ -0,0 +1,66 @@ +- name: create our unarchive destination + file: + path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" + state: directory + +- name: test that unarchive works with an archive that contains non-ascii filenames + unarchive: + # Both the filename of the tarball and the filename inside the tarball have + # nonascii chars + src: "test-unarchive-nonascii-くらとみ.tar.gz" + dest: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" + mode: "u+rwX,go+rX" + remote_src: no + register: nonascii_result0 + +- name: Check that file is really there + stat: + path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz/storage/àâæçéèïîôœ(copy)!@#$%^&-().jpg" + register: nonascii_stat0 + +- name: Assert that nonascii tests succeeded + assert: + that: + - "nonascii_result0.changed == true" + - "nonascii_stat0.stat.exists == true" + +- name: remove nonascii test + file: + path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" + state: absent + +- name: test non-ascii with different LC_ALL + block: + - name: create our unarchive destination + file: + path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" + state: directory + + - name: test that unarchive works with an archive that contains non-ascii filenames + unarchive: + # Both the filename of the tarball and the filename inside the tarball have + # nonascii chars + src: "test-unarchive-nonascii-くらとみ.tar.gz" + dest: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" + mode: "u+rwX,go+rX" + remote_src: no + register: nonascii_result0 + + - name: Check that file is really there + stat: + path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz/storage/àâæçéèïîôœ(copy)!@#$%^&-().jpg" + register: nonascii_stat0 + + - name: Assert that nonascii tests succeeded + assert: + that: + - "nonascii_result0.changed == true" + - "nonascii_stat0.stat.exists == true" + + - name: remove nonascii test + file: + path: "{{ remote_tmp_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" + state: absent + + environment: + LC_ALL: C diff --git a/test/integration/targets/unarchive/tasks/test_owner_group.yml b/test/integration/targets/unarchive/tasks/test_owner_group.yml new file mode 100644 index 0000000..227ad9c --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_owner_group.yml @@ -0,0 +1,164 @@ +- block: + - name: Create a group to chown to + group: + name: testgroup + register: testgroup + + - name: Create a user to chown to + user: + name: testuser + groups: + - testgroup + register: testuser + + - set_fact: + outdir: '{{remote_tmp_dir}}/test-unarchive-{{ ext | replace(".", "_") }}' + + - debug: + msg: Username test + + # username + - name: create our unarchive destinations + file: + path: '{{outdir}}' + state: directory + + - name: unarchive a file + unarchive: + src: '{{remote_tmp_dir}}/{{archive}}' + dest: '{{outdir}}' + list_files: True + remote_src: yes + owner: testuser + + - name: stat an output file + stat: + path: '{{outdir}}/{{testfile}}' + register: stat + + - name: verify that the file has the right owner + assert: + that: + - stat.stat.exists + - stat.stat.pw_name == testuser.name + - stat.stat.uid == testuser.uid + + - name: nuke destination + file: + path: '{{outdir}}' + state: absent + + - debug: + msg: uid test + + # uid + - name: create our unarchive destinations + file: + path: '{{outdir}}' + state: directory + + - name: unarchive a file + unarchive: + src: '{{remote_tmp_dir}}/{{archive}}' + dest: '{{outdir}}' + list_files: True + remote_src: yes + owner: '{{ testuser.uid }}' + + - name: stat an output file + stat: + path: '{{outdir}}/{{testfile}}' + register: stat + + - name: verify that the file has the right owner + assert: + that: + - stat.stat.exists + - stat.stat.pw_name == testuser.name + - stat.stat.uid == testuser.uid + + - name: nuke destination + file: + path: '{{outdir}}' + state: absent + + - debug: + msg: groupname test + + # groupname + - name: create our unarchive destinations + file: + path: '{{outdir}}' + state: directory + + - name: unarchive a file + unarchive: + src: '{{remote_tmp_dir}}/{{archive}}' + dest: '{{outdir}}' + list_files: True + remote_src: yes + group: testgroup + + - name: stat an output file + stat: + path: '{{outdir}}/{{testfile}}' + register: stat + + - name: verify that the file has the right owner + assert: + that: + - stat.stat.exists + - stat.stat.gr_name == testgroup.name + - stat.stat.gid == testgroup.gid + + - name: nuke destination + file: + path: '{{outdir}}' + state: absent + + - debug: + msg: gid test + + # gid + - name: create our unarchive destinations + file: + path: '{{outdir}}' + state: directory + + - name: unarchive a file + unarchive: + src: '{{remote_tmp_dir}}/{{archive}}' + dest: '{{outdir}}' + list_files: True + remote_src: yes + group: '{{ testgroup.gid }}' + + - name: stat an output file + stat: + path: '{{outdir}}/{{testfile}}' + register: stat + + - name: verify that the file has the right owner + assert: + that: + - stat.stat.exists + - stat.stat.gr_name == testgroup.name + - stat.stat.gid == testgroup.gid + + - name: nuke destination + file: + path: '{{outdir}}' + state: absent + + always: + - name: Remove testuser + user: + name: testuser + state: absent + remove: yes + force: yes + + - name: Remove testgroup + group: + name: testgroup + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_ownership_top_folder.yml b/test/integration/targets/unarchive/tasks/test_ownership_top_folder.yml new file mode 100644 index 0000000..da40108 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_ownership_top_folder.yml @@ -0,0 +1,50 @@ +- name: Test unarchiving as root and apply different ownership to top folder + vars: + ansible_become: yes + ansible_become_user: root + ansible_become_password: null + block: + - name: Create top folder owned by root + file: + path: "{{ test_user.home }}/tarball-top-folder" + state: directory + owner: root + + - name: Add a file owned by root + copy: + src: foo.txt + dest: "{{ test_user.home }}/tarball-top-folder/foo-unarchive.txt" + mode: preserve + + - name: Create a tarball as root. This tarball won't list the top folder when doing "tar tvf test-tarball.tar.gz" + shell: tar -czf test-tarball.tar.gz tarball-top-folder/foo-unarchive.txt + args: + chdir: "{{ test_user.home }}" + creates: "{{ test_user.home }}/test-tarball.tar.gz" + + - name: Create unarchive destination folder in {{ test_user.home }}/unarchivetest3-unarchive + file: + path: "{{ test_user.home }}/unarchivetest3-unarchive" + state: directory + owner: "{{ test_user.name }}" + group: "{{ test_user.group }}" + + - name: "unarchive the tarball as root. apply ownership for {{ test_user.name }}" + unarchive: + src: "{{ test_user.home }}/test-tarball.tar.gz" + dest: "{{ test_user.home }}/unarchivetest3-unarchive" + remote_src: yes + list_files: True + owner: "{{ test_user.name }}" + group: "{{ test_user.group }}" + + - name: Stat the extracted top folder + stat: + path: "{{ test_user.home }}/unarchivetest3-unarchive/tarball-top-folder" + register: top_folder_info + + - name: "verify that extracted top folder is owned by {{ test_user.name }}" + assert: + that: + - top_folder_info.stat.pw_name == test_user.name + - top_folder_info.stat.gid == test_user.group diff --git a/test/integration/targets/unarchive/tasks/test_parent_not_writeable.yml b/test/integration/targets/unarchive/tasks/test_parent_not_writeable.yml new file mode 100644 index 0000000..bfb082c --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_parent_not_writeable.yml @@ -0,0 +1,32 @@ +- name: check if /tmp/foo-unarchive.text exists + stat: + path: /tmp/foo-unarchive.txt + ignore_errors: True + register: unarchive04 + +- name: fail if the proposed destination file exists for safey + fail: + msg: /tmp/foo-unarchive.txt already exists, aborting + when: unarchive04.stat.exists + +- name: try unarchiving to /tmp + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.tar.gz' + dest: /tmp + remote_src: true + register: unarchive05 + +- name: verify that the file was marked as changed + assert: + that: + - "unarchive05.changed == true" + +- name: verify that the file was unarchived + file: + path: /tmp/foo-unarchive.txt + state: file + +- name: remove our unarchive destination + file: + path: /tmp/foo-unarchive.txt + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_quotable_characters.yml b/test/integration/targets/unarchive/tasks/test_quotable_characters.yml new file mode 100644 index 0000000..0a3c2cc --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_quotable_characters.yml @@ -0,0 +1,38 @@ +- name: create our unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + state: directory + +- name: create a directory with quotable chars + file: + path: '{{ remote_tmp_dir }}/test-quotes~root' + state: directory + +- name: unarchive into directory with quotable chars + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz" + dest: "{{ remote_tmp_dir }}/test-quotes~root" + remote_src: yes + register: unarchive08 + +- name: Test that unarchive succeeded + assert: + that: + - "unarchive08.changed == true" + +- name: unarchive into directory with quotable chars a second time + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz" + dest: "{{ remote_tmp_dir }}/test-quotes~root" + remote_src: yes + register: unarchive09 + +- name: Test that unarchive did nothing + assert: + that: + - "unarchive09.changed == false" + +- name: remove quotable chars test + file: + path: '{{ remote_tmp_dir }}/test-quotes~root' + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_symlink.yml b/test/integration/targets/unarchive/tasks/test_symlink.yml new file mode 100644 index 0000000..fcb7282 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_symlink.yml @@ -0,0 +1,64 @@ +- name: Create a destination dir + file: + path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + state: directory + +- name: Create a symlink to the detination dir + file: + path: "{{ remote_tmp_dir }}/link-to-unarchive-dir" + src: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + state: "link" + +- name: test that unarchive works when dest is a symlink to a dir + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz" + dest: "{{ remote_tmp_dir }}/link-to-unarchive-dir" + mode: "u+rwX,go+rX" + remote_src: yes + register: unarchive_11 + +- name: Check that file is really there + stat: + path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/foo-unarchive.txt" + register: unarchive11_stat0 + +- name: Assert that unarchive when dest is a symlink to a dir worked + assert: + that: + - "unarchive_11.changed == true" + - "unarchive11_stat0.stat.exists == true" + +- name: remove our tar.gz unarchive destination + file: + path: '{{ remote_tmp_dir }}/test-unarchive-tar-gz' + state: absent + +- name: Create a file + file: + path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + state: touch + +- name: Create a symlink to the file + file: + src: "{{ remote_tmp_dir }}/test-unarchive-tar-gz" + path: "{{ remote_tmp_dir }}/link-to-unarchive-file" + state: "link" + +- name: test that unarchive fails when dest is a link to a file + unarchive: + src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz" + dest: "{{ remote_tmp_dir }}/link-to-unarchive-file" + mode: "u+rwX,go+rX" + remote_src: yes + ignore_errors: True + register: unarchive_12 + +- name: Assert that unarchive when dest is a file failed + assert: + that: + - "unarchive_12.failed == true" + +- name: remove our tar.gz unarchive destination + file: + path: '{{ remote_tmp_dir }}/test-unarchive-tar-gz' + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_tar.yml b/test/integration/targets/unarchive/tasks/test_tar.yml new file mode 100644 index 0000000..0a02041 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_tar.yml @@ -0,0 +1,33 @@ +- name: create our tar unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar' + state: directory + +- name: unarchive a tar file + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.tar' + dest: '{{remote_tmp_dir}}/test-unarchive-tar' + remote_src: yes + register: unarchive01 + +- name: verify that the file was marked as changed + assert: + that: + - "unarchive01.changed == true" + +- name: verify that the file was unarchived + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar/foo-unarchive.txt' + state: file + +- name: remove our tar unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar' + state: absent + +- name: test owner/group perms + include_tasks: test_owner_group.yml + vars: + ext: tar + archive: test-unarchive.tar + testfile: foo-unarchive.txt diff --git a/test/integration/targets/unarchive/tasks/test_tar_gz.yml b/test/integration/targets/unarchive/tasks/test_tar_gz.yml new file mode 100644 index 0000000..e88f77b --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_tar_gz.yml @@ -0,0 +1,35 @@ +- name: create our tar.gz unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + state: directory + +- name: unarchive a tar.gz file + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.tar.gz' + dest: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + remote_src: yes + register: unarchive02 + +- name: verify that the file was marked as changed + assert: + that: + - "unarchive02.changed == true" + # Verify that no file list is generated + - "'files' not in unarchive02" + +- name: verify that the file was unarchived + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt' + state: file + +- name: remove our tar.gz unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + state: absent + +- name: test owner/group perms + include_tasks: test_owner_group.yml + vars: + ext: tar.gz + archive: test-unarchive.tar.gz + testfile: foo-unarchive.txt diff --git a/test/integration/targets/unarchive/tasks/test_tar_gz_creates.yml b/test/integration/targets/unarchive/tasks/test_tar_gz_creates.yml new file mode 100644 index 0000000..fa3a23f --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_tar_gz_creates.yml @@ -0,0 +1,53 @@ +- name: create our tar.gz unarchive destination for creates + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + state: directory + +- name: unarchive a tar.gz file with creates set + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.tar.gz' + dest: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + creates: '{{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt' + remote_src: yes + register: unarchive02b + +- name: verify that the file was marked as changed + assert: + that: + - "unarchive02b.changed == true" + +- name: verify that the file was unarchived + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt' + state: file + +- name: unarchive a tar.gz file with creates over an existing file + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.tar.gz' + dest: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + creates: '{{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt' + remote_src: yes + register: unarchive02c + +- name: verify that the file was not marked as changed + assert: + that: + - "unarchive02c.changed == false" + +- name: unarchive a tar.gz file with creates over an existing file using complex_args + unarchive: + src: "{{remote_tmp_dir}}/test-unarchive.tar.gz" + dest: "{{remote_tmp_dir}}/test-unarchive-tar-gz" + remote_src: yes + creates: "{{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt" + register: unarchive02d + +- name: verify that the file was not marked as changed + assert: + that: + - "unarchive02d.changed == false" + +- name: remove our tar.gz unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-gz' + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_tar_gz_keep_newer.yml b/test/integration/targets/unarchive/tasks/test_tar_gz_keep_newer.yml new file mode 100644 index 0000000..aec9454 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_tar_gz_keep_newer.yml @@ -0,0 +1,57 @@ +- name: create our tar.gz unarchive destination for keep-newer + file: + path: "{{remote_tmp_dir}}/test-unarchive-tar-gz" + state: directory + +- name: Create a newer file that we would replace + copy: + dest: "{{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt" + content: boo + mode: preserve + +- name: unarchive a tar.gz file but avoid overwriting newer files (keep_newer=true) + unarchive: + src: "{{remote_tmp_dir}}/test-unarchive.tar.gz" + dest: "{{remote_tmp_dir}}/test-unarchive-tar-gz" + remote_src: yes + keep_newer: true + register: unarchive02f + +- name: Make sure the file still contains 'boo' + shell: cat {{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt + register: unarchive02f_cat + +- name: remove our tar.gz unarchive destination + file: + path: "{{remote_tmp_dir}}/test-unarchive-tar-gz" + state: absent + +- name: create our tar.gz unarchive destination for keep-newer (take 2) + file: + path: "{{remote_tmp_dir}}/test-unarchive-tar-gz" + state: directory + +- name: unarchive a tar.gz file and overwrite newer files (keep_newer=false) + unarchive: + src: "{{remote_tmp_dir}}/test-unarchive.tar.gz" + dest: "{{remote_tmp_dir}}/test-unarchive-tar-gz" + remote_src: yes + keep_newer: false + register: unarchive02g + +- name: Make sure the file still contains 'boo' + shell: cat {{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt + register: unarchive02g_cat + +- name: remove our tar.gz unarchive destination + file: + path: "{{remote_tmp_dir}}/test-unarchive-tar-gz" + state: absent + +- name: verify results + assert: + that: + - unarchive02f is changed + - unarchive02f_cat.stdout == 'boo' + - unarchive02g is changed + - unarchive02g_cat.stdout != 'boo' diff --git a/test/integration/targets/unarchive/tasks/test_tar_gz_owner_group.yml b/test/integration/targets/unarchive/tasks/test_tar_gz_owner_group.yml new file mode 100644 index 0000000..e99f038 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_tar_gz_owner_group.yml @@ -0,0 +1,50 @@ +- block: + - name: Create a group to chown to + group: + name: testgroup + + - name: Create a user to chown to + user: + name: testuser + groups: + - testgroup + + - name: create our tar.gz unarchive destination for chown + file: + path: "{{remote_tmp_dir}}/test-unarchive-tar-gz" + state: directory + + - name: unarchive a tar.gz file with owner and group set to the above user + unarchive: + src: "{{remote_tmp_dir}}/test-unarchive.tar.gz" + dest: "{{remote_tmp_dir}}/test-unarchive-tar-gz" + remote_src: yes + owner: testuser + group: testgroup + register: unarchive02e + + - name: Stat a file in the directory we unarchived to + stat: + path: "{{remote_tmp_dir}}/test-unarchive-tar-gz/foo-unarchive.txt" + register: unarchive02e_file_stat + + - name: verify results + assert: + that: + - unarchive02e is changed + - unarchive02e_file_stat.stat.exists + - unarchive02e_file_stat.stat.pw_name == 'testuser' + - unarchive02e_file_stat.stat.gr_name == 'testgroup' + + always: + - name: Remove testuser + user: + name: testuser + state: absent + remove: yes + force: yes + + - name: Remove testgroup + group: + name: testgroup + state: absent diff --git a/test/integration/targets/unarchive/tasks/test_tar_zst.yml b/test/integration/targets/unarchive/tasks/test_tar_zst.yml new file mode 100644 index 0000000..18b1281 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_tar_zst.yml @@ -0,0 +1,40 @@ +# Only do this whole file when the "zstd" executable is present +- when: + - zstd_available.rc == 0 + - gnu_tar.stdout != "" + block: + - name: create our tar.zst unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-zst' + state: directory + + - name: unarchive a tar.zst file + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.tar.zst' + dest: '{{remote_tmp_dir}}/test-unarchive-tar-zst' + remote_src: yes + register: unarchive02 + + - name: verify that the file was marked as changed + assert: + that: + - "unarchive02.changed == true" + # Verify that no file list is generated + - "'files' not in unarchive02" + + - name: verify that the file was unarchived + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-zst/foo-unarchive.txt' + state: file + + - name: remove our tar.zst unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-tar-zst' + state: absent + + - name: test owner/group perms + include_tasks: test_owner_group.yml + vars: + ext: tar.zst + archive: test-unarchive.tar.zst + testfile: foo-unarchive.txt diff --git a/test/integration/targets/unarchive/tasks/test_unprivileged_user.yml b/test/integration/targets/unarchive/tasks/test_unprivileged_user.yml new file mode 100644 index 0000000..8ee1db4 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_unprivileged_user.yml @@ -0,0 +1,63 @@ +- name: Test unarchiving twice as unprivileged user + vars: + ansible_become: yes + ansible_become_user: "{{ test_user_name }}" + ansible_become_password: "{{ test_user_plaintext_password }}" + block: + - name: prep our file + copy: + src: foo.txt + dest: "{{ test_user.home }}/foo-unarchive.txt" + mode: preserve + + - name: Prep a zip file as {{ test_user.name }} user + shell: zip unarchivetest1-unarchive.zip foo-unarchive.txt + args: + chdir: "{{ test_user.home }}" + creates: "{{ test_user.home }}/unarchivetest1-unarchive.zip" + + - name: create our zip unarchive destination as {{ test_user.name }} user + file: + path: "{{ test_user.home }}/unarchivetest1-unarchive-zip" + state: directory + + - name: unarchive a zip file as {{ test_user.name }} user + unarchive: + src: "{{ test_user.home }}/unarchivetest1-unarchive.zip" + dest: "{{ test_user.home }}/unarchivetest1-unarchive-zip" + remote_src: yes + list_files: True + register: unarchive10 + + - name: stat the unarchived file + stat: + path: "{{ test_user.home }}/unarchivetest1-unarchive-zip/foo-unarchive.txt" + register: archive_path + + - name: verify that the tasks performed as expected + assert: + that: + - unarchive10 is changed + # Verify that file list is generated + - "'files' in unarchive10" + - "{{unarchive10['files']| length}} == 1" + - "'foo-unarchive.txt' in unarchive10['files']" + - archive_path.stat.exists + + - name: repeat the last request to verify no changes + unarchive: + src: "{{ test_user.home }}/unarchivetest1-unarchive.zip" + dest: "{{ test_user.home }}/unarchivetest1-unarchive-zip" + remote_src: yes + list_files: True + register: unarchive10b + + # Due to a bug in the date calculation used to determine if a change + # was made or not, this check is unreliable. This seems to only happen on + # Ubuntu 1604. + # https://github.com/ansible/ansible/blob/58145dff9ca1a713f8ed295a0076779a91c41cba/lib/ansible/modules/unarchive.py#L472-L474 + - name: Check that unarchiving again reports no change + assert: + that: + - unarchive10b is not changed + ignore_errors: yes diff --git a/test/integration/targets/unarchive/tasks/test_zip.yml b/test/integration/targets/unarchive/tasks/test_zip.yml new file mode 100644 index 0000000..cf03946 --- /dev/null +++ b/test/integration/targets/unarchive/tasks/test_zip.yml @@ -0,0 +1,57 @@ +- name: create our zip unarchive destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-zip' + state: directory + +- name: unarchive a zip file + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.zip' + dest: '{{remote_tmp_dir}}/test-unarchive-zip' + list_files: True + remote_src: yes + register: unarchive03 + +- name: verify that the file was marked as changed + assert: + that: + - "unarchive03.changed == true" + # Verify that file list is generated + - "'files' in unarchive03" + - "{{unarchive03['files']| length}} == 3" + - "'foo-unarchive.txt' in unarchive03['files']" + - "'foo-unarchive-777.txt' in unarchive03['files']" + - "'FOO-UNAR.TXT' in unarchive03['files']" + +- name: verify that the file was unarchived + file: + path: '{{remote_tmp_dir}}/test-unarchive-zip/{{item}}' + state: file + with_items: + - foo-unarchive.txt + - foo-unarchive-777.txt + - FOO-UNAR.TXT + +- name: repeat the last request to verify no changes + unarchive: + src: '{{remote_tmp_dir}}/test-unarchive.zip' + dest: '{{remote_tmp_dir}}/test-unarchive-zip' + list_files: true + remote_src: true + register: unarchive03b + +- name: verify that the task was not marked as changed + assert: + that: + - "unarchive03b.changed == false" + +- name: nuke zip destination + file: + path: '{{remote_tmp_dir}}/test-unarchive-zip' + state: absent + +- name: test owner/group perms + include_tasks: test_owner_group.yml + vars: + ext: zip + archive: test-unarchive.zip + testfile: foo-unarchive.txt diff --git a/test/integration/targets/unarchive/vars/Darwin.yml b/test/integration/targets/unarchive/vars/Darwin.yml new file mode 100644 index 0000000..902feed --- /dev/null +++ b/test/integration/targets/unarchive/vars/Darwin.yml @@ -0,0 +1 @@ +unarchive_packages: [] diff --git a/test/integration/targets/unarchive/vars/FreeBSD.yml b/test/integration/targets/unarchive/vars/FreeBSD.yml new file mode 100644 index 0000000..0f5c401 --- /dev/null +++ b/test/integration/targets/unarchive/vars/FreeBSD.yml @@ -0,0 +1,4 @@ +unarchive_packages: + - unzip + - zip + - zstd diff --git a/test/integration/targets/unarchive/vars/Linux.yml b/test/integration/targets/unarchive/vars/Linux.yml new file mode 100644 index 0000000..6110934 --- /dev/null +++ b/test/integration/targets/unarchive/vars/Linux.yml @@ -0,0 +1,4 @@ +unarchive_packages: + - tar + - unzip + - zip -- cgit v1.2.3