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

This commit is contained in:
Yury Semikhatsky 2021-01-12 15:56:29 -08:00 committed by GitHub
parent 0bf7477c24
commit 29c34325c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -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;

View File

@ -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',
}]);
});