From 1dc7fb1f3feb50e2abefd9bb355d6124219bf5a0 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 23 Feb 2021 19:14:37 -0800 Subject: [PATCH] test: add more tests for Set-Cookie in fulfill (#5570) --- test/page-request-fulfill.spec.ts | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/page-request-fulfill.spec.ts b/test/page-request-fulfill.spec.ts index c90374ed3b..61d4c49072 100644 --- a/test/page-request-fulfill.spec.ts +++ b/test/page-request-fulfill.spec.ts @@ -202,3 +202,52 @@ it('should support Set-Cookie header', (test, { browserName }) => { secure: false }]); }); + +it('should ignore secure Set-Cookie header for insecure requests', (test, { browserName }) => { + test.fixme(browserName === 'webkit'); +}, async ({context, page, server}) => { + await page.route('http://example.com/', (route, request) => { + route.fulfill({ + headers: { + 'Set-Cookie': 'name=value; domain=.example.com; Path=/; Secure' + }, + contentType: 'text/html', + body: 'done' + }); + }); + await page.goto('http://example.com'); + expect(await context.cookies()).toEqual([]); +}); + +it('should use Set-Cookie header in future requests', (test, { browserName }) => { + test.fixme(browserName === 'webkit'); +}, async ({context, page, server}) => { + await page.route(server.EMPTY_PAGE, (route, request) => { + route.fulfill({ + headers: { + 'Set-Cookie': 'name=value' + }, + contentType: 'text/html', + body: 'done' + }); + }); + await page.goto(server.EMPTY_PAGE); + expect(await context.cookies()).toEqual([{ + sameSite: 'None', + name: 'name', + value: 'value', + domain: 'localhost', + path: '/', + expires: -1, + httpOnly: false, + secure: false + }]); + + let cookie = ''; + server.setRoute('/foo.html', (req, res) => { + cookie = req.headers.cookie; + res.end(); + }); + await page.goto(server.PREFIX + '/foo.html'); + expect(cookie).toBe('name=value'); +});