Skip to content

Commit

Permalink
Add tests for generateRegistries with an existing CODEQL_REGISTRIES…
Browse files Browse the repository at this point in the history
…_AUTH
  • Loading branch information
aeisenberg committed Feb 9, 2023
1 parent 3c81243 commit 5492b7d
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/codeql.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.js.map

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions lib/config-utils.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.test.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ test("does not pass a code scanning config or qlconfig file to the CLI when CLI
t.false(hasConfigArg, "Should NOT have injected a codescanning config");

// should not have passed a qlconfig file
const hasQlconfigArg = args.find((arg: string) =>
const hasQlconfigArg = args.some((arg: string) =>
arg.startsWith("--qlconfig=")
);
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
Expand Down
32 changes: 30 additions & 2 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,7 @@ test("downloadPacks-with-registries", async (t) => {
// associated env vars
return await util.withTmpDir(async (tmpDir) => {
process.env.GITHUB_TOKEN = "not-a-token";
process.env.CODEQL_REGISTRIES_AUTH = "not-a-registries-auth";
process.env.CODEQL_REGISTRIES_AUTH = undefined;
const logger = getRunnerLogger(true);

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

// Verify that the env vars were unset.
t.deepEqual(process.env.GITHUB_TOKEN, "not-a-token");
t.deepEqual(process.env.CODEQL_REGISTRIES_AUTH, "not-a-registries-auth");
t.deepEqual(process.env.CODEQL_REGISTRIES_AUTH, undefined);
});
});

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

test("generateRegistries prefers original CODEQL_REGISTRIES_AUTH", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env.CODEQL_REGISTRIES_AUTH = "original";
const registriesInput = yaml.dump([
{
url: "http://ghcr.io",
packages: ["codeql/*", "dsp-testing/*"],
token: "not-a-token",
},
]);
const codeQL = setCodeQL({
// Accepted CLI versions are 2.10.4 or higher
getVersion: () => Promise.resolve(CODEQL_VERSION_GHES_PACK_DOWNLOAD),
});
const logger = getRunnerLogger(true);
const { registriesAuthTokens, qlconfigFile } =
await configUtils.generateRegistries(
registriesInput,
codeQL,
tmpDir,
logger
);

t.is(registriesAuthTokens, "original");
t.is(qlconfigFile, path.join(tmpDir, "qlconfig.yml"));
});
});

// getLanguages

const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
Expand Down
2 changes: 1 addition & 1 deletion src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ export async function generateRegistries(
return {
registriesAuthTokens:
// if the user has explicitly set the CODEQL_REGISTRIES_AUTH env var then use that
process.env["CODEQL_REGISTRIES_AUTH"] ?? registriesAuthTokens,
process.env.CODEQL_REGISTRIES_AUTH ?? registriesAuthTokens,
qlconfigFile,
};
}
Expand Down

0 comments on commit 5492b7d

Please sign in to comment.