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>;
+6
View File
@@ -160,6 +160,12 @@ try {
await page.waitForFunction(() => window.authPanel.shadowRoot.querySelector("nf-editor")?.shadowRoot);
}
await page.screenshot({ path: join(out, `symcon-access-${name}.png`) });
if (name === "admin") {
const switched = new Client(); assert.equal((await switched.login("reader", "reader-new-test-password")).status, 303);
await context.setCookie({ name: "NFSC_Session_12345", value: switched.cookies.get("NFSC_Session_12345"), url: base + hook + "/", path: hook + "/", httpOnly: true, sameSite: "Strict" });
await page.waitForFunction(() => document.querySelector("nextfloor-panel")?.hass?.user?.name === "reader");
assert.equal(await page.evaluate(() => document.querySelector("nextfloor-panel").hass.user.is_admin), false, "a shared-cookie account switch removes stale admin data in other tabs");
}
if (name === "reader") {
await Promise.all([page.waitForNavigation({ waitUntil: "networkidle0" }), page.click('.nf-session-bar button')]);
await page.waitForSelector("#username"); await page.goBack({ waitUntil: "networkidle0" });