From efb92e2714025a125f7ddc2ff85584c7dc47bc7b Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 11 Feb 2026 18:02:24 +0000 Subject: [PATCH] Skip checks for non-URLs for now --- lib/start-proxy-action.js | 23 ++++++++++++--------- src/start-proxy/reachability.test.ts | 26 ++++++++++++++++++++++- src/start-proxy/reachability.ts | 31 ++++++++++++++++------------ 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 4ae2ad5a6..072924405 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -121728,10 +121728,10 @@ var NetworkReachabilityBackend = class { this.agent = new import_https_proxy_agent.HttpsProxyAgent(`http://${proxy.host}:${proxy.port}`); } agent; - async checkConnection(registry) { + async checkConnection(url) { return new Promise((resolve2, reject) => { const req = https.request( - getAddressString(registry), + url, { agent: this.agent, method: "HEAD", @@ -121768,21 +121768,24 @@ async function checkConnections(logger, proxy, backend) { } for (const registry of proxy.registries) { const address = getAddressString(registry); - try { - logger.debug(`Testing connection to ${address}...`); - const statusCode = await backend.checkConnection(registry); + const url = URL.parse(address); + if (url === null) { logger.info( - `Successfully tested connection to ${address} (${statusCode})` + `Skipping check for ${address} since it is not a valid URL.` ); + continue; + } + try { + logger.debug(`Testing connection to ${url}...`); + const statusCode = await backend.checkConnection(url); + logger.info(`Successfully tested connection to ${url} (${statusCode})`); result.add(registry); } catch (e) { if (e instanceof ReachabilityError && e.statusCode !== void 0) { - logger.error( - `Connection test to ${address} failed. (${e.statusCode})` - ); + logger.error(`Connection test to ${url} failed. (${e.statusCode})`); } else { logger.error( - `Connection test to ${address} failed: ${getErrorMessage(e)}` + `Connection test to ${url} failed: ${getErrorMessage(e)}` ); } } diff --git a/src/start-proxy/reachability.test.ts b/src/start-proxy/reachability.test.ts index 84cd4f9dc..cbba99399 100644 --- a/src/start-proxy/reachability.test.ts +++ b/src/start-proxy/reachability.test.ts @@ -16,7 +16,7 @@ import { ProxyInfo, Registry } from "./types"; setupTests(test); class MockReachabilityBackend implements ReachabilityBackend { - public async checkConnection(_registry: Registry): Promise { + public async checkConnection(_url: URL): Promise { return 200; } } @@ -94,3 +94,27 @@ test("checkConnections - handles other exceptions", async (t) => { `Finished testing connections`, ]); }); + +test("checkConnections - handles invalid URLs", async (t) => { + const backend = new MockReachabilityBackend(); + const messages = await withRecordingLoggerAsync(async (logger) => { + const reachable = await checkConnections( + logger, + { + ...proxyInfo, + registries: [ + { + type: "nuget_feed", + url: "localhost", + }, + ], + }, + backend, + ); + t.is(reachable.size, 0); + }); + checkExpectedLogMessages(t, messages, [ + `Skipping check for localhost since it is not a valid URL.`, + `Finished testing connections`, + ]); +}); diff --git a/src/start-proxy/reachability.ts b/src/start-proxy/reachability.ts index ec0df946a..2951c8a0c 100644 --- a/src/start-proxy/reachability.ts +++ b/src/start-proxy/reachability.ts @@ -19,13 +19,13 @@ export class ReachabilityError extends Error { */ export interface ReachabilityBackend { /** - * Performs a test HTTP request to the specified `registry`. Resolves to the status code, + * Performs a test HTTP request to the specified `url`. Resolves to the status code, * if a successful status code was obtained. Otherwise throws * - * @param registry The registry to try and reach. + * @param url The URL of the registry to try and reach. * @returns The successful status code (in the `<400` range). */ - checkConnection: (registry: Registry) => Promise; + checkConnection: (url: URL) => Promise; } class NetworkReachabilityBackend implements ReachabilityBackend { @@ -35,10 +35,10 @@ class NetworkReachabilityBackend implements ReachabilityBackend { this.agent = new HttpsProxyAgent(`http://${proxy.host}:${proxy.port}`); } - public async checkConnection(registry: Registry): Promise { + public async checkConnection(url: URL): Promise { return new Promise((resolve, reject) => { const req = https.request( - getAddressString(registry), + url, { agent: this.agent, method: "HEAD", @@ -93,22 +93,27 @@ export async function checkConnections( for (const registry of proxy.registries) { const address = getAddressString(registry); - try { - logger.debug(`Testing connection to ${address}...`); - const statusCode = await backend.checkConnection(registry); + const url = URL.parse(address); + if (url === null) { logger.info( - `Successfully tested connection to ${address} (${statusCode})`, + `Skipping check for ${address} since it is not a valid URL.`, ); + continue; + } + + try { + logger.debug(`Testing connection to ${url}...`); + const statusCode = await backend.checkConnection(url); + + logger.info(`Successfully tested connection to ${url} (${statusCode})`); result.add(registry); } catch (e) { if (e instanceof ReachabilityError && e.statusCode !== undefined) { - logger.error( - `Connection test to ${address} failed. (${e.statusCode})`, - ); + logger.error(`Connection test to ${url} failed. (${e.statusCode})`); } else { logger.error( - `Connection test to ${address} failed: ${getErrorMessage(e)}`, + `Connection test to ${url} failed: ${getErrorMessage(e)}`, ); } }