Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(client-certificates): finish browser TLS handshake before closing on server close (#43133)
Pavel Feldman0ba75cb38d06
diff --git a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.tsindex 2f4afc91bc..606a156429 100644--- a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts+++ b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts@@ -108,7 +108,8 @@ class SocksProxyConnection {this.uid = uid;this.host = host;this.port = port;- this._serverCloseEventListener = () => {+ this._serverCloseEventListener = async () => {+ await this._brorwserDecrypted?.catch(() => {});this._browserEncrypted.destroy();};this._browserEncrypted = new stream.Duplex({diff --git a/tests/library/client-certificates.spec.ts b/tests/library/client-certificates.spec.tsindex c967ced534..be946e0a73 100644--- a/tests/library/client-certificates.spec.ts+++ b/tests/library/client-certificates.spec.ts@@ -32,6 +32,7 @@ type TestOptions = {http2?: boolean;enableHTTP1FallbackWhenUsingHttp2?: boolean;useFakeLocalhost?: boolean;+ rejectUnauthorized?: boolean;}): Promise<string>,};@@ -47,7 +48,7 @@ const test = base.extend<TestOptions>({fs.readFileSync(asset('client-certificates/server/server_cert.pem')),],requestCert: true,- rejectUnauthorized: false,+ rejectUnauthorized: options?.rejectUnauthorized ?? false,allowHTTP1: options?.enableHTTP1FallbackWhenUsingHttp2,}, (req: (http2.Http2ServerRequest | http.IncomingMessage), res: http2.Http2ServerResponse | http.ServerResponse) => {const tlsSocket = req.socket as import('tls').TLSSocket;@@ -391,6 +392,23 @@ test.describe('browser', () => {await page.close();});+ test('should complete browser TLS handshake when server rejects client certificate after it', {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43092' },+ }, async ({ browser, startCCServer, asset, browserName, isMac }) => {+ const serverURL = await startCCServer({ rejectUnauthorized: true, useFakeLocalhost: browserName === 'webkit' && isMac });+ const page = await browser.newPage({+ ignoreHTTPSErrors: true,+ clientCertificates: [{+ origin: new URL(serverURL).origin,+ certPath: asset('client-certificates/client/self-signed/cert.pem'),+ keyPath: asset('client-certificates/client/self-signed/key.pem'),+ }],+ });+ const error = await page.goto(serverURL).catch(e => e);+ expect(error.message).toMatch(/net::ERR_EMPTY_RESPONSE|NS_ERROR_NET_RESET|Connection terminated unexpectedly|The network connection was lost/);+ await page.close();+ });+test('should pass with matching certificates', async ({ browser, startCCServer, asset, browserName, isMac }) => {const serverURL = await startCCServer({ useFakeLocalhost: browserName === 'webkit' && isMac });const page = await browser.newPage({