diff options
author | Abhijeet Kasurde <akasurde@redhat.com> | 2024-10-01 17:48:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-01 17:48:57 +0200 |
commit | 79e8c4c26c85f39101dad71ae4ecf468f939583b (patch) | |
tree | 2ef01c97466ca71c252b8131a68b69729721dba6 /test/units/modules | |
parent | Prevent condor from being installed and fulfilling libfmt dependency (#84023) (diff) | |
download | ansible-79e8c4c26c85f39101dad71ae4ecf468f939583b.tar.xz ansible-79e8c4c26c85f39101dad71ae4ecf468f939583b.zip |
debconf: set empty password value (#83217)
Fixes: #83214
---------
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Diffstat (limited to 'test/units/modules')
-rw-r--r-- | test/units/modules/test_debconf.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/units/modules/test_debconf.py b/test/units/modules/test_debconf.py new file mode 100644 index 0000000000..2ec1d6c29b --- /dev/null +++ b/test/units/modules/test_debconf.py @@ -0,0 +1,63 @@ +# Copyright: Contributors to the Ansible project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +from __future__ import annotations + +import pytest + +from ansible.modules.debconf import get_password_value + + +password_testdata = [ + pytest.param( + ( + "ddclient2 ddclient/password1 password Sample", + "ddclient2", + "ddclient/password1", + "password", + ), + "Sample", + id="valid_password", + ), + pytest.param( + ( + "ddclient2 ddclient/password1 password", + "ddclient2", + "ddclient/password1", + "password", + ), + '', + id="invalid_password", + ), + pytest.param( + ( + "ddclient2 ddclient/password password", + "ddclient2", + "ddclient/password1", + "password", + ), + '', + id="invalid_password_none", + ), + pytest.param( + ( + "ddclient2 ddclient/password", + "ddclient2", + "ddclient/password", + "password", + ), + '', + id="invalid_line", + ), +] + + +@pytest.mark.parametrize("test_input,expected", password_testdata) +def test_get_password_value(mocker, test_input, expected): + module = mocker.MagicMock() + mocker.patch.object( + module, "get_bin_path", return_value="/usr/bin/debconf-get-selections" + ) + mocker.patch.object(module, "run_command", return_value=(0, test_input[0], "")) + + res = get_password_value(module, *test_input[1:]) + assert res == expected |