跳到正文
cccskills
免费在 GitHub 公开

keycloak-tests

Authors and runs integration tests against Keycloak - uses Testcontainers Keycloak module to spin up an isolated server per test class, imports realm JSON for fixtures, exercises OIDC discovery / token endpoint / token introspection / admin REST API; tests password / authorization-code / client-credentials / token-exchange flows; covers UMA (User-Managed Access) permission tickets. Use when the user works with self-hosted Keycloak and needs unit / integration tests for realms, clients, users, or auth flows.

中文简介正在准备中。当前显示原文说明。

testland/qa星标 13(GitHub 13 + cccskills 0)
集成工具DockerPlaywright

实测评分 未实测

查看安装方法

包含的文件(13)

  • SKILL.md8.7 KB
  • .tessl-plugin/plugin.json643 B
  • evals/expired-token-still-opens-the-api/criteria.json7.5 KB
  • evals/expired-token-still-opens-the-api/task.md11.1 KB
  • evals/mobile-login-test-copied-from-the-legacy-one/criteria.json9.0 KB
  • evals/mobile-login-test-copied-from-the-legacy-one/task.md9.6 KB
  • evals/realm-export-about-to-be-committed-with-live-secrets/criteria.json7.9 KB
  • evals/realm-export-about-to-be-committed-with-live-secrets/task.md10.9 KB
  • evals/token-requests-404-after-the-server-upgrade/criteria.json6.7 KB
  • evals/token-requests-404-after-the-server-upgrade/task.md8.3 KB
  • evals/two-ci-builds-fighting-over-the-same-login-server/criteria.json6.9 KB
  • evals/two-ci-builds-fighting-over-the-same-login-server/task.md9.1 KB
  • references/endpoint-recipes.md1.3 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

keycloak-tests

Overview

Per keycloak.org/docs/latest/server_admin/index.html:

"Keycloak is a single sign on solution for web apps and RESTful web services."

The two foundational concepts per kc-admin:

"A realm manages a set of users, credentials, roles, and groups. A user belongs to and logs into a realm. Realms are isolated from one another and can only manage and authenticate the users that they control."

"Clients are entities that can request Keycloak to authenticate a user. Most often, clients are applications and services that want to use Keycloak to secure themselves and provide a single sign-on solution."

For tests: spin up Keycloak via Testcontainers, import a realm fixture (JSON exported from a known-good config), then exercise the OIDC endpoints from your application.

When to use

  • The repo uses Keycloak as IdP (self-hosted, often Quarkus-based for newer deployments).
  • Tests need an isolated Keycloak instance per test class (vs a shared dev IdP).
  • A test verifies authorization-code, client-credentials, password (deprecated), or token-exchange flows.
  • Custom auth flows (per kc-admin: "password-less browser login flow") need integration coverage.

How to use

  1. Start Keycloak per test class with the Testcontainers module, pinning an explicit image tag (Step 1).
  2. Author and mount a stripped test-realm.json fixture via withRealmImportFile() or KEYCLOAK_IMPORT (Step 2).
  3. Exercise the realm's token endpoint for each flow under test - authorization-code, client-credentials, password for legacy only (Steps 3-4).
  4. Validate resource-server integration through token introspection (Step 5).
  5. Cover realm / client / user provisioning through the Admin REST API where the app manages them (Step 7).
  6. Run the suite in CI with Docker on the runner; no service container needed (Step 8).

Step 1 - Testcontainers Keycloak setup

from testcontainers.keycloak import KeycloakContainer
import requests

@pytest.fixture(scope="session")
def keycloak():
    with KeycloakContainer("quay.io/keycloak/keycloak:25.0") as kc:
        kc.start()
        yield kc

For Java:

@Container
static KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:25.0")
    .withRealmImportFile("test-realm.json");

The Testcontainers Keycloak module ships at testcontainers.com/modules/keycloak.

Step 2 - Realm import fixture

Author one canonical test-realm.json per test scope (or per class if scopes differ). Realm JSON exports from Admin Console (Realm Settings → Action → Export). Strip secrets from exports before checking in:

# Trim sensitive fields before commit
jq 'del(.. | .secret? // .credential.value? // empty)' realm.json > test-realm.json

Mount the file via withRealmImportFile() (Java) or environment variable KEYCLOAK_IMPORT (Python testcontainers).

