- platform.allowed_logins (default asel, 7601978, dana): allowlisted logins, project invitees and members, and local CLI accounts may log in - enforced in the Gitea OAuth callback, on every web request (removal takes effect at once) and on every remote MCP request (401) - CLI: peppa platform allowlist | allow <login> | deny <login> - tests: one per spec scenario (69 e2e total, green) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
2.1 KiB
TypeScript
44 lines
2.1 KiB
TypeScript
// 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);
|
|
});
|
|
});
|