Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cookies): make filtering by url work with subdomains #4989

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/server/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export function filterCookies(cookies: types.NetworkCookie[], urls: string[]): t
if (!parsedURLs.length)
return true;
for (const parsedURL of parsedURLs) {
if (parsedURL.hostname !== c.domain)
let domain = c.domain;
if (!domain.startsWith('.'))
domain = '.' + domain;
if (!('.' + parsedURL.hostname).endsWith(domain))
continue;
if (!parsedURL.pathname.startsWith(c.path))
continue;
Expand Down
30 changes: 30 additions & 0 deletions test/browsercontext-cookies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,33 @@ it('should get cookies from multiple urls', async ({context}) => {
sameSite: 'None',
}]);
});

it('should work with subdomain cookie', async ({context, page, server}) => {
await context.addCookies([{
domain: '.foo.com',
path: '/',
name: 'doggo',
value: 'woofs',
secure: true
}]);
expect(await context.cookies('https://foo.com')).toEqual([{
name: 'doggo',
value: 'woofs',
domain: '.foo.com',
path: '/',
expires: -1,
httpOnly: false,
secure: true,
sameSite: 'None',
}]);
expect(await context.cookies('https://sub.foo.com')).toEqual([{
name: 'doggo',
value: 'woofs',
domain: '.foo.com',
path: '/',
expires: -1,
httpOnly: false,
secure: true,
sameSite: 'None',
}]);
});