From c0aecbfd572d727a0f34aad600ddf02e5d88e660 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 10 Dec 2021 13:12:14 -0800 Subject: [PATCH] test: add test for firefox proxy failure (#10853) References #10095 --- tests/proxy.spec.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/proxy.spec.ts b/tests/proxy.spec.ts index ccb8690005..cae931521b 100644 --- a/tests/proxy.spec.ts +++ b/tests/proxy.spec.ts @@ -94,6 +94,39 @@ it('should authenticate', async ({ browserType, server }) => { await browser.close(); }); +it('should work with authenticate followed by redirect', async ({ browserName, browserType, server }) => { + it.fixme(browserName === 'firefox', 'https://github.com/microsoft/playwright/issues/10095'); + function hasAuth(req, res) { + const auth = req.headers['proxy-authorization']; + if (!auth) { + res.writeHead(407, 'Proxy Authentication Required', { + 'Proxy-Authenticate': 'Basic realm="Access to internal site"' + }); + res.end(); + return false; + } + return true; + } + server.setRoute('/page1.html', async (req, res) => { + if (!hasAuth(req, res)) + return; + res.writeHead(302, { location: '/page2.html' }); + res.end(); + }); + server.setRoute('/page2.html', async (req, res) => { + if (!hasAuth(req, res)) + return; + res.end('Served by the proxy'); + }); + const browser = await browserType.launch({ + proxy: { server: `localhost:${server.PORT}`, username: 'user', password: 'secret' } + }); + const page = await browser.newPage(); + await page.goto('http://non-existent.com/page1.html'); + expect(await page.title()).toBe('Served by the proxy'); + await browser.close(); +}); + it('should exclude patterns', async ({ browserType, server, browserName, headless }) => { it.fixme(browserName === 'chromium' && !headless, 'Chromium headed crashes with CHECK(!in_frame_tree_) in RenderFrameImpl::OnDeleteFrame.');