mirror of
https://github.com/ansible-middleware/keycloak.git
synced 2026-11-23 15:40:35 +00:00
keycloak_user: fix check mode reporting changed=True for every existing user
In check mode, the desired group memberships were built as a set and compared with the stored memberships, a list, through is_struct_included(). It has no branch for sets and falls back to comparing their string forms, which never match, so check mode reported a change for every existing user, with or without groups. Check mode now decides like normal mode: a group given by name or by path counts as joined when the user is already a member. That rule moves from update_user_groups_membership() into filter_groups_to_add_to_and_remove_from_user(), which both modes use, and the groups reported in check mode no longer list a group given by path twice. Add check mode tests, including groups given by path. Fixes #442 Signed-off-by: Filipe Rosa Capela <Filipe.Capela-CIC.Netherlands1@ibm.com>
This commit is contained in:
@@ -219,3 +219,129 @@
|
||||
that:
|
||||
- create_result.changed
|
||||
- create_result.end_state.requiredActions == []
|
||||
|
||||
- name: Create user for check mode tests
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
username: check-mode-user
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
state: present
|
||||
|
||||
- name: Re-run with identical input in check mode
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
username: check-mode-user
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
state: present
|
||||
check_mode: true
|
||||
register: check_mode_result
|
||||
|
||||
- name: Assert check mode reports no change for identical input
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- check_mode_result is not changed
|
||||
|
||||
- name: Add the user to a group
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
username: check-mode-user
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
groups:
|
||||
- name: test
|
||||
state: present
|
||||
|
||||
- name: Re-run with identical groups in check mode
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
username: check-mode-user
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
groups:
|
||||
- name: test
|
||||
state: present
|
||||
check_mode: true
|
||||
register: check_mode_result
|
||||
|
||||
- name: Assert check mode reports no change for identical groups
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- check_mode_result is not changed
|
||||
|
||||
- name: Join a second group in check mode
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
username: check-mode-user
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
groups:
|
||||
- name: test
|
||||
- name: test2
|
||||
state: present
|
||||
check_mode: true
|
||||
register: check_mode_result
|
||||
|
||||
- name: Assert check mode reports joining a group as a change
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- check_mode_result is changed
|
||||
|
||||
- name: Create a parent group and a subgroup for check mode tests
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
name: "{{ item.name }}"
|
||||
parents: "{{ item.parents | default(omit) }}"
|
||||
state: present
|
||||
loop:
|
||||
- name: check-mode-parent
|
||||
- name: check-mode-child
|
||||
parents:
|
||||
- name: check-mode-parent
|
||||
|
||||
- name: Add the user to the subgroup by path
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
username: check-mode-user
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
groups:
|
||||
- name: test
|
||||
- name: /check-mode-parent/check-mode-child
|
||||
state: present
|
||||
|
||||
- name: Re-run with identical groups given by path in check mode
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
username: check-mode-user
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
groups:
|
||||
- name: test
|
||||
- name: /check-mode-parent/check-mode-child
|
||||
state: present
|
||||
check_mode: true
|
||||
register: check_mode_result
|
||||
|
||||
- name: Assert check mode reports no change for identical groups given by path
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- check_mode_result is not changed
|
||||
- check_mode_result.end_state.groups | sort == ['check-mode-child', 'test']
|
||||
|
||||
- name: Leave the subgroup by path in check mode
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
username: check-mode-user
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
groups:
|
||||
- name: test
|
||||
- name: /check-mode-parent/check-mode-child
|
||||
state: absent
|
||||
state: present
|
||||
check_mode: true
|
||||
register: check_mode_result
|
||||
|
||||
- name: Assert check mode reports leaving a group given by path as a change
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- check_mode_result is changed
|
||||
- check_mode_result.end_state.groups == ['test']
|
||||
|
||||
- name: Delete user for check mode tests
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
username: check-mode-user
|
||||
realm: "{{ ephemeral_realm }}"
|
||||
state: absent
|
||||
register: check_mode_delete_result
|
||||
|
||||
- name: Assert user for check mode tests is deleted
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- check_mode_delete_result.changed
|
||||
|
||||
Reference in New Issue
Block a user