add CodeQL cmd to config

This commit is contained in:
Robert Brignull 2020-08-19 15:54:23 +01:00
parent 360e77a083
commit 038c4ebdf7
21 changed files with 187 additions and 138 deletions

View file

@ -16,7 +16,7 @@ const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const sinon_1 = __importDefault(require("sinon"));
const api = __importStar(require("./api-client"));
const CodeQL = __importStar(require("./codeql"));
const codeql_1 = require("./codeql");
const configUtils = __importStar(require("./config-utils"));
const testing_utils_1 = require("./testing-utils");
const util = __importStar(require("./util"));
@ -60,7 +60,7 @@ ava_1.default("load empty config", async (t) => {
process.env['GITHUB_WORKSPACE'] = tmpDir;
setInput('config-file', undefined);
setInput('languages', 'javascript,python');
CodeQL.setCodeQL({
const codeQL = codeql_1.setCodeQL({
resolveQueries: async function () {
return {
byLanguage: {},
@ -69,8 +69,8 @@ ava_1.default("load empty config", async (t) => {
};
},
});
const config = await configUtils.initConfig(tmpDir, tmpDir);
t.deepEqual(config, await configUtils.getDefaultConfig(tmpDir, tmpDir));
const config = await configUtils.initConfig(tmpDir, tmpDir, codeQL);
t.deepEqual(config, await configUtils.getDefaultConfig(tmpDir, tmpDir, codeQL));
});
});
ava_1.default("loading config saves config", async (t) => {
@ -79,7 +79,7 @@ ava_1.default("loading config saves config", async (t) => {
process.env['GITHUB_WORKSPACE'] = tmpDir;
setInput('config-file', undefined);
setInput('languages', 'javascript,python');
CodeQL.setCodeQL({
const codeQL = codeql_1.setCodeQL({
resolveQueries: async function () {
return {
byLanguage: {},
@ -92,7 +92,7 @@ ava_1.default("loading config saves config", async (t) => {
t.false(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir)));
// Sanity check that getConfig throws before we have called initConfig
await t.throwsAsync(() => configUtils.getConfig(tmpDir));
const config1 = await configUtils.initConfig(tmpDir, tmpDir);
const config1 = await configUtils.initConfig(tmpDir, tmpDir, codeQL);
// The saved config file should now exist
t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir)));
// And that same newly-initialised config should now be returned by getConfig
@ -106,7 +106,7 @@ ava_1.default("load input outside of workspace", async (t) => {
process.env['GITHUB_WORKSPACE'] = tmpDir;
setInput('config-file', '../input');
try {
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
throw new Error('initConfig did not throw error');
}
catch (err) {
@ -121,7 +121,7 @@ ava_1.default("load non-local input with invalid repo syntax", async (t) => {
// no filename given, just a repo
setInput('config-file', 'octo-org/codeql-config@main');
try {
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
throw new Error('initConfig did not throw error');
}
catch (err) {
@ -137,7 +137,7 @@ ava_1.default("load non-existent input", async (t) => {
setInput('config-file', 'input');
setInput('languages', 'javascript');
try {
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
throw new Error('initConfig did not throw error');
}
catch (err) {
@ -149,7 +149,7 @@ ava_1.default("load non-empty input", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;
CodeQL.setCodeQL({
const codeQL = codeql_1.setCodeQL({
resolveQueries: async function () {
return {
byLanguage: {
@ -190,11 +190,12 @@ ava_1.default("load non-empty input", async (t) => {
},
tempDir: tmpDir,
toolCacheDir: tmpDir,
codeQLCmd: codeQL.getPath(),
};
fs.writeFileSync(path.join(tmpDir, 'input'), inputFileContents, 'utf8');
setInput('config-file', 'input');
setInput('languages', 'javascript');
const actualConfig = await configUtils.initConfig(tmpDir, tmpDir);
const actualConfig = await configUtils.initConfig(tmpDir, tmpDir, codeQL);
// Should exactly equal the object we constructed earlier
t.deepEqual(actualConfig, expectedConfig);
});
@ -209,7 +210,7 @@ ava_1.default("default queries are used", async (t) => {
// We determine this by whether CodeQL.resolveQueries is called
// with the correct arguments.
const resolveQueriesArgs = [];
CodeQL.setCodeQL({
const codeQL = codeql_1.setCodeQL({
resolveQueries: async function (queries, extraSearchPath) {
resolveQueriesArgs.push({ queries, extraSearchPath });
return {
@ -233,7 +234,7 @@ ava_1.default("default queries are used", async (t) => {
fs.writeFileSync(path.join(tmpDir, 'input'), inputFileContents, 'utf8');
setInput('config-file', 'input');
setInput('languages', 'javascript');
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeQL);
// Check resolve queries was called correctly
t.deepEqual(resolveQueriesArgs.length, 1);
t.deepEqual(resolveQueriesArgs[0].queries, ['javascript-code-scanning.qls']);
@ -244,7 +245,7 @@ ava_1.default("API client used when reading remote config", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;
CodeQL.setCodeQL({
const codeQL = codeql_1.setCodeQL({
resolveQueries: async function () {
return {
byLanguage: {
@ -277,7 +278,7 @@ ava_1.default("API client used when reading remote config", async (t) => {
fs.mkdirSync(path.join(tmpDir, 'foo/bar'), { recursive: true });
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
setInput('languages', 'javascript');
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeQL);
t.assert(spyGetContents.called);
});
});
@ -290,7 +291,7 @@ ava_1.default("Remote config handles the case where a directory is provided", as
const repoReference = 'octo-org/codeql-config/config.yaml@main';
setInput('config-file', repoReference);
try {
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
throw new Error('initConfig did not throw error');
}
catch (err) {
@ -309,7 +310,7 @@ ava_1.default("Invalid format of remote config handled correctly", async (t) =>
const repoReference = 'octo-org/codeql-config/config.yaml@main';
setInput('config-file', repoReference);
try {
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
throw new Error('initConfig did not throw error');
}
catch (err) {
@ -323,7 +324,7 @@ ava_1.default("No detected languages", async (t) => {
process.env['GITHUB_WORKSPACE'] = tmpDir;
mockListLanguages([]);
try {
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
throw new Error('initConfig did not throw error');
}
catch (err) {
@ -337,7 +338,7 @@ ava_1.default("Unknown languages", async (t) => {
process.env['GITHUB_WORKSPACE'] = tmpDir;
setInput('languages', 'ruby,english');
try {
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
throw new Error('initConfig did not throw error');
}
catch (err) {
@ -350,7 +351,7 @@ function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGen
return await util.withTmpDir(async (tmpDir) => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;
CodeQL.setCodeQL({
const codeQL = codeql_1.setCodeQL({
resolveQueries: async function () {
return {
byLanguage: {},
@ -364,7 +365,7 @@ function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGen
setInput('config-file', 'input');
setInput('languages', 'javascript');
try {
await configUtils.initConfig(tmpDir, tmpDir);
await configUtils.initConfig(tmpDir, tmpDir, codeQL);
throw new Error('initConfig did not throw error');
}
catch (err) {