Skip to content

🏰 test: Cover Back-Channel Logout With Real Keycloak - #18586

Draft
AtefBellaaj wants to merge 6 commits into
atef/ai-2415-bcl-07-logout-login-reasonfrom
atef/ai-2415-bcl-08-keycloak-e2e
Draft

AtefBellaaj wants to merge 6 commits into
atef/ai-2415-bcl-07-logout-login-reasonfrom
atef/ai-2415-bcl-08-keycloak-e2e

Conversation

@AtefBellaaj

@AtefBellaaj AtefBellaaj commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The existing recovery tests mock provider grants in several paths. They cannot check how real Keycloak token rotation interacts with browser login and admin refresh retries. This PR adds browser and HTTP tests against real Keycloak and MongoDB. It also tests session logout, races, outages, and mode changes. Application behavior is unchanged.

Stack: the OpenID back-channel logout stack #18434 → #18435 → #18633 → #18436 → #18437 → #18438 → #18439 → #18583 → this PR. This PR targets atef/ai-2415-bcl-07-logout-login-reason (#18583). Related to AI-2415 (ClickHouse/ai#4540) and AI-2656 (ClickHouse/ai#5057).

How it works

Chromium login -> Keycloak -> LibreChat -> dedicated MongoDB
Keycloak logout -> capture proxy -> LibreChat logout receiver
CI -> separate browser and protocol jobs

Each run creates its own containers, ports, database, and keys. LibreChat runs with NODE_ENV=production. A test gate pauses real database operations to control callback and refresh races. The proxy holds signed logout messages in memory for replay checks.

Tests run headlessly by default. The background case switches real tabs and checks that the app tab is hidden. Request errors omit credential headers, and authentication traces are disabled.

Type of change

  • Tests / tooling / CI
  • Documentation

Testing

Tested environments/configuration: macOS ARM64, Node 24.22.3, Playwright 1.62.1, Keycloak 26.1.5, and MongoDB 8.0.20. Tests cover local and reused provider tokens, plus off, record, and enforce modes.

Automated tests: all 24 tests passed headlessly, with no skips or retries. A 25th case, a logout token with a tampered signature in enforce mode, was added after that run; CI runs it.

Group Result Coverage
Browser 11 passed Separate sessions, delayed responses, missing cookies, callback and refresh races, and the real Keycloak Logout button with foreground and hidden-tab renewal
Protocol 13 passed Admin rotation and stale retries, independent login limits, real provider outage and recovery, real invalid grants, duplicate logout, restart, mode changes, MongoDB failure and recovery, and failed delivery

The app build, scoped Prettier and ESLint checks, and strict E2E TypeScript checks passed. The admin regression checks real refresh and verification HTTP endpoints with browser-issued credentials. Admin panel UI and authorization-code exchange are outside that test.

Eight admin renewals with LOGIN_MAX=7 still allow another real browser login. When Keycloak is stopped, admin renewal returns 503 AUTH_SESSION_CHECK_UNAVAILABLE. The same credential works after the failed grant's existing lease expires and the provider restarts. With local session checks off, Keycloak rejects the grant and admin renewal returns 401 REFRESH_FAILED. An early local-token MongoDB lookup failure also returns 503 and preserves cookies.

Screenshots / recordings

No user-facing change.

Risk / compatibility

CI needs Docker and Chromium. It installs Chromium with --no-shell; the system font install and the report upload do not fail the job. The workflow runs both test groups for PRs targeting the parent branch.

The delivery test kept the capture proxy running while LibreChat was down. Keycloak made one attempt and received HTTP 502 during the 120-second observation. The session stayed valid until a successful redelivery. The logout guide now states this measured limit; the test does not establish a general retry policy.

Checklist

  • I reviewed my own changes
  • Relevant tests have been added or updated
  • Existing relevant tests pass
  • The change does not introduce new warnings or errors
  • User-facing or complex behavior is documented where necessary
  • Required dependency changes have been merged/published: 📯 feat: Explain OpenID Session Endings After Refresh Denial #18583
  • Required documentation PR: N/A

@danny-avila danny-avila left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings inline. I checked that no application code changed, that the test gate is not reachable from production, and that no secrets are committed.

