mirror of
https://github.com/ansible-middleware/keycloak.git
synced 2026-11-23 15:40:35 +00:00
Merge pull request #407 from Yabk/bugfix/keycloak_group_parents
keycloak_group: fix subgroup lookup on Keycloak older than 25
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
client: molecule-client
|
||||
scope: molecule-scope
|
||||
group: molecule-group
|
||||
subgroup: molecule-subgroup
|
||||
user: molecule-user
|
||||
flow: molecule-flow
|
||||
flow_v2: molecule-flow-v2
|
||||
@@ -559,6 +560,61 @@
|
||||
roles:
|
||||
- name: "{{ client_role }}"
|
||||
|
||||
- name: keycloak_group — create subgroup below the parent group
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
realm: "{{ target_realm }}"
|
||||
name: "{{ subgroup }}"
|
||||
parents:
|
||||
- name: "{{ group }}"
|
||||
state: present
|
||||
register: subgroup_result
|
||||
|
||||
- name: Assert subgroup was created below the parent group
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- subgroup_result is changed
|
||||
- subgroup_result.end_state.path == '/' ~ group ~ '/' ~ subgroup
|
||||
|
||||
- name: keycloak_group — create enough siblings to exceed the children page size
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
realm: "{{ target_realm }}"
|
||||
name: "{{ subgroup }}-{{ item }}"
|
||||
parents:
|
||||
- name: "{{ group }}"
|
||||
state: present
|
||||
loop: "{{ range(1, 13) | list }}"
|
||||
|
||||
- name: keycloak_group — look up a subgroup sorting past the children page size
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
realm: "{{ target_realm }}"
|
||||
name: "{{ subgroup }}-9"
|
||||
parents:
|
||||
- name: "{{ group }}"
|
||||
state: present
|
||||
register: subgroup_paging_result
|
||||
|
||||
- name: Assert subgroup lookup is not limited to the first page of children
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- subgroup_paging_result is not changed
|
||||
- subgroup_paging_result.end_state.path == '/' ~ group ~ '/' ~ subgroup ~ '-9'
|
||||
|
||||
- name: keycloak_realm_rolemapping — assign realm role to subgroup via parents
|
||||
middleware_automation.keycloak.keycloak_realm_rolemapping:
|
||||
realm: "{{ target_realm }}"
|
||||
group_name: "{{ subgroup }}"
|
||||
parents:
|
||||
- name: "{{ group }}"
|
||||
state: present
|
||||
roles:
|
||||
- name: "{{ role }}"
|
||||
register: subgroup_rolemapping_result
|
||||
|
||||
- name: Assert realm role was mapped to the subgroup
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- subgroup_rolemapping_result is changed
|
||||
|
||||
- name: keycloak_client_rolescope — restrict realm role on client
|
||||
middleware_automation.keycloak.keycloak_client_rolescope:
|
||||
realm: "{{ target_realm }}"
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
keycloak_admin_user: "admin"
|
||||
keycloak_uri: "http://localhost:8080"
|
||||
keycloak_context: "/auth"
|
||||
parent_group: molecule-parent-group
|
||||
child_group: molecule-child-group
|
||||
tasks:
|
||||
- name: Populate service facts
|
||||
ansible.builtin.service_facts:
|
||||
@@ -24,3 +26,53 @@
|
||||
until: keycloak_auth_response.status == 200
|
||||
retries: 2
|
||||
delay: 2
|
||||
|
||||
# This Keycloak is older than 23, so its group children endpoint accepts no
|
||||
# GET request and the subgroup lookup has to fall back to the subgroups
|
||||
# inlined in the parent group representation.
|
||||
- name: Verify subgroup handling on a pre-23 Keycloak
|
||||
module_defaults:
|
||||
group/middleware_automation.keycloak.keycloak:
|
||||
auth_keycloak_url: "{{ keycloak_uri }}{{ keycloak_context }}"
|
||||
auth_realm: master
|
||||
auth_username: "{{ keycloak_admin_user }}"
|
||||
auth_password: "{{ keycloak_admin_password }}"
|
||||
validate_certs: false
|
||||
realm: master
|
||||
block:
|
||||
- name: keycloak_group — create parent group
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
name: "{{ parent_group }}"
|
||||
state: present
|
||||
|
||||
- name: keycloak_group — create subgroup below the parent group
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
name: "{{ child_group }}"
|
||||
parents:
|
||||
- name: "{{ parent_group }}"
|
||||
state: present
|
||||
register: subgroup_result
|
||||
|
||||
- name: Assert subgroup was created below the parent group
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- subgroup_result is changed
|
||||
- subgroup_result.end_state.path == '/' ~ parent_group ~ '/' ~ child_group
|
||||
|
||||
- name: keycloak_group — look the subgroup up through parents again
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
name: "{{ child_group }}"
|
||||
parents:
|
||||
- name: "{{ parent_group }}"
|
||||
state: present
|
||||
register: subgroup_lookup_result
|
||||
|
||||
- name: Assert the existing subgroup was found instead of re-created
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- subgroup_lookup_result is not changed
|
||||
always:
|
||||
- name: keycloak_group — remove parent group and its subtree
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
name: "{{ parent_group }}"
|
||||
state: absent
|
||||
|
||||
Reference in New Issue
Block a user