Skip to content

Commit 2a384c1

Browse files
committed
Move credentialToStr and add tests
1 parent b2ff80d commit 2a384c1

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

lib/start-proxy-action.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/start-proxy-action.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { KnownLanguage } from "./languages";
1212
import { getActionsLogger, Logger } from "./logging";
1313
import {
1414
Credential,
15+
credentialToStr,
1516
getCredentials,
1617
getDownloadUrl,
1718
parseLanguage,
@@ -309,10 +310,4 @@ async function getProxyBinaryPath(logger: Logger): Promise<string> {
309310
return proxyBin;
310311
}
311312

312-
function credentialToStr(c: Credential): string {
313-
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${
314-
c.username
315-
}; Password: ${c.password !== undefined}; Token: ${c.token !== undefined}`;
316-
}
317-
318313
void runWrapper();

src/start-proxy.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,20 @@ test("getDownloadUrl returns matching release asset", async (t) => {
301301
t.is(info.version, defaults.cliVersion);
302302
t.is(info.url, "url-we-want");
303303
});
304+
305+
test("credentialToStr - hides passwords/tokens", (t) => {
306+
const secret = "password123";
307+
const credential = {
308+
type: "maven_credential",
309+
};
310+
t.false(
311+
startProxyExports
312+
.credentialToStr({ password: secret, ...credential })
313+
.includes(secret),
314+
);
315+
t.false(
316+
startProxyExports
317+
.credentialToStr({ token: secret, ...credential })
318+
.includes(secret),
319+
);
320+
});

src/start-proxy.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,14 @@ export async function getDownloadUrl(
277277
version: UPDATEJOB_PROXY_VERSION,
278278
};
279279
}
280+
281+
/**
282+
* Pretty-prints a `Credential` value to a string, but hides the actual password or token values.
283+
*
284+
* @param c The credential to convert to a string.
285+
*/
286+
export function credentialToStr(c: Credential): string {
287+
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${
288+
c.username
289+
}; Password: ${c.password !== undefined}; Token: ${c.token !== undefined}`;
290+
}

0 commit comments

Comments
 (0)