Move credentialToStr and add tests

This commit is contained in:
Michael B. Gale
2026-01-29 10:07:51 +00:00
parent b2ff80ddac
commit 2a384c1c14
4 changed files with 32 additions and 9 deletions
+3 -3
View File
@@ -119143,6 +119143,9 @@ async function getDownloadUrl(logger) {
version: UPDATEJOB_PROXY_VERSION
};
}
function credentialToStr(c) {
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${c.username}; Password: ${c.password !== void 0}; Token: ${c.token !== void 0}`;
}
// src/status-report.ts
var os = __toESM(require("os"));
@@ -119935,9 +119938,6 @@ async function getProxyBinaryPath(logger) {
proxyBin = path.join(proxyBin, proxyFileName);
return proxyBin;
}
function credentialToStr(c) {
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${c.username}; Password: ${c.password !== void 0}; Token: ${c.token !== void 0}`;
}
void runWrapper();
/*! Bundled license information:
+1 -6
View File
@@ -12,6 +12,7 @@ import { KnownLanguage } from "./languages";
import { getActionsLogger, Logger } from "./logging";
import {
Credential,
credentialToStr,
getCredentials,
getDownloadUrl,
parseLanguage,
@@ -309,10 +310,4 @@ async function getProxyBinaryPath(logger: Logger): Promise<string> {
return proxyBin;
}
function credentialToStr(c: Credential): string {
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${
c.username
}; Password: ${c.password !== undefined}; Token: ${c.token !== undefined}`;
}
void runWrapper();
+17
View File
@@ -301,3 +301,20 @@ test("getDownloadUrl returns matching release asset", async (t) => {
t.is(info.version, defaults.cliVersion);
t.is(info.url, "url-we-want");
});
test("credentialToStr - hides passwords/tokens", (t) => {
const secret = "password123";
const credential = {
type: "maven_credential",
};
t.false(
startProxyExports
.credentialToStr({ password: secret, ...credential })
.includes(secret),
);
t.false(
startProxyExports
.credentialToStr({ token: secret, ...credential })
.includes(secret),
);
});
+11
View File
@@ -277,3 +277,14 @@ export async function getDownloadUrl(
version: UPDATEJOB_PROXY_VERSION,
};
}
/**
* Pretty-prints a `Credential` value to a string, but hides the actual password or token values.
*
* @param c The credential to convert to a string.
*/
export function credentialToStr(c: Credential): string {
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${
c.username
}; Password: ${c.password !== undefined}; Token: ${c.token !== undefined}`;
}