Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions dashboard/e2e/sign-in-methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { expect, test, type Page, type Route } from "@playwright/test";
// install checks the account itself. An install with neither shows no GitHub
// button. Every API call is answered here.

type Methods = { password: boolean; google: boolean; github: boolean };
type Methods = { password: boolean; google: boolean; github: boolean; senders?: { setup: string | null; reset_codes: string | null } };
type ForgotReply = { status: string; message: string; email?: string };

async function mockApi(page: Page, opts: { selfHosted: boolean; methods: Methods | "missing"; status?: string }) {
async function mockApi(page: Page, opts: { selfHosted: boolean; methods: Methods | "missing"; status?: string; forgot?: ForgotReply }) {
const calls: string[] = [];
const json = (route: Route, body: unknown, status = 200) =>
route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
Expand All @@ -31,6 +32,7 @@ async function mockApi(page: Page, opts: { selfHosted: boolean; methods: Methods
? json(route, { user_id: "u_1", team_id: "t_1", github_login: "a-dev", email: "dev@acme.example", avatar_url: "", role: "owner", status: opts.status })
: json(route, { error: "unauthorized" }, 401);
}
if (p === "/auth/forgot-password" && opts.forgot) return json(route, opts.forgot);
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 }] });
Expand Down Expand Up @@ -124,3 +126,69 @@ test("removed GitHub app: 'sign in with GitHub again' only where GitHub sign-in
await page.goto("/");
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.
const SENDERS = { setup: "coderhelm@acme.example", reset_codes: "no-reply@verificationemail.com" };

async function askForReset(page: Page, email: string) {
await page.goto("/");
await page.getByRole("button", { name: "Forgot password?" }).click();
await page.getByLabel("Email").fill(email);
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");
});

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);
});

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." },
});
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);
});

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." },
});
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")).not.toContainText("Amazon Cognito");
});
81 changes: 79 additions & 2 deletions dashboard/e2e/team.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ interface Backend {
changes: { at: string; actor: string; action: string; role_id: string; role_name: string; detail: string }[];
/** You hold this custom role (your record's role); requests run as `selfRole`. */
selfCustom?: string;
/** GitHub sign-in works here (`GET /auth/methods`). */
githubSignIn?: boolean;
}

// The gateway's rules for custom roles, as the mock answers them.
Expand Down Expand Up @@ -140,6 +142,22 @@ async function mockApi(page: Page, selfRole = "admin", init: Partial<Backend> =
const body = req.postData() ? (JSON.parse(req.postData() as string) as Record<string, unknown>) : null;
db.calls.push({ method, path: p, body, search: url.search });
const self = db.members.find((m) => m.is_self);
if (p === "/auth/methods") return json(route, { password: true, google: false, github: db.githubSignIn ?? false });
if (p === "/api/users/setup-emails" && method === "POST") {
if (LEVEL[selfRole] < 3) return json(route, { error: "Only admins and owners can do that." }, 403);
const hour = Date.now() - 3600_000;
const sent_at: Record<string, string> = {};
let skipped = 0;
for (const m of db.members.filter((x) => x.needs_setup)) {
if (m.setup_email_sent_at && new Date(m.setup_email_sent_at).getTime() > hour) {
skipped += 1;
continue;
}
m.setup_email_sent_at = new Date().toISOString();
sent_at[m.user_id] = m.setup_email_sent_at;
}
return json(route, { sent: Object.keys(sent_at).length, skipped_recent: skipped, failed: 0, sent_at });
}
if (p === "/api/me") return json(route, { user_id: self?.user_id ?? "u-admin", team_id: "t_1", github_login: null, email: self?.email ?? "", avatar_url: "", role: selfRole });
if (p === "/api/usage") return json(route, { month: "2026-01", total_tokens: 0, tokens_in: 0, tokens_out: 0, total_runs: 0, max_tokens: 0 });
if (p === "/api/banners") return json(route, { banners: [] });
Expand Down Expand Up @@ -483,20 +501,79 @@ test("self-hosted: a member who never signed in here gets a set-up email from th
const mia = db.members.find((x) => x.user_id === "u-mem")!;
mia.needs_setup = true;
await page.goto("/settings/team");
await expect(row(page, "Mia Member").getByTestId("setup-status")).toHaveText("Hasn't set up an account here yet");
await expect(row(page, "Mia Member").getByTestId("setup-status")).toHaveText("Hasn't signed in here yet");
// Only that member: everyone else has signed in here.
await expect(members(page).getByTestId("setup-status")).toHaveCount(1);
await expect(row(page, "Mia Member").getByRole("button", { name: "Send set-up email" })).toBeVisible();
await row(page, "Mia Member").getByRole("button", { name: "More actions for Mia Member" }).click();
await page.getByRole("menuitem", { name: "Send set-up email" }).click();
await expect(page.getByText("Set-up email sent to mia@example.com")).toBeVisible();
await expect(row(page, "Mia Member").getByTestId("setup-status")).toHaveText(/^Set-up email sent /);
await expect(row(page, "Mia Member").getByTestId("setup-sent")).toHaveText(/^Set-up email sent /);
await expect(row(page, "Mia Member").getByRole("button", { name: "Send the set-up email again" })).toBeVisible();
expect(db.calls.some((c) => c.method === "POST" && c.path === "/api/users/u-mem/setup-email")).toBe(true);
// Sent before: the menu says it goes again.
await row(page, "Mia Member").getByRole("button", { name: "More actions for Mia Member" }).click();
await expect(page.getByRole("menuitem", { name: "Send the set-up email again" })).toBeVisible();
await shot(page, "team-setup-email");
});

