keycloak-testslisted
Install: claude install-skill testland/qa-skills
# keycloak-tests
## Overview
Tests start their own Keycloak in a container, import a committed realm
fixture, check the realm is up, then drive the real OIDC endpoints. A
realm holds users, credentials, roles and groups; a client is an
application that asks Keycloak to authenticate users
([Server Admin Guide][kc-admin]).
## When to use
- The app uses self-hosted Keycloak as its identity provider.
- Tests need an isolated Keycloak per run instead of a shared dev or
staging server.
- A test covers client-credentials, authorization-code + PKCE, password
(legacy only), token exchange, UMA permissions, or introspection.
## Step 1 - Start Keycloak per run with a pinned tag
```python
# tests/auth/conftest.py
import pytest
import requests
from testcontainers.keycloak import KeycloakContainer
@pytest.fixture(scope="session")
def keycloak():
kc = KeycloakContainer("quay.io/keycloak/keycloak:26.0") \
.with_realm_import_file("tests/auth/fixtures/test-realm.json")
with kc: # the context manager starts and stops the container
yield kc
```
`with_realm_import_file()` mounts the file at
`/opt/keycloak/data/import/realm.json` and adds `--import-realm` to the
`start-dev` command; `start()` waits for `/health/ready`. The admin
user comes from the container (`test` / `test` unless passed), not from
environment variables pointing at another server
([testcontainers-python Keycloak module][tc-py]). The default image is
`latest`, so always pass a tag.
Java ([test