Files
ansible-middleware.keycloak/molecule/keycloak_modules/keycloak_authentication/verify.yml
T
Martin Cihlar c51f290d64 AMW-616 Port 24 community.general keycloak integration tests to molecule
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
2026-10-08 20:48:09 +02:00

132 lines
4.8 KiB
YAML

---
# Ported from community.general tests/integration/targets/keycloak_authentication
# Tests authentication flow CRUD: create from copy, create with conditional OTP,
# update config, verify config uniqueness via realm export, and delete.
- name: Set auth flow test variables
ansible.builtin.set_fact:
keycloak_no_otp_required_pattern_original: 'X-Forwarded-For: 10\.[0-9\.:]+'
keycloak_no_otp_required_pattern_modified: 'X-Original-Forwarded-For: 10\.[0-9\.:]+'
- name: Create auth flow from first broker login copy
middleware_automation.keycloak.keycloak_authentication:
realm: "{{ ephemeral_realm }}"
alias: "Test first broker login"
copyFrom: "first broker login"
authenticationExecutions:
- providerId: "idp-review-profile"
requirement: "REQUIRED"
authenticationConfig:
alias: "Test review profile config"
config:
update.profile.on.first.login: "missing"
- name: Create conditional OTP auth flow
middleware_automation.keycloak.keycloak_authentication:
realm: "{{ ephemeral_realm }}"
alias: "My conditional browser otp"
description: "browser based authentication with otp"
providerId: "basic-flow"
authenticationExecutions:
- displayName: Cookie
providerId: auth-cookie
requirement: ALTERNATIVE
- displayName: Kerberos
providerId: auth-spnego
requirement: DISABLED
- displayName: Identity Provider Redirector
providerId: identity-provider-redirector
requirement: ALTERNATIVE
- displayName: My browser otp forms
requirement: ALTERNATIVE
- displayName: Username Password Form
flowAlias: My browser otp forms
providerId: auth-username-password-form
requirement: REQUIRED
- displayName: My browser otp Browser - Conditional OTP
flowAlias: My browser otp forms
requirement: REQUIRED
providerId: "auth-conditional-otp-form"
authenticationConfig:
alias: my-conditional-otp-config
config:
defaultOtpOutcome: "force"
noOtpRequiredForHeaderPattern: "{{ keycloak_no_otp_required_pattern_original }}"
state: present
- name: Update conditional OTP auth flow config
middleware_automation.keycloak.keycloak_authentication:
realm: "{{ ephemeral_realm }}"
alias: "My conditional browser otp"
description: "browser based authentication with otp"
providerId: "basic-flow"
authenticationExecutions:
- displayName: Cookie
providerId: auth-cookie
requirement: ALTERNATIVE
- displayName: Kerberos
providerId: auth-spnego
requirement: DISABLED
- displayName: Identity Provider Redirector
providerId: identity-provider-redirector
requirement: ALTERNATIVE
- displayName: My browser otp forms
requirement: ALTERNATIVE
- displayName: Username Password Form
flowAlias: My browser otp forms
providerId: auth-username-password-form
requirement: REQUIRED
- displayName: My browser otp Browser - Conditional OTP
flowAlias: My browser otp forms
requirement: REQUIRED
providerId: "auth-conditional-otp-form"
authenticationConfig:
alias: my-conditional-otp-config
config:
defaultOtpOutcome: "force"
noOtpRequiredForHeaderPattern: "{{ keycloak_no_otp_required_pattern_modified }}"
state: present
register: result
- name: Get access token for realm export
ansible.builtin.uri:
url: "{{ auth_keycloak_url }}/realms/{{ auth_realm }}/protocol/openid-connect/token"
method: POST
status_code: 200
body_format: form-urlencoded
body:
grant_type: "password"
client_id: "admin-cli"
username: "{{ auth_username }}"
password: "{{ auth_password }}"
register: token_response
- name: Extract access token
ansible.builtin.set_fact:
access_token: "{{ token_response.json.access_token }}"
- name: Export ephemeral realm
ansible.builtin.uri:
url: "{{ auth_keycloak_url }}/admin/realms/{{ ephemeral_realm }}/partial-export?exportClients=false&exportGroupsAndRoles=false"
method: POST
headers:
Accept: application/json
User-agent: Ansible
Authorization: "Bearer {{ access_token }}"
body_format: form-urlencoded
body: {}
register: exported_realm
no_log: true
- name: Assert my-conditional-otp-config exists only once
ansible.builtin.assert:
that:
- exported_realm.json.authenticatorConfig | selectattr('alias', 'equalto', 'my-conditional-otp-config') | list | length == 1
- name: Delete conditional OTP auth flow
middleware_automation.keycloak.keycloak_authentication:
realm: "{{ ephemeral_realm }}"
alias: "My conditional browser otp"
state: absent
register: result