test("self-hosted: someone copied over shows they haven't signed in here, not their old activity", async ({ page }) => {
const db = await mockApi(page, "admin", { githubSignIn: true });
db.members.push(
member({ user_id: "u-al", email: "al.chan@acme.example", name: "Al Chan", github_login: "achan", github_id: "777", sign_in: "email_and_github", last_active_at: ago(5 * DAY), needs_setup: true }),
);
await page.goto("/settings/team");
const al = row(page, "Al Chan");
await expect(al.getByTestId("setup-status")).toHaveText("Hasn't signed in here yet");
await expect(al).not.toContainText("Active 5 days ago");
await expect(al.getByTestId("previous-activity")).toHaveText("Last active on the previous Coderhelm, 5 days ago");
await expect(al.getByTestId("github-sign-in")).toHaveText("Can sign in with GitHub (achan)");
await expect(al.getByRole("button", { name: "Send set-up email" })).toBeVisible();
// People who signed in here keep their plain activity time.
await expect(row(page, "Sam Rivera")).toContainText("Active 5 days ago");
await expect(page.getByText("· 1 haven't signed in here yet")).toBeVisible();
});

test("self-hosted: without GitHub sign-in, no GitHub line for someone copied over", async ({ page }) => {
const db = await mockApi(page, "admin", { githubSignIn: false });
db.members.push(member({ user_id: "u-al", email: "al.chan@acme.example", name: "Al Chan", github_login: "achan", github_id: "777", needs_setup: true }));
await page.goto("/settings/team");
await expect(row(page, "Al Chan").getByTestId("setup-status")).toBeVisible();
await expect(row(page, "Al Chan").getByTestId("github-sign-in")).toHaveCount(0);
});

test("self-hosted: the banner counts who hasn't set up an account and sends to all, skipping the last hour", async ({ page }) => {
const db = await mockApi(page);
const mia = db.members.find((x) => x.user_id === "u-mem")!;
const jo = db.members.find((x) => x.user_id === "u-jo")!;
const sam = db.members.find((x) => x.user_id === "u-sam")!;
mia.needs_setup = true;
sam.needs_setup = true;
jo.needs_setup = true;
jo.setup_email_sent_at = ago(20 * 60_000);
await page.goto("/settings/team");
const banner = page.getByTestId("setup-banner");
await expect(banner).toContainText("3 people haven't set up an account here yet");
await expect(page.getByText("· 3 haven't signed in here yet")).toBeVisible();
await banner.getByRole("button", { name: "Send set-up emails to all" }).click();
await expect(page.getByText("Set-up email sent to 2 people. 1 person got one in the last hour and was skipped.")).toBeVisible();
expect(db.calls.filter((c) => c.method === "POST" && c.path === "/api/users/setup-emails")).toHaveLength(1);
await expect(row(page, "Mia Member").getByTestId("setup-sent")).toHaveText(/^Set-up email sent /);
await expect(row(page, "Sam Rivera").getByTestId("setup-sent")).toHaveText(/^Set-up email sent /);
await shot(page, "team-setup-banner");
});

test("the set-up banner has no send button for someone who can't invite", async ({ page }) => {
const db = await mockApi(page, "member");
db.members.find((x) => x.user_id === "u-sam")!.needs_setup = true;
await page.goto("/settings/team");
const banner = page.getByTestId("setup-banner");
await expect(banner).toContainText("1 person hasn't set up an account here yet");
await expect(banner).toContainText("Ask an admin to send them the set-up email.");
await expect(banner.getByRole("button", { name: "Send set-up emails to all" })).toHaveCount(0);
await expect(row(page, "Sam Rivera").getByRole("button", { name: "Send set-up email" })).toHaveCount(0);
});

test("no set-up email for members who signed in, or for someone who can't invite", async ({ page }) => {
await mockApi(page);
await page.goto("/settings/team");
Expand Down
3 changes: 3 additions & 0 deletions dashboard/e2e/wide-data/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const USERS = [
{ user_id: "u_owner", email: EMAIL, name: "Olivia Owner-With-A-Very-Long-Double-Barrelled-Surname", github_login: "olivia-owner-with-a-long-github-login", github_id: null, avatar_url: null, role: "owner", status: "active", sign_in: "email", invited_by: null, last_active_at: iso(60), updated_at: iso(600), is_self: false },
{ user_id: "u_self", email: `dana.${EMAIL}`, name: "Dana Developer", github_login: "dana-developer-with-a-long-login", github_id: null, avatar_url: null, role: "owner", status: "active", sign_in: "github", invited_by: null, last_active_at: iso(5), updated_at: iso(600), is_self: true },
{ user_id: "u_inv", email: `invited.person.${EMAIL}`, name: null, github_login: null, github_id: null, avatar_url: null, role: "member", status: "invited", sign_in: "email", invited_by: EMAIL, last_active_at: null, updated_at: iso(60 * 24), is_self: false },
// Copied from another Coderhelm and never signed in here: the status, the old activity, the GitHub line and the row button.
{ user_id: "u_moved", email: `moved.person.${EMAIL}`, name: "Moved Person-With-A-Very-Long-Double-Barrelled-Surname", github_login: "moved-person-with-a-long-github-login", github_id: "4242", avatar_url: null, role: "member", status: "active", sign_in: "email_and_github", invited_by: null, last_active_at: iso(60 * 24 * 5), updated_at: iso(600), needs_setup: true, setup_email_sent_at: iso(60 * 24), is_self: false },
{ user_id: "u_view", email: `viewer.${EMAIL}`, name: "Jo Viewer", github_login: null, github_id: null, avatar_url: null, role: "viewer", status: "active", sign_in: "email", invited_by: null, last_active_at: iso(60 * 24 * 9), updated_at: iso(60 * 24 * 9), is_self: false },
];

Expand Down Expand Up @@ -236,6 +238,7 @@ export const settingsData: Handler = ({ method, path, url }) => {
headers: { "webhook-id": "evt_01JBEVNT8M1N4P7Q0R3S6T9V2WWIDEWIDEWIDE", "webhook-signature": "[redacted]", "user-agent": LONG_URL },
}] };
}
if (p === "/auth/methods") return { password: true, google: false, github: true, senders: { setup: `coderhelm.${EMAIL}`, reset_codes: "no-reply@verificationemail.com" } };
if (p === "/api/users") return { users: USERS };
// Your own two-factor sign-in (both deployments): kept on by a team's rule.
if (p === "/api/users/2fa") {
Expand Down
Loading
Loading