test: isolate proxy creds between contexts (#31565)

This commit is contained in:
Max Schmitt 2024-07-05 13:24:06 +02:00 committed by GitHub
parent b79f3076ee
commit f56978edb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,7 +14,9 @@
* limitations under the License.
*/
import http from 'http';
import { browserTest as it, expect } from '../config/browserTest';
import type net from 'net';
it.skip(({ mode }) => mode.startsWith('service'));
@ -413,3 +415,39 @@ it('does launch without a port', async ({ contextFactory }) => {
});
await context.close();
});
it('should isolate proxy credentials between contexts on navigation', async ({ contextFactory, browserName, server }) => {
it.fixme(browserName === 'firefox', 'https://github.com/microsoft/playwright/issues/31525');
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/31525' });
server.setRoute('/target.html', async (req, res) => {
const authHeader = req.headers['proxy-authorization'];
if (!authHeader) {
res.writeHead(407, { 'Proxy-Authenticate': 'Basic realm="proxy"' });
res.end('Proxy authorization required');
return;
}
const [username,] = Buffer.from(authHeader.split(' ')[1], 'base64').toString().split(':');
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`Hello <div data-testid=user>${username}</div>!\n`);
});
const context1 = await contextFactory({
proxy: { server: server.PREFIX, username: 'user1', password: 'secret1' }
});
const page1 = await context1.newPage();
await page1.goto('http://non-existent.com/target.html');
await expect(page1.getByTestId('user')).toHaveText('user1');
const context2 = await contextFactory({
proxy: { server: server.PREFIX, username: 'user2', password: 'secret2' }
});
const page2 = await context2.newPage();
await page2.goto('http://non-existent.com/target.html');
await expect(page2.getByTestId('user')).toHaveText('user2');
await page1.goto('http://non-existent.com/target.html');
await expect(page1.getByTestId('user')).toHaveText('user1');
});