diff --git a/dashboard/e2e/sign-in-methods.spec.ts b/dashboard/e2e/sign-in-methods.spec.ts index 115721b1..d121b2a5 100644 --- a/dashboard/e2e/sign-in-methods.spec.ts +++ b/dashboard/e2e/sign-in-methods.spec.ts @@ -33,6 +33,7 @@ async function mockApi(page: Page, opts: { selfHosted: boolean; methods: Methods : json(route, { error: "unauthorized" }, 401); } if (p === "/auth/forgot-password" && opts.forgot) return json(route, opts.forgot); + if (p === "/auth/signup") return json(route, { status: "verification_required", message: "If that email can join here, we've sent a verification code." }); if (p === "/api/usage") return json(route, { month: "2026-01", tokens_in: 0, tokens_out: 0, total_runs: 0, total_tokens: 0, max_tokens: 0 }); if (p === "/api/banners") return json(route, { banners: [] }); if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_1", org: "acme", status: "deactivated", current: true }] }); @@ -127,8 +128,9 @@ test("removed GitHub app: 'sign in with GitHub again' only where GitHub sign-in await expect(page.getByRole("link", { name: "Then sign in with GitHub again" })).toHaveAttribute("href", /^\/auth\/github$/); }); -// Forgot password on a self-hosted install says what happened for that email, and where the -// email comes from, so someone whose mail filter holds it back can ask IT to allow it. +// Forgot password gives one answer for every email, so the page can't be used to learn who has +// an account here or is on the team. It names both senders, so someone whose mail filter holds +// one back can ask IT to allow it. const SENDERS = { setup: "coderhelm@acme.example", reset_codes: "no-reply@verificationemail.com" }; async function askForReset(page: Page, email: string) { @@ -138,57 +140,77 @@ async function askForReset(page: Page, email: string) { await page.getByRole("button", { name: "Send", exact: true }).click(); } -test("forgot password, account here: the code is on its way from Amazon Cognito's address", async ({ page }) => { - const { calls } = await mockApi(page, { - selfHosted: true, - methods: { password: true, google: false, github: false, senders: SENDERS }, - forgot: { status: "code_sent", message: "We sent a reset code to jo@acme.example.", email: "jo@acme.example" }, - }); - await askForReset(page, "jo@acme.example"); - await expect(page.getByRole("status").filter({ hasText: "sent" })).toHaveText("We sent a reset code to jo@acme.example."); - await expect(page.getByTestId("sender-note")).toContainText( - "The reset code comes from no-reply@verificationemail.com (Amazon Cognito, which signs people in here).", - ); - await expect(page.getByTestId("sender-note")).toContainText("ask IT to allow that address"); - await expect(page.getByLabel("Reset code")).toBeVisible(); - expect(calls).toContain("/auth/forgot-password"); -}); +/** The page's error box (not Next's route announcer, which is an alert too). */ +const errorBox = (page: Page) => page.getByTestId("auth-error"); -test("forgot password, on the team with no account here: a set-up link instead, from the install's sender", async ({ page }) => { - await mockApi(page, { - selfHosted: true, - methods: { password: true, google: false, github: false, senders: SENDERS }, - forgot: { status: "setup_sent", message: "You don't have an account here yet. We sent you a set-up link instead." }, - }); - await askForReset(page, "al@acme.example"); - await expect(page.getByRole("status").filter({ hasText: "sent" })).toHaveText("You don't have an account here yet. We sent you a set-up link instead."); - await expect(page.getByTestId("sender-note")).toContainText("The set-up link comes from coderhelm@acme.example."); - await expect(page.getByTestId("sender-note")).not.toContainText("verificationemail.com"); - // No code to type: the link in the email sets up the account. - await expect(page.getByLabel("Reset code")).toHaveCount(0); -}); +/** What the page shows after asking: the message, the sender lines, and what comes next. */ +async function shown(page: Page) { + await expect(page.getByLabel("Reset code")).toBeVisible(); + return { + message: await page.getByRole("status").innerText(), + senders: await page.getByTestId("sender-note").locator("p").allInnerTexts(), + setupNote: await page.getByTestId("setup-link-instead").innerText(), + errors: await errorBox(page).count(), + }; +} -test("forgot password, not on this install: says so, sends nothing, no sender line", async ({ page }) => { - await mockApi(page, { - selfHosted: true, - methods: { password: true, google: false, github: false, senders: SENDERS }, - forgot: { status: "no_account", message: "There's no account for who@else.example on this CoderHelm. Ask an admin to add you." }, +// Whatever a server answers (the one `sent`, or a per-case status an older gateway gave), the +// page reads the same: has an account, on the team without one, invited, not on this install. +const REPLIES: ForgotReply[] = [ + { status: "sent", message: "If that email can sign in here, we've sent a reset code or a set-up link." }, + { status: "code_sent", message: "We sent a reset code to jo@acme.example.", email: "jo@acme.example" }, + { status: "setup_sent", message: "You don't have an account here yet. We sent you a set-up link instead." }, + { status: "invited", message: "jo@acme.example has an invite here but no account yet." }, + { status: "no_account", message: "There's no account for jo@acme.example on this CoderHelm. Ask an admin to add you." }, +]; + +test("forgot password: the same message, senders and next step for every case", async ({ page }) => { + const seen = []; + for (const forgot of REPLIES) { + const { calls } = await mockApi(page, { + selfHosted: true, + methods: { password: true, google: false, github: false, senders: SENDERS }, + forgot, + }); + await askForReset(page, "jo@acme.example"); + seen.push(await shown(page)); + expect(calls).toContain("/auth/forgot-password"); + await page.unrouteAll({ behavior: "ignoreErrors" }); + } + expect(seen[0]).toEqual({ + message: "If jo@acme.example can sign in here, we've sent a reset code or a set-up link.", + senders: [ + "Reset codes come from no-reply@verificationemail.com (Amazon Cognito, which signs people in here).", + "Set-up links come from coderhelm@acme.example.", + "Not in your inbox after a few minutes? Check spam or quarantine, or ask IT to allow those addresses.", + ], + setupNote: "Got a set-up link instead of a code? There's no code to enter: open the link in that email to set up your account.", + errors: 0, }); - await askForReset(page, "who@else.example"); - await expect(page.getByRole("alert").filter({ hasText: "no account" })).toHaveText( - "There's no account for who@else.example on this CoderHelm. Ask an admin to add you.", - ); - await expect(page.getByTestId("sender-note")).toHaveCount(0); - await expect(page.getByLabel("Reset code")).toHaveCount(0); + for (const s of seen) expect(s).toEqual(seen[0]); }); test("forgot password with an SES sender for Cognito: that address, not Cognito's", async ({ page }) => { await mockApi(page, { selfHosted: true, methods: { password: true, google: false, github: false, senders: { setup: "coderhelm@acme.example", reset_codes: "noreply@acme.example" } }, - forgot: { status: "code_sent", message: "We sent a reset code to jo@acme.example." }, + forgot: REPLIES[0], }); await askForReset(page, "jo@acme.example"); - await expect(page.getByTestId("sender-note")).toContainText("The reset code comes from noreply@acme.example."); + await expect(page.getByTestId("sender-note")).toContainText("Reset codes come from noreply@acme.example."); await expect(page.getByTestId("sender-note")).not.toContainText("Amazon Cognito"); }); + +test("self-hosted sign-up from an invite link: one answer, whoever the email is", async ({ page }) => { + const { calls } = await mockApi(page, { selfHosted: true, methods: { password: true, google: false, github: false, senders: SENDERS } }); + await page.goto("/?invite=1"); + await page.getByLabel("Email").fill("jo@acme.example"); + await page.getByLabel("Password, at least 8 characters").fill("Acme2026x"); + await page.getByRole("button", { name: "Create account" }).click(); + await expect(page.getByRole("status")).toHaveText( + "If jo@acme.example can join here, we've sent a verification code. No code after a few minutes? If you already have an account, sign in or use Forgot password; otherwise ask an admin to invite you.", + ); + await expect(page.getByLabel("Verification code")).toBeVisible(); + await expect(errorBox(page)).toHaveCount(0); + expect(calls).toContain("/auth/signup"); +}); diff --git a/dashboard/src/components/client-shell.tsx b/dashboard/src/components/client-shell.tsx index 15bbd1d7..00e0f067 100644 --- a/dashboard/src/components/client-shell.tsx +++ b/dashboard/src/components/client-shell.tsx @@ -4,7 +4,7 @@ import { can } from "@/lib/capabilities"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { type ReactNode, useEffect, useRef, useState } from "react"; -import { api, ApiError, TEAM_MOVED, TWO_FACTOR_REQUIRED, movedUrl, type ForgotStatus, type SignInSenders, type UsageInfo, type Banner, type TeamInfo } from "@/lib/api"; +import { api, ApiError, TEAM_MOVED, TWO_FACTOR_REQUIRED, movedUrl, type SignInSenders, type UsageInfo, type Banner, type TeamInfo } from "@/lib/api"; import { pushToDataLayer } from "@/lib/gtm"; import { formatTokens, limitName, reachedLimit, USAGE_CHANGED, usageBreakdown, usageLimits } from "@/lib/usage"; import { TokenMeters } from "@/components/token-meters"; @@ -1000,23 +1000,35 @@ const USE_PASSWORD_MESSAGE = const COGNITO_DEFAULT_SENDER = "no-reply@verificationemail.com"; /** - * Where the email that forgot-password just sent comes from, so a person whose mail filter - * holds it back can ask IT to allow that address. Shown only when the install said who sends. + * What the sign-in page says after Forgot password, the same for every email: it never says + * whether the email has an account here, is on the team, is invited, or is unknown. */ -function SenderNote({ status, senders }: { status: ForgotStatus | null; senders?: SignInSenders }) { - if (!status || !senders) return null; - let line = ""; - if (status === "code_sent" && senders.reset_codes) { +function forgotSentMessage(email: string, selfHosted: boolean): string { + return selfHosted + ? `If ${email} can sign in here, we've sent a reset code or a set-up link.` + : `If ${email} can sign in here, we've sent a reset code.`; +} + +/** + * Who sends both emails Forgot password can send, so a person whose mail filter holds one back + * can ask IT to allow it. The same lines whatever the email; shown when the install said who sends. + */ +function SenderNote({ senders }: { senders?: SignInSenders }) { + if (!senders) return null; + const lines: string[] = []; + if (senders.reset_codes) { const who = senders.reset_codes === COGNITO_DEFAULT_SENDER ? " (Amazon Cognito, which signs people in here)" : ""; - line = `The reset code comes from ${senders.reset_codes}${who}.`; - } else if ((status === "setup_sent" || status === "setup_recent") && senders.setup) { - line = `The set-up link comes from ${senders.setup}.`; + lines.push(`Reset codes come from ${senders.reset_codes}${who}.`); } - if (!line) return null; + if (senders.setup) lines.push(`Set-up links come from ${senders.setup}.`); + if (lines.length === 0) return null; return ( -
- {line} Not in your inbox after a few minutes? Check spam or quarantine, or ask IT to allow that address. -
+{l}
)} ++ Not in your inbox after a few minutes? Check spam or quarantine, or ask IT to allow {lines.length > 1 ? "those addresses" : "that address"}. +
+Enter the code and your new password
+ {selfHosted && ( ++ Got a set-up link instead of a code? There's no code to enter: open the link in that email to set up your account. +
+ )}