Skip to content

Commit f6d19ed

Browse files
committed
Formatting
1 parent ecf7232 commit f6d19ed

6 files changed

+57
-35
lines changed

Diff for: lib/start-proxy.js

+8-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: lib/start-proxy.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: lib/start-proxy.test.js

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: lib/start-proxy.test.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/start-proxy.test.ts

+29-24
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,34 @@ test("getCredentials returns all credentials when no language specified", async
8282
});
8383

8484
test("getCredentials throws an error when non-printable characters are used", async (t) => {
85-
const invalidCredentials = [
86-
{ type: "nuget_feed", host: "1nuget.pkg.github.com", token: "abc\u0000" }, // Non-printable character in token
87-
{ type: "nuget_feed", host: "2nuget.pkg.github.com\u0001" }, // Non-printable character in host
88-
{ type: "nuget_feed", host: "3nuget.pkg.github.com", password: "ghi\u0002" }, // Non-printable character in password
89-
{ type: "nuget_feed", host: "4nuget.pkg.github.com", password: "ghi\x00" }, // Non-printable character in password
90-
];
85+
const invalidCredentials = [
86+
{ type: "nuget_feed", host: "1nuget.pkg.github.com", token: "abc\u0000" }, // Non-printable character in token
87+
{ type: "nuget_feed", host: "2nuget.pkg.github.com\u0001" }, // Non-printable character in host
88+
{
89+
type: "nuget_feed",
90+
host: "3nuget.pkg.github.com",
91+
password: "ghi\u0002",
92+
}, // Non-printable character in password
93+
{ type: "nuget_feed", host: "4nuget.pkg.github.com", password: "ghi\x00" }, // Non-printable character in password
94+
];
9195

92-
for (const invalidCredential of invalidCredentials) {
93-
const credentialsInput = Buffer.from(
94-
JSON.stringify([invalidCredential]),
95-
).toString("base64");
96+
for (const invalidCredential of invalidCredentials) {
97+
const credentialsInput = Buffer.from(
98+
JSON.stringify([invalidCredential]),
99+
).toString("base64");
96100

97-
t.throws(
98-
() =>
99-
startProxyExports.getCredentials(
100-
getRunnerLogger(true),
101-
undefined,
102-
credentialsInput,
103-
undefined,
104-
),
105-
{
106-
message: "Invalid credentials - fields must contain only printable characters",
107-
},
108-
);
109-
}
110-
});
101+
t.throws(
102+
() =>
103+
startProxyExports.getCredentials(
104+
getRunnerLogger(true),
105+
undefined,
106+
credentialsInput,
107+
undefined,
108+
),
109+
{
110+
message:
111+
"Invalid credentials - fields must contain only printable characters",
112+
},
113+
);
114+
}
115+
});

Diff for: src/start-proxy.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ export function getCredentials(
5454
let parsed: Credential[];
5555
try {
5656
parsed = JSON.parse(credentialsStr) as Credential[];
57-
} catch (error) {
57+
} catch {
5858
// Don't log the error since it might contain sensitive information.
5959
logger.error("Failed to parse the credentials data.");
6060
throw new Error("Invalid credentials format.");
6161
}
6262

63-
let out: Credential[] = [];
63+
const out: Credential[] = [];
6464
for (const e of parsed) {
6565
if (e.url === undefined && e.host === undefined) {
6666
// The proxy needs one of these to work. If both are defined, the url has the precedence.
@@ -73,13 +73,21 @@ export function getCredentials(
7373
continue;
7474
}
7575

76-
7776
const isPrintable = (str: string | undefined): boolean => {
7877
return str ? /^[\x20-\x7E]*$/.test(str) : true;
7978
};
8079

81-
if (!isPrintable(e.type) || !isPrintable(e.host) || !isPrintable(e.url) || !isPrintable(e.username) || !isPrintable(e.password) || !isPrintable(e.token)) {
82-
throw new Error("Invalid credentials - fields must contain only printable characters");
80+
if (
81+
!isPrintable(e.type) ||
82+
!isPrintable(e.host) ||
83+
!isPrintable(e.url) ||
84+
!isPrintable(e.username) ||
85+
!isPrintable(e.password) ||
86+
!isPrintable(e.token)
87+
) {
88+
throw new Error(
89+
"Invalid credentials - fields must contain only printable characters",
90+
);
8391
}
8492

8593
out.push({

0 commit comments

Comments
 (0)