From a146ef2c67bb200e1d0b49534c4dde9a0762f042 Mon Sep 17 00:00:00 2001 From: Charlie Kolb Date: Mon, 14 Sep 2026 17:19:11 +0200 Subject: [PATCH] test: Guard every custom lookup and drop the internal export Apply the lookup wrapper whenever the caller passes a lookup function, also for a loopback hostname. A custom lookup can resolve that name to another address, so the block moves to the resolved address in every case. Remove the package export for the guard file. The configs load it by path and nothing imports it. Co-Authored-By: Claude Fable 5.1 --- packages/@n8n/vitest-config/package.json | 5 ----- packages/@n8n/vitest-config/setup/network-guard.ts | 14 ++++++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/@n8n/vitest-config/package.json b/packages/@n8n/vitest-config/package.json index 21f1c044958..6178d62ed29 100644 --- a/packages/@n8n/vitest-config/package.json +++ b/packages/@n8n/vitest-config/package.json @@ -45,11 +45,6 @@ "require": "./dist/setup/frontend.js", "types": "./dist/setup/frontend.d.ts" }, - "./setup/network-guard": { - "import": "./dist/setup/network-guard.js", - "require": "./dist/setup/network-guard.js", - "types": "./dist/setup/network-guard.d.ts" - }, "./node": { "import": "./dist/node.js", "require": "./dist/node.js", diff --git a/packages/@n8n/vitest-config/setup/network-guard.ts b/packages/@n8n/vitest-config/setup/network-guard.ts index 8648aaacd9d..fd50c5cb721 100644 --- a/packages/@n8n/vitest-config/setup/network-guard.ts +++ b/packages/@n8n/vitest-config/setup/network-guard.ts @@ -75,17 +75,19 @@ if (!allowNetwork && !Reflect.has(net.Socket.prototype, installedFlag)) { Reflect.set(net.Socket.prototype, installedFlag, true); net.Socket.prototype.connect = function connect(this: net.Socket, ...args: unknown[]) { const target = connectTarget(args); + if (target.path) return Reflect.apply(originalConnect, this, args) as net.Socket; const host = target.host ?? 'localhost'; - if (!target.path && !LOOPBACK.test(host)) { - if (typeof target.lookup !== 'function') { - // Async, like a real connect failure. A sync throw breaks `tls.connect`. - process.nextTick(() => this.destroy(blockedError(host, target.port))); - return this; - } + if (typeof target.lookup === 'function') { + // A custom lookup can resolve a loopback name to another address, so + // the block always moves to the resolved address here. const guarded = { ...target, lookup: guardLookup(target, target.lookup) }; // Node owns the normalized array, the caller owns a plain options object. if (Array.isArray(args[0])) args[0][0] = guarded; else args[0] = guarded; + } else if (!LOOPBACK.test(host)) { + // Async, like a real connect failure. A sync throw breaks `tls.connect`. + process.nextTick(() => this.destroy(blockedError(host, target.port))); + return this; } return Reflect.apply(originalConnect, this, args) as net.Socket; } as typeof net.Socket.prototype.connect;