From feb8d421dcd006eb498b8086eaf8a9bab53dc0ec Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:31:27 +0200 Subject: [PATCH] [PR #6847/41e3f4d5 backport][stable-6] htpasswd: add integration tests (#6849) htpasswd: add integration tests (#6847) (cherry picked from commit 41e3f4d5fa024ffe716f16ac8157c0a793d5081e) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- tests/integration/targets/htpasswd/aliases | 7 ++ .../targets/htpasswd/handlers/main.yml | 9 ++ .../targets/htpasswd/meta/main.yml | 7 ++ .../targets/htpasswd/tasks/main.yml | 83 +++++++++++++++++++ .../targets/htpasswd/vars/main.yml | 6 ++ 5 files changed, 112 insertions(+) create mode 100644 tests/integration/targets/htpasswd/aliases create mode 100644 tests/integration/targets/htpasswd/handlers/main.yml create mode 100644 tests/integration/targets/htpasswd/meta/main.yml create mode 100644 tests/integration/targets/htpasswd/tasks/main.yml create mode 100644 tests/integration/targets/htpasswd/vars/main.yml diff --git a/tests/integration/targets/htpasswd/aliases b/tests/integration/targets/htpasswd/aliases new file mode 100644 index 0000000000..e3339b2106 --- /dev/null +++ b/tests/integration/targets/htpasswd/aliases @@ -0,0 +1,7 @@ +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +azp/posix/2 +destructive +needs/root diff --git a/tests/integration/targets/htpasswd/handlers/main.yml b/tests/integration/targets/htpasswd/handlers/main.yml new file mode 100644 index 0000000000..6befa0cd32 --- /dev/null +++ b/tests/integration/targets/htpasswd/handlers/main.yml @@ -0,0 +1,9 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: remove passlib + ansible.builtin.pip: + name: passlib + state: absent diff --git a/tests/integration/targets/htpasswd/meta/main.yml b/tests/integration/targets/htpasswd/meta/main.yml new file mode 100644 index 0000000000..982de6eb03 --- /dev/null +++ b/tests/integration/targets/htpasswd/meta/main.yml @@ -0,0 +1,7 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +dependencies: + - setup_remote_tmp_dir diff --git a/tests/integration/targets/htpasswd/tasks/main.yml b/tests/integration/targets/htpasswd/tasks/main.yml new file mode 100644 index 0000000000..7b5dc3c511 --- /dev/null +++ b/tests/integration/targets/htpasswd/tasks/main.yml @@ -0,0 +1,83 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: install passlib + ansible.builtin.pip: + name: passlib + notify: remove passlib + +- name: add bob (check mode) + community.general.htpasswd: + path: "{{ htpasswd_path }}" + name: bob + password: c00lbob + check_mode: true + register: add_bob_check + +- name: add bob + community.general.htpasswd: + path: "{{ htpasswd_path }}" + name: bob + password: c00lbob + register: add_bob + +- name: add bob (idempotency) + community.general.htpasswd: + path: "{{ htpasswd_path }}" + name: bob + password: c00lbob + register: add_bob_idempot + +- name: add bob new password + community.general.htpasswd: + path: "{{ htpasswd_path }}" + name: bob + password: SUPERsecret + register: add_bob_newpw + +- name: add bob new password (idempotency) + community.general.htpasswd: + path: "{{ htpasswd_path }}" + name: bob + password: SUPERsecret + register: add_bob_newpw_idempot + +- name: test add bob assertions + ansible.builtin.assert: + that: + - add_bob_check is changed + - add_bob is changed + - add_bob_idempot is not changed + - add_bob_newpw is changed + - add_bob_newpw_idempot is not changed + +- name: remove bob (check mode) + community.general.htpasswd: + path: "{{ htpasswd_path }}" + name: bob + state: absent + check_mode: true + register: del_bob_check + +- name: remove bob + community.general.htpasswd: + path: "{{ htpasswd_path }}" + name: bob + state: absent + register: del_bob + +- name: remove bob (idempotency) + community.general.htpasswd: + path: "{{ htpasswd_path }}" + name: bob + state: absent + register: del_bob_idempot + +- name: test remove bob assertions + ansible.builtin.assert: + that: + - del_bob_check is changed + - del_bob is changed + - del_bob_idempot is not changed diff --git a/tests/integration/targets/htpasswd/vars/main.yml b/tests/integration/targets/htpasswd/vars/main.yml new file mode 100644 index 0000000000..ff81959c4f --- /dev/null +++ b/tests/integration/targets/htpasswd/vars/main.yml @@ -0,0 +1,6 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +htpasswd_path: "{{ remote_tmp_dir }}/dot_htpasswd"