From 9638fee90efedb123d2ee90183104fad6b189e55 Mon Sep 17 00:00:00 2001 From: GiHoon1123 Date: Fri, 10 Jul 2026 15:44:53 +0900 Subject: [PATCH] test: handle plain HTTP proxy requests in the PROXY auth mock Node 26.5.0 bundles Undici 8.7.0, which changed how it proxies plain http:// requests: instead of always tunneling through CONNECT, it now sends them directly to the proxy with an absolute-URI request line, per the standard HTTP proxying behavior. The AUTH_TYPE=PROXY test mock only ever handled CONNECT (used for the tunneling case) and unconditionally replied "okay" to any other request. Under Node 26.5.0 this "okay" body got parsed as registry JSON/tarball data, failing with "Unexpected token 'o', "okay" is not valid JSON" or TAR_BAD_ARCHIVE. Parse the absolute-URI request line, and for requests to the test's mock host forward them into the existing mock registry server's own request handler (reusing its logic via `server.emit('request', ...)` rather than duplicating it) instead of replying with a stub. The existing CONNECT handling is untouched. Verified: reverting this fix and running under Node 26.5.0 reproduces the exact reported failures (TAR_BAD_ARCHIVE / JSON parse error) in all 4 PROXY-mode tests; with the fix, all 4 pass. Full main.test.ts suite (114 tests) passes identically under both Node 22 and 26.5.0. Fixes: https://github.com/nodejs/corepack/issues/868 --- tests/_registryServer.mjs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/_registryServer.mjs b/tests/_registryServer.mjs index 61bb77829..aaad93548 100644 --- a/tests/_registryServer.mjs +++ b/tests/_registryServer.mjs @@ -167,8 +167,21 @@ const server = createServer((req, res) => { if (process.env.AUTH_TYPE === `PROXY`) { const proxy = createServer((req, res) => { - res.writeHead(200, {[`Content-Type`]: `text/plain`}); - res.end(`okay`); + let url; + try { + url = new URL(req.url); + } catch { + res.writeHead(404).end(`Not Found`); + return; + } + + if (url.protocol !== `http:` || url.host !== `example.com`) { + res.writeHead(404).end(`Not Found`); + return; + } + + req.url = `${url.pathname}${url.search}`; + server.emit(`request`, req, res); }); proxy.on(`connect`, (req, clientSocket, head) => { if (req.url !== `example.com:80`) {