fix: preserve scoped utility topology and refresh sessions across tabs

This commit is contained in:
jhartworks committed 2026-11-16 16:38:10 +01:00
1 parent 1d67e8ceba
commit 984d9af232
6 files changed
+58 -24

No files matched your search

+7
View File
@@ -21,6 +21,13 @@ test("an expired session is distinguished from a forbidden operation", async (co
await assert.rejects(callSymcon({ endpoint: "/hook/fixture", csrf: "csrf-fixture" }, "bootstrap"), SymconAuthError);
});
test("a replaced session clears stale tabs, while a denied control does not sign the user out", async (context) => {
const mock = context.mock.method(globalThis, "fetch", async () => new Response('{"error":"csrf_invalid"}', { status: 403 }));
await assert.rejects(callSymcon({ endpoint: "/hook/fixture", csrf: "old-csrf" }, "bootstrap"), SymconAuthError);
mock.mock.mockImplementation(async () => new Response('{"error":"control_forbidden"}', { status: 403 }));
await assert.rejects(callSymcon({ endpoint: "/hook/fixture", csrf: "current-csrf" }, "variables/action"), (e: Error) => !(e instanceof SymconAuthError) && e.message === "control_forbidden");
});
test("small replies remain compatible and transport negotiation is explicit", async (context) => {
context.mock.method(globalThis, "fetch", async (_url: string, init: RequestInit) => {
const request = JSON.parse(String(init.body));
+2
View File
@@ -38,6 +38,8 @@ async function request(settings: SymconEndpoint, action: string, payload: Record
}
if (!response.ok || !body || typeof body !== "object" || "error" in body) {
const error = body && typeof body === "object" && "error" in body ? (body as { error?: unknown }).error : `HTTP ${response.status}`;
// Another tab can replace the shared cookie with a different account. Clear this tab's old data too.
if (error === "csrf_invalid") throw new SymconAuthError("Die Anmeldung hat sich geändert. Bitte erneut laden.");
throw new Error(String(error));
}
return body as Record<string, unknown>;