feat(accounts): locked registration, for staging
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:
1 parent
02e8269d4d
commit
23cae691a9
11 files changed
+111
-22
No files matched your search
@@ -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");
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user