Skip to content

Commit 262a15f

Browse files
committed
Add generic non-printable chars test for OIDC configs
1 parent 022ff3c commit 262a15f

1 file changed

Lines changed: 31 additions & 106 deletions

File tree

src/start-proxy.test.ts

Lines changed: 31 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -351,112 +351,37 @@ test("getCredentials throws an error when non-printable characters are used", as
351351
}
352352
});
353353

354-
const validAzureCredential: startProxyExports.AzureConfig = {
355-
"tenant-id": "12345678-1234-1234-1234-123456789012",
356-
"client-id": "abcdef01-2345-6789-abcd-ef0123456789",
357-
};
358-
359-
const validAwsCredential: startProxyExports.AWSConfig = {
360-
"aws-region": "us-east-1",
361-
"account-id": "123456789012",
362-
"role-name": "MY_ROLE",
363-
domain: "MY_DOMAIN",
364-
"domain-owner": "987654321098",
365-
audience: "custom-audience",
366-
};
367-
368-
const validJFrogCredential: startProxyExports.JFrogConfig = {
369-
"jfrog-oidc-provider-name": "MY_PROVIDER",
370-
audience: "jfrog-audience",
371-
"identity-mapping-name": "my-mapping",
372-
};
373-
374-
test("getCredentials throws an error when non-printable characters are used for Azure OIDC", (t) => {
375-
for (const key of Object.keys(validAzureCredential)) {
376-
const invalidAzureCredential = {
377-
...validAzureCredential,
378-
[key]: "123\x00",
379-
};
380-
const invalidCredential: startProxyExports.RawCredential = {
381-
type: "nuget_feed",
382-
host: `${key}.nuget.pkg.github.com`,
383-
...invalidAzureCredential,
384-
};
385-
const credentialsInput = toEncodedJSON([invalidCredential]);
386-
387-
t.throws(
388-
() =>
389-
startProxyExports.getCredentials(
390-
getRunnerLogger(true),
391-
undefined,
392-
credentialsInput,
393-
undefined,
394-
),
395-
{
396-
message:
397-
"Invalid credentials - fields must contain only printable characters",
398-
},
399-
);
400-
}
401-
});
402-
403-
test("getCredentials throws an error when non-printable characters are used for AWS OIDC", (t) => {
404-
for (const key of Object.keys(validAwsCredential)) {
405-
const invalidAwsCredential = {
406-
...validAwsCredential,
407-
[key]: "123\x00",
408-
};
409-
const invalidCredential: startProxyExports.RawCredential = {
410-
type: "nuget_feed",
411-
host: `${key}.nuget.pkg.github.com`,
412-
...invalidAwsCredential,
413-
};
414-
const credentialsInput = toEncodedJSON([invalidCredential]);
415-
416-
t.throws(
417-
() =>
418-
startProxyExports.getCredentials(
419-
getRunnerLogger(true),
420-
undefined,
421-
credentialsInput,
422-
undefined,
423-
),
424-
{
425-
message:
426-
"Invalid credentials - fields must contain only printable characters",
427-
},
428-
);
429-
}
430-
});
431-
432-
test("getCredentials throws an error when non-printable characters are used for JFrog OIDC", (t) => {
433-
for (const key of Object.keys(validJFrogCredential)) {
434-
const invalidJFrogCredential = {
435-
...validJFrogCredential,
436-
[key]: "123\x00",
437-
};
438-
const invalidCredential: startProxyExports.RawCredential = {
439-
type: "nuget_feed",
440-
host: `${key}.nuget.pkg.github.com`,
441-
...invalidJFrogCredential,
442-
};
443-
const credentialsInput = toEncodedJSON([invalidCredential]);
444-
445-
t.throws(
446-
() =>
447-
startProxyExports.getCredentials(
448-
getRunnerLogger(true),
449-
undefined,
450-
credentialsInput,
451-
undefined,
452-
),
453-
{
454-
message:
455-
"Invalid credentials - fields must contain only printable characters",
456-
},
457-
);
458-
}
459-
});
354+
for (const oidcSchemaInfo of startProxyExports.oidcSchemas) {
355+
test(`getCredentials throws when non-printable characters are used (${oidcSchemaInfo.name} OIDC)`, (t) => {
356+
const validCredential = makeFromSchema(true, oidcSchemaInfo.schema);
357+
for (const key of Object.keys(validCredential)) {
358+
const invalidAuthConfig = {
359+
...validCredential,
360+
[key]: "123\x00",
361+
};
362+
const invalidCredential: startProxyExports.RawCredential = {
363+
type: "nuget_feed",
364+
host: `${key}.nuget.pkg.github.com`,
365+
...invalidAuthConfig,
366+
};
367+
const credentialsInput = toEncodedJSON([invalidCredential]);
368+
369+
t.throws(
370+
() =>
371+
startProxyExports.getCredentials(
372+
getRunnerLogger(true),
373+
undefined,
374+
credentialsInput,
375+
undefined,
376+
),
377+
{
378+
message:
379+
"Invalid credentials - fields must contain only printable characters",
380+
},
381+
);
382+
}
383+
});
384+
}
460385

461386
test("getCredentials accepts OIDC configurations", (t) => {
462387
const oidcConfigurations = startProxyExports.oidcSchemas.map(

0 commit comments

Comments
 (0)