Public: anyone can read this; the crew can change it.
The passkeys page's Server-Timing names its phases: session, each read, render #3474
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3446-the-passkeys-page-s-server-timing-names → main 1 commit fork 1 thread · 1 unresolved
2 files
changed +54
−2
src/web/pages/passkeys.ts +8 −2
| @@ -23,6 +23,7 @@ import { createSession } from "../../core/sessions.ts"; | ||
| 23 | 23 | import { recoveryAccount, requestRecovery, spendRecoveryLink } from "../../actions/verify.ts"; |
| 24 | 24 | import { getUserById, isActive } from "../../core/users.ts"; |
| 25 | 25 | import { crossOrigin, type Ctx } from "../../http/context.ts"; |
| 26 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 26 | 27 | import { clientAddress, clientBucket } from "../../http/peer.ts"; |
| 27 | 28 | import { STRANGER_MAX } from "../../http/limits.ts"; |
| 28 | 29 | import { boundedBody, json, str } from "../../http/respond.ts"; |
| @@ -61,8 +62,11 @@ function sessionOnly(ctx: Ctx): Response | undefined { | ||
| 61 | 62 | |
| 62 | 63 | // GET /settings/passkeys |
| 63 | 64 | export function passkeysPage(ctx: Ctx): Response { |
| 65 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 64 | 66 | if (!ctx.auth.user) return signInFirst(ctx); |
| 65 | const keys = listPasskeys(ctx.app.db, ctx.auth.user.id); | |
| 67 | const user = ctx.auth.user; | |
| 68 | const keys = timePhase(ctx.request, "passkeys", () => listPasskeys(ctx.app.db, user.id)); | |
| 69 | const rendering = performance.now(); | |
| 66 | 70 | const body = html`<p class="muted small mb"> |
| 67 | 71 | A passkey signs you in with a fingerprint, face or device PIN instead of |
| 68 | 72 | a password. Add one per device; each can be removed on its own. |
| @@ -99,7 +103,9 @@ export function passkeysPage(ctx: Ctx): Response { | ||
| 99 | 103 | </div>`, |
| 100 | 104 | { head: html`<h3>New passkey</h3>` }, |
| 101 | 105 | )}`; |
| 102 | return accountShell(ctx, "passkeys", "Passkeys", body, 200, passkeyJs); | |
| 106 | const response = accountShell(ctx, "passkeys", "Passkeys", body, 200, passkeyJs); | |
| 107 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 108 | return response; | |
| 103 | 109 | } |
| 104 | 110 | |
| 105 | 111 | // POST /settings/passkeys/options — a challenge for a new passkey. |
test/passkeys-timing.test.ts added +46
| @@ -0,0 +1,46 @@ | ||
| 1 | /** The passkeys page names its phases in Server-Timing (#3446). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 8 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 9 | ||
| 10 | let dataDir = ""; | |
| 11 | let app: App, servers: Servers, bearer = ""; | |
| 12 | ||
| 13 | beforeAll(async () => { | |
| 14 | dataDir = await mkdtemp(join(tmpdir(), "forge-pktime-")); | |
| 15 | app = createApp({ dataDir, port: 0 }); | |
| 16 | servers = await serve(app); | |
| 17 | const admin = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "correct-horse-battery" }); | |
| 18 | if (!admin.ok) throw new Error(admin.error); | |
| 19 | const minted = await fetch(`${servers.url}/api/v1/tokens`, { | |
| 20 | method: "POST", | |
| 21 | headers: { "content-type": "application/json" }, | |
| 22 | body: JSON.stringify({ adminConfirm: true, username: "alice", password: "correct-horse-battery", name: "cli", scope: "admin" }), | |
| 23 | }); | |
| 24 | bearer = ((await minted.json()) as { token: string }).token; | |
| 25 | }); | |
| 26 | ||
| 27 | afterAll(async () => { | |
| 28 | servers.stop(); | |
| 29 | app.close(); | |
| 30 | await rm(dataDir, { recursive: true, force: true }); | |
| 31 | }); | |
| 32 | ||
| 33 | test("the passkeys page names session, passkeys and render once each", async () => { | |
| 34 | const res = await fetch(`${servers.url}/settings/passkeys`, { headers: { authorization: `Bearer ${bearer}` } }); | |
| 35 | const page = await res.text(); | |
| 36 | expect(res.status).toBe(200); | |
| 37 | expect(page).toContain("New passkey"); | |
| 38 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 39 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 40 | const names = parts.map((p) => p.split(";")[0]!); | |
| 41 | for (const n of ["session", "passkeys", "render"]) { | |
| 42 | expect(names.filter((x) => x === n).length).toBe(1); | |
| 43 | const part = parts.find((p) => p.startsWith(`${n};`))!; | |
| 44 | expect(Number(/dur=([\d.]+)/.exec(part)?.[1])).not.toBeNaN(); | |
| 45 | } | |
| 46 | }); |
new above
offline
Comment cites #3446; make sure it names the issue this pull closes.