diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 06:22:15 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 06:22:15 +0000 |
commit | 0202b47f95a87598276869ab7f07f57e8a4c8a87 (patch) | |
tree | 21f101dcceb98166b117c40dab3d79d5b2ad8eed /ansible_collections/community/hrobot/tests | |
parent | Adding upstream version 10.0.1+dfsg. (diff) | |
download | ansible-upstream.tar.xz ansible-upstream.zip |
Adding upstream version 10.1.0+dfsg.upstream/10.1.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/community/hrobot/tests')
-rw-r--r-- | ansible_collections/community/hrobot/tests/unit/plugins/modules/test_boot.py | 8 | ||||
-rw-r--r-- | ansible_collections/community/hrobot/tests/unit/plugins/plugin_utils/test_unsafe.py | 133 |
2 files changed, 138 insertions, 3 deletions
diff --git a/ansible_collections/community/hrobot/tests/unit/plugins/modules/test_boot.py b/ansible_collections/community/hrobot/tests/unit/plugins/modules/test_boot.py index 7117afb21..87842fbaf 100644 --- a/ansible_collections/community/hrobot/tests/unit/plugins/modules/test_boot.py +++ b/ansible_collections/community/hrobot/tests/unit/plugins/modules/test_boot.py @@ -473,9 +473,11 @@ class TestHetznerBoot(BaseTestModule): .expect_form_value('dist', 'Debian 11 base') .expect_form_value('arch', '32') .expect_form_value('lang', 'fr') - .expect_form_present('authorized_key') - # .expect_form_value('authorized_key', 'e4:47:42:71:81:62:bf:06:1c:23:fa:f3:8f:7b:6f:d0') - # .expect_form_value('authorized_key', 'aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99') + .expect_form_present('authorized_key[]') + .expect_form_values('authorized_key[]', [ + 'e4:47:42:71:81:62:bf:06:1c:23:fa:f3:8f:7b:6f:d0', + 'aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99', + ]) .result_json({ 'linux': create_linux_active(dist='Debian 11 base', lang='fr', arch=32, authorized_key=[ { diff --git a/ansible_collections/community/hrobot/tests/unit/plugins/plugin_utils/test_unsafe.py b/ansible_collections/community/hrobot/tests/unit/plugins/plugin_utils/test_unsafe.py new file mode 100644 index 000000000..f33318a71 --- /dev/null +++ b/ansible_collections/community/hrobot/tests/unit/plugins/plugin_utils/test_unsafe.py @@ -0,0 +1,133 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2024, Felix Fontein <felix@fontein.de> +# 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 + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + + +import pytest + +from ansible.utils.unsafe_proxy import AnsibleUnsafe + +from ansible_collections.community.hrobot.plugins.plugin_utils.unsafe import ( + make_unsafe, +) + + +TEST_MAKE_UNSAFE = [ + ( + u'text', + [], + [ + (), + ], + ), + ( + u'{{text}}', + [ + (), + ], + [], + ), + ( + b'text', + [], + [ + (), + ], + ), + ( + b'{{text}}', + [ + (), + ], + [], + ), + ( + { + 'skey': 'value', + 'ukey': '{{value}}', + 1: [ + 'value', + '{{value}}', + { + 1.0: '{{value}}', + 2.0: 'value', + }, + ], + }, + [ + ('ukey', ), + (1, 1), + (1, 2, 1.0), + ], + [ + ('skey', ), + (1, 0), + (1, 2, 2.0), + ], + ), + ( + ['value', '{{value}}'], + [ + (1, ), + ], + [ + (0, ), + ], + ), +] + + +@pytest.mark.parametrize("value, check_unsafe_paths, check_safe_paths", TEST_MAKE_UNSAFE) +def test_make_unsafe(value, check_unsafe_paths, check_safe_paths): + unsafe_value = make_unsafe(value) + assert unsafe_value == value + for check_path in check_unsafe_paths: + obj = unsafe_value + for elt in check_path: + obj = obj[elt] + assert isinstance(obj, AnsibleUnsafe) + for check_path in check_safe_paths: + obj = unsafe_value + for elt in check_path: + obj = obj[elt] + assert not isinstance(obj, AnsibleUnsafe) + + +def test_make_unsafe_dict_key(): + value = { + b'test': 1, + u'test': 2, + } + unsafe_value = make_unsafe(value) + assert unsafe_value == value + for obj in unsafe_value: + assert not isinstance(obj, AnsibleUnsafe) + + value = { + b'{{test}}': 1, + u'{{test}}': 2, + } + unsafe_value = make_unsafe(value) + assert unsafe_value == value + for obj in unsafe_value: + assert isinstance(obj, AnsibleUnsafe) + + +def test_make_unsafe_set(): + value = set([b'test', u'test']) + unsafe_value = make_unsafe(value) + assert unsafe_value == value + for obj in unsafe_value: + assert not isinstance(obj, AnsibleUnsafe) + + value = set([b'{{test}}', u'{{test}}']) + unsafe_value = make_unsafe(value) + assert unsafe_value == value + for obj in unsafe_value: + assert isinstance(obj, AnsibleUnsafe) |