call setupActionsVars in the tests too

This commit is contained in:
Robert 2021-03-16 13:43:28 +00:00
parent d698cb3d2b
commit 378f30f95d
10 changed files with 58 additions and 38 deletions

6
lib/codeql.test.js generated
View file

@ -30,6 +30,7 @@ const sampleGHAEApiDetails = {
}; };
ava_1.default("download codeql bundle cache", async (t) => { ava_1.default("download codeql bundle cache", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
const versions = ["20200601", "20200610"]; const versions = ["20200601", "20200610"];
for (let i = 0; i < versions.length; i++) { for (let i = 0; i < versions.length; i++) {
const version = versions[i]; const version = versions[i];
@ -45,6 +46,7 @@ ava_1.default("download codeql bundle cache", async (t) => {
}); });
ava_1.default("download codeql bundle cache explicitly requested with pinned different version cached", async (t) => { ava_1.default("download codeql bundle cache explicitly requested with pinned different version cached", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
nock_1.default("https://example.com") nock_1.default("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`) .get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`)); .replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
@ -59,6 +61,7 @@ ava_1.default("download codeql bundle cache explicitly requested with pinned dif
}); });
ava_1.default("don't download codeql bundle cache with pinned different version cached", async (t) => { ava_1.default("don't download codeql bundle cache with pinned different version cached", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
nock_1.default("https://example.com") nock_1.default("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`) .get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`)); .replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
@ -71,6 +74,7 @@ ava_1.default("don't download codeql bundle cache with pinned different version
}); });
ava_1.default("download codeql bundle cache with different version cached (not pinned)", async (t) => { ava_1.default("download codeql bundle cache with different version cached (not pinned)", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
nock_1.default("https://example.com") nock_1.default("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`) .get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`)); .replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
@ -91,6 +95,7 @@ ava_1.default("download codeql bundle cache with different version cached (not p
}); });
ava_1.default('download codeql bundle cache with pinned different version cached if "latests" tools specified', async (t) => { ava_1.default('download codeql bundle cache with pinned different version cached if "latests" tools specified', async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
nock_1.default("https://example.com") nock_1.default("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`) .get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`)); .replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
@ -111,6 +116,7 @@ ava_1.default('download codeql bundle cache with pinned different version cached
}); });
ava_1.default("download codeql bundle from github ae endpoint", async (t) => { ava_1.default("download codeql bundle from github ae endpoint", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
const bundleAssetID = 10; const bundleAssetID = 10;
const platform = process.platform === "win32" const platform = process.platform === "win32"
? "win64" ? "win64"

File diff suppressed because one or more lines are too long

21
lib/runner.js generated
View file

@ -77,21 +77,6 @@ function parseTraceProcessLevel() {
} }
return undefined; return undefined;
} }
// Sets environment variables that make using some libraries designed for
// use only on actions safe to use outside of actions.
//
// Obviously this is not a tremendously great thing we're doing and it
// would be better to write our own implementation of libraries to use
// outside of actions. For now this works well enough.
//
// Currently this list of libraries that is deemed to now be safe includes:
// - @actions/tool-cache
//
// Also see "queries/unguarded-action-lib.ql".
function setupActionsVars(tempDir, toolsDir) {
process.env["RUNNER_TEMP"] = tempDir;
process.env["RUNNER_TOOL_CACHE"] = toolsDir;
}
program program
.command("init") .command("init")
.description("Initializes CodeQL") .description("Initializes CodeQL")
@ -115,7 +100,7 @@ program
try { try {
const tempDir = getTempDir(cmd.tempDir); const tempDir = getTempDir(cmd.tempDir);
const toolsDir = getToolsDir(cmd.toolsDir); const toolsDir = getToolsDir(cmd.toolsDir);
setupActionsVars(tempDir, toolsDir); util_1.setupActionsVars(tempDir, toolsDir);
// Wipe the temp dir // Wipe the temp dir
logger.info(`Cleaning temp directory ${tempDir}`); logger.info(`Cleaning temp directory ${tempDir}`);
fs.rmdirSync(tempDir, { recursive: true }); fs.rmdirSync(tempDir, { recursive: true });
@ -195,7 +180,7 @@ program
throw new Error("Config file could not be found at expected location. " + throw new Error("Config file could not be found at expected location. " +
"Was the 'init' command run with the same '--temp-dir' argument as this command."); "Was the 'init' command run with the same '--temp-dir' argument as this command.");
} }
setupActionsVars(config.tempDir, config.toolCacheDir); util_1.setupActionsVars(config.tempDir, config.toolCacheDir);
importTracerEnvironment(config); importTracerEnvironment(config);
let language = undefined; let language = undefined;
if (cmd.language !== undefined) { if (cmd.language !== undefined) {
@ -244,7 +229,7 @@ program
throw new Error("Config file could not be found at expected location. " + throw new Error("Config file could not be found at expected location. " +
"Was the 'init' command run with the same '--temp-dir' argument as this command."); "Was the 'init' command run with the same '--temp-dir' argument as this command.");
} }
setupActionsVars(config.tempDir, config.toolCacheDir); util_1.setupActionsVars(config.tempDir, config.toolCacheDir);
const auth = await util_1.getGitHubAuth(logger, cmd.githubAuth, cmd.githubAuthStdin); const auth = await util_1.getGitHubAuth(logger, cmd.githubAuth, cmd.githubAuthStdin);
const apiDetails = { const apiDetails = {
auth, auth,

File diff suppressed because one or more lines are too long

16
lib/util.js generated
View file

@ -320,4 +320,20 @@ async function getGitHubAuth(logger, githubAuth, fromStdIn, readable = process.s
throw new Error("No GitHub authentication token was specified. Please provide a token via the GITHUB_TOKEN environment variable, or by adding the `--github-auth-stdin` flag and passing the token via standard input."); throw new Error("No GitHub authentication token was specified. Please provide a token via the GITHUB_TOKEN environment variable, or by adding the `--github-auth-stdin` flag and passing the token via standard input.");
} }
exports.getGitHubAuth = getGitHubAuth; exports.getGitHubAuth = getGitHubAuth;
// Sets environment variables that make using some libraries designed for
// use only on actions safe to use outside of actions.
//
// Obviously this is not a tremendously great thing we're doing and it
// would be better to write our own implementation of libraries to use
// outside of actions. For now this works well enough.
//
// Currently this list of libraries that is deemed to now be safe includes:
// - @actions/tool-cache
//
// Also see "queries/unguarded-action-lib.ql".
function setupActionsVars(tempDir, toolsDir) {
process.env["RUNNER_TEMP"] = tempDir;
process.env["RUNNER_TOOL_CACHE"] = toolsDir;
}
exports.setupActionsVars = setupActionsVars;
//# sourceMappingURL=util.js.map //# sourceMappingURL=util.js.map

File diff suppressed because one or more lines are too long

View file

@ -65,7 +65,7 @@ class RunnerEntrypoint extends Function {
* Does this runner entry point set the RUNNER_TEMP and * Does this runner entry point set the RUNNER_TEMP and
* RUNNER_TOOL_CACHE env vars which make some actions libraries * RUNNER_TOOL_CACHE env vars which make some actions libraries
* safe to use outside of actions. * safe to use outside of actions.
* See "setupActionsVars" in "runner.ts". * See "setupActionsVars" in "util.ts".
*/ */
predicate setsActionsEnvVars() { predicate setsActionsEnvVars() {
// This is matching code of the following format, where "this" // This is matching code of the following format, where "this"

View file

@ -24,6 +24,8 @@ const sampleGHAEApiDetails = {
test("download codeql bundle cache", async (t) => { test("download codeql bundle cache", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
const versions = ["20200601", "20200610"]; const versions = ["20200601", "20200610"];
for (let i = 0; i < versions.length; i++) { for (let i = 0; i < versions.length; i++) {
@ -56,6 +58,8 @@ test("download codeql bundle cache", async (t) => {
test("download codeql bundle cache explicitly requested with pinned different version cached", async (t) => { test("download codeql bundle cache explicitly requested with pinned different version cached", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
nock("https://example.com") nock("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`) .get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile( .replyWithFile(
@ -96,6 +100,8 @@ test("download codeql bundle cache explicitly requested with pinned different ve
test("don't download codeql bundle cache with pinned different version cached", async (t) => { test("don't download codeql bundle cache with pinned different version cached", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
nock("https://example.com") nock("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`) .get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile( .replyWithFile(
@ -131,6 +137,8 @@ test("don't download codeql bundle cache with pinned different version cached",
test("download codeql bundle cache with different version cached (not pinned)", async (t) => { test("download codeql bundle cache with different version cached (not pinned)", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
nock("https://example.com") nock("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`) .get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile( .replyWithFile(
@ -181,6 +189,8 @@ test("download codeql bundle cache with different version cached (not pinned)",
test('download codeql bundle cache with pinned different version cached if "latests" tools specified', async (t) => { test('download codeql bundle cache with pinned different version cached if "latests" tools specified', async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
nock("https://example.com") nock("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`) .get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile( .replyWithFile(
@ -232,6 +242,8 @@ test('download codeql bundle cache with pinned different version cached if "late
test("download codeql bundle from github ae endpoint", async (t) => { test("download codeql bundle from github ae endpoint", async (t) => {
await util.withTmpDir(async (tmpDir) => { await util.withTmpDir(async (tmpDir) => {
util.setupActionsVars(tmpDir, tmpDir);
const bundleAssetID = 10; const bundleAssetID = 10;
const platform = const platform =

View file

@ -21,6 +21,7 @@ import {
getThreadsFlag, getThreadsFlag,
parseGithubUrl, parseGithubUrl,
getGitHubAuth, getGitHubAuth,
setupActionsVars,
} from "./util"; } from "./util";
const program = new Command(); const program = new Command();
@ -86,22 +87,6 @@ function parseTraceProcessLevel(): number | undefined {
return undefined; return undefined;
} }
// Sets environment variables that make using some libraries designed for
// use only on actions safe to use outside of actions.
//
// Obviously this is not a tremendously great thing we're doing and it
// would be better to write our own implementation of libraries to use
// outside of actions. For now this works well enough.
//
// Currently this list of libraries that is deemed to now be safe includes:
// - @actions/tool-cache
//
// Also see "queries/unguarded-action-lib.ql".
function setupActionsVars(tempDir: string, toolsDir: string) {
process.env["RUNNER_TEMP"] = tempDir;
process.env["RUNNER_TOOL_CACHE"] = toolsDir;
}
interface InitArgs { interface InitArgs {
languages: string | undefined; languages: string | undefined;
queries: string | undefined; queries: string | undefined;

View file

@ -390,3 +390,19 @@ export async function getGitHubAuth(
"No GitHub authentication token was specified. Please provide a token via the GITHUB_TOKEN environment variable, or by adding the `--github-auth-stdin` flag and passing the token via standard input." "No GitHub authentication token was specified. Please provide a token via the GITHUB_TOKEN environment variable, or by adding the `--github-auth-stdin` flag and passing the token via standard input."
); );
} }
// Sets environment variables that make using some libraries designed for
// use only on actions safe to use outside of actions.
//
// Obviously this is not a tremendously great thing we're doing and it
// would be better to write our own implementation of libraries to use
// outside of actions. For now this works well enough.
//
// Currently this list of libraries that is deemed to now be safe includes:
// - @actions/tool-cache
//
// Also see "queries/unguarded-action-lib.ql".
export function setupActionsVars(tempDir: string, toolsDir: string) {
process.env["RUNNER_TEMP"] = tempDir;
process.env["RUNNER_TOOL_CACHE"] = toolsDir;
}