test(proxy): add a failing test for HTTPS proxy CONNECT User Agent (#5972)

This commit is contained in:
Pavel Feldman 2021-03-27 13:26:39 +08:00 committed by GitHub
parent 2cce8850b7
commit 49bbc2bc76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,7 @@
*/ */
import { it, expect } from './fixtures'; import { it, expect } from './fixtures';
import net from 'net';
it('should throw for bad server value', async ({browserType, browserOptions}) => { it('should throw for bad server value', async ({browserType, browserOptions}) => {
const error = await browserType.launch({ const error = await browserType.launch({
@ -172,3 +173,33 @@ it('does launch without a port', async ({ browserType, browserOptions }) => {
}); });
await browser.close(); await browser.close();
}); });
it('should use proxy', test => {
test.fixme('Non-emulated user agent is used in proxy CONNECT');
}, async ({ browserType, browserOptions }) => {
let requestText = '';
// This is our proxy server
const server = net.createServer(socket => {
socket.on('data', data => {
requestText = data.toString();
socket.end();
});
});
await new Promise(f => server.listen(0, f));
const browser = await browserType.launch({
...browserOptions,
proxy: { server: `http://127.0.0.1:${(server.address() as any).port}` }
});
const page = await browser.newPage({
userAgent: 'MyUserAgent'
});
// HTTPS over HTTP proxy will start with CONNECT request.
await page.goto('https://bing.com/').catch(() => {});
await browser.close();
server.close();
// This connect request should have emulated user agent.
expect(requestText).toContain('MyUserAgent');
});