Public: anyone can read this; the crew can change it.
Connections: email_check.verified_at is read nowhere once #18222 lands, and is dropped when no release in play reads it #18327
Merged 10h 8m ago, live in production
scout/forge:scout/18324-connections-email-check-verified-at-is-r → main 0 commits fork
5 files
changed +58
−12
src/core/accounts.ts +3 −3
| @@ -62,7 +62,7 @@ export function listAccounts(db: Database, only = ""): AccountRow[] { | ||
| 62 | 62 | suspended_at: string | null; |
| 63 | 63 | removed_at: string | null; |
| 64 | 64 | waiting_at: string | null; |
| 65 | verified_at: string | null; | |
| 65 | proven_at: string | null; | |
| 66 | 66 | repos: number; |
| 67 | 67 | apps: number; |
| 68 | 68 | spent: number | null; |
| @@ -72,7 +72,7 @@ export function listAccounts(db: Database, only = ""): AccountRow[] { | ||
| 72 | 72 | >( |
| 73 | 73 | `SELECT u.id, u.username, u.display_name, u.is_admin, u.is_agent, |
| 74 | 74 | u.created_at, u.suspended_at, u.removed_at, u.waiting_at, |
| 75 | ${provenEmailAt("u")} AS verified_at, | |
| 75 | ${provenEmailAt("u")} AS proven_at, | |
| 76 | 76 | (SELECT COUNT(*) FROM repo r WHERE r.owner_id = u.id) AS repos, |
| 77 | 77 | (SELECT COUNT(*) FROM app a JOIN repo r ON r.id = a.repo_id |
| 78 | 78 | WHERE r.owner_id = u.id) AS apps, |
| @@ -102,7 +102,7 @@ export function listAccounts(db: Database, only = ""): AccountRow[] { | ||
| 102 | 102 | suspendedAt: r.suspended_at, |
| 103 | 103 | removedAt: r.removed_at, |
| 104 | 104 | waiting: r.waiting_at !== null && r.removed_at === null, |
| 105 | verified: r.is_agent === 1 || r.verified_at !== null, | |
| 105 | verified: r.is_agent === 1 || r.proven_at !== null, | |
| 106 | 106 | }; |
| 107 | 107 | }); |
| 108 | 108 | } |
src/core/people_rows.ts +3 −3
| @@ -34,8 +34,8 @@ export function wordFilter(raw: string | null | undefined): RoleWord | null { | ||
| 34 | 34 | /** Every person and crew member, most recently seen first; never-seen last, newest first. */ |
| 35 | 35 | export function peopleByActivity(db: Database, only: RoleWord | null = null): PersonRow[] { |
| 36 | 36 | const rows = db |
| 37 | .query<{ username: string; is_admin: number; is_agent: number; member: string | null; seen: string | null; usd: number | null; suspended_at: string | null; verified_at: string | null }, []>( | |
| 38 | `SELECT u.username, u.is_admin, u.is_agent, m.user_id AS member, g.usd_per_month AS usd, u.suspended_at, ${provenEmailAt("u")} AS verified_at, | |
| 37 | .query<{ username: string; is_admin: number; is_agent: number; member: string | null; seen: string | null; usd: number | null; suspended_at: string | null; proven_at: string | null }, []>( | |
| 38 | `SELECT u.username, u.is_admin, u.is_agent, m.user_id AS member, g.usd_per_month AS usd, u.suspended_at, ${provenEmailAt("u")} AS proven_at, | |
| 39 | 39 | MAX(COALESCE((SELECT MAX(s.last_seen_at) FROM session s WHERE s.user_id = u.id), ''), |
| 40 | 40 | COALESCE((SELECT MAX(t.last_used_at) FROM token t WHERE t.user_id = u.id), '')) AS seen |
| 41 | 41 | FROM user u LEFT JOIN member m ON m.user_id = u.id |
| @@ -51,7 +51,7 @@ export function peopleByActivity(db: Database, only: RoleWord | null = null): Pe | ||
| 51 | 51 | word, |
| 52 | 52 | usdPerMonth: word === "member" || word === "guest" ? r.usd : null, |
| 53 | 53 | suspendedAt: r.suspended_at, |
| 54 | verified: r.verified_at !== null, | |
| 54 | verified: r.proven_at !== null, | |
| 55 | 55 | lastSeen: r.seen === null || r.seen === "" ? null : r.seen, |
| 56 | 56 | }; |
| 57 | 57 | }); |
src/core/proven_identities.ts +3 −3
| @@ -43,15 +43,15 @@ export interface Identity { | ||
| 43 | 43 | export function emailIdentity(db: Database, userId: string): Identity | undefined { |
| 44 | 44 | const user = db |
| 45 | 45 | .query< |
| 46 | { email: string; kind: string; is_agent: number; verified_at: string | null }, | |
| 46 | { email: string; kind: string; is_agent: number; proven_at: string | null }, | |
| 47 | 47 | [string] |
| 48 | 48 | >( |
| 49 | `SELECT u.email, u.kind, u.is_agent, ${provenEmailAt("u")} AS verified_at FROM user u WHERE u.id = ?1`, | |
| 49 | `SELECT u.email, u.kind, u.is_agent, ${provenEmailAt("u")} AS proven_at FROM user u WHERE u.id = ?1`, | |
| 50 | 50 | ) |
| 51 | 51 | .get(userId); |
| 52 | 52 | if (user === null) return undefined; |
| 53 | 53 | const vouched = user.is_agent === 1 || user.kind === "org"; |
| 54 | return { kind: "email", name: user.email, proven: vouched || user.verified_at !== null, since: user.verified_at }; | |
| 54 | return { kind: "email", name: user.email, proven: vouched || user.proven_at !== null, since: user.proven_at }; | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
src/core/roles.ts +3 −3
| @@ -153,9 +153,9 @@ export interface Person { | ||
| 153 | 153 | /** Every person (not an agent, not an organization) with role and model grant, newest first, in one query. */ |
| 154 | 154 | export function listPeople(db: Database): Person[] { |
| 155 | 155 | return db |
| 156 | .query<{ username: string; is_admin: number; member: number | null; usd: number | null; suspended_at: string | null; verified_at: string | null }, []>( | |
| 156 | .query<{ username: string; is_admin: number; member: number | null; usd: number | null; suspended_at: string | null; proven_at: string | null }, []>( | |
| 157 | 157 | `SELECT u.username, u.is_admin, m.user_id AS member, g.usd_per_month AS usd, u.suspended_at, |
| 158 | ${provenEmailAt("u")} AS verified_at | |
| 158 | ${provenEmailAt("u")} AS proven_at | |
| 159 | 159 | FROM user u |
| 160 | 160 | LEFT JOIN member m ON m.user_id = u.id |
| 161 | 161 | LEFT JOIN model_grant g ON g.user_id = u.id |
| @@ -168,6 +168,6 @@ export function listPeople(db: Database): Person[] { | ||
| 168 | 168 | role: r.is_admin === 1 ? "admin" : r.member !== null ? "member" : "guest", |
| 169 | 169 | usdPerMonth: r.usd, |
| 170 | 170 | suspendedAt: r.suspended_at, |
| 171 | verified: r.verified_at !== null, | |
| 171 | verified: r.proven_at !== null, | |
| 172 | 172 | })); |
| 173 | 173 | } |
test/verify.test.ts +46
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 8 | 8 | import { Database } from "bun:sqlite"; |
| 9 | 9 | import { mkdtemp, rm } from "node:fs/promises"; |
| 10 | import { readFileSync } from "node:fs"; | |
| 10 | 11 | import { tmpdir } from "node:os"; |
| 11 | 12 | import { join } from "node:path"; |
| 12 | 13 | import { createApp, type App } from "../src/app.ts"; |
| @@ -146,3 +147,48 @@ describe("the migration moves every proof into a connection", () => { | ||
| 146 | 147 | expect(listConnections(db, "u3").map((c) => [c.ident, c.proven, c.uses.feedback])).toEqual([["[email protected]", false, false]]); |
| 147 | 148 | }); |
| 148 | 149 | }); |
| 150 | ||
| 151 | describe("email_check.verified_at is read nowhere (#18324)", () => { | |
| 152 | // v0.7.744, the release in play when this landed, still writes and reads the column, so it is | |
| 153 | // kept (#875); this release only stops asking it. What the older process writes there during | |
| 154 | // a roll proves nothing here, and a link it marked used stays used by the connection. | |
| 155 | let dataDir: string; | |
| 156 | let app: App; | |
| 157 | const NOW = Date.parse("2026-12-05T12:00:00Z"); | |
| 158 | beforeAll(async () => { | |
| 159 | dataDir = await mkdtemp(join(tmpdir(), "forge-verify-col-")); | |
| 160 | app = createApp({ dataDir, port: 0 }); | |
| 161 | }); | |
| 162 | afterAll(async () => { | |
| 163 | app.db.close(); | |
| 164 | await rm(dataDir, { recursive: true, force: true }); | |
| 165 | }); | |
| 166 | ||
| 167 | test("the older release's verified_at proves nothing: not the gate, the list, nor the members list", async () => { | |
| 168 | const made = await createUser(app.db, { origin: "seed", trusted: false, username: "gil", email: "[email protected]" }); | |
| 169 | if (!made.ok) throw new Error(made.error); | |
| 170 | app.db.query("UPDATE email_check SET verified_at = ?2 WHERE user_id = ?1").run(made.value.id, new Date(NOW).toISOString()); | |
| 171 | expect(emailVerified(app.db, made.value.id)).toBe(false); | |
| 172 | expect(listPeople(app.db).find((p) => p.username === "gil")?.verified).toBe(false); | |
| 173 | expect(issueRecovery(app.db, made.value.id, NOW)).toBeUndefined(); | |
| 174 | }); | |
| 175 | ||
| 176 | test("a used link cannot be used again, whatever the column says", async () => { | |
| 177 | const made = await createUser(app.db, { origin: "seed", trusted: false, username: "hal", email: "[email protected]" }); | |
| 178 | if (!made.ok) throw new Error(made.error); | |
| 179 | const token = issueLink(app.db, made.value.id, made.value.email, NOW)!; | |
| 180 | expect(consumeLink(app.db, token, NOW)).toBe(made.value.id); | |
| 181 | app.db.query("UPDATE email_check SET verified_at = NULL WHERE user_id = ?1").run(made.value.id); | |
| 182 | expect(consumeLink(app.db, token, NOW)).toBeUndefined(); | |
| 183 | expect(listPeople(app.db).find((p) => p.username === "hal")?.verified).toBe(true); | |
| 184 | }); | |
| 185 | ||
| 186 | test("outside the migrations, nothing that says an email is proven names verified_at", () => { | |
| 187 | // The tables with a verified_at of their own (app_domain, cloud_account) are another thing; | |
| 188 | // these are the files that answer "is this email proven", and they ask the connection. | |
| 189 | const src = join(import.meta.dir, "../src/core"); | |
| 190 | const readers = ["verify.ts", "roles.ts", "proven_identities.ts", "accounts.ts", "people_rows.ts"] | |
| 191 | .filter((f) => /\bverified_at\b/.test(readFileSync(join(src, f), "utf8"))); | |
| 192 | expect(readers).toEqual([]); | |
| 193 | }); | |
| 194 | }); |
new above
offline