Step 3 - Test the OIDC token endpoint

Per RFC 6749 (cited in oauth-flow-test-author) the token endpoint accepts grant_type plus flow-specific params. Keycloak's token endpoint:

{server-url}/realms/{realm-name}/protocol/openid-connect/token
def test_password_grant(keycloak):
    server_url = keycloak.get_url()
    response = requests.post(
        f"{server_url}/realms/test/protocol/openid-connect/token",
        data={
            "grant_type": "password",
            "client_id": "test-client",
            "client_secret": "test-secret",
            "username": "alice",
            "password": "alicepass",
        },
    )
    assert response.status_code == 200
    body = response.json()
    assert "access_token" in body
    assert body["token_type"] == "Bearer"
    assert "expires_in" in body

Note: the password grant is deprecated per RFC 9700 (Best Current Practice for OAuth 2.0 Security) - use it only for legacy test scenarios; new code should use authorization-code + PKCE.

Step 4 - Test client-credentials grant

For service-to-service auth:

def test_client_credentials_grant(keycloak):
    response = requests.post(
        f"{keycloak.get_url()}/realms/test/protocol/openid-connect/token",
        data={
            "grant_type": "client_credentials",
            "client_id": "service-account-client",
            "client_secret": "secret",
        },
    )
    assert response.status_code == 200
    token = response.json()["access_token"]
    # Then call the protected resource:
    api_response = requests.get(
        "http://my-api/protected",
        headers={"Authorization": f"Bearer {token}"},
    )
    assert api_response.status_code == 200

Step 5 - Test token introspection

For RP (Resource Provider) integration, POST the token to the realm's /token/introspect endpoint with client auth and assert active is true (plus username / preferred_username). Full recipe: references/endpoint-recipes.md.

Step 6 - Test custom authentication flows

Per kc-admin, Keycloak supports custom auth flows (e.g., "Creating a password-less browser login flow"). Custom flows are configured via the Admin Console + exported in realm JSON.

Test pattern: import a realm with the custom flow, then exercise the browser flow via Playwright or a mock OIDC client. The exact pattern depends on the custom flow - consult the per-flow docs on kc-admin.

Step 7 - Admin REST API tests

Keycloak exposes its admin functionality via REST. Pattern: obtain an admin-realm token, then call the admin endpoints (e.g. create a user via /admin/realms/{realm}/users). Full recipe: references/endpoint-recipes.md.

Step 8 - CI integration

services:
  # No service container needed - Testcontainers manages Keycloak per test
steps:
  - run: pytest tests/integration/auth/ -v

Testcontainers requires Docker on the runner; GitHub Actions ubuntu-latest has it pre-installed.

Worked example

A service needs its /protected API to accept only Keycloak-issued tokens. The test class starts quay.io/keycloak/keycloak:25.0 via Testcontainers and imports test-realm.json carrying a service-account-client (Steps 1-2). The test POSTs a client_credentials grant to {url}/realms/test/protocol/openid-connect/token, pulls access_token, then calls /protected with Authorization: Bearer <token> and asserts 200 (Step 4). A second test introspects the same token and asserts active is true (Step 5). CI runs pytest tests/integration/auth/ -v on an ubuntu-latest runner where Docker is preinstalled (Step 8).

Anti-patterns

Anti-patternWhy it failsFix
Share a dev Keycloak between testsTest interference; flakyPer-class Testcontainers (Step 1)
Use password grant in tests for new flowsDeprecated per RFC 9700; misleading test coverageAuthorization-code + PKCE for new flows (cross-ref oauth-flow-test-author)
Commit secrets in realm JSONSecrets leakStrip via jq pipeline (Step 2)
Hardcode Keycloak URLTests fail when port changesUse keycloak.get_url() (Step 1)
Skip introspection in resource-server testsToken-validation logic untestedAlways cover introspection or local JWT validation (Step 5)

Limitations

  • Keycloak version evolves; pin a specific tag (e.g., 25.0) in Testcontainers, not latest.
  • Custom auth-flow tests require browser automation (Playwright / Selenium) for full coverage.
  • Performance tests of Keycloak (token-issuance throughput) are out of scope; use k6-load-testing (in the qa-load-testing plugin).
  • Per kc-admin, CLI / Admin REST API command examples evolve per release; cite the version in test setup.

