From 1a0eca3555da206b41fe4b8abbba9ef343abcf0f Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 14 Jul 2026 19:33:01 +0100 Subject: [PATCH] Validate `proxy` argument in tests --- src/config/file.test.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/config/file.test.ts b/src/config/file.test.ts index b07ea71ba..6f6b4a5d9 100644 --- a/src/config/file.test.ts +++ b/src/config/file.test.ts @@ -86,7 +86,22 @@ test.serial("getRemoteConfig uses proxy when it is supposed to", async (t) => { .stub(client.rest.repos, "getContent") // eslint-disable-next-line @typescript-eslint/no-unsafe-argument .resolves(response as any); - sinon.stub(api, "getApiClientWithExternalAuth").value(() => client); + + // We stub `getApiClientWithExternalAuth` so that it throws if no + // proxy is provided and returns the client otherwise. This allows us + // to verify the result in the following test cases. + const errorMessage = "No `proxy` was provided by the caller."; + sinon + .stub(api, "getApiClientWithExternalAuth") + .callsFake((_details, proxy) => { + // Throw if proxy isn't defined. + if (proxy === undefined) { + throw new Error(errorMessage); + } + // Otherwise return the client object. + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return client as unknown as any; + }); const target = callee(getRemoteConfig) .withDefaultActionsEnv() @@ -110,11 +125,11 @@ test.serial("getRemoteConfig uses proxy when it is supposed to", async (t) => { env.set(RegistryProxyVars.PROXY_PORT, "1234"); }) .notLogs(t, "Using private registry proxy at 'http://localhost:1234'") - .passes(t.truthy); + .throws(t, { message: errorMessage }); // And not when the environment variables aren't set. await target .withFeatures([Feature.ProxyApiRequests, Feature.NewRemoteFileAddresses]) .notLogs(t, "Using private registry proxy at 'http://localhost:1234'") - .passes(t.truthy); + .throws(t, { message: errorMessage }); });