fix(auth): a tab acts only as the account it was built for, and the review's other findings

A tab names the account it was claimed for on every request, beacon and upload
(X-Siftlode-Expect-Account); current_user and /auth/logout refuse a mismatch with
401 account_changed and keep the session, so a tab left showing the account
signed in before reloads instead of writing to the new one.

/auth/login clears a connect marker left by an abandoned connect, and a link
completes only on a session that still holds. The prefs merge reads the row
under a lock. A tab's sessionStorage records its own owner. A page the account
loses is given up, address bar and remembered page included. The panel layouts
are preferences; the storage contract also refuses a key handed to the Storage
API or to usePref outside its kind. A refused sign-in as someone else and a
failed sign-out say so. The chromium-only e2e specs are in the gate register,
the member walk waits for its requests, and devices.spec checks the save itself.
This commit is contained in:
2026-10-21 01:05:12 +02:00
parent 28b77fed1e
commit 94418a087e
39 changed files with 576 additions and 78 deletions
+26 -7
View File
@@ -19,21 +19,39 @@ const CORE = [
"settings",
];
/** Collect every admin call and every refused response the page makes while `run` goes. */
async function watchRequests(page: Page, run: () => Promise<void>): Promise<string[]> {
const isApi = (url: string) => new URL(url).pathname.startsWith("/api/");
/** Collect every admin call and every failed API answer the page gets while `run` goes. `run` is
* handed `settled`, which waits until no API request of the page is in flight: an error state
* renders only once its request has answered, and a check made before that passes on a page that
* is still loading. */
async function watchRequests(
page: Page,
run: (settled: () => Promise<void>) => Promise<void>,
): Promise<string[]> {
const bad: string[] = [];
const pending = new Set<Request>();
const onRequest = (r: Request) => {
if (!isApi(r.url())) return;
pending.add(r);
if (new URL(r.url()).pathname.startsWith("/api/admin")) bad.push(`admin call ${r.url()}`);
};
const onDone = (r: Request) => pending.delete(r);
const onResponse = (r: Response) => {
if (r.status() === 401 || r.status() === 403) bad.push(`${r.status()} ${r.url()}`);
if (isApi(r.url()) && r.status() >= 400) bad.push(`${r.status()} ${r.url()}`);
};
const settled = () => expect.poll(() => pending.size, { timeout: 15_000 }).toBe(0);
page.on("request", onRequest);
page.on("requestfinished", onDone);
page.on("requestfailed", onDone);
page.on("response", onResponse);
try {
await run();
await run(settled);
await settled();
} finally {
page.off("request", onRequest);
page.off("requestfinished", onDone);
page.off("requestfailed", onDone);
page.off("response", onResponse);
}
return bad;
@@ -43,7 +61,7 @@ test.describe("a member", () => {
test("gets no admin entry, and every page of the rail opens without an error", async ({
page,
}) => {
const bad = await watchRequests(page, async () => {
const bad = await watchRequests(page, async (settled) => {
await openApp(page);
await expect(page.getByTestId("nav-admin")).toHaveCount(0);
@@ -59,6 +77,7 @@ test.describe("a member", () => {
for (const id of ids) {
await page.getByTestId(`nav-${id}`).click();
await expect(page.getByTestId(`nav-${id}`)).toHaveAttribute("aria-current", "page");
await settled();
// An error state is a `role=alert` StateMessage; a page that failed to load shows one.
await expect(page.getByRole("alert"), `error state on ${id}`).toHaveCount(0);
}
@@ -71,8 +90,8 @@ test.describe("a member", () => {
const bad = await watchRequests(page, () => openApp(page, `/?page=${id}`));
expect(bad, id).toEqual([]);
await expect(page.getByTestId("nav-admin")).toHaveCount(0);
// The member lands on one of their own pages instead.
await expect(page.locator('[data-testid^="nav-"][aria-current="page"]')).toHaveCount(1);
// The member lands on the feed instead, and the rail says so.
await expect(page.getByTestId("nav-feed")).toHaveAttribute("aria-current", "page");
}
});
});