Files
authentik/web/playwright.config.js
Teffen EllisandPlaypen Agent 5130e752d5 web/i18n, core: Persist locale in a cookie and reload to switch (#25156)
* web/test: skip the vendor CAPTCHA tests on CI

The @vendor-network tests load CAPTCHA widgets from the vendors' servers,
which CI can't rely on reaching. They fail on nearly every run and use up
the five-failure budget before other tests get to run. Skip them when CI is
set; they still run locally.

* web/test: fix the ak-mdx docs link and application wizard flakes

The ak-mdx link test expected relative docs links to resolve to
next.goauthentik.io. That's only the pre-release docs host: a build with
GIT_BUILD_HASH set, like the CI image, resolves them to the versioned host
(version-<major>-<minor>.goauthentik.io). So the test failed whenever it ran
in CI, and only looked intermittent because CI stops after five failures and
the vendor CAPTCHA tests often used those up first. Accept either host.

The application wizard's provider step now settles its fields before moving
on, so the test's next "Next" click could land on that step's button again
and leave the wizard short of the review step. Wait for the bindings step to
show before continuing.

* web: persist locale in a cookie and reload to switch

Locale becomes fixed for the lifetime of a page: instead of switching live
in JavaScript, every locale-change path now persists the preference to the
Django language cookie (which LocaleMiddleware already reads) and reloads,
so the server re-renders every string — including server-rendered flow
challenges — in the new locale. This structurally rules out the mixed
client/server language state behind #18179 / #22954.

- add persistLocale/applyLocaleChange helpers backed by the authentik_language
  cookie; switch the flow locale selector, the user-settings prompt stage, and
  the session controller's post-render locale application to persist + reload
- drop the sessionStorage['authentik:locale'] path and remove it from
  autoDetectLanguage; the server-resolved hint (window.authentik.locale) is now
  authoritative, with navigator.languages only relevant on a first anonymous visit
- honor ?locale= server-side in LocaleOverrideMiddleware (validated via
  check_for_language) so the shell and the web UI, which read the same parameter,
  cannot disagree. It sits directly after ImpersonateMiddleware, which wraps the
  rest of the chain in the user's saved locale, so an explicit override wins
- unit-test the cookie helper; test the server-side ?locale= override

Live-switching machinery (LocaleContextController observer, msg() thunks) is
removed separately in a follow-up.

Co-authored-by: Playpen Agent <[email protected]>

* Clean up cookie parsing, tests.

---------

Co-authored-by: Playpen Agent <[email protected]>
2026-10-02 01:27:13 +01:00

122 lines
3.6 KiB
JavaScript

/**
* @import {
* LogFn,
* Logger
* } from "pino"
* @file Playwright configuration.
* @see https://playwright.dev/docs/test-configuration
*/
import { ConsoleLogger } from "#logger/node";
import { defineConfig, devices } from "@playwright/test";
const CI = !!process.env.CI;
/**
* @type {Map<string, Logger>}
*/
const LoggerCache = new Map();
const baseURL = process.env.AK_TEST_RUNNER_PAGE_URL ?? "http://localhost:9000";
export default defineConfig({
testDir: "./test/browser",
fullyParallel: true,
forbidOnly: CI,
retries: CI ? 1 : 0,
workers: "50%",
// Every action here is a round trip to a real authentik instance that the other
// workers are hitting too — creating an entity is a POST plus a table refresh, not a
// local state change. Playwright's 5s assertion default is written for in-process UI
// and is optimistic for that, so raise the floor rather than sprinkling per-assertion
// timeouts. Individual steps that are slow for a known reason still say so locally.
timeout: 60_000,
expect: {
timeout: 15_000,
},
maxFailures: CI ? 5 : 2,
// These load CAPTCHA widgets from their vendors' servers, which CI can't rely on reaching.
grepInvert: CI ? /@vendor-network/ : undefined,
reporter: CI
? [
// ---
["github"],
["html", { open: "never", outputFolder: "playwright-report" }],
// Codecov test analytics ingests JUnit XML, not Playwright's JSON.
["junit", { outputFile: "playwright-report/results.xml" }],
]
: [
// ---
["list", { printSteps: true }],
["html", { open: "never" }],
],
use: {
testIdAttribute: "data-test-id",
baseURL,
trace: "on-first-retry",
screenshot: "only-on-failure",
video: CI ? "retain-on-failure" : "off",
colorScheme: "dark",
launchOptions: {
logger: {
isEnabled() {
return true;
},
log: (name, severity, message, _args) => {
let logger = LoggerCache.get(name);
if (!logger) {
logger = ConsoleLogger.child({
name: `Playwright ${name.toUpperCase()}`,
});
LoggerCache.set(name, logger);
}
/**
* @type {LogFn}
*/
let log;
switch (severity) {
case "verbose":
log = logger.debug;
break;
case "warning":
log = logger.warn;
break;
case "error":
log = logger.error;
break;
default:
log = logger.info;
break;
}
if (name === "api") {
log = logger.debug;
}
log.call(logger, message.toString());
},
},
},
},
/* Configure projects for major browsers */
projects: [
{
name: "prerequisites",
testMatch: /prerequisites\.setup\.ts/,
},
{
name: "chromium",
dependencies: ["prerequisites"],
use: {
...devices["Desktop Chrome"],
},
},
],
});