Skip to content

Commit fca1fa0

Browse files
committed
cherry-pick(#31973): chore: run client-certificate tests in service mode
1 parent ff11273 commit fca1fa0

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

packages/playwright-core/src/server/fetch.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import type * as channels from '@protocol/channels';
1818
import type { LookupAddress } from 'dns';
1919
import http from 'http';
20-
import fs from 'fs';
2120
import https from 'https';
2221
import type { Readable, TransformCallback } from 'stream';
2322
import { pipeline, Transform } from 'stream';
@@ -26,7 +25,7 @@ import zlib from 'zlib';
2625
import type { HTTPCredentials } from '../../types/types';
2726
import { TimeoutSettings } from '../common/timeoutSettings';
2827
import { getUserAgent } from '../utils/userAgent';
29-
import { assert, createGuid, isUnderTest, monotonicTime } from '../utils';
28+
import { assert, createGuid, monotonicTime } from '../utils';
3029
import { HttpsProxyAgent, SocksProxyAgent } from '../utilsBundle';
3130
import { BrowserContext, verifyClientCertificates } from './browserContext';
3231
import { CookieStore, domainMatches } from './cookieStore';
@@ -199,8 +198,6 @@ export abstract class APIRequestContext extends SdkObject {
199198
...clientCertificatesToTLSOptions(this._defaultOptions().clientCertificates, requestUrl.origin),
200199
__testHookLookup: (params as any).__testHookLookup,
201200
};
202-
if (process.env.PWTEST_UNSUPPORTED_CUSTOM_CA && isUnderTest())
203-
options.ca = [fs.readFileSync(process.env.PWTEST_UNSUPPORTED_CUSTOM_CA)];
204201
// rejectUnauthorized = undefined is treated as true in Node.js 12.
205202
if (params.ignoreHTTPSErrors || defaults.ignoreHTTPSErrors)
206203
options.rejectUnauthorized = false;

packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import fs from 'fs';
2222
import tls from 'tls';
2323
import stream from 'stream';
2424
import { createSocket, createTLSSocket } from '../utils/happy-eyeballs';
25-
import { isUnderTest, ManualPromise } from '../utils';
25+
import { ManualPromise } from '../utils';
2626
import type { SocksSocketClosedPayload, SocksSocketDataPayload, SocksSocketRequestedPayload } from '../common/socksProxy';
2727
import { SocksProxy } from '../common/socksProxy';
2828
import type * as channels from '@protocol/channels';
@@ -152,8 +152,6 @@ class SocksProxyConnection {
152152
};
153153
if (!net.isIP(this.host))
154154
tlsOptions.servername = this.host;
155-
if (process.env.PWTEST_UNSUPPORTED_CUSTOM_CA && isUnderTest())
156-
tlsOptions.ca = [fs.readFileSync(process.env.PWTEST_UNSUPPORTED_CUSTOM_CA)];
157155
const targetTLS = tls.connect(tlsOptions);
158156

159157
targetTLS.on('secureConnect', () => {

tests/library/client-certificates.spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ test.use({
8282
}
8383
});
8484

85-
test.skip(({ mode }) => mode !== 'default');
86-
8785
const kDummyFileName = __filename;
8886
const kValidationSubTests: [BrowserContextOptions, string][] = [
8987
[{ clientCertificates: [{ origin: 'test' }] }, 'None of cert, key, passphrase or pfx is specified'],
@@ -114,7 +112,7 @@ test.describe('fetch', () => {
114112

115113
test('should fail with no client certificates provided', async ({ playwright, startCCServer }) => {
116114
const serverURL = await startCCServer();
117-
const request = await playwright.request.newContext();
115+
const request = await playwright.request.newContext({ ignoreHTTPSErrors: true });
118116
const response = await request.get(serverURL);
119117
expect(response.status()).toBe(401);
120118
expect(await response.text()).toContain('Sorry, but you need to provide a client certificate to continue.');
@@ -123,6 +121,7 @@ test.describe('fetch', () => {
123121

124122
test('should keep supporting http', async ({ playwright, server, asset }) => {
125123
const request = await playwright.request.newContext({
124+
ignoreHTTPSErrors: true,
126125
clientCertificates: [{
127126
origin: new URL(server.PREFIX).origin,
128127
certPath: asset('client-certificates/client/trusted/cert.pem'),
@@ -139,6 +138,7 @@ test.describe('fetch', () => {
139138
test('should throw with untrusted client certs', async ({ playwright, startCCServer, asset }) => {
140139
const serverURL = await startCCServer();
141140
const request = await playwright.request.newContext({
141+
ignoreHTTPSErrors: true,
142142
clientCertificates: [{
143143
origin: new URL(serverURL).origin,
144144
certPath: asset('client-certificates/client/self-signed/cert.pem'),
@@ -155,6 +155,7 @@ test.describe('fetch', () => {
155155
test('pass with trusted client certificates', async ({ playwright, startCCServer, asset }) => {
156156
const serverURL = await startCCServer();
157157
const request = await playwright.request.newContext({
158+
ignoreHTTPSErrors: true,
158159
clientCertificates: [{
159160
origin: new URL(serverURL).origin,
160161
certPath: asset('client-certificates/client/trusted/cert.pem'),
@@ -171,6 +172,7 @@ test.describe('fetch', () => {
171172
test('should work in the browser with request interception', async ({ browser, playwright, startCCServer, asset }) => {
172173
const serverURL = await startCCServer();
173174
const request = await playwright.request.newContext({
175+
ignoreHTTPSErrors: true,
174176
clientCertificates: [{
175177
origin: new URL(serverURL).origin,
176178
certPath: asset('client-certificates/client/trusted/cert.pem'),
@@ -213,6 +215,7 @@ test.describe('browser', () => {
213215
test('should fail with no client certificates', async ({ browser, startCCServer, asset, browserName }) => {
214216
const serverURL = await startCCServer({ useFakeLocalhost: browserName === 'webkit' && process.platform === 'darwin' });
215217
const page = await browser.newPage({
218+
ignoreHTTPSErrors: true,
216219
clientCertificates: [{
217220
origin: 'https://not-matching.com',
218221
certPath: asset('client-certificates/client/trusted/cert.pem'),
@@ -227,6 +230,7 @@ test.describe('browser', () => {
227230
test('should fail with self-signed client certificates', async ({ browser, startCCServer, asset, browserName }) => {
228231
const serverURL = await startCCServer({ useFakeLocalhost: browserName === 'webkit' && process.platform === 'darwin' });
229232
const page = await browser.newPage({
233+
ignoreHTTPSErrors: true,
230234
clientCertificates: [{
231235
origin: new URL(serverURL).origin,
232236
certPath: asset('client-certificates/client/self-signed/cert.pem'),
@@ -241,6 +245,7 @@ test.describe('browser', () => {
241245
test('should pass with matching certificates', async ({ browser, startCCServer, asset, browserName }) => {
242246
const serverURL = await startCCServer({ useFakeLocalhost: browserName === 'webkit' && process.platform === 'darwin' });
243247
const page = await browser.newPage({
248+
ignoreHTTPSErrors: true,
244249
clientCertificates: [{
245250
origin: new URL(serverURL).origin,
246251
certPath: asset('client-certificates/client/trusted/cert.pem'),
@@ -278,6 +283,7 @@ test.describe('browser', () => {
278283
test('should pass with matching certificates and trailing slash', async ({ browser, startCCServer, asset, browserName }) => {
279284
const serverURL = await startCCServer({ useFakeLocalhost: browserName === 'webkit' && process.platform === 'darwin' });
280285
const page = await browser.newPage({
286+
ignoreHTTPSErrors: true,
281287
clientCertificates: [{
282288
origin: serverURL,
283289
certPath: asset('client-certificates/client/trusted/cert.pem'),
@@ -307,6 +313,7 @@ test.describe('browser', () => {
307313
const enableHTTP1FallbackWhenUsingHttp2 = browserName === 'webkit' && process.platform === 'linux';
308314
const serverURL = await startCCServer({ http2: true, enableHTTP1FallbackWhenUsingHttp2 });
309315
const page = await browser.newPage({
316+
ignoreHTTPSErrors: true,
310317
clientCertificates: [{
311318
origin: new URL(serverURL).origin,
312319
certPath: asset('client-certificates/client/trusted/cert.pem'),
@@ -335,6 +342,7 @@ test.describe('browser', () => {
335342
const serverURL = await startCCServer({ http2: true, enableHTTP1FallbackWhenUsingHttp2: true });
336343
const browser = await browserType.launch({ args: ['--disable-http2'] });
337344
const page = await browser.newPage({
345+
ignoreHTTPSErrors: true,
338346
clientCertificates: [{
339347
origin: new URL(serverURL).origin,
340348
certPath: asset('client-certificates/client/trusted/cert.pem'),
@@ -359,7 +367,6 @@ test.describe('browser', () => {
359367
test.fixme(browserName === 'webkit' && process.platform === 'linux', 'WebKit on Linux does not support http2 https://bugs.webkit.org/show_bug.cgi?id=276990');
360368
test.skip(+process.versions.node.split('.')[0] < 20, 'http2.performServerHandshake is not supported in older Node.js versions');
361369

362-
process.env.PWTEST_UNSUPPORTED_CUSTOM_CA = asset('empty.html');
363370
const serverURL = await startCCServer({ http2: true });
364371
const page = await browser.newPage({
365372
clientCertificates: [{
@@ -383,6 +390,7 @@ test.describe('browser', () => {
383390
test('should pass with matching certificates', async ({ launchPersistent, startCCServer, asset, browserName }) => {
384391
const serverURL = await startCCServer({ useFakeLocalhost: browserName === 'webkit' && process.platform === 'darwin' });
385392
const { page } = await launchPersistent({
393+
ignoreHTTPSErrors: true,
386394
clientCertificates: [{
387395
origin: new URL(serverURL).origin,
388396
certPath: asset('client-certificates/client/trusted/cert.pem'),

0 commit comments

Comments
 (0)