fix: allow proxy credentials with empty password (#4779)

This commit is contained in:
Yury Semikhatsky 2020-12-21 11:47:13 -08:00 committed by GitHub
parent ee417791d6
commit 94ee48f8ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View file

@ -265,8 +265,8 @@ export abstract class BrowserContext extends EventEmitter {
if (!proxy)
return;
const { username, password } = proxy;
if (username && password)
this._options.httpCredentials = { username, password };
if (username)
this._options.httpCredentials = { username, password: password || '' };
}
async _setRequestInterceptor(handler: network.RouteHandler | undefined): Promise<void> {

View file

@ -125,6 +125,28 @@ it('should authenticate', async ({contextFactory, contextOptions, server}) => {
await browser.close();
});
it('should authenticate with empty password', async ({contextFactory, contextOptions, server}) => {
server.setRoute('/target.html', async (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();
} else {
res.end(`<html><title>${auth}</title></html>`);
}
});
const browser = await contextFactory({
...contextOptions,
proxy: { server: `localhost:${server.PORT}`, username: 'user', password: '' }
});
const page = await browser.newPage();
await page.goto('http://non-existent.com/target.html');
expect(await page.title()).toBe('Basic ' + Buffer.from('user:').toString('base64'));
await browser.close();
});
it('should exclude patterns', (test, { browserName, headful }) => {
test.fixme(browserName === 'chromium' && headful, 'Chromium headful crashes with CHECK(!in_frame_tree_) in RenderFrameImpl::OnDeleteFrame.');
}, async ({contextFactory, contextOptions, server}) => {