Comment thread .github/workflows/openid.yml Outdated
- '.nvmrc'
- '.github/workflows/openid.yml'
- '!**.md'
merge_group:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs on every merge queue entry, but openid.yml is not in SUITES in .github/scripts/merge-gate.mjs. So it costs about 15 runner minutes per entry and blocks nothing.

Either add it to the gate, or drop merge_group and keep it advisory on PRs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The workflow ran on merge_group, but the gate's SUITES list doesn't include it, so it only cost time there. Removed in 7c1be5a.

Comment thread .github/workflows/openid.yml Outdated
cache: npm
- run: npm ci
- run: npx tsc -p e2e/openid/tsconfig.json
- run: npx playwright install --with-deps chromium

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

playwright-mock.yml made the font install best effort with a time bound, and put continue-on-error on the artifact upload, after outages turned passing runs red. Same here please, for this step and the upload below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partly. The browser suite can't run without chromium (browser.spec.ts:43), so that install stays required. Fixed in 6e9636f, following lighthouse.yml: a required --no-shell chromium install, a best-effort font install (continue-on-error, 4-minute timeout), and continue-on-error with a 3-minute timeout on the artifact upload.

expect(Boolean(row.providerSession)).toBe(false);
const receiver = await legacy.context.request
.post(`${harness.baseURL}/oauth/openid/backchannel-logout`, {
form: { logout_token: 'invalid' },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only invalid token sent to the real route, and it runs in off mode, so it gets 404 before any validation.

Please add a case that sends a tampered signature in enforce and expects 400 with nothing revoked. A wrong audience and a stale token would be good too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The only invalid token was sent in off mode and expected a 404, so the signature check was never tested. Fixed in ca0f9d4: a new case in enforce mode sends a token with a tampered signature, expects a 400, and checks that nothing is revoked.

Comment thread e2e/openid/harness.cjs Outdated
'mongo:8.0.20',
'--bind_ip_all',
);
const mongoURI = `mongodb://127.0.0.1:${mongoPort}/${database}?serverSelectionTimeoutMS=2000&socketTimeoutMS=2000`;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2 second socket timeout applies to the whole app under test, not just the outage cases. Any query slower than 2 seconds on a busy runner fails.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. socketTimeoutMS=2000 reached the app through the shared URI and could cut off slow but valid queries. Removed in 77e29ce. serverSelectionTimeoutMS=2000 stays, so a missing MongoDB still fails fast.

@lia-by-librechat lia-by-librechat Bot changed the title test(auth): cover back-channel logout with real Keycloak 🏰 test: Cover Back-Channel Logout With Real Keycloak Nov 20, 2026
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2415-bcl-08-keycloak-e2e branch from 2f8df3f to b7422b7 Compare November 20, 2026 17:07
@AtefBellaaj
AtefBellaaj removed this pull request from stack #18441 November 20, 2026 17:09
@AtefBellaaj
AtefBellaaj added this pull request to stack #18634 November 20, 2026 17:12
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2415-bcl-08-keycloak-e2e branch from b7422b7 to c35b23d Compare November 20, 2026 17:26
@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T17:48:42.918267Z c35b23d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: c35b23d249

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2415-bcl-08-keycloak-e2e branch from c35b23d to 77e29ce Compare November 20, 2026 18:24
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2415-bcl-08-keycloak-e2e branch from 77e29ce to 1a26949 Compare November 20, 2026 19:26
The merge gate does not list openid.yml in SUITES, so a merge-group run was never required and only spent runner time.
…ailures

Install the lockfile-pinned Chromium with --no-shell as a required step, install the optional font packages on a best-effort basis, and cap the artifact upload so it cannot fail or stall the job. The Keycloak Playwright config selects the chromium channel because the headless shell is no longer installed.
…e mode

Capture a real Keycloak logout token while the app is down, flip one signature byte, and check that the receiver answers 400 and leaves the session refreshable. The untampered token is then accepted, so the rejection comes from the signature alone. replay() takes an optional token edit for this.
The app shares this URI, and a two-second socket timeout can cut off slow valid queries. Server selection keeps its two-second limit so outage tests still fail fast.
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2415-bcl-08-keycloak-e2e branch from 1a26949 to f4dc2aa Compare November 20, 2026 19:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants