Skip to content

Commit c2ceabb

Browse files
committed
test: send secure cookies to subdomain.localhost
This is a follow-up to microsoft#35771.
1 parent c3c842c commit c2ceabb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/library/browsercontext-proxy.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,41 @@ it('should use proxy', async ({ contextFactory, server, proxyServer }) => {
6464
await context.close();
6565
});
6666

67+
it('should send secure cookies to subdomain.localhost', async ({ contextFactory, browserName, server, proxyServer }) => {
68+
proxyServer.forwardTo(server.PORT);
69+
const context = await contextFactory({
70+
proxy: { server: `localhost:${proxyServer.PORT}` },
71+
});
72+
server.setRoute('/set-cookie.html', async (req, res) => {
73+
res.setHeader('Set-Cookie', [`non-secure=1; HttpOnly`, `secure=1; HttpOnly; Secure`]);
74+
res.end();
75+
});
76+
server.setRoute('/read-cookie.html', async (req, res) => {
77+
res.setHeader('Content-Type', `text/html`);
78+
res.end(`<div>Cookie: ${req.headers.cookie.split(';').map(c => c.trim()).sort().join('; ')}</div>`);
79+
});
80+
81+
const page = await context.newPage();
82+
83+
await page.goto(`http://subdomain.localhost/set-cookie.html`);
84+
85+
const cookies = await context.cookies('http://subdomain.localhost');
86+
expect(cookies.map(({ name, domain }) => ({ name, domain }))).toEqual([
87+
{
88+
name: 'non-secure',
89+
domain: 'subdomain.localhost',
90+
},
91+
...(browserName === 'webkit' ? [] : [{
92+
name: 'secure',
93+
domain: 'subdomain.localhost',
94+
}]),
95+
]);
96+
97+
await page.goto(`http://subdomain.localhost/read-cookie.html`);
98+
await expect(page.locator('div')).toHaveText(browserName === 'webkit' ? 'Cookie: non-secure=1' : 'Cookie: non-secure=1; secure=1');
99+
100+
await context.close();
101+
});
67102

68103
it('should set cookie for top-level domain', {
69104
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/18362' }

0 commit comments

Comments
 (0)