8000 Add tests for `generateRegistries` with an existing CODEQL_REGISTRIES… · github/codeql-action@60afa75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 60afa75

Browse files
committed
Add tests for generateRegistries with an existing CODEQL_REGISTRIES_AUTH
1 parent 3c81243 commit 60afa75

File tree

8 files changed

+58
-10
lines changed

8 files changed

+58
-10
lines changed

lib/codeql.test.js

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/config-utils.js

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/config-utils.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/config-utils.test.js

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

lib/config-utils.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/codeql.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ test("does not pass a code scanning config or qlconfig file to the CLI when CLI
10251025
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
10261026

10271027
// should not have passed a qlconfig file
1028-
const hasQlconfigArg = args.find((arg: string) =>
1028+
const hasQlconfigArg = args.some((arg: string) =>
10291029
arg.startsWith("--qlconfig=")
10301030
);
10311031
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");

src/config-utils.test.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ test("downloadPacks-with-registries", async (t) => {
23002300
// associated env vars
23012301
return await util.withTmpDir(async (tmpDir) => {
23022302
process.env.GITHUB_TOKEN = "not-a-token";
2303-
process.env.CODEQL_REGISTRIES_AUTH = "not-a-registries-auth";
2303+
process.env.CODEQL_REGISTRIES_AUTH = undefined;
23042304
const logger = getRunnerLogger(true);
23052305

23062306
const registriesInput = yaml.dump([
@@ -2382,7 +2382,7 @@ test("downloadPacks-with-registries", async (t) => {
23822382

23832383
// Verify that the env vars were unset.
23842384
t.deepEqual(process.env.GITHUB_TOKEN, "not-a-token");
2385-
t.deepEqual(process.env.CODEQL_REGISTRIES_AUTH, "not-a-registries-auth");
2385+
t.deepEqual(process.env.CODEQL_REGISTRIES_AUTH, undefined);
23862386
});
23872387
});
23882388

@@ -2521,6 +2521,34 @@ test("no generateRegistries when registries is undefined", async (t) => {
25212521
});
25222522
});
25232523

2524+
test(" 8000 ;generateRegistries prefers original CODEQL_REGISTRIES_AUTH", async (t) => {
2525+
return await util.withTmpDir(async (tmpDir) => {
2526+
process.env.CODEQL_REGISTRIES_AUTH = "original";
2527+
const registriesInput = yaml.dump([
2528+
{
2529+
url: "http://ghcr.io",
2530+
packages: ["codeql/*", "dsp-testing/*"],
2531+
token: "not-a-token",
2532+
},
2533+
]);
2534+
const codeQL = setCodeQL({
2535+
// Accepted CLI versions are 2.10.4 or higher
2536+
getVersion: () => Promise.resolve(CODEQL_VERSION_GHES_PACK_DOWNLOAD),
2537+
});
2538+
const logger = getRunnerLogger(true);
2539+
const { registriesAuthTokens, qlconfigFile } =
2540+
await configUtils.generateRegistries(
2541+
registriesInput,
2542+
codeQL,
2543+
tmpDir,
2544+
logger
2545+
);
2546+
2547+
t.is(registriesAuthTokens, "original");
2548+
t.is(qlconfigFile, `${tmpDir}/qlconfig.yml`);
2549+
});
2550+
});
2551+
25242552
// getLanguages
25252553

25262554
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");

src/config-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ export async function generateRegistries(
19931993
return {
19941994
registriesAuthTokens:
19951995
// if the user has explicitly set the CODEQL_REGISTRIES_AUTH env var then use that
1996-
process.env["CODEQL_REGISTRIES_AUTH"] ?? registriesAuthTokens,
1996+
process.env.CODEQL_REGISTRIES_AUTH ?? registriesAuthTokens,
19971997
qlconfigFile,
19981998
};
19991999
}

0 commit comments

Comments
 (0)
0