From 70f4b7d6460f8fb9af614f7c99f065b5564d134d Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman <rjeffman@redhat.com> Date: Wed, 23 Feb 2022 18:08:22 -0300 Subject: [PATCH] ipauser: Refactor module due to fix on arguments comparison. Due to a change in 'ansible_freeipa_module.compare_args_ipa', playbook parameters using empty strings are correctly evaluated, and do not need to be removed before comparison is performed. A new test playbook, with tests for clearing attributes with an empty string ("") is available at: tests/user/test_user_empty_lists.yml --- plugins/modules/ipauser.py | 14 ------ tests/user/test_user_empty_lists.yml | 71 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 tests/user/test_user_empty_lists.yml diff --git a/plugins/modules/ipauser.py b/plugins/modules/ipauser.py index fb0fbc47..739b27b5 100644 --- a/plugins/modules/ipauser.py +++ b/plugins/modules/ipauser.py @@ -1103,20 +1103,6 @@ def main(): if "noprivate" in args: del args["noprivate"] - # Ignore sshpubkey if it is empty (for resetting) - # and not set in for the user - if "ipasshpubkey" not in res_find and \ - "ipasshpubkey" in args and \ - args["ipasshpubkey"] == ['']: - del args["ipasshpubkey"] - - # Ignore userauthtype if it is empty (for resetting) - # and not set in for the user - if "ipauserauthtype" not in res_find and \ - "ipauserauthtype" in args and \ - args["ipauserauthtype"] == ['']: - del args["ipauserauthtype"] - # For all settings is args, check if there are # different settings in the find result. # If yes: modify diff --git a/tests/user/test_user_empty_lists.yml b/tests/user/test_user_empty_lists.yml new file mode 100644 index 00000000..45bb829a --- /dev/null +++ b/tests/user/test_user_empty_lists.yml @@ -0,0 +1,71 @@ +--- +- name: Test users + hosts: "{{ ipa_test_host | default('ipaserver') }}" + become: no + gather_facts: no + + tasks: + # SETUP + - name: Remove test users + ipauser: + ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" + name: testuser + state: absent + + - name: Ensure user testuser is present + ipauser: + ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" + name: testuser + first: test + last: user + userauthtype: password,radius,otp + sshpubkey: + # yamllint disable-line rule:line-length + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCqmVDpEX5gnSjKuv97AyzOhaUMMKz8ahOA3GY77tVC4o68KNgMCmDSEG1/kOIaElngNLaCha3p/2iAcU9Bi1tLKUlm2bbO5NHNwHfRxY/3cJtq+/7D1vxJzqThYwI4F9vr1WxyY2+mMTv3pXbfAJoR8Mu06XaEY5PDetlDKjHLuNWF+/O7ZU8PsULTa1dJZFrtXeFpmUoLoGxQBvlrlcPI1zDciCSU24t27Zan5Py2l5QchyI7yhCyMM77KDtj5+AFVpmkb9+zq50rYJAyFVeyUvwjzErvQrKJzYpA0NyBp7vskWbt36M16/M/LxEK7HA6mkcakO3ESWx5MT1LAjvdlnxbWG3787MxweHXuB8CZU+9bZPFBaJ+VQtOfJ7I8eH0S16moPC4ak8FlcFvOH8ERDPWLFDqfy09yaZ7bVIF0//5ZI7Nf3YDe3S7GrBX5ieYuECyP6UNkTx9BRsAQeVvXEc6otzB7iCSnYBMGUGzCqeigoAWaVQUONsSR3Uatks= pinky@ipaserver.el81.local # noqa 204 + + # TESTS - action: user + - name: Ensure user testuser present with empty sshpubkey + ipauser: + ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" + name: testuser + sshpubkey: "" + register: result + failed_when: not result.changed or result.failed + + - name: Ensure user testuser present with empty sshpubkey, again + ipauser: + ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" + name: testuser + sshpubkey: "" + register: result + failed_when: result.changed or result.failed + + - name: Ensure user testuser present with empty userauthtype + ipauser: + ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" + name: testuser + userauthtype: "" + register: result + failed_when: not result.changed or result.failed + + - name: Ensure user testuser present with empty userauthtype, again + ipauser: + ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" + name: testuser + userauthtype: "" + register: result + failed_when: result.changed or result.failed + + # CLEANUP + - name: Remove test users + ipauser: + ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" + name: testuser + state: absent -- GitLab