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:
@@ -6,6 +6,7 @@ import {
|
||||
del,
|
||||
type FakeInstance,
|
||||
fakeInstance,
|
||||
federationOff,
|
||||
formWithFile,
|
||||
get,
|
||||
patch,
|
||||
@@ -25,6 +26,7 @@ import {
|
||||
import {
|
||||
deliverOutbox,
|
||||
identityClaims,
|
||||
withdrawAllGrants,
|
||||
} from "../../services/identity-provider-service.ts";
|
||||
import { getUserById } from "../../services/user-service.ts";
|
||||
import type {
|
||||
@@ -105,6 +107,7 @@ test("identity provider: metadata and keys are served at the well-known paths",
|
||||
assertEquals(body.authorization_endpoint, `${BASE_URL}/authorize`);
|
||||
assertEquals(body.gerbeur_redirect_uri, `${BASE_URL}/federation/callback`);
|
||||
assertEquals(body.gerbeur_federation, 1);
|
||||
assertEquals(body.gerbeur_outgoing, true);
|
||||
const jwks = await get("/.well-known/jwks.json");
|
||||
const keys = JSON.parse(new TextDecoder().decode(jwks.bytes)).keys;
|
||||
assertEquals(keys[0].crv, "Ed25519");
|
||||
@@ -260,6 +263,40 @@ test("identity provider: the instances a user signed in to hear of their changes
|
||||
);
|
||||
});
|
||||
|
||||
test("identity provider: with sign-ins elsewhere off, no instance signs the users in, and their grants are withdrawn", async () => {
|
||||
const fake = await fakeInstance(CLIENT);
|
||||
using _net = network(fake);
|
||||
const user = await createUser();
|
||||
const { verifier, challenge } = pkce();
|
||||
const pending = new URL(
|
||||
(await authorize(user.auth, challenge)).data.redirectTo,
|
||||
).searchParams.get("code")!;
|
||||
|
||||
using _off = federationOff("outgoing");
|
||||
const meta = await get("/.well-known/openid-configuration");
|
||||
assertEquals(
|
||||
(JSON.parse(new TextDecoder().decode(meta.bytes)) as InstanceMetadata)
|
||||
.gerbeur_outgoing,
|
||||
false,
|
||||
);
|
||||
assertEquals(
|
||||
(await get(`/api/oauth/clients?client_id=${encodeURIComponent(CLIENT)}`, {
|
||||
auth: user.auth,
|
||||
})).status,
|
||||
403,
|
||||
);
|
||||
assertEquals((await authorize(user.auth, challenge)).status, 403);
|
||||
|
||||
assertEquals(await withdrawAllGrants(), 1);
|
||||
await until(() => fake.received.length === 1);
|
||||
assertEquals(decodeJwt(fake.received[0]).type, "revoke");
|
||||
assertEquals((await trade(pending, verifier)).status, 400);
|
||||
assertEquals(
|
||||
(await get<FederationGrant[]>("/api/me/grants", { auth: user.auth })).data,
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
test("identity provider: an event an instance fails to take waits in the outbox", async () => {
|
||||
const fake = await fakeInstance(CLIENT);
|
||||
using _net = network(fake, () => new Response("", { status: 503 }));
|
||||
|
||||
Reference in New Issue
Block a user