From bfa5e66ca56adfb386ae0c06f5eb00c0f141815c Mon Sep 17 00:00:00 2001 From: Vita Batrla Date: Wed, 21 Jan 2026 21:46:33 +0100 Subject: [PATCH] test: make proxy tests runnable when there is a system proxy Some client-proxy tests set HTTP_PROXY variable in the environment. It's OK in general, however, in some specific cases, the user might have already defined his own http_proxy setting in the environment. The lowercase user setting takes precedence and leads to a test failure. The fix cleans up the environment to avoid an interaction between user and test proxy settings. PR-URL: https://github.com/nodejs/node/pull/61473 Reviewed-By: Joyee Cheung --- test/common/proxy-server.js | 35 +++++++++---------- .../test-http2-allow-http1-upgrade-ws.js | 3 +- test/parallel/test-inspector-network-fetch.js | 1 + 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/test/common/proxy-server.js b/test/common/proxy-server.js index 723fe0ea5c6b..ddfd43d3b366 100644 --- a/test/common/proxy-server.js +++ b/test/common/proxy-server.js @@ -156,17 +156,22 @@ function spawnPromisified(...args) { }); } +function spawnOptions(envExtension) { + const env = { ...process.env }; + // Cleanup the environment to avoid interference with client proxy tests. + for (const key of ['http_proxy', 'https_proxy', 'no_proxy']) { + delete env[key]; + delete env[key.toUpperCase()]; + } + return { env: { ...env, ...envExtension } }; +} + async function checkProxied(type, envExtension, expectation, cliArgsExtension = []) { const script = type === 'fetch' ? fixtures.path('fetch-and-log.mjs') : fixtures.path('request-and-log.js'); const { code, signal, stdout, stderr } = await spawnPromisified( process.execPath, - [...cliArgsExtension, script], { - env: { - NO_LOG_REQUEST: '1', - ...process.env, - ...envExtension, - }, - }); + [...cliArgsExtension, script], + spawnOptions({ ...envExtension, NO_LOG_REQUEST: '1' })); assert.deepStrictEqual({ stderr: stderr.trim(), @@ -193,24 +198,16 @@ exports.runProxiedRequest = async function(envExtension, cliArgsExtension = []) const fixtures = require('./fixtures'); return spawnPromisified( process.execPath, - [...cliArgsExtension, fixtures.path('request-and-log.js')], { - env: { - ...process.env, - ...envExtension, - }, - }); + [...cliArgsExtension, fixtures.path('request-and-log.js')], + spawnOptions(envExtension)); }; exports.runProxiedPOST = async function(envExtension) { const fixtures = require('./fixtures'); return spawnPromisified( process.execPath, - [fixtures.path('post-resource-and-log.js')], { - env: { - ...process.env, - ...envExtension, - }, - }); + [fixtures.path('post-resource-and-log.js')], + spawnOptions(envExtension)); }; exports.startTestServers = async function(options = {}) { diff --git a/test/parallel/test-http2-allow-http1-upgrade-ws.js b/test/parallel/test-http2-allow-http1-upgrade-ws.js index 028dc4e4cde7..2988071650d1 100644 --- a/test/parallel/test-http2-allow-http1-upgrade-ws.js +++ b/test/parallel/test-http2-allow-http1-upgrade-ws.js @@ -25,7 +25,8 @@ const WebSocketServer = require('../common/websocket-server'); await new Promise((resolve, reject) => { const ws = new WebSocket(`wss://localhost:${server.address().port}`, { dispatcher: new undici.EnvHttpProxyAgent({ - connect: { rejectUnauthorized: false } + connect: { rejectUnauthorized: false }, + noProxy: '*', }) }); ws.addEventListener('open', common.mustCall(() => { diff --git a/test/parallel/test-inspector-network-fetch.js b/test/parallel/test-inspector-network-fetch.js index 790446c84bfb..d86049b9c000 100644 --- a/test/parallel/test-inspector-network-fetch.js +++ b/test/parallel/test-inspector-network-fetch.js @@ -18,6 +18,7 @@ undici.setGlobalDispatcher(new undici.EnvHttpProxyAgent({ connect: { rejectUnauthorized: false, }, + noProxy: '*', })); const session = new inspector.Session();