Add tests for generateRegistries with an existing CODEQL_REGISTRIES_AUTH
This commit is contained in:
parent
3c81243bb1
commit
5492b7d104
8 changed files with 58 additions and 10 deletions
2
lib/codeql.test.js
generated
2
lib/codeql.test.js
generated
|
|
@ -676,7 +676,7 @@ const injectedConfigMacro = ava_1.default.macro({
|
||||||
const hasConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
const hasConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
||||||
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
|
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
|
||||||
// should not have passed a qlconfig file
|
// should not have passed a qlconfig file
|
||||||
const hasQlconfigArg = args.find((arg) => arg.startsWith("--qlconfig="));
|
const hasQlconfigArg = args.some((arg) => arg.startsWith("--qlconfig="));
|
||||||
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
||||||
});
|
});
|
||||||
(0, ava_1.default)("passes a code scanning config AND qlconfig to the CLI when CLI config passing is enabled", async (t) => {
|
(0, ava_1.default)("passes a code scanning config AND qlconfig to the CLI when CLI config passing is enabled", async (t) => {
|
||||||
|
|
|
||||||
2
lib/config-utils.js
generated
2
lib/config-utils.js
generated
|
|
@ -1119,7 +1119,7 @@ async function generateRegistries(registriesInput, codeQL, tempDir, logger) {
|
||||||
return {
|
return {
|
||||||
registriesAuthTokens:
|
registriesAuthTokens:
|
||||||
// if the user has explicitly set the CODEQL_REGISTRIES_AUTH env var then use that
|
// 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,
|
qlconfigFile,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
24
lib/config-utils.test.js
generated
24
lib/config-utils.test.js
generated
|
|
@ -1128,7 +1128,7 @@ const calculateAugmentationErrorMacro = ava_1.default.macro({
|
||||||
// associated env vars
|
// associated env vars
|
||||||
return await util.withTmpDir(async (tmpDir) => {
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
process.env.GITHUB_TOKEN = "not-a-token";
|
process.env.GITHUB_TOKEN = "not-a-token";
|
||||||
process.env.CODEQL_REGISTRIES_AUTH = "not-a-registries-auth";
|
process.env.CODEQL_REGISTRIES_AUTH = undefined;
|
||||||
const logger = (0, logging_1.getRunnerLogger)(true);
|
const logger = (0, logging_1.getRunnerLogger)(true);
|
||||||
const registriesInput = yaml.dump([
|
const registriesInput = yaml.dump([
|
||||||
{
|
{
|
||||||
|
|
@ -1187,7 +1187,7 @@ const calculateAugmentationErrorMacro = ava_1.default.macro({
|
||||||
]);
|
]);
|
||||||
// Verify that the env vars were unset.
|
// Verify that the env vars were unset.
|
||||||
t.deepEqual(process.env.GITHUB_TOKEN, "not-a-token");
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
(0, ava_1.default)("downloadPacks-with-registries fails on 2.10.3", async (t) => {
|
(0, ava_1.default)("downloadPacks-with-registries fails on 2.10.3", async (t) => {
|
||||||
|
|
@ -1277,6 +1277,26 @@ const calculateAugmentationErrorMacro = ava_1.default.macro({
|
||||||
t.is(qlconfigFile, undefined);
|
t.is(qlconfigFile, undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
(0, ava_1.default)("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 = (0, codeql_1.setCodeQL)({
|
||||||
|
// Accepted CLI versions are 2.10.4 or higher
|
||||||
|
getVersion: () => Promise.resolve(codeql_1.CODEQL_VERSION_GHES_PACK_DOWNLOAD),
|
||||||
|
});
|
||||||
|
const logger = (0, logging_1.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
|
// getLanguages
|
||||||
const mockRepositoryNwo = (0, repository_1.parseRepositoryNwo)("owner/repo");
|
const mockRepositoryNwo = (0, repository_1.parseRepositoryNwo)("owner/repo");
|
||||||
// eslint-disable-next-line github/array-foreach
|
// eslint-disable-next-line github/array-foreach
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -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");
|
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
|
||||||
|
|
||||||
// should not have passed a qlconfig file
|
// should not have passed a qlconfig file
|
||||||
const hasQlconfigArg = args.find((arg: string) =>
|
const hasQlconfigArg = args.some((arg: string) =>
|
||||||
arg.startsWith("--qlconfig=")
|
arg.startsWith("--qlconfig=")
|
||||||
);
|
);
|
||||||
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
||||||
|
|
|
||||||
|
|
@ -2300,7 +2300,7 @@ test("downloadPacks-with-registries", async (t) => {
|
||||||
// associated env vars
|
// associated env vars
|
||||||
return await util.withTmpDir(async (tmpDir) => {
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
process.env.GITHUB_TOKEN = "not-a-token";
|
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 logger = getRunnerLogger(true);
|
||||||
|
|
||||||
const registriesInput = yaml.dump([
|
const registriesInput = yaml.dump([
|
||||||
|
|
@ -2382,7 +2382,7 @@ test("downloadPacks-with-registries", async (t) => {
|
||||||
|
|
||||||
// Verify that the env vars were unset.
|
// Verify that the env vars were unset.
|
||||||
t.deepEqual(process.env.GITHUB_TOKEN, "not-a-token");
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -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
|
// getLanguages
|
||||||
|
|
||||||
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
|
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
|
||||||
|
|
|
||||||
|
|
@ -1993,7 +1993,7 @@ export async function generateRegistries(
|
||||||
return {
|
return {
|
||||||
registriesAuthTokens:
|
registriesAuthTokens:
|
||||||
// if the user has explicitly set the CODEQL_REGISTRIES_AUTH env var then use that
|
// 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,
|
qlconfigFile,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue