Add regression test for a bundle URL without a tag

This commit is contained in:
Henry Mercer
2023-02-03 19:11:40 +00:00
parent b95df0b2e7
commit e0fc1c91b2
3 changed files with 112 additions and 92 deletions

78
lib/codeql.test.js generated
View File

@@ -327,43 +327,51 @@ for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
t.is(cachedVersions.length, 2); t.is(cachedVersions.length, 2);
}); });
}); });
(0, ava_1.default)("download codeql bundle from github ae endpoint", async (t) => { for (const isBundleVersionInUrl of [true, false]) {
await util.withTmpDir(async (tmpDir) => { const inclusionString = isBundleVersionInUrl
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir); ? "includes"
const bundleAssetID = 10; : "does not include";
const platform = process.platform === "win32" (0, ava_1.default)(`download codeql bundle from github ae endpoint (URL ${inclusionString} bundle version)`, async (t) => {
? "win64" await util.withTmpDir(async (tmpDir) => {
: process.platform === "linux" (0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
? "linux64" const bundleAssetID = 10;
: "osx64"; const platform = process.platform === "win32"
const codeQLBundleName = `codeql-bundle-${platform}.tar.gz`; ? "win64"
(0, nock_1.default)("https://example.githubenterprise.com") : process.platform === "linux"
.get(`/api/v3/enterprise/code-scanning/codeql-bundle/find/${defaults.bundleVersion}`) ? "linux64"
.reply(200, { : "osx64";
assets: { [codeQLBundleName]: bundleAssetID }, const codeQLBundleName = `codeql-bundle-${platform}.tar.gz`;
const eventualDownloadUrl = isBundleVersionInUrl
? `https://example.githubenterprise.com/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`
: `https://example.githubenterprise.com/api/v3/repos/github/codeql-action/releases/assets/${bundleAssetID}`;
(0, nock_1.default)("https://example.githubenterprise.com")
.get(`/api/v3/enterprise/code-scanning/codeql-bundle/find/${defaults.bundleVersion}`)
.reply(200, {
assets: { [codeQLBundleName]: bundleAssetID },
});
(0, nock_1.default)("https://example.githubenterprise.com")
.get(`/api/v3/enterprise/code-scanning/codeql-bundle/download/${bundleAssetID}`)
.reply(200, {
url: eventualDownloadUrl,
});
(0, nock_1.default)("https://example.githubenterprise.com")
.get(eventualDownloadUrl.replace("https://example.githubenterprise.com", ""))
.replyWithFile(200, path_1.default.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
mockApiDetails(sampleGHAEApiDetails);
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
process.env["GITHUB_ACTION_REPOSITORY"] = "github/codeql-action";
const result = await codeql.setupCodeQL(undefined, sampleGHAEApiDetails, tmpDir, util.GitHubVariant.GHAE, false, {
cliVersion: defaults.cliVersion,
tagName: defaults.bundleVersion,
variant: util.GitHubVariant.GHAE,
}, (0, logging_1.getRunnerLogger)(true), false);
t.is(result.toolsSource, init_1.ToolsSource.Download);
t.assert(Number.isInteger(result.toolsDownloadDurationMs));
const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 1);
}); });
(0, nock_1.default)("https://example.githubenterprise.com")
.get(`/api/v3/enterprise/code-scanning/codeql-bundle/download/${bundleAssetID}`)
.reply(200, {
url: `https://example.githubenterprise.com/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`,
});
(0, nock_1.default)("https://example.githubenterprise.com")
.get(`/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`)
.replyWithFile(200, path_1.default.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
mockApiDetails(sampleGHAEApiDetails);
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
process.env["GITHUB_ACTION_REPOSITORY"] = "github/codeql-action";
const result = await codeql.setupCodeQL(undefined, sampleGHAEApiDetails, tmpDir, util.GitHubVariant.GHAE, false, {
cliVersion: defaults.cliVersion,
tagName: defaults.bundleVersion,
variant: util.GitHubVariant.GHAE,
}, (0, logging_1.getRunnerLogger)(true), false);
t.is(result.toolsSource, init_1.ToolsSource.Download);
t.assert(Number.isInteger(result.toolsDownloadDurationMs));
const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 1);
}); });
}); }
(0, ava_1.default)("getExtraOptions works for explicit paths", (t) => { (0, ava_1.default)("getExtraOptions works for explicit paths", (t) => {
t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []); t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []);
t.deepEqual(codeql.getExtraOptions({ foo: [42] }, ["foo"], []), ["42"]); t.deepEqual(codeql.getExtraOptions({ foo: [42] }, ["foo"], []), ["42"]);

File diff suppressed because one or more lines are too long

View File

@@ -468,71 +468,83 @@ test('downloads bundle if "latest" tools specified but not cached', async (t) =>
}); });
}); });
test("download codeql bundle from github ae endpoint", async (t) => { for (const isBundleVersionInUrl of [true, false]) {
await util.withTmpDir(async (tmpDir) => { const inclusionString = isBundleVersionInUrl
setupActionsVars(tmpDir, tmpDir); ? "includes"
: "does not include";
test(`download codeql bundle from github ae endpoint (URL ${inclusionString} bundle version)`, async (t) => {
await util.withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
const bundleAssetID = 10; const bundleAssetID = 10;
const platform = const platform =
process.platform === "win32" process.platform === "win32"
? "win64" ? "win64"
: process.platform === "linux" : process.platform === "linux"
? "linux64" ? "linux64"
: "osx64"; : "osx64";
const codeQLBundleName = `codeql-bundle-${platform}.tar.gz`; const codeQLBundleName = `codeql-bundle-${platform}.tar.gz`;
nock("https://example.githubenterprise.com") const eventualDownloadUrl = isBundleVersionInUrl
.get( ? `https://example.githubenterprise.com/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`
`/api/v3/enterprise/code-scanning/codeql-bundle/find/${defaults.bundleVersion}` : `https://example.githubenterprise.com/api/v3/repos/github/codeql-action/releases/assets/${bundleAssetID}`;
)
.reply(200, {
assets: { [codeQLBundleName]: bundleAssetID },
});
nock("https://example.githubenterprise.com") nock("https://example.githubenterprise.com")
.get( .get(
`/api/v3/enterprise/code-scanning/codeql-bundle/download/${bundleAssetID}` `/api/v3/enterprise/code-scanning/codeql-bundle/find/${defaults.bundleVersion}`
) )
.reply(200, { .reply(200, {
url: `https://example.githubenterprise.com/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`, assets: { [codeQLBundleName]: bundleAssetID },
}); });
nock("https://example.githubenterprise.com") nock("https://example.githubenterprise.com")
.get( .get(
`/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}` `/api/v3/enterprise/code-scanning/codeql-bundle/download/${bundleAssetID}`
) )
.replyWithFile( .reply(200, {
200, url: eventualDownloadUrl,
path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`) });
nock("https://example.githubenterprise.com")
.get(
eventualDownloadUrl.replace(
"https://example.githubenterprise.com",
""
)
)
.replyWithFile(
200,
path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`)
);
mockApiDetails(sampleGHAEApiDetails);
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
process.env["GITHUB_ACTION_REPOSITORY"] = "github/codeql-action";
const result = await codeql.setupCodeQL(
undefined,
sampleGHAEApiDetails,
tmpDir,
util.GitHubVariant.GHAE,
false,
{
cliVersion: defaults.cliVersion,
tagName: defaults.bundleVersion,
variant: util.GitHubVariant.GHAE,
},
getRunnerLogger(true),
false
); );
mockApiDetails(sampleGHAEApiDetails); t.is(result.toolsSource, ToolsSource.Download);
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false); t.assert(Number.isInteger(result.toolsDownloadDurationMs));
process.env["GITHUB_ACTION_REPOSITORY"] = "github/codeql-action";
const result = await codeql.setupCodeQL( const cachedVersions = toolcache.findAllVersions("CodeQL");
undefined, t.is(cachedVersions.length, 1);
sampleGHAEApiDetails, });
tmpDir,
util.GitHubVariant.GHAE,
false,
{
cliVersion: defaults.cliVersion,
tagName: defaults.bundleVersion,
variant: util.GitHubVariant.GHAE,
},
getRunnerLogger(true),
false
);
t.is(result.toolsSource, ToolsSource.Download);
t.assert(Number.isInteger(result.toolsDownloadDurationMs));
const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 1);
}); });
}); }
test("getExtraOptions works for explicit paths", (t) => { test("getExtraOptions works for explicit paths", (t) => {
t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []); t.deepEqual(codeql.getExtraOptions({}, ["foo"], []), []);