diff --git a/packages/http-caching-proxy/src/__tests__/integration/http-caching-proxy.integration.ts b/packages/http-caching-proxy/src/__tests__/integration/http-caching-proxy.integration.ts index b80378066511..0f06c895bed6 100644 --- a/packages/http-caching-proxy/src/__tests__/integration/http-caching-proxy.integration.ts +++ b/packages/http-caching-proxy/src/__tests__/integration/http-caching-proxy.integration.ts @@ -14,9 +14,9 @@ import {once} from 'node:events'; import http from 'node:http'; import {AddressInfo} from 'node:net'; import path from 'node:path'; +import {URL} from 'node:url'; import {rimraf} from 'rimraf'; import tunnel, {ProxyOptions as TunnelProxyOptions} from 'tunnel'; -import {URL} from 'node:url'; import {HttpCachingProxy, ProxyOptions} from '../../http-caching-proxy'; const CACHE_DIR = path.join(__dirname, '.cache'); @@ -84,7 +84,9 @@ describe('HttpCachingProxy', () => { // Increase the timeout to accommodate slow network connections this.timeout(30000); - await givenRunningProxy(); + // Disable SSL validation for this test to avoid certificate issues + // with example.com in different Node.js versions and environments + await givenRunningProxy({rejectUnauthorized: false}); const result = await makeRequest({ url: 'https://example.com', }); diff --git a/packages/http-caching-proxy/src/http-caching-proxy.ts b/packages/http-caching-proxy/src/http-caching-proxy.ts index 6fdf2f65d8f8..89c761aed051 100644 --- a/packages/http-caching-proxy/src/http-caching-proxy.ts +++ b/packages/http-caching-proxy/src/http-caching-proxy.ts @@ -8,9 +8,9 @@ import debugFactory from 'debug'; import {once} from 'node:events'; import { createServer, + Server as HttpServer, IncomingMessage, OutgoingHttpHeaders, - Server as HttpServer, ServerResponse, } from 'node:http'; import {AddressInfo} from 'node:net'; @@ -48,6 +48,14 @@ export interface ProxyOptions { * Timeout to connect to the target service */ timeout?: number; + + /** + * Whether to reject unauthorized SSL certificates. + * Set to false to allow self-signed certificates in test environments. + * + * Default: true (strict SSL validation) + */ + rejectUnauthorized?: boolean; } const DEFAULT_OPTIONS = { @@ -55,6 +63,7 @@ const DEFAULT_OPTIONS = { ttl: 24 * 60 * 60 * 1000, logError: true, timeout: 0, + rejectUnauthorized: true, }; interface CachedMetadata { @@ -89,6 +98,10 @@ export class HttpCachingProxy { // http status code. Please note that Axios creates a new error in such // condition and the original low-level error is lost validateStatus: () => true, + // Configure SSL certificate validation based on options + httpsAgent: new (require('node:https').Agent)({ + rejectUnauthorized: this._options.rejectUnauthorized, + }), }); }