v4: a deployment chooses which ways federated sign-in goes — every instance took users of the others and let its own sign in to them, with no way to turn either off. GERBEUR_FEDERATION_INCOMING=0 keeps users of other instances out: the login and register pages offer no other instance, /manage no list of instances, their sign-ins are refused, and those already in are signed out until it is on again, their homes' events still applied meanwhile. GERBEUR_FEDERATION_OUTGOING=0 keeps the instance's users from signing in elsewhere: its /authorize page lets no instance sign them in, its metadata says so (gerbeur_outgoing), which other instances check before sending anyone there, the settings page lists no instances, and at startup every grant is withdrawn, which signs them out there. Both are on by default and reach the client through index.html. The dev instance gerbeur (:3000) takes no users of the others, while its own still sign in to them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
khannurien
2026-10-09 16:18:21 +00:00
parent 66e402bd91
commit 83dc44050e
26 changed files with 420 additions and 121 deletions

View File

@@ -1,9 +1,11 @@
import {
count,
createUser,
db,
del,
type FakeInstance,
fakeInstance,
federationOff,
formWithFile,
get,
patch,
@@ -193,6 +195,48 @@ test("federation: blocking an instance refuses its users and ends their sessions
assertEquals((await get("/api/me", { auth })).status, 200);
});
test("federation: with sign-ins from other instances off, none starts or finishes, and those in are out until it is on", async () => {
const home = await fakeInstance(HOME);
using _net = network(home);
await trust(HOME);
const { token } = (await signIn(home, ALICE)).data as AuthResponse;
const auth = { Authorization: `Bearer ${token}` };
const started = await post<FederationLoginResponse>(
"/api/federation/logins",
{ json: { instance: "home.test" } },
);
const state = new URL(started.data.authorizeUrl).searchParams.get("state");
const code = home.issue(started.data.authorizeUrl, ALICE);
{
using _off = federationOff("incoming");
assertEquals((await get("/api/me", { auth })).status, 401);
assertEquals(
(await post("/api/federation/logins", {
json: { instance: "home.test" },
})).status,
403,
);
assertEquals(
(await post("/api/federation/sessions", { json: { code, state } }))
.status,
403,
);
}
assertEquals((await get("/api/me", { auth })).status, 200);
});
test("federation: a home whose users don't sign in elsewhere is refused before the user leaves", async () => {
const home = await fakeInstance(HOME, { gerbeur_outgoing: false });
using _net = network(home);
await trust(HOME);
const start = await post("/api/federation/logins", {
json: { instance: "home.test" },
});
assertEquals(start.status, 403);
assertEquals(count(`SELECT COUNT(*) AS n FROM federation_logins;`), 0);
});
test("federation: only admins edit the peers, which must answer as gerbeurs", async () => {
const home = await fakeInstance(HOME);
using _net = network(home);