// PEP-16: only allowlisted people, project invitees/members and local accounts get in. import assert from "node:assert/strict"; import { after, describe, test } from "node:test"; import { core, db, project, teardown } from "./helpers.ts"; process.env.PEPPA_SECRET = "mock-secret-for-tests"; after(teardown); describe("login allowlist", () => { test("Разрешённый логин", async () => { await core.setAllowedLogins(db, ["asel", "Dana"]); assert.equal(await core.isLoginAllowed(db, "dana"), true); assert.equal(await core.isLoginAllowed(db, "DANA"), true, "case-insensitive"); }); test("Посторонний аккаунт Gitea", async () => { assert.equal(await core.isLoginAllowed(db, "spammer1"), false); const u = await core.upsertUserFromGitea(db, { id: 901, login: "spammer1" }, { access_token: "x" }); assert.equal(await core.isUserAllowed(db, u), false); }); test("Приглашённый в проект", async () => { const p = await project({ turns: [] }); const proj = await core.getProject(db, p.key); assert.equal(await core.addMember(db, proj, "bob", null), "invited"); assert.equal(await core.isLoginAllowed(db, "bob"), true); const bob = await core.upsertUserFromGitea(db, { id: 902, login: "bob" }, { access_token: "x" }); assert.equal(await core.isUserAllowed(db, bob), true, "member after accepting the invite"); assert.equal((await core.projectForUser(db, bob.id, proj.id)).id, proj.id); }); test("Исключён из списка", async () => { const dana = await core.upsertUserFromGitea(db, { id: 903, login: "dana" }, { access_token: "x" }); assert.equal(await core.isUserAllowed(db, dana), true); await core.setAllowedLogins(db, (await core.allowedLogins(db)).filter((l) => l !== "dana")); assert.equal(await core.isUserAllowed(db, dana), false, "web session and MCP token stop working"); }); test("local accounts without Gitea (mock-…) are always allowed", async () => { const m = await core.upsertUserFromGitea(db, { id: -77, login: "mock-local" }, { access_token: "x" }); assert.equal(await core.isUserAllowed(db, m), true); }); });