References

  • kc-admin - Keycloak Server Admin Guide: realms, clients, custom flows
  • testcontainers.com/modules/keycloak - Testcontainers module
  • IETF RFC 6749 - OAuth 2.0 (cross-ref oauth-flow-test-author)
  • IETF RFC 7636 - PKCE (cross-ref oauth-flow-test-author)
  • IETF RFC 9700 - OAuth 2.0 Security Best Current Practice
  • auth0-tests, okta-tests - sister IdP tools
  • oauth-flow-test-author, session-management-test-author - build-an-X authors

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Builds a CI gate that fails the build on **new** WCAG / a11y violations introduced by a PR while grandfathering pre-existing violations on a per-rule / per-page baseline. Aggregates verdicts from axe-core / pa11y / Lighthouse a11y / WAVE / IBM Equal Access scans. Use when a project has accumulated a11y debt and a strict "zero violations" gate would block every PR - the ratchet pattern lets the team ship while preventing regressions.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Workflow skill that builds an A/B-test validity checklist from an experiment proposal, walking the canonical design-correctness gates - pre-registered OEC/power/guardrails, randomization unit + SRM check, assignment integrity, telemetry, peeking discipline, novelty/primacy, post-experiment SRM re-check - into a per-experiment checklist + sign-off form. Use when launching, auditing, or governing an experiment. For pitfall mechanics (guardrails, peeking) see experiment-results-interpreter's references; to read an already-valid result use experiment-results-interpreter; for per-SDK harness tests use experiment-sdk-testing - this gates DESIGN, not SDK code.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

The single install-flow skill: the reference contract for the PWA install flow (installability gate fields, `beforeinstallprompt` handshake, per-platform paths - Android WebAPK / iOS Share menu / Firefox no-op - and the `display-mode` post-install signal, in references/install-flow-reference.md) plus the build-an-X workflow that emits the Add-to-Home-Screen suite. Walks the four-stage timeline, emitting one test per gate cell per [web.dev/articles/install-criteria][install-criteria], the deferred-prompt → `prompt()` → `userChoice` chain per [web.dev/articles/customize-install][customize-install], the iOS Safari manual-metadata branch (`apple-touch-icon`) per [web.dev/learn/pwa/installation][learn-pwa], and the post-install `(display-mode: standalone)` MQ assertion. Output: a Playwright spec with per-stage cells plus a coverage matrix. Use when a PWA's manifest, icons, or install handler change, when install conversion drops at an unknown stage, or when triaging a flaky install assertion.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Build-an-X workflow that uses an LLM to map existing tests to spec sections - given a spec doc + the test suite, the LLM identifies which tests cover which sections, surfaces uncovered sections (gap), and recommends specific tests to add. Output is a coverage matrix per spec ID. Scope is mapping tests that already exist and naming the gaps, not authoring tests for new acceptance criteria. Use when a spec doc and a test suite both exist but nobody can say which requirements are actually covered - before a release sign-off, an audit, or a decision about where to spend the next round of test effort.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Generates tests from natural-language specs (acceptance criteria, user stories, requirements) using an LLM, with confidence scoring per test case (LLM self-assessment plus heuristics: assertion quality, naming, completeness), batching uncertain cases for human review, and integration with the team's existing test framework. Use when the user asks to generate unit tests from acceptance criteria, convert user stories to test cases, automate test creation from requirements, or augment a spec-driven test suite with AI-generated stubs that are then curated before merge.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Configures Allure Report (test-runner adapter install, `allure-results` directory wiring, `categories.json` for failure classification, `history-trend.json` retention via the copy-history-between-runs pattern), runs the Allure CLI to convert `allure-results` to a static HTML site, and uploads the report as a CI artifact. Use when the team needs richer test reporting than JUnit XML - step-level attachments, per-test history, retry tracking, and severity / epic / feature labeling across framework-agnostic adapters (pytest, Jest, JUnit, TestNG, NUnit, Mocha). As a rich static HTML report generator, it is the open-source alternative to the sunset ExtentReports (JVM/.NET per-test HTML narrative); for hosted cross-run flakiness analytics rather than a static per-run report use currents-integration.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

查看 testland 的全部技能

报告此技能的问题