feat(accounts): locked registration, for staging
Pull request / title (pull_request) Successful in 1s
CI / test (pull_request) Successful in 1m28s
CI / image (apps/api/Dockerfile, t5de-hub-api) (pull_request) Skipped
CI / image (apps/web/Dockerfile, t5de-hub-web) (pull_request) Skipped

A third registration setting, locked: every new account waits for a
moderator's approval, Discord sign-ins too, and only approved accounts sign
in to T5DE's other sites. Today staging's closed registration still lets any
Discord account in as a basic account, straight into Music's staging (and
soon payments' staging, with PayPal's sandbox).

The gate is the OAuth provider's postLogin check: an unapproved account is
sent to the website's waiting page and no code is issued, on every authorize
request and /oauth2/continue. Open and closed behave as before, so prod's
Music sign-ins don't change.
This commit is contained in:
dhkatz committed 2026-11-20 12:29:19 -08:00
1 parent 02e8269d4d
commit 23cae691a9
11 files changed
+111 -22

No files matched your search

+20 -1
View File
@@ -2,7 +2,7 @@
// verified email only, and never links by matching email; a basic account finishes setting up with a username and
// password; a member links Discord from their own session. Discord itself is stood in for below.
import { afterAll, beforeAll, expect, test } from "bun:test";
import { openDatabase, type Database } from "@t5de/db";
import { eq, openDatabase, schema, type Database } from "@t5de/db";
import { createApp } from "../src/app";
import { createAuth } from "../src/auth";
import { ImvuClient } from "../src/imvu";
@@ -203,3 +203,22 @@ test("a member links Discord from their own session; a Discord account already i
expect(refused.searchParams.get("error")).toBe("account_already_linked_to_different_user");
expect((await call(fay, "GET", "/api/v1/account")).json.discord.linked).toBe(false);
});
test("with registration locked, a Discord sign-in waits for approval too, and finishing setup keeps the approval", async () => {
await settings.setRegistration("locked");
try {
const gil: Cookie = { v: "" };
await viaDiscord(gil, { id: "1008", username: "gil", email: "[email protected]", verified: true });
const me = (await call(gil, "GET", "/api/v1/me")).json.person;
expect(me).toMatchObject({ kind: "basic", approved: false });
// Approved by a moderator, then finishing setup: still approved.
await db.update(schema.user).set({ approved: true }).where(eq(schema.user.id, me.id));
expect((await call(gil, "POST", "/api/v1/account/finish", { username: "gil", password: "a long password" })).json.person).toMatchObject({
kind: "member",
approved: true,
});
} finally {
await settings.setRegistration("open");
}
});
+37 -1
View File
@@ -20,10 +20,11 @@ let db: Database;
let close: () => Promise<void>;
let base: string;
let stop: () => void;
let settings: Settings;
beforeAll(async () => {
({ db, close } = await openDatabase("memory"));
const settings = new Settings(db, { registration: "open" });
settings = new Settings(db, { registration: "open" });
const auth = createAuth(db, { apiURL, webURL, secret: "test-secret-test-secret-test-secret-1234", rateLimit: false, settings, clients: [music] });
await seedClients(db, apiURL, [music]);
const imvu = new ImvuClient("http://imvu.test", (async () => Response.json({ denormalized: {} })) as unknown as typeof fetch);
@@ -185,3 +186,38 @@ test("a website session still links as before", async () => {
expect((await call(dee, "GET", "/api/v1/account/imvu")).status).toBe(200);
});
test("with registration locked, only approved accounts sign in to Music; closed doesn't stop anyone", async () => {
// Closed (prod): a member waiting for the hub's approval still signs in to Music.
await settings.setRegistration("closed");
const eli = await signUp("eli");
expect((await call(eli, "GET", "/api/v1/me")).json.person.approved).toBe(false);
await musicSignIn(eli);
await settings.setRegistration("locked");
try {
const fin = await signUp("fin");
const id = (await call(fin, "GET", "/api/v1/me")).json.person.id;
// Sent to the website (which says they're waiting), with no code for Music.
const a = await authorizeURL("openid profile imvu");
const r = await call(fin, "GET", a.path);
expect(r.status).toBe(302);
const to = new URL(r.location);
expect(to.origin + to.pathname).toBe(`${webURL}/`);
expect(to.searchParams.get("code")).toBeNull();
// Continuing from that page doesn't get past it either.
const cont = await call(fin, "POST", "/api/auth/oauth2/continue", { postLogin: true, oauth_query: to.search.slice(1) });
const again = new URL(cont.json.url);
expect(again.origin + again.pathname).toBe(`${webURL}/`);
expect(again.searchParams.get("code")).toBeNull();
// Nor does eli, approved for nothing: locked holds back everyone unapproved.
const b = await call(eli, "GET", (await authorizeURL("openid")).path);
expect(new URL(b.location).origin + new URL(b.location).pathname).toBe(`${webURL}/`);
// Once a moderator approves, it works.
await db.update(schema.user).set({ approved: true }).where(eq(schema.user.id, id));
await musicSignIn(fin);
} finally {
await settings.setRegistration("open");
}
});