fix(cookies): make filtering by url work with subdomains (#4989)
This commit is contained in:
parent
0bf7477c24
commit
29c34325c9
|
|
@ -26,7 +26,10 @@ export function filterCookies(cookies: types.NetworkCookie[], urls: string[]): t
|
||||||
if (!parsedURLs.length)
|
if (!parsedURLs.length)
|
||||||
return true;
|
return true;
|
||||||
for (const parsedURL of parsedURLs) {
|
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;
|
continue;
|
||||||
if (!parsedURL.pathname.startsWith(c.path))
|
if (!parsedURL.pathname.startsWith(c.path))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -169,3 +169,33 @@ it('should get cookies from multiple urls', async ({context}) => {
|
||||||
sameSite: 'None',
|
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',
|
||||||
|
}]);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue