Skip to content

Commit 159302f

Browse files
PiquelChipsclaude
andcommitted
test(sdk): the browser spec checks what the page could store, not the shared cookie jar
In CI the client page and auth share localhost, and browsers keep cookies per host, so the jar showed auth's own session cookie. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a700eb6 commit 159302f

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎tests/browser/browser-client.spec.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,18 @@ async function setUp(
110110
return { ...passkeys, handle };
111111
}
112112

113-
/** Nothing the page stores holds `tokens`, and the client's origin has no cookie. */
114-
async function expectNoStoredTokens(page: Page, context: BrowserContext, tokens: string[]) {
113+
/**
114+
* Nothing the page stores holds `tokens`, and it set no cookie. The SDK runs in the
115+
* page, so it could only write cookies `document.cookie` shows; the browser's own
116+
* cookie jar would also show auth's, which share the client's host in CI.
117+
*/
118+
async function expectNoStoredTokens(page: Page, tokens: string[]) {
115119
const stored = await page.evaluate(() => ({
116120
local: Object.entries(localStorage),
117121
session: Object.entries(sessionStorage),
118122
cookie: document.cookie
119123
}));
120124
expect(stored).toEqual({ local: [], session: [], cookie: '' });
121-
expect(await context.cookies(client)).toEqual([]);
122125
const everything = JSON.stringify(stored);
123126
for (const token of tokens) expect(everything).not.toContain(token);
124127
}
@@ -136,7 +139,7 @@ test('the browser client signs in with a redirect, and restores with prompt=none
136139
expect(signedIn?.username).toBe(handle);
137140
// Back where the login left from, without the code.
138141
expect(page.url()).toBe(`${client}/notes`);
139-
await expectNoStoredTokens(page, context, signedIn?.tokens ?? []);
142+
await expectNoStoredTokens(page, signedIn?.tokens ?? []);
140143

141144
// Tokens live in memory only: after a reload, auth's session signs in again silently.
142145
await page.reload();
@@ -146,7 +149,7 @@ test('the browser client signs in with a redirect, and restores with prompt=none
146149
expect(restored?.username).toBe(handle);
147150
expect(page.url()).toBe(`${client}/notes`);
148151
expect(requests.prompts).toEqual([null, 'none']);
149-
await expectNoStoredTokens(page, context, restored?.tokens ?? []);
152+
await expectNoStoredTokens(page, restored?.tokens ?? []);
150153
});
151154

152155
test('the browser client signs in with a passkey without leaving the page', async ({
@@ -164,7 +167,7 @@ test('the browser client signs in with a passkey without leaving the page', asyn
164167
const signedIn = await inPage(page, 'passkey', { scopes: ['profile'] });
165168
expect(signedIn?.username).toBe(handle);
166169
expect(navigations).toEqual([]);
167-
await expectNoStoredTokens(page, context, signedIn?.tokens ?? []);
170+
await expectNoStoredTokens(page, signedIn?.tokens ?? []);
168171
expect(
169172
(await context.cookies(authUrl)).filter((cookie) => cookie.name === '__Host-piquel_session')
170173
).toEqual([]);

0 commit comments

Comments
 (0)