Skip to content

make e2e auth extensible for multiple IdPs and auth modes - #190

Merged
wolfoo2931 merged 23 commits into
mainfrom
test_auth_providers
Jul 30, 2026
Merged

make e2e auth extensible for multiple IdPs and auth modes#190
wolfoo2931 merged 23 commits into
mainfrom
test_auth_providers

Conversation

@wolfoo2931

@wolfoo2931 wolfoo2931 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Extract the provider-specific login UI interaction from Session.getSession into pluggable IdP adapters (specs.wdio/helpers/idp/, selected via TEST_IDP, default auth0) and the app-side login flow into auth mode strategies (specs.wdio/helpers/auth_mode/, selected via TEST_AUTH_MODE, default confidential). This prepares adding Authentik to the test matrix and a future public-client/bearer mode leg without touching session.ts again.

Also replace the hardcoded test user email pattern with a TEST_USERS env variable (comma-separated list), wired into the wdio CI workflows.

Summary by CodeRabbit

  • New Features
    • Added configurable auth-mode and identity-provider support for WebdriverIO end-to-end sessions (Auth0, dev OIDC, Authentik) plus Auth-mode-specific login flows.
    • Added support for selecting test users via comma-separated TEST_USERS.
    • Extended OIDC configuration with an optional custom token audience.
  • Bug Fixes
    • Improved reliability of login/session setup across auth flows.
    • Updated socket authentication to verify auth earlier and reject unauthorized connections.
  • Documentation / CI
    • Centralized WebdriverIO test environment configuration in CI workflows.
    • Updated E2E test documentation and added local Authentik E2E setup examples.

Extract the provider-specific login UI interaction from Session.getSession
into pluggable IdP adapters (specs.wdio/helpers/idp/, selected via TEST_IDP,
default auth0) and the app-side login flow into auth mode strategies
(specs.wdio/helpers/auth_mode/, selected via TEST_AUTH_MODE, default
confidential). This prepares adding Authentik to the test matrix and a
future public-client/bearer mode leg without touching session.ts again.

Also replace the hardcoded test user email pattern with a TEST_USERS env
variable (comma-separated list), wired into the wdio CI workflows.
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

WDIO authentication now supports configurable auth modes and identity providers, derives test emails from TEST_USERS, and supports public OIDC and Authentik flows. The SDK accepts custom token audiences, raw requests use access tokens, WebSocket authentication runs in middleware, and CI workflows centralize test configuration.

Changes

WDIO authentication flow

