mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
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)
|
||||
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;
|
||||
|
||||
@ -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',
|
||||
}]);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user