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
86 changes: 75 additions & 11 deletions dashboard/e2e/require-sso.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { expect, test, type Page, type Route } from "@playwright/test";

// Require single sign-on, with the team's Okta or its own Microsoft Entra
// tenant. Settings, Sign-in rules shows each provider, what turning it on
// needs, the recovery words before and after, who isn't linked and their
// one-time links. The sign-in screen, for a team that requires it, shows only
// tenant. Settings, Sign-in rules shows the state now, a provider to choose,
// what turning it on needs (each step done or not, and how to do it), why the
// button is off, the consequences once in the confirm, who isn't linked and
// their one-time links. The sign-in screen, for a team that requires it, shows only
// that provider: no password form, and no owner's way around it. Every API
// call is answered here; nothing reaches Okta, Microsoft or a real backend.

Expand Down Expand Up @@ -177,36 +178,99 @@ for (const width of [1280, 390]) {
test("each provider says what turning it on needs; only a ready one can be chosen", async ({ page }) => {
await mock(page, { signedIn: true });
await page.goto("/settings/sign-in");
await expect(page.getByTestId("require-sso-state")).toContainText("Off");
// The readiest provider is chosen first; Okta is one step short.
await expect(page.getByTestId("sso-choose-microsoft")).toHaveAttribute("aria-checked", "true");
await expect(page.getByTestId("sso-choose-okta")).toContainText("1 step left");
await page.getByTestId("sso-choose-okta").click();
const okta = page.getByTestId("sso-option-okta");
await expect(page.getByTestId("require-sso-okta")).toBeDisabled();
await expect(okta.getByTestId("need-session-okta")).toHaveAttribute("data-ok", "no");
await expect(okta.getByTestId("need-owner-okta")).toHaveAttribute("data-ok", "yes");
await expect(page.getByTestId("require-sso-reason")).toHaveText("Finish the step above first.");
await page.getByTestId("sso-choose-microsoft").click();
await expect(page.getByTestId("require-sso-microsoft")).toBeEnabled();
// Recovery is said next to the choice, before anything is turned on.
await expect(page.getByTestId("require-sso-reason")).toHaveCount(0);
// Recovery, keys and support access are folded into the details, said once.
await page.getByText("If Microsoft Entra is down, and other details").click();
await expect(page.getByTestId("sso-recovery-microsoft")).toContainText("nobody can sign in until it's fixed");
await expect(page.getByTestId("require-sso-keys")).toContainText("Keys follow their maker");
await expect(page.getByTestId("require-sso-support")).toContainText("read-only, never a session in your team");
await expect(page.getByTestId("require-sso-keys")).toContainText("suspended, not deleted");
await expect(page.getByTestId("require-sso-support")).toContainText("never a session in your team");
await noSidewaysScroll(page);
});

test("requirements unmet say why and keep the button off; met, it confirms with the consequences", async ({ page }) => {
const state = await mock(page, {
signedIn: true,
options: [
{ provider: "okta", name: "Okta", set_up: false, enabled: false, domains_verified: false, session_from_provider: false, is_owner: true },
{ provider: "microsoft", name: "Microsoft Entra", ...READY },
],
unlinked: [{ user_id: "ann", email: "ann@example.org", name: "Ann Lee", role: "member" }],
});
await page.goto("/settings/sign-in");
await page.getByTestId("sso-choose-okta").click();
await expect(page.getByTestId("sso-choose-okta")).toContainText("3 steps left");
await expect(page.getByTestId("need-on-okta")).toHaveAttribute("data-ok", "no");
// Each open step says how to do it: setup is a link to the Okta section.
await expect(page.getByTestId("go-setup-okta")).toHaveText("Set up Okta");
await expect(page.getByTestId("go-setup-okta")).toHaveAttribute("href", "#okta");
await expect(page.getByTestId("need-session-okta")).toContainText("Once Okta is on, sign in with it");
await expect(page.getByTestId("require-sso-okta")).toBeDisabled();
await expect(page.getByTestId("require-sso-reason")).toHaveText("Finish the 3 steps above first.");
await noSidewaysScroll(page);

await page.getByTestId("sso-choose-microsoft").click();
await expect(page.getByTestId("require-sso-microsoft")).toBeEnabled();
await expect(page.getByTestId("require-sso-reason")).toHaveCount(0);
await page.getByTestId("require-sso-microsoft").click();
const dialog = page.getByTestId("require-sso-confirm");
await expect(dialog).toContainText("Require Microsoft Entra for everyone on this team?");
await expect(dialog.getByTestId("consequence-sessions")).toContainText("the owner's included");
await expect(dialog.getByTestId("consequence-unlinked")).toContainText("Ann Lee hasn't linked Microsoft Entra");
await expect(dialog.getByTestId("consequence-keys")).toContainText("nightly-ci");
await expect(dialog.getByTestId("consequence-recovery")).toContainText("support verifies them out of band");
await noSidewaysScroll(page);
// Cancel sends nothing.
await dialog.getByRole("button", { name: "Cancel" }).click();
await expect(dialog).toHaveCount(0);
expect(state.puts).toEqual([]);
});

test("a member who isn't the owner is told why the button is off", async ({ page }) => {
await mock(page, {
signedIn: true,
options: [
{ provider: "okta", name: "Okta", ...READY, is_owner: false },
{ provider: "microsoft", name: "Microsoft Entra", ...READY, is_owner: false },
],
});
await page.goto("/settings/sign-in");
await expect(page.getByTestId("need-owner-okta")).toHaveAttribute("data-ok", "no");
await expect(page.getByTestId("require-sso-okta")).toBeDisabled();
await expect(page.getByTestId("require-sso-reason")).toHaveText("Only the owner can turn this on.");
});

test("turning it on confirms the recovery and who isn't linked, then sends the provider", async ({ page }) => {
const state = await mock(page, {
signedIn: true,
unlinked: [{ user_id: "ann", email: "ann@example.org", name: "Ann Lee", role: "member" }],
});
await page.goto("/settings/sign-in");
await page.getByTestId("require-sso-microsoft").click();
const confirm = page.getByTestId("confirm-dialog");
await expect(confirm).toContainText("Require single sign-on with Microsoft Entra for everyone on this team?");
const confirm = page.getByTestId("require-sso-confirm");
await expect(confirm).toContainText("Require Microsoft Entra for everyone on this team?");
await expect(confirm).toContainText("If Microsoft Entra is down or misconfigured, nobody can sign in until it's fixed.");
await expect(confirm).toContainText("Ann Lee");
await expect(confirm).toContainText("the owner's included");
// Keys follow their maker: the ones that will be suspended are named.
await expect(confirm).toContainText("These keys are suspended until their maker links Microsoft Entra: nightly-ci.");
await expect(confirm).toContainText("stays ended if you turn this off later");
await noSidewaysScroll(page);
await page.getByRole("button", { name: "Require Microsoft Entra" }).click();
await page.getByTestId("require-sso-confirm-yes").click();
await expect.poll(() => state.puts.at(-1)).toEqual({ require_sso: "microsoft", acknowledge_unlinked: true });
await expect(page.getByTestId("require-sso-state")).toContainText("Required with Microsoft Entra");
await expect(page.getByTestId("require-sso-state")).toContainText("Required: Microsoft Entra");
await expect(page.getByTestId("suspended-keys-microsoft")).toContainText("nightly-ci");
await expect(page.getByTestId("sso-recovery")).toContainText("support verifies them out of band");
});

Expand All @@ -215,7 +279,7 @@ for (const width of [1280, 390]) {
await page.goto("/settings/sign-in");
await expect(page.getByTestId("keys-unread")).toContainText("couldn't read the team's keys");
await page.getByTestId("require-sso-microsoft").click();
const confirm = page.getByTestId("confirm-dialog");
const confirm = page.getByTestId("require-sso-confirm");
await expect(confirm).toContainText("couldn't read the team's keys, so it can't say which would be suspended");
await expect(confirm).not.toContainText("These keys are suspended");
await noSidewaysScroll(page);
Expand Down
30 changes: 20 additions & 10 deletions dashboard/scripts/ui-lint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
//
// Errors (fail the run):
// model-name a Claude model named in page text; names come from lib/models.ts
// brand "Coderhelm" anywhere in src; the product is "CoderHelm", as on the site,
// the logo, the repositories and the docs
// brand "Coderhelm" or "Coder Helm" anywhere in src or in the e2e specs and their
// mock data (what the screenshots show); the product is "CoderHelm", as on
// the site, the logo, the repositories and the docs. Words the server sends
// are shown through productWords() (settings/sign-in/require-sso.tsx)
// jargon openspec, "<something> pass", TOTP, HMAC, "Log Analyzer" in UI copy
// unlabeled-input an <input>, <textarea> or <select> with no label, beyond the baseline
// page-route a page (src/app/**/page.tsx) with no entry in lib/routes.ts, so the top bar can't name it
Expand Down Expand Up @@ -63,7 +65,8 @@ const GITHUB = !!process.env.GITHUB_ACTIONS;
const REPO_PREFIX = path.relative(path.resolve(ROOT, ".."), ROOT);

const MODEL_NAME = /\b(?:Claude\s+)?(?:Opus|Sonnet|Haiku|Fable)\s+\d+(?:\.\d+)?\b|\bClaude\s+\d+(?:\.\d+)?\b/;
const BRAND = /\bCoderhelm\b/g;
const BRAND = /\bCoder(?:helm|\s+Helm)\b/g;
const E2E = path.join(ROOT, "e2e");
const JARGON = [
{ re: /\bopen\s?spec\b/i, say: "openspec: say \"spec\" or what the files are" },
{
Expand Down Expand Up @@ -207,19 +210,26 @@ function wideFromSm(cls) {
return !tokens.some((t) => /^sm:(w-|max-w-|inline-flex|inline-block|flex-none|self-)/.test(t));
}

for (const file of walk(SRC)) {
const rel = path.relative(ROOT, file).split(path.sep).join("/");
const source = fs.readFileSync(file, "utf8");
const tsx = file.endsWith(".tsx");

// brand: the whole file, comments included.
/** brand: the whole file, comments included. */
function brandCheck(rel, source) {
for (const m of source.matchAll(BRAND)) {
const lineText = source.slice(source.lastIndexOf("\n", m.index) + 1, source.indexOf("\n", m.index));
if (allowed("brand", rel, lineText)) continue;
const before = source.slice(0, m.index);
const line = before.split("\n").length;
errors.push({ rule: "brand", file: rel, line, col: m.index - before.lastIndexOf("\n"), message: "\"Coderhelm\": the product is spelled \"CoderHelm\"" });
errors.push({ rule: "brand", file: rel, line, col: m.index - before.lastIndexOf("\n"), message: `"${m[0]}": the product is spelled "CoderHelm"` });
}
}

// The e2e specs and their mock data are what the screenshots show: brand only.
for (const file of walk(E2E)) brandCheck(path.relative(ROOT, file).split(path.sep).join("/"), fs.readFileSync(file, "utf8"));

for (const file of walk(SRC)) {
const rel = path.relative(ROOT, file).split(path.sep).join("/");
const source = fs.readFileSync(file, "utf8");
const tsx = file.endsWith(".tsx");

brandCheck(rel, source);

// break-all: cuts words that would fit on the next line.
for (const m of source.matchAll(/\bbreak-all\b/g)) {
Expand Down
Loading
Loading