Layer / File(s) Summary
Authentication contracts and selectors
specs.wdio/helpers/auth_mode/types.ts, specs.wdio/helpers/idp/types.ts, specs.wdio/helpers/auth_mode/index.ts, specs.wdio/helpers/idp/index.ts
Defines authentication interfaces and selects registered strategies or IDP adapters from environment variables.
Authentication mode and provider implementations
specs.wdio/helpers/auth_mode/*, specs.wdio/helpers/idp/*
Implements confidential and public login flows plus Auth0, development OIDC, and Authentik provider interactions.
Session orchestration and CI configuration
specs.wdio/helpers/session.ts, bin/test.wdio.sh, .github/actions/setup-*.yml, .github/workflows/wdio-*.yml, CONTRIBUTING.md
Resolves indexed test users, runs the configured login sequence, enables public-mode headers, centralizes workflow setup, and documents required CI variables.
Public OIDC test application and SDK integration
specs.wdio/testapp/*, wdio.conf.ts, src/browser_sdk/*, specs.wdio/helpers/lr_expects.ts
Adds public-client build and callback wiring, custom OIDC audiences, access-token request authentication, and user readiness checks.
Hermetic Authentik environment
.env.authentik.example, .github/actions/setup-authentik/*, .vscode/settings.json
Adds Docker Compose, blueprint, composite-action, environment, and editor configuration for Authentik-backed E2E tests.
Socket authentication middleware
lib/client-server-bus/drivers/ws/server/index.ts
Authenticates Socket.IO connections before acknowledgment and stores the verified user ID for connection authorization.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Session
  participant TestApp
  participant AuthMode
  participant IdP
  participant LinkedRecords
  Session->>TestApp: initialize configured client
  Session->>AuthMode: initiateLogin
  AuthMode->>IdP: start OIDC login
  Session->>IdP: submit test user credentials
  IdP-->>TestApp: redirect to callback
  TestApp->>LinkedRecords: establish authenticated session
  Session->>AuthMode: completeLogin
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: extensible E2E authentication across multiple IdPs and auth modes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test_auth_providers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@specs.wdio/helpers/auth_mode/confidential.ts`:
- Line 9: Replace the broad selector in the login flow with a resilient selector
that uniquely targets the Login link, using its stable id, test attribute, or
exact link text instead of the first anchor returned by browser.$.

In `@specs.wdio/helpers/idp/auth0.ts`:
- Around line 8-20: Update the consent handling after the initial login-button
click in the auth flow to wait for navigation or a consent-screen-specific
condition before querying the shared submit-button selector. Ensure the login
button cannot be clicked twice, then click the consent button only after the
consent screen is ready while preserving the existing optional-consent behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0250f04d-03fb-43c5-baf8-de7d2c390e51

📥 Commits

Reviewing files that changed from the base of the PR and between 5d77cea and 5441a8d.

📒 Files selected for processing (10)
  • .github/workflows/wdio-load-tests.yml
  • .github/workflows/wdio-tests.yml
  • CONTRIBUTING.md
  • specs.wdio/helpers/auth_mode/confidential.ts
  • specs.wdio/helpers/auth_mode/index.ts
  • specs.wdio/helpers/auth_mode/types.ts
  • specs.wdio/helpers/idp/auth0.ts
  • specs.wdio/helpers/idp/index.ts
  • specs.wdio/helpers/idp/types.ts
  • specs.wdio/helpers/session.ts

Comment thread specs.wdio/helpers/auth_mode/confidential.ts
Comment thread specs.wdio/helpers/idp/auth0.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@specs.wdio/helpers/auth_mode/public.ts`:
- Around line 34-38: Update the authentication polling callback in
browser.waitUntil to use browser.execute with an async function instead of
deprecated executeAsync. Return the result of lr.isAuthenticated() directly, or
false when lr is unavailable, and remove the done callback usage.

In `@specs.wdio/testapp/client.ts`:
- Around line 14-25: Update the LinkedRecords constructor call in client
initialization to pass a fourth argument with deferUserInfoFetching enabled,
preventing user-info retrieval until the redirect callback establishes the token
while preserving the existing configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2cb8e07f-3dfd-433f-bb83-5b32cae60710

📥 Commits

Reviewing files that changed from the base of the PR and between 5441a8d and a4f2ec4.

📒 Files selected for processing (12)
  • bin/test.wdio.sh
  • specs.wdio/helpers/auth_mode/index.ts
  • specs.wdio/helpers/auth_mode/public.ts
  • specs.wdio/helpers/idp/auth0.ts
  • specs.wdio/helpers/idp/dev_oidc.ts
  • specs.wdio/helpers/idp/index.ts
  • specs.wdio/helpers/lr_expects.ts
  • specs.wdio/testapp/client.ts
  • specs.wdio/testapp/webpack.config.js
  • src/browser_sdk/oidc.ts
  • src/browser_sdk/records_repository.ts
  • wdio.conf.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • specs.wdio/helpers/idp/index.ts
  • specs.wdio/helpers/auth_mode/index.ts
  • specs.wdio/helpers/idp/auth0.ts

Comment thread specs.wdio/helpers/auth_mode/public.ts
Comment thread specs.wdio/testapp/client.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/wdio-tests.yml:
- Line 17: Update the TEST_USERS configuration in the wdio workflow to read the
comma-separated test-user list from secrets.TEST_USERS or an equivalent
environment-scoped secret, removing all email addresses from the workflow
source.
- Around line 79-80: Disable checkout credential persistence in both checkout
steps in .github/workflows/wdio-tests.yml at lines 79-80 and 93-94 by setting
persist-credentials to false, before the local setup-node-deps action runs.
- Line 59: Use the string key ['5432'] when reading service ports in both
PostgreSQL service-port references: .github/workflows/wdio-tests.yml lines 59-59
and 85-85. Update both occurrences without changing the surrounding WDIO job
configuration.

In `@specs.wdio/testapp/client.ts`:
- Around line 23-24: Await the redirect callback completion before invoking
ensureUserIdIsKnown in the LinkedRecords initialization flow. Reuse the
awaitable public callback-handling API exposed by the OIDC implementation,
ensuring token establishment finishes before user-info retrieval; keep the defer
flag and avoid starting a second concurrent callback.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 60b9bd6f-65f1-4357-8cef-6750f3c95515

📥 Commits

Reviewing files that changed from the base of the PR and between a4f2ec4 and cd81de5.

📒 Files selected for processing (4)
  • .github/actions/setup-node-deps/action.yml
  • .github/workflows/wdio-tests.yml
  • lib/client-server-bus/drivers/ws/server/index.ts
  • specs.wdio/testapp/client.ts

Comment thread .github/workflows/wdio-tests.yml Outdated
Comment thread .github/workflows/wdio-tests.yml
Comment thread .github/workflows/wdio-tests.yml Outdated
Comment thread specs.wdio/testapp/client.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/actions/setup-authentik/action.yml:
- Line 8: Update the Docker Compose startup step in the setup-authentik action
so it explicitly waits for or verifies Authentik blueprint provisioning before
the action returns. Do not rely solely on docker compose up --wait; add a
provisioning completion check using the existing worker or Authentik service
flow, and only proceed once OAuth applications and test users are created for
WDIO.

In @.github/actions/setup-authentik/docker-compose.yml:
- Line 43: Update both Authentik service image references in the Docker Compose
configuration from 2025.8 to the patched 2025.8.6 release, including the image
at the commented location and the second Authentik service image.

In @.github/workflows/wdio-tests.yml:
- Around line 103-104: Update both Authentik job checkout steps in
.github/workflows/wdio-tests.yml at lines 103-104 and 122-123 to set
persist-credentials to false, while leaving the subsequent setup-node-deps local
action steps unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 63b79a4f-7211-4adf-8f7c-f64d07bf456a

📥 Commits

Reviewing files that changed from the base of the PR and between cd81de5 and 09782e2.

📒 Files selected for processing (9)
  • .env.authentik.example
  • .github/actions/setup-authentik/action.yml
  • .github/actions/setup-authentik/blueprints/e2e-test-setup.yaml
  • .github/actions/setup-authentik/docker-compose.yml
  • .github/workflows/wdio-tests.yml
  • .vscode/settings.json
  • specs.wdio/helpers/auth_mode/public.ts
  • specs.wdio/helpers/idp/authentik.ts
  • specs.wdio/helpers/idp/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • specs.wdio/helpers/idp/index.ts
  • specs.wdio/helpers/auth_mode/public.ts

Comment thread .github/actions/setup-authentik/action.yml
Comment thread .github/actions/setup-authentik/docker-compose.yml
Comment thread .github/workflows/wdio-tests.yml Outdated
…mode

The LinkedRecords constructor fires handleRedirectCallback() in the
background (it can't be async) when landing back from the IdP with
?code&state. The test app called ensureUserIdIsKnown() right after
construction without waiting for that exchange to finish, so the first
request could go out before an access token was available. Memoize
handleRedirectCallback() so it's safe to await from the test app without
triggering a second concurrent callback.
docker compose --wait only waits for containers to report healthy, not for
authentik's own background blueprint discovery to finish provisioning the
flows/cert/scope-mappings the e2e blueprint's !Find lookups depend on,
causing an intermittent race on a freshly started worker.
With REUSE_TEST_BROWSERS=true (npm run wdio:fast), the first test in a run
logs all 4 browsers into the hermetic Authentik container concurrently,
which means 4 concurrent password-stage hashes competing for the runner's
CPU - slower than the near-instant dev-oidc/auth0 flows these 10s waits
were originally tuned for. Bump both window.lr checks to 30s, matching the
other Authentik-aware waits already in auth_mode/public.ts.
Both auth paths in authentication.ts constructed a fresh express-openid-connect
or express-oauth2-jwt-bearer middleware inside the per-request handler, so every
single request re-ran OIDC issuer discovery (and JWKS setup for the bearer path)
from scratch. Fast against dev-oidc/Auth0, but against the CPU-constrained
hermetic Authentik container used in CI this added multi-second latency to
every request, making auth-mode test runs crawl or appear to hang.

Build both middlewares once (the OIDC one cached per distinct ?prompt= value,
since that's the only thing that varies) and reuse them. Also fixes a latent
bug this exposed: afterCallback ignored its own req/res arguments in favor of
the outer handler's, which only worked by accident because a fresh instance
used to be built per request.
@wolfoo2931 wolfoo2931 changed the title Make E2E auth extensible for multiple IdPs and auth modes make e2e auth extensible for multiple IdPs and auth modes Jul 30, 2026
wdio-tests-pg.yml covers the postgres 15/17/18 + PGlite backend matrix
using dev-oidc as a cheap stand-in IdP. wdio-tests-auth0.yml covers
Auth0 confidential/public client mode against PGlite. The disabled
Authentik jobs move into their own wdio-tests-authentik.yml, now
enabled but manual-only (workflow_dispatch), since they're too heavy
to run on every push/PR.
@wolfoo2931
wolfoo2931 merged commit 1c713d2 into main Jul 30, 2026
13 checks passed
@wolfoo2931
wolfoo2931 deleted the test_auth_providers branch July 30, 2026 18:07
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.

1 participant