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
410 lines
16 KiB
YAML
410 lines
16 KiB
YAML
---
|
|
# Ported from community.general tests/integration/targets/keycloak_client
|
|
# Tests protocol_mapper CRUD, flow binding overrides, client_scopes_behavior,
|
|
# attribute updates, and post-logout redirect URIs / backchannel logout URL.
|
|
|
|
- name: Load client test variables
|
|
ansible.builtin.include_vars:
|
|
file: vars.yml
|
|
|
|
# --- Protocol mapper create, idempotency, and modification ---
|
|
|
|
- name: Desire client
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers1 }}"
|
|
register: desire_client_not_present
|
|
|
|
- name: Desire client again with same props
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers1 }}"
|
|
register: desire_client_when_present_and_same
|
|
|
|
- name: Check client again with same props
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers2_unordered }}"
|
|
authorization_services_enabled: false
|
|
check_mode: true
|
|
register: check_client_when_present_and_same
|
|
|
|
- name: Assert changes not detected in last two tasks (desire when same, and check)
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_when_present_and_same is not changed
|
|
- check_client_when_present_and_same is not changed
|
|
|
|
- name: Check client again with changed props
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers1 }}"
|
|
authorization_services_enabled: false
|
|
service_accounts_enabled: false
|
|
check_mode: true
|
|
register: check_client_when_present_and_changed
|
|
|
|
- name: Assert changes detected in last tasks
|
|
ansible.builtin.assert:
|
|
that:
|
|
- check_client_when_present_and_changed is changed
|
|
|
|
- name: Check client with modified protocol_mappers idempotence
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers3_modifed }}"
|
|
authorization_services_enabled: false
|
|
service_accounts_enabled: true
|
|
register: check_client_protocol_mappers_idempotence
|
|
|
|
- name: Assert idempotence changes to protocol_mappers
|
|
ansible.builtin.assert:
|
|
that:
|
|
- check_client_protocol_mappers_idempotence is changed
|
|
- end_state.protocolMappers | length == 3
|
|
- end_state.protocolMappers | selectattr('name', 'equalto', 'email_verified') | list | length == 0
|
|
- end_state.protocolMappers | selectattr('name', 'equalto', 'address') | list | length == 1
|
|
- end_state.protocolMappers | selectattr('name', 'equalto', 'email') | list | length == 1
|
|
- end_state.protocolMappers | selectattr('name', 'equalto', 'family_name') | list | length == 1
|
|
- email.config is defined
|
|
- email.config['access.token.claim'] == "false"
|
|
vars:
|
|
end_state: "{{ check_client_protocol_mappers_idempotence.end_state }}"
|
|
email: "{{ end_state.protocolMappers | selectattr('name', 'equalto', 'email') | first | default({}) }}"
|
|
|
|
# --- Flow binding overrides ---
|
|
|
|
- name: Desire client with flow binding overrides
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers1 }}"
|
|
authentication_flow_binding_overrides:
|
|
browser_name: browser
|
|
direct_grant_name: direct grant
|
|
register: desire_client_with_flow_binding_overrides
|
|
|
|
- name: Assert flows are set
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_flow_binding_overrides is changed
|
|
- "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
|
|
- desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.browser | length > 0
|
|
- desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.direct_grant | length > 0
|
|
|
|
- name: Backup flow UUIDs
|
|
ansible.builtin.set_fact:
|
|
flow_browser_uuid: "{{ desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.browser }}"
|
|
flow_direct_grant_uuid: "{{ desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.direct_grant }}"
|
|
|
|
- name: Desire client with flow binding overrides remove direct_grant_name
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers1 }}"
|
|
authentication_flow_binding_overrides:
|
|
browser_name: browser
|
|
register: desire_client_with_flow_binding_overrides
|
|
|
|
- name: Assert flows are updated
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_flow_binding_overrides is changed
|
|
- "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
|
|
- desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.browser | length > 0
|
|
- "'direct_grant' not in desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides"
|
|
|
|
- name: Desire client with flow binding overrides remove browser add direct_grant
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers1 }}"
|
|
authentication_flow_binding_overrides:
|
|
direct_grant_name: direct grant
|
|
register: desire_client_with_flow_binding_overrides
|
|
|
|
- name: Assert flows are updated
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_flow_binding_overrides is changed
|
|
- "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
|
|
- "'browser' not in desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides"
|
|
- desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.direct_grant | length > 0
|
|
|
|
- name: Desire client with flow binding overrides with UUIDs
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers1 }}"
|
|
authentication_flow_binding_overrides:
|
|
browser: "{{ flow_browser_uuid }}"
|
|
direct_grant: "{{ flow_direct_grant_uuid }}"
|
|
register: desire_client_with_flow_binding_overrides
|
|
|
|
- name: Assert flows are updated
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_flow_binding_overrides is changed
|
|
- "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
|
|
- desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.browser == flow_browser_uuid
|
|
- desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.direct_grant == flow_direct_grant_uuid
|
|
|
|
- name: Unset flow binding overrides
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id }}"
|
|
state: present
|
|
redirect_uris: "{{ redirect_uris1 }}"
|
|
attributes: "{{ client_attributes1 }}"
|
|
protocol_mappers: "{{ protocol_mappers1 }}"
|
|
authentication_flow_binding_overrides:
|
|
browser: "{{ None }}"
|
|
direct_grant: null
|
|
register: desire_client_with_flow_binding_overrides
|
|
|
|
- name: Assert flows are removed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_flow_binding_overrides is changed
|
|
- "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
|
|
- "'browser' not in desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides"
|
|
- "'direct_grant' not in desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides"
|
|
|
|
# --- Client scopes behavior ---
|
|
|
|
- name: Create a scope1 client scope
|
|
middleware_automation.keycloak.keycloak_client_scope:
|
|
realm: "{{ ephemeral_realm }}"
|
|
name: scope1
|
|
description: "test 1"
|
|
protocol: openid-connect
|
|
|
|
- name: Create a scope2 client scope
|
|
middleware_automation.keycloak.keycloak_client_scope:
|
|
realm: "{{ ephemeral_realm }}"
|
|
name: scope2
|
|
description: "test 2"
|
|
protocol: openid-connect
|
|
|
|
- name: Create a scope3 client scope
|
|
middleware_automation.keycloak.keycloak_client_scope:
|
|
realm: "{{ ephemeral_realm }}"
|
|
name: scope3
|
|
description: "test 3"
|
|
protocol: openid-connect
|
|
|
|
- name: Create Keycloak client with default_client_scopes (idempotent behavior)
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_scopes_behavior: idempotent
|
|
default_client_scopes: ['scope1']
|
|
optional_client_scopes: ['scope2']
|
|
client_id: testSD-bug
|
|
state: present
|
|
register: desire_client_with_default_client_scopes
|
|
|
|
- name: Assert default_client_scopes and optional_client_scopes are set correctly
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_default_client_scopes is changed
|
|
- '"scope1" in end_state.defaultClientScopes'
|
|
- '"scope2" in end_state.optionalClientScopes'
|
|
- end_state.defaultClientScopes | length == 1
|
|
- end_state.optionalClientScopes | length == 1
|
|
vars:
|
|
end_state: "{{ desire_client_with_default_client_scopes.end_state }}"
|
|
|
|
- name: Update Keycloak client with new scopes (ignore behavior, check mode)
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
default_client_scopes: ['scope3']
|
|
optional_client_scopes: ['scope3']
|
|
client_id: testSD-bug
|
|
state: present
|
|
check_mode: true
|
|
register: desire_client_with_default_client_scopes
|
|
|
|
- name: Assert client scopes remain unchanged with ignore behavior
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_default_client_scopes is not changed
|
|
- end_state.defaultClientScopes | length == 1
|
|
- end_state.optionalClientScopes | length == 1
|
|
- '"scope1" in end_state.defaultClientScopes'
|
|
- '"scope2" in end_state.optionalClientScopes'
|
|
vars:
|
|
end_state: "{{ desire_client_with_default_client_scopes.end_state }}"
|
|
|
|
- name: Update Keycloak client with conflicting scopes (patch behavior, should fail)
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_scopes_behavior: patch
|
|
default_client_scopes: ['scope3']
|
|
optional_client_scopes: ['scope1', 'scope2', 'scope3']
|
|
client_id: testSD-bug
|
|
state: present
|
|
ignore_errors: true
|
|
register: desire_client_with_default_client_scopes
|
|
|
|
- name: Assert patch behavior fails when scope is both default and optional
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_default_client_scopes is failed
|
|
- "'scope3' in desire_client_with_default_client_scopes.msg"
|
|
|
|
- name: Update Keycloak client with new scopes (patch behavior)
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_scopes_behavior: patch
|
|
default_client_scopes: ['scope1', 'scope3']
|
|
optional_client_scopes: []
|
|
client_id: testSD-bug
|
|
state: present
|
|
register: desire_client_with_default_client_scopes
|
|
|
|
- name: Assert client scopes are patched correctly
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_default_client_scopes is changed
|
|
- end_state.defaultClientScopes | length == 2
|
|
- end_state.optionalClientScopes | length == 1
|
|
- '"scope1" in end_state.defaultClientScopes'
|
|
- '"scope3" in end_state.defaultClientScopes'
|
|
- '"scope2" in end_state.optionalClientScopes'
|
|
vars:
|
|
end_state: "{{ desire_client_with_default_client_scopes.end_state }}"
|
|
|
|
- name: Update Keycloak client with empty default_client_scopes (idempotent behavior)
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_scopes_behavior: idempotent
|
|
default_client_scopes: []
|
|
optional_client_scopes: ['scope3']
|
|
client_id: testSD-bug
|
|
state: present
|
|
register: desire_client_with_default_client_scopes
|
|
|
|
- name: Assert idempotent behavior with empty default_client_scopes
|
|
ansible.builtin.assert:
|
|
that:
|
|
- desire_client_with_default_client_scopes is changed
|
|
- end_state.defaultClientScopes | length == 0
|
|
- end_state.optionalClientScopes | length == 1
|
|
- '"scope3" in end_state.optionalClientScopes'
|
|
vars:
|
|
end_state: "{{ desire_client_with_default_client_scopes.end_state }}"
|
|
|
|
# --- Attribute updates ---
|
|
|
|
- name: Create client with initial attributes
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id_2 }}"
|
|
state: present
|
|
attributes: "{{ client_attributes1 }}"
|
|
register: check_client_when_present_and_attributes_modified
|
|
|
|
- name: Update client attributes
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: "{{ client_id_2 }}"
|
|
state: present
|
|
attributes: "{{ client_attributes2 }}"
|
|
register: check_client_when_present_and_attributes_modified
|
|
|
|
- name: Assert client attributes are updated
|
|
ansible.builtin.assert:
|
|
that:
|
|
- check_client_when_present_and_attributes_modified is changed
|
|
- end_state.attributes["backchannel.logout.revoke.offline.tokens"] == 'false'
|
|
- end_state.attributes["backchannel.logout.session.required"] == 'false'
|
|
- end_state.attributes["oauth2.device.authorization.grant.enabled"] == 'false'
|
|
vars:
|
|
end_state: "{{ check_client_when_present_and_attributes_modified.end_state }}"
|
|
|
|
# --- Post-logout redirect URIs and backchannel logout URL ---
|
|
|
|
- name: Create client with post logout redirect URIs and backchannel logout URL
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: logout-test-client
|
|
valid_post_logout_redirect_uris: "{{ post_logout_redirect_uris }}"
|
|
backchannel_logout_url: "{{ backchannel_logout_url }}"
|
|
state: present
|
|
register: result_create_logout_client
|
|
|
|
- name: Assert logout client is created with correct attributes
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result_create_logout_client is changed
|
|
- result_create_logout_client.end_state.attributes["post.logout.redirect.uris"] is defined
|
|
- result_create_logout_client.end_state.attributes["backchannel.logout.url"] == backchannel_logout_url
|
|
|
|
- name: Re-create client with same logout fields (idempotency)
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: logout-test-client
|
|
valid_post_logout_redirect_uris: "{{ post_logout_redirect_uris }}"
|
|
backchannel_logout_url: "{{ backchannel_logout_url }}"
|
|
state: present
|
|
register: result_idempotent_logout_client
|
|
|
|
- name: Assert logout client is idempotent
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result_idempotent_logout_client is not changed
|
|
|
|
- name: Update client logout fields
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: logout-test-client
|
|
valid_post_logout_redirect_uris:
|
|
- "https://example.com/new-logout"
|
|
backchannel_logout_url: "https://example.com/new-backchannel"
|
|
state: present
|
|
register: result_update_logout_client
|
|
|
|
- name: Assert logout client fields are updated
|
|
ansible.builtin.assert:
|
|
that:
|
|
- result_update_logout_client is changed
|
|
- result_update_logout_client.end_state.attributes["backchannel.logout.url"] == "https://example.com/new-backchannel"
|
|
|
|
- name: Delete logout test client
|
|
middleware_automation.keycloak.keycloak_client:
|
|
realm: "{{ ephemeral_realm }}"
|
|
client_id: logout-test-client
|
|
state: absent
|