Skip to content

Commit e9938e3

Browse files
committed
Check that proxy configurations are an array
1 parent 4c57370 commit e9938e3

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

lib/start-proxy.js

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

lib/start-proxy.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/start-proxy.test.js

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

lib/start-proxy.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/start-proxy.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ test("getCredentials prefers registriesCredentials over registrySecrets", async
2626
t.is(credentials[0].host, "npm.pkg.github.com");
2727
});
2828

29+
test("getCredentials throws an error when configurations are not an array", async (t) => {
30+
const registryCredentials = Buffer.from(
31+
JSON.stringify({ type: "npm_registry", token: "abc" }),
32+
).toString("base64");
33+
34+
t.throws(
35+
() =>
36+
startProxyExports.getCredentials(
37+
getRunnerLogger(true),
38+
undefined,
39+
registryCredentials,
40+
undefined,
41+
),
42+
{
43+
message:
44+
"Expected credentials data to be an array of configurations, but it is not.",
45+
},
46+
);
47+
});
48+
2949
test("getCredentials throws error when credential missing host and url", async (t) => {
3050
const registryCredentials = Buffer.from(
3151
JSON.stringify([{ type: "npm_registry", token: "abc" }]),

src/start-proxy.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ export function getCredentials(
6363
throw new ConfigurationError("Invalid credentials format.");
6464
}
6565

66+
// Check that the parsed data is indeed an array.
67+
if (!Array.isArray(parsed)) {
68+
throw new ConfigurationError(
69+
"Expected credentials data to be an array of configurations, but it is not.",
70+
);
71+
}
72+
6673
const out: Credential[] = [];
6774
for (const e of parsed) {
6875
// Mask credentials to reduce chance of accidental leakage in logs.

0 commit comments

Comments
 (0)