mirror of
https://github.com/ansible-middleware/keycloak.git
synced 2026-11-21 14:48:50 +00:00
Port integration tests from community.general keycloak modules into the keycloak collection molecule test framework (keycloak_modules scenario), adapting for KC 26.x behavioral changes and middleware module differences. Ported modules: keycloak_authentication, keycloak_authz_authorization_scope, keycloak_authz_permission, keycloak_client, keycloak_client_rolescope, keycloak_client_scope_rolemappings, keycloak_client_scope_type, keycloak_clientsecret_info, keycloak_clientsecret_regenerate, keycloak_component_info, keycloak_group, keycloak_group_rolemapping, keycloak_identity_provider, keycloak_modules_authentication, keycloak_realm, keycloak_realm_key, keycloak_realm_users_info, keycloak_role, keycloak_user, keycloak_user_federation, keycloak_user_rolemapping, keycloak_userprofile. KC 26.x adaptations: - serviceAccountsEnabled defaults to true on new clients - Default Policy/Resource no longer auto-created for authz clients - Built-in admin role rejects PUT updates (403) - Invalid credentials return HTTP 400 instead of 401 - LDAP federation no longer auto-creates mappers Other fixes: - Variable collision avoidance (role/group/client register overwriting play-level vars via include_vars) - Ansible 2.19+ native Jinja dict handling (endpoint combine filter) - Jinja embedded template warnings in assert expressions - Auth fallback prevention in invalid-token tests
142 lines
4.7 KiB
YAML
142 lines
4.7 KiB
YAML
---
|
|
# Ported from community.general tests/integration/targets/keycloak_user_rolemapping
|
|
# Tests service account role mapping (realm and client roles) and cross-client mapping.
|
|
|
|
- name: Load user rolemapping test variables
|
|
ansible.builtin.include_vars:
|
|
file: vars.yml
|
|
|
|
- name: Create client with service account for rolemapping test
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
service_accounts_enabled: true
|
|
state: present
|
|
register: rolemapping_client
|
|
|
|
- name: Create realm role for service account mapping
|
|
middleware_automation.keycloak.keycloak_role:
|
|
realm: "{{ ephemeral_realm }}"
|
|
name: "{{ test_role }}"
|
|
description: "{{ description_1 }}"
|
|
state: present
|
|
|
|
- name: Map realm role to client service account
|
|
middleware_automation.keycloak.keycloak_user_rolemapping:
|
|
realm: "{{ ephemeral_realm }}"
|
|
service_account_user_client_id: "{{ client_id }}"
|
|
roles:
|
|
- name: "{{ test_role }}"
|
|
state: present
|
|
register: result
|
|
|
|
- name: Assert realm role is assigned to service account
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result is changed
|
|
- result.end_state | selectattr("clientRole", "eq", false) | selectattr("name", "eq", test_role) | list | count > 0
|
|
|
|
- name: Unmap realm role from client service account
|
|
middleware_automation.keycloak.keycloak_user_rolemapping:
|
|
realm: "{{ ephemeral_realm }}"
|
|
service_account_user_client_id: "{{ client_id }}"
|
|
roles:
|
|
- name: "{{ test_role }}"
|
|
state: absent
|
|
register: result
|
|
|
|
- name: Assert realm role is unassigned from service account
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result is changed
|
|
- (result.end_state | length) == (result.existing | length) - 1
|
|
- result.existing | selectattr("clientRole", "eq", false) | selectattr("name", "eq", test_role) | list | count > 0
|
|
- result.end_state | selectattr("clientRole", "eq", false) | selectattr("name", "eq", test_role) | list | count == 0
|
|
|
|
- name: Delete existing realm role
|
|
middleware_automation.keycloak.keycloak_role:
|
|
realm: "{{ ephemeral_realm }}"
|
|
name: "{{ test_role }}"
|
|
state: absent
|
|
|
|
- name: Create second client for cross-client role mapping test
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id_2 }}"
|
|
service_accounts_enabled: true
|
|
state: present
|
|
register: client_2
|
|
|
|
- name: Create new client role
|
|
middleware_automation.keycloak.keycloak_role:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
name: "{{ test_role }}"
|
|
description: "{{ description_1 }}"
|
|
state: present
|
|
|
|
- name: Map client role to user with no existing roles for that client
|
|
middleware_automation.keycloak.keycloak_user_rolemapping:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
service_account_user_client_id: "{{ client_id_2 }}"
|
|
roles:
|
|
- name: "{{ test_role }}"
|
|
state: present
|
|
register: result
|
|
|
|
- name: Assert client role is assigned to user with no prior roles
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result is changed
|
|
- result.end_state | selectattr("clientRole", "eq", true) | selectattr("name", "eq", test_role) | list | count > 0
|
|
|
|
- name: Unmap the cross-client role mapping
|
|
middleware_automation.keycloak.keycloak_user_rolemapping:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
service_account_user_client_id: "{{ client_id_2 }}"
|
|
roles:
|
|
- name: "{{ test_role }}"
|
|
state: absent
|
|
register: result
|
|
|
|
- name: Assert cross-client role mapping is removed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result is changed
|
|
- result.end_state == []
|
|
|
|
- name: Map client role to client service account
|
|
middleware_automation.keycloak.keycloak_user_rolemapping:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
service_account_user_client_id: "{{ client_id }}"
|
|
roles:
|
|
- name: "{{ test_role }}"
|
|
state: present
|
|
register: result
|
|
|
|
- name: Assert client role is assigned
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result is changed
|
|
- result.end_state | selectattr("clientRole", "eq", true) | selectattr("name", "eq", test_role) | list | count > 0
|
|
|
|
- name: Unmap client role from client service account
|
|
middleware_automation.keycloak.keycloak_user_rolemapping:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
service_account_user_client_id: "{{ client_id }}"
|
|
roles:
|
|
- name: "{{ test_role }}"
|
|
state: absent
|
|
register: result
|
|
|
|
- name: Assert client role is unassigned
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result is changed
|
|
- result.end_state == []
|
|
- result.existing | selectattr("clientRole", "eq", true) | selectattr("name", "eq", test_role) | list | count > 0
|