From 6e67ef61f266b641e068a9727bc22f7fef13cc5e Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 16 Mar 2026 12:47:06 +0000 Subject: [PATCH] Refactor PAT test into a `test.macro` --- src/start-proxy.test.ts | 67 +++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/src/start-proxy.test.ts b/src/start-proxy.test.ts index 755189c21..8186991b8 100644 --- a/src/start-proxy.test.ts +++ b/src/start-proxy.test.ts @@ -439,42 +439,49 @@ test("getCredentials accepts OIDC configurations", (t) => { t.assert(credentials.some((c) => startProxyExports.isJFrogConfig(c))); }); -test("getCredentials logs a warning when a PAT is used without a username", async (t) => { - const loggedMessages = []; - const logger = getRecordingLogger(loggedMessages); - const likelyWrongCredentials = toEncodedJSON([ - { - type: "git_server", - host: "https://github.com/", - password: `ghp_${makeTestToken()}`, - }, - ]); +const testPATWarning = test.macro({ + exec: async (t: ExecutionContext) => { + const loggedMessages = []; + const logger = getRecordingLogger(loggedMessages); + const likelyWrongCredentials = toEncodedJSON([ + { + type: "git_server", + host: "https://github.com/", + password: `ghp_${makeTestToken()}`, + }, + ]); - const results = startProxyExports.getCredentials( - logger, - undefined, - likelyWrongCredentials, - undefined, - ); + const results = startProxyExports.getCredentials( + logger, + undefined, + likelyWrongCredentials, + undefined, + ); - // The configuration should be accepted, despite the likely problem. - t.assert(results); - t.is(results.length, 1); - t.is(results[0].type, "git_server"); - t.is(results[0].host, "https://github.com/"); + // The configuration should be accepted, despite the likely problem. + t.assert(results); + t.is(results.length, 1); + t.is(results[0].type, "git_server"); + t.is(results[0].host, "https://github.com/"); - if (startProxyExports.isUsernamePassword(results[0])) { - t.assert(results[0].password?.startsWith("ghp_")); - } else { - t.fail("Expected a `UsernamePassword`-based credential."); - } + if (startProxyExports.isUsernamePassword(results[0])) { + t.assert(results[0].password?.startsWith("ghp_")); + } else { + t.fail("Expected a `UsernamePassword`-based credential."); + } - // A warning should have been logged. - checkExpectedLogMessages(t, loggedMessages, [ - "using a GitHub Personal Access Token (PAT), but no username was provided", - ]); + // A warning should have been logged. + checkExpectedLogMessages(t, loggedMessages, [ + "using a GitHub Personal Access Token (PAT), but no username was provided", + ]); + }, + + title: (providedTitle = "") => + `getCredentials logs a warning when a PAT is used - ${providedTitle}`, }); +test("password without a username", testPATWarning); + test("getCredentials returns all credentials for Actions when using LANGUAGE_TO_REGISTRY_TYPE", async (t) => { const credentialsInput = toEncodedJSON(mixedCredentials);