Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Pavel Feldman49bbc2bc764c
diff --git a/test/proxy.spec.ts b/test/proxy.spec.ts
index fc54ad06b7..0803cb7852 100644
--- a/test/proxy.spec.ts
+++ b/test/proxy.spec.ts
@@ -15,6 +15,7 @@
*/
import { it, expect } from './fixtures';
+import net from 'net';
it('should throw for bad server value', async ({browserType, browserOptions}) => {
const error = await browserType.launch({
@@ -172,3 +173,33 @@ it('does launch without a port', async ({ browserType, browserOptions }) => {
});
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');
+});