2020-09-10 20:02:33 +03:00
|
|
|
"use strict";
|
2021-07-27 19:59:59 +03:00
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
if (k2 === undefined) k2 = k;
|
2023-01-18 23:00:33 +03:00
|
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
|
|
}
|
|
|
|
Object.defineProperty(o, k2, desc);
|
2021-07-27 19:59:59 +03:00
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
o[k2] = m[k];
|
|
|
|
}));
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
}) : function(o, v) {
|
|
|
|
o["default"] = v;
|
|
|
|
});
|
2020-09-10 20:02:33 +03:00
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
var result = {};
|
2021-07-27 19:59:59 +03:00
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
__setModuleDefault(result, mod);
|
2020-09-10 20:02:33 +03:00
|
|
|
return result;
|
|
|
|
};
|
2020-09-29 16:43:37 +03:00
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
};
|
2020-09-10 20:02:33 +03:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
const fs = __importStar(require("fs"));
|
2021-04-17 00:52:39 +03:00
|
|
|
const path = __importStar(require("path"));
|
2020-09-29 16:43:37 +03:00
|
|
|
const ava_1 = __importDefault(require("ava"));
|
2021-06-03 19:32:44 +03:00
|
|
|
const yaml = __importStar(require("js-yaml"));
|
2023-02-17 22:19:38 +03:00
|
|
|
const sinon = __importStar(require("sinon"));
|
2020-09-29 16:43:37 +03:00
|
|
|
const analyze_1 = require("./analyze");
|
|
|
|
const codeql_1 = require("./codeql");
|
2023-02-17 22:19:38 +03:00
|
|
|
const feature_flags_1 = require("./feature-flags");
|
2020-10-01 13:03:30 +03:00
|
|
|
const languages_1 = require("./languages");
|
|
|
|
const logging_1 = require("./logging");
|
2020-09-10 20:02:33 +03:00
|
|
|
const testing_utils_1 = require("./testing-utils");
|
2020-10-01 13:03:30 +03:00
|
|
|
const util = __importStar(require("./util"));
|
2021-09-10 23:53:13 +03:00
|
|
|
(0, testing_utils_1.setupTests)(ava_1.default);
|
2020-09-10 20:02:33 +03:00
|
|
|
// Checks that the duration fields are populated for the correct language
|
2021-04-01 14:38:13 +03:00
|
|
|
// and correct case of builtin or custom. Also checks the correct search
|
|
|
|
// paths are set in the database analyze invocation.
|
2021-09-10 23:53:13 +03:00
|
|
|
(0, ava_1.default)("status report fields and search path setting", async (t) => {
|
2021-04-01 14:38:13 +03:00
|
|
|
let searchPathsUsed = [];
|
2020-09-10 20:02:33 +03:00
|
|
|
return await util.withTmpDir(async (tmpDir) => {
|
2021-09-10 23:53:13 +03:00
|
|
|
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
2020-09-18 11:52:44 +03:00
|
|
|
const memoryFlag = "";
|
|
|
|
const addSnippetsFlag = "";
|
|
|
|
const threadsFlag = "";
|
2021-06-03 19:32:44 +03:00
|
|
|
const packs = {
|
2022-04-27 05:47:59 +03:00
|
|
|
[languages_1.Language.cpp]: ["a/b@1.0.0"],
|
|
|
|
[languages_1.Language.java]: ["c/d@2.0.0"],
|
2021-06-03 19:32:44 +03:00
|
|
|
};
|
2020-09-10 20:02:33 +03:00
|
|
|
for (const language of Object.values(languages_1.Language)) {
|
2021-09-10 23:53:13 +03:00
|
|
|
(0, codeql_1.setCodeQL)({
|
2021-06-08 02:05:32 +03:00
|
|
|
packDownload: async () => ({ packs: [] }),
|
2021-06-04 16:28:55 +03:00
|
|
|
databaseRunQueries: async (_db, searchPath) => {
|
|
|
|
searchPathsUsed.push(searchPath);
|
|
|
|
},
|
|
|
|
databaseInterpretResults: async (_db, _queriesRun, sarifFile) => {
|
2021-04-17 00:52:39 +03:00
|
|
|
fs.writeFileSync(sarifFile, JSON.stringify({
|
|
|
|
runs: [
|
2021-08-26 15:46:22 +03:00
|
|
|
// references a rule with the lines-of-code tag, so baseline should be injected
|
2021-07-21 12:27:42 +03:00
|
|
|
{
|
|
|
|
tool: {
|
|
|
|
extensions: [
|
|
|
|
{
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
properties: {
|
|
|
|
tags: ["lines-of-code"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
properties: {
|
|
|
|
metricResults: [
|
|
|
|
{
|
|
|
|
rule: {
|
|
|
|
index: 0,
|
|
|
|
toolComponent: {
|
|
|
|
index: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
value: 123,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2021-04-17 00:52:39 +03:00
|
|
|
{},
|
|
|
|
],
|
|
|
|
}));
|
2021-05-20 02:01:06 +03:00
|
|
|
return "";
|
2021-04-17 00:52:39 +03:00
|
|
|
},
|
2022-11-11 21:08:17 +03:00
|
|
|
databasePrintBaseline: async () => "",
|
2021-04-17 00:52:39 +03:00
|
|
|
});
|
2021-04-01 14:38:13 +03:00
|
|
|
searchPathsUsed = [];
|
2020-09-10 20:02:33 +03:00
|
|
|
const config = {
|
|
|
|
languages: [language],
|
|
|
|
queries: {},
|
|
|
|
pathsIgnore: [],
|
|
|
|
paths: [],
|
|
|
|
originalUserInput: {},
|
|
|
|
tempDir: tmpDir,
|
2020-09-18 11:52:44 +03:00
|
|
|
codeQLCmd: "",
|
2021-02-15 12:29:10 +03:00
|
|
|
gitHubVersion: {
|
|
|
|
type: util.GitHubVariant.DOTCOM,
|
|
|
|
},
|
2021-05-17 12:35:09 +03:00
|
|
|
dbLocation: path.resolve(tmpDir, "codeql_databases"),
|
2021-06-03 19:32:44 +03:00
|
|
|
packs,
|
2021-10-28 16:15:22 +03:00
|
|
|
debugMode: false,
|
2022-01-07 16:11:51 +03:00
|
|
|
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
|
|
|
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
2022-06-20 02:44:24 +03:00
|
|
|
augmentationProperties: {
|
|
|
|
injectedMlQueries: false,
|
|
|
|
packsInputCombines: false,
|
|
|
|
queriesInputCombines: false,
|
|
|
|
},
|
2022-08-02 19:52:22 +03:00
|
|
|
trapCaches: {},
|
2022-08-15 16:44:43 +03:00
|
|
|
trapCacheDownloadTime: 0,
|
2020-09-10 20:02:33 +03:00
|
|
|
};
|
2021-05-17 12:35:09 +03:00
|
|
|
fs.mkdirSync(util.getCodeQLDatabasePath(config, language), {
|
2020-09-18 11:52:44 +03:00
|
|
|
recursive: true,
|
|
|
|
});
|
2020-09-10 20:02:33 +03:00
|
|
|
config.queries[language] = {
|
2020-09-18 11:52:44 +03:00
|
|
|
builtin: ["foo.ql"],
|
2020-09-10 20:02:33 +03:00
|
|
|
custom: [],
|
|
|
|
};
|
2022-10-11 20:39:40 +03:00
|
|
|
const builtinStatusReport = await (0, analyze_1.runQueries)(tmpDir, memoryFlag, addSnippetsFlag, threadsFlag, undefined, config, (0, logging_1.getRunnerLogger)(true), (0, testing_utils_1.createFeatures)([]));
|
2021-06-03 19:32:44 +03:00
|
|
|
const hasPacks = language in packs;
|
2021-06-09 23:19:49 +03:00
|
|
|
const statusReportKeys = Object.keys(builtinStatusReport).sort();
|
|
|
|
if (hasPacks) {
|
|
|
|
t.deepEqual(statusReportKeys.length, 3, statusReportKeys.toString());
|
|
|
|
t.deepEqual(statusReportKeys[0], `analyze_builtin_queries_${language}_duration_ms`);
|
|
|
|
t.deepEqual(statusReportKeys[1], `analyze_custom_queries_${language}_duration_ms`);
|
|
|
|
t.deepEqual(statusReportKeys[2], `interpret_results_${language}_duration_ms`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
t.deepEqual(statusReportKeys[0], `analyze_builtin_queries_${language}_duration_ms`);
|
|
|
|
t.deepEqual(statusReportKeys[1], `interpret_results_${language}_duration_ms`);
|
|
|
|
}
|
2020-09-10 20:02:33 +03:00
|
|
|
config.queries[language] = {
|
|
|
|
builtin: [],
|
2021-04-01 14:38:13 +03:00
|
|
|
custom: [
|
|
|
|
{
|
|
|
|
queries: ["foo.ql"],
|
|
|
|
searchPath: "/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
queries: ["bar.ql"],
|
|
|
|
searchPath: "/2",
|
|
|
|
},
|
|
|
|
],
|
2020-09-10 20:02:33 +03:00
|
|
|
};
|
2022-10-11 20:39:40 +03:00
|
|
|
const customStatusReport = await (0, analyze_1.runQueries)(tmpDir, memoryFlag, addSnippetsFlag, threadsFlag, undefined, config, (0, logging_1.getRunnerLogger)(true), (0, testing_utils_1.createFeatures)([]));
|
2021-06-04 16:28:55 +03:00
|
|
|
t.deepEqual(Object.keys(customStatusReport).length, 2);
|
2020-09-10 20:02:33 +03:00
|
|
|
t.true(`analyze_custom_queries_${language}_duration_ms` in customStatusReport);
|
2021-06-03 19:32:44 +03:00
|
|
|
const expectedSearchPathsUsed = hasPacks
|
|
|
|
? [undefined, undefined, "/1", "/2", undefined]
|
|
|
|
: [undefined, "/1", "/2"];
|
|
|
|
t.deepEqual(searchPathsUsed, expectedSearchPathsUsed);
|
2021-06-04 16:28:55 +03:00
|
|
|
t.true(`interpret_results_${language}_duration_ms` in customStatusReport);
|
2020-09-10 20:02:33 +03:00
|
|
|
}
|
2021-06-03 19:32:44 +03:00
|
|
|
verifyQuerySuites(tmpDir);
|
2020-09-10 20:02:33 +03:00
|
|
|
});
|
2021-06-03 19:32:44 +03:00
|
|
|
function verifyQuerySuites(tmpDir) {
|
|
|
|
const qlsContent = [
|
|
|
|
{
|
|
|
|
query: "foo.ql",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const qlsContent2 = [
|
|
|
|
{
|
|
|
|
query: "bar.ql",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
for (const lang of Object.values(languages_1.Language)) {
|
|
|
|
t.deepEqual(readContents(`${lang}-queries-builtin.qls`), qlsContent);
|
|
|
|
t.deepEqual(readContents(`${lang}-queries-custom-0.qls`), qlsContent);
|
|
|
|
t.deepEqual(readContents(`${lang}-queries-custom-1.qls`), qlsContent2);
|
|
|
|
}
|
|
|
|
function readContents(name) {
|
|
|
|
const x = fs.readFileSync(path.join(tmpDir, "codeql_databases", name), "utf8");
|
|
|
|
console.log(x);
|
2021-07-28 00:12:26 +03:00
|
|
|
return yaml.load(fs.readFileSync(path.join(tmpDir, "codeql_databases", name), "utf8"));
|
2021-06-03 19:32:44 +03:00
|
|
|
}
|
|
|
|
}
|
2020-09-10 20:02:33 +03:00
|
|
|
});
|
2023-02-17 22:19:38 +03:00
|
|
|
function mockCodeQL() {
|
|
|
|
return {
|
|
|
|
getVersion: async () => "2.12.2",
|
|
|
|
databaseRunQueries: sinon.spy(),
|
|
|
|
databaseInterpretResults: async () => "",
|
|
|
|
databasePrintBaseline: async () => "",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function createBaseConfig(tmpDir) {
|
|
|
|
return {
|
|
|
|
languages: [],
|
|
|
|
queries: {},
|
|
|
|
pathsIgnore: [],
|
|
|
|
paths: [],
|
|
|
|
originalUserInput: {},
|
|
|
|
tempDir: "tempDir",
|
|
|
|
codeQLCmd: "",
|
|
|
|
gitHubVersion: {
|
|
|
|
type: util.GitHubVariant.DOTCOM,
|
|
|
|
},
|
|
|
|
dbLocation: path.resolve(tmpDir, "codeql_databases"),
|
|
|
|
packs: {},
|
|
|
|
debugMode: false,
|
|
|
|
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
|
|
|
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
|
|
|
augmentationProperties: {
|
|
|
|
injectedMlQueries: false,
|
|
|
|
packsInputCombines: false,
|
|
|
|
queriesInputCombines: false,
|
|
|
|
},
|
|
|
|
trapCaches: {},
|
|
|
|
trapCacheDownloadTime: 0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function createQueryConfig(builtin, custom) {
|
|
|
|
return {
|
|
|
|
builtin,
|
|
|
|
custom: custom.map((c) => ({ searchPath: "/search", queries: [c] })),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
async function runQueriesWithConfig(config, features) {
|
|
|
|
for (const language of config.languages) {
|
|
|
|
fs.mkdirSync(util.getCodeQLDatabasePath(config, language), {
|
|
|
|
recursive: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return (0, analyze_1.runQueries)("sarif-folder", "--memFlag", "--addSnippetsFlag", "--threadsFlag", undefined, config, (0, logging_1.getRunnerLogger)(true), (0, testing_utils_1.createFeatures)(features));
|
|
|
|
}
|
|
|
|
function getDatabaseRunQueriesCalls(mock) {
|
|
|
|
return mock.databaseRunQueries.getCalls();
|
|
|
|
}
|
|
|
|
(0, ava_1.default)("optimizeForLastQueryRun for one language", async (t) => {
|
|
|
|
return await util.withTmpDir(async (tmpDir) => {
|
|
|
|
const codeql = mockCodeQL();
|
|
|
|
(0, codeql_1.setCodeQL)(codeql);
|
|
|
|
const config = createBaseConfig(tmpDir);
|
|
|
|
config.languages = [languages_1.Language.cpp];
|
|
|
|
config.queries.cpp = createQueryConfig(["foo.ql"], []);
|
|
|
|
await runQueriesWithConfig(config, []);
|
|
|
|
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [true]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
(0, ava_1.default)("optimizeForLastQueryRun for two languages", async (t) => {
|
|
|
|
return await util.withTmpDir(async (tmpDir) => {
|
|
|
|
const codeql = mockCodeQL();
|
|
|
|
(0, codeql_1.setCodeQL)(codeql);
|
|
|
|
const config = createBaseConfig(tmpDir);
|
|
|
|
config.languages = [languages_1.Language.cpp, languages_1.Language.java];
|
|
|
|
config.queries.cpp = createQueryConfig(["foo.ql"], []);
|
|
|
|
config.queries.java = createQueryConfig(["bar.ql"], []);
|
|
|
|
await runQueriesWithConfig(config, []);
|
|
|
|
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [true, true]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
(0, ava_1.default)("optimizeForLastQueryRun for two languages, with custom queries", async (t) => {
|
|
|
|
return await util.withTmpDir(async (tmpDir) => {
|
|
|
|
const codeql = mockCodeQL();
|
|
|
|
(0, codeql_1.setCodeQL)(codeql);
|
|
|
|
const config = createBaseConfig(tmpDir);
|
|
|
|
config.languages = [languages_1.Language.cpp, languages_1.Language.java];
|
|
|
|
config.queries.cpp = createQueryConfig(["foo.ql"], ["c1.ql", "c2.ql"]);
|
|
|
|
config.queries.java = createQueryConfig(["bar.ql"], ["c3.ql"]);
|
|
|
|
await runQueriesWithConfig(config, []);
|
|
|
|
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [false, false, true, false, true]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
(0, ava_1.default)("optimizeForLastQueryRun for two languages, with custom queries and packs", async (t) => {
|
|
|
|
return await util.withTmpDir(async (tmpDir) => {
|
|
|
|
const codeql = mockCodeQL();
|
|
|
|
(0, codeql_1.setCodeQL)(codeql);
|
|
|
|
const config = createBaseConfig(tmpDir);
|
|
|
|
config.languages = [languages_1.Language.cpp, languages_1.Language.java];
|
|
|
|
config.queries.cpp = createQueryConfig(["foo.ql"], ["c1.ql", "c2.ql"]);
|
|
|
|
config.queries.java = createQueryConfig(["bar.ql"], ["c3.ql"]);
|
|
|
|
config.packs.cpp = ["a/cpp-pack1@0.1.0"];
|
|
|
|
config.packs.java = ["b/java-pack1@0.2.0", "b/java-pack2@0.3.3"];
|
|
|
|
await runQueriesWithConfig(config, []);
|
|
|
|
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [false, false, false, true, false, false, true]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
(0, ava_1.default)("optimizeForLastQueryRun for one language, CliConfigFileEnabled", async (t) => {
|
|
|
|
return await util.withTmpDir(async (tmpDir) => {
|
|
|
|
const codeql = mockCodeQL();
|
|
|
|
(0, codeql_1.setCodeQL)(codeql);
|
|
|
|
const config = createBaseConfig(tmpDir);
|
|
|
|
config.languages = [languages_1.Language.cpp];
|
|
|
|
await runQueriesWithConfig(config, [feature_flags_1.Feature.CliConfigFileEnabled]);
|
|
|
|
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [true]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
(0, ava_1.default)("optimizeForLastQueryRun for two languages, CliConfigFileEnabled", async (t) => {
|
|
|
|
return await util.withTmpDir(async (tmpDir) => {
|
|
|
|
const codeql = mockCodeQL();
|
|
|
|
(0, codeql_1.setCodeQL)(codeql);
|
|
|
|
const config = createBaseConfig(tmpDir);
|
|
|
|
config.languages = [languages_1.Language.cpp, languages_1.Language.java];
|
|
|
|
await runQueriesWithConfig(config, [feature_flags_1.Feature.CliConfigFileEnabled]);
|
|
|
|
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [true, true]);
|
|
|
|
});
|
|
|
|
});
|
2022-06-27 23:13:55 +03:00
|
|
|
(0, ava_1.default)("validateQueryFilters", (t) => {
|
|
|
|
t.notThrows(() => (0, analyze_1.validateQueryFilters)([]));
|
|
|
|
t.notThrows(() => (0, analyze_1.validateQueryFilters)(undefined));
|
|
|
|
t.notThrows(() => {
|
|
|
|
return (0, analyze_1.validateQueryFilters)([
|
|
|
|
{
|
|
|
|
exclude: {
|
|
|
|
"problem.severity": "recommendation",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
exclude: {
|
|
|
|
"tags contain": ["foo", "bar"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
include: {
|
|
|
|
"problem.severity": "something-to-think-about",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
include: {
|
|
|
|
"tags contain": ["baz", "bop"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
t.throws(() => {
|
|
|
|
return (0, analyze_1.validateQueryFilters)([
|
|
|
|
{
|
|
|
|
exclude: {
|
|
|
|
"tags contain": ["foo", "bar"],
|
|
|
|
},
|
|
|
|
include: {
|
|
|
|
"tags contain": ["baz", "bop"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
}, { message: /Query filter must have exactly one key/ });
|
|
|
|
t.throws(() => {
|
|
|
|
return (0, analyze_1.validateQueryFilters)([{ xxx: "foo" }]);
|
|
|
|
}, { message: /Only "include" or "exclude" filters are allowed/ });
|
2022-08-23 19:25:59 +03:00
|
|
|
t.throws(() => {
|
2023-01-18 23:22:33 +03:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
2022-08-23 19:25:59 +03:00
|
|
|
return (0, analyze_1.validateQueryFilters)({ exclude: "foo" });
|
|
|
|
}, {
|
|
|
|
message: /Query filters must be an array of "include" or "exclude" entries/,
|
|
|
|
});
|
2022-06-27 23:13:55 +03:00
|
|
|
});
|
|
|
|
const convertPackToQuerySuiteEntryMacro = ava_1.default.macro({
|
|
|
|
exec: (t, packSpec, suiteEntry) => t.deepEqual((0, analyze_1.convertPackToQuerySuiteEntry)(packSpec), suiteEntry),
|
|
|
|
title: (_providedTitle, packSpec) => `Query Suite Entry: ${packSpec}`,
|
|
|
|
});
|
|
|
|
(0, ava_1.default)(convertPackToQuerySuiteEntryMacro, "a/b", {
|
|
|
|
qlpack: "a/b",
|
|
|
|
from: undefined,
|
|
|
|
version: undefined,
|
|
|
|
query: undefined,
|
|
|
|
queries: undefined,
|
|
|
|
apply: undefined,
|
|
|
|
});
|
|
|
|
(0, ava_1.default)(convertPackToQuerySuiteEntryMacro, "a/b@~1.2.3", {
|
|
|
|
qlpack: "a/b",
|
|
|
|
from: undefined,
|
|
|
|
version: "~1.2.3",
|
|
|
|
query: undefined,
|
|
|
|
queries: undefined,
|
|
|
|
apply: undefined,
|
|
|
|
});
|
|
|
|
(0, ava_1.default)(convertPackToQuerySuiteEntryMacro, "a/b:my/path", {
|
|
|
|
qlpack: undefined,
|
|
|
|
from: "a/b",
|
|
|
|
version: undefined,
|
|
|
|
query: undefined,
|
|
|
|
queries: "my/path",
|
|
|
|
apply: undefined,
|
|
|
|
});
|
|
|
|
(0, ava_1.default)(convertPackToQuerySuiteEntryMacro, "a/b@~1.2.3:my/path", {
|
|
|
|
qlpack: undefined,
|
|
|
|
from: "a/b",
|
|
|
|
version: "~1.2.3",
|
|
|
|
query: undefined,
|
|
|
|
queries: "my/path",
|
|
|
|
apply: undefined,
|
|
|
|
});
|
|
|
|
(0, ava_1.default)(convertPackToQuerySuiteEntryMacro, "a/b:my/path/query.ql", {
|
|
|
|
qlpack: undefined,
|
|
|
|
from: "a/b",
|
|
|
|
version: undefined,
|
|
|
|
query: "my/path/query.ql",
|
|
|
|
queries: undefined,
|
|
|
|
apply: undefined,
|
|
|
|
});
|
|
|
|
(0, ava_1.default)(convertPackToQuerySuiteEntryMacro, "a/b@~1.2.3:my/path/query.ql", {
|
|
|
|
qlpack: undefined,
|
|
|
|
from: "a/b",
|
|
|
|
version: "~1.2.3",
|
|
|
|
query: "my/path/query.ql",
|
|
|
|
queries: undefined,
|
|
|
|
apply: undefined,
|
|
|
|
});
|
|
|
|
(0, ava_1.default)(convertPackToQuerySuiteEntryMacro, "a/b:my/path/suite.qls", {
|
|
|
|
qlpack: undefined,
|
|
|
|
from: "a/b",
|
|
|
|
version: undefined,
|
|
|
|
query: undefined,
|
|
|
|
queries: undefined,
|
|
|
|
apply: "my/path/suite.qls",
|
|
|
|
});
|
|
|
|
(0, ava_1.default)(convertPackToQuerySuiteEntryMacro, "a/b@~1.2.3:my/path/suite.qls", {
|
|
|
|
qlpack: undefined,
|
|
|
|
from: "a/b",
|
|
|
|
version: "~1.2.3",
|
|
|
|
query: undefined,
|
|
|
|
queries: undefined,
|
|
|
|
apply: "my/path/suite.qls",
|
|
|
|
});
|
|
|
|
(0, ava_1.default)("convertPackToQuerySuiteEntry Failure", (t) => {
|
|
|
|
t.throws(() => (0, analyze_1.convertPackToQuerySuiteEntry)("this-is-not-a-pack"));
|
|
|
|
});
|
|
|
|
(0, ava_1.default)("createQuerySuiteContents", (t) => {
|
|
|
|
const yamlResult = (0, analyze_1.createQuerySuiteContents)(["query1.ql", "query2.ql"], [
|
|
|
|
{
|
|
|
|
exclude: { "problem.severity": "recommendation" },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
include: { "problem.severity": "recommendation" },
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const expected = `- query: query1.ql
|
|
|
|
- query: query2.ql
|
|
|
|
- exclude:
|
|
|
|
problem.severity: recommendation
|
|
|
|
- include:
|
|
|
|
problem.severity: recommendation
|
|
|
|
`;
|
|
|
|
t.deepEqual(yamlResult, expected);
|
|
|
|
});
|
2020-09-10 20:02:33 +03:00
|
|
|
//# sourceMappingURL=analyze.test.js.map
|