diff --git a/tests/e2e/ui/helpers/userOnboarding.ts b/tests/e2e/ui/helpers/userOnboarding.ts index a1ea6e5e82b..14e2b0257b2 100644 --- a/tests/e2e/ui/helpers/userOnboarding.ts +++ b/tests/e2e/ui/helpers/userOnboarding.ts @@ -57,3 +57,13 @@ export async function expectUnrestrictedDashboard(page: Page): Promise { expect(info.ok(), `Read own user with dashboard session: HTTP ${info.status()}`).toBe(true); expect((await info.json()).user_id).toBe(session.user_id); } + +export async function logInThroughLoginPage(page: Page, email: string, password: string): Promise { + await page.goto(`${rootPath()}/ui/login`); + await page.getByPlaceholder("Enter your username").fill(email); + await page.getByPlaceholder("Enter your password").fill(password); + await page.getByRole("button", { name: "Login", exact: true }).click(); + await page.waitForURL((url) => url.pathname.startsWith(`${rootPath()}/ui`) && !url.pathname.includes("/login"), { + timeout: 30_000, + }); +} diff --git a/tests/e2e/ui/tests/auth/logout.spec.ts b/tests/e2e/ui/tests/auth/logout.spec.ts index 351ba91e8d7..92c31456353 100644 --- a/tests/e2e/ui/tests/auth/logout.spec.ts +++ b/tests/e2e/ui/tests/auth/logout.spec.ts @@ -1,10 +1,14 @@ import { test, expect } from "@playwright/test"; -import { ADMIN_STORAGE_PATH } from "../../constants"; +import { Role, users } from "../../fixtures/users"; +import { logInThroughLoginPage } from "../../helpers/userOnboarding"; test.describe("Logout", () => { - test.use({ storageState: ADMIN_STORAGE_PATH }); + test.use({ storageState: { cookies: [], origins: [] } }); test("Clicking Logout clears the session and forces re-login on a protected page", async ({ page }) => { + const admin = users[Role.ProxyAdmin]; + await logInThroughLoginPage(page, admin.email, admin.password); + await page.goto("/ui"); // Scope to the sidebar; the top-bar breadcrumb also shows "Virtual Keys". await expect(page.getByRole("complementary").getByText("Virtual Keys")).toBeVisible({ timeout: 10_000 }); diff --git a/tests/e2e/ui/tests/auth/proxyLogoutUrl.spec.ts b/tests/e2e/ui/tests/auth/proxyLogoutUrl.spec.ts index 7f6cc6f2f87..3a79ce82717 100644 --- a/tests/e2e/ui/tests/auth/proxyLogoutUrl.spec.ts +++ b/tests/e2e/ui/tests/auth/proxyLogoutUrl.spec.ts @@ -1,5 +1,6 @@ import { test, expect } from "@playwright/test"; -import { ADMIN_STORAGE_PATH } from "../../constants"; +import { Role, users } from "../../fixtures/users"; +import { logInThroughLoginPage } from "../../helpers/userOnboarding"; /** * Runs as part of the standard e2e suite: both `run_e2e.sh` and the CircleCI @@ -16,9 +17,12 @@ const LOGOUT_URL = process.env.PROXY_LOGOUT_URL ?? ""; test.skip(!LOGOUT_URL, "Requires PROXY_LOGOUT_URL env var"); test.describe("PROXY_LOGOUT_URL redirect", () => { - test.use({ storageState: ADMIN_STORAGE_PATH }); + test.use({ storageState: { cookies: [], origins: [] } }); test("Logout clears the session and redirects to PROXY_LOGOUT_URL", async ({ page }) => { + const admin = users[Role.ProxyAdmin]; + await logInThroughLoginPage(page, admin.email, admin.password); + const target = new URL(LOGOUT_URL); // Stub the external logout destination so the assertion doesn't depend on @@ -46,8 +50,8 @@ test.describe("PROXY_LOGOUT_URL redirect", () => { await expect(page.getByRole("complementary").getByText("Virtual Keys")).toBeVisible({ timeout: 15_000 }); await settingsLoaded; - // Pre-condition: we start authenticated. The admin storage state carries a - // `token` cookie, so a real logout has something to tear down. + // Pre-condition: we start authenticated. The fresh login set a `token` + // cookie, so a real logout has something to tear down. const tokensBefore = (await page.context().cookies()).filter((c) => c.name === "token"); expect(tokensBefore.length, "should start logged in with a token cookie").toBeGreaterThan(0);