Skip to content

Commit

Permalink
Avoid passing an undefined qlconfig arg
Browse files Browse the repository at this point in the history
  • Loading branch information
henrymercer authored and aeisenberg committed Mar 7, 2023
1 parent 8340258 commit 4366485
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions lib/codeql.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.test.js.map

Large diffs are not rendered by default.

35 changes: 32 additions & 3 deletions src/codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ test("passes a code scanning config AND qlconfig to the CLI when CLI config pass
t.truthy(hasQlconfigArg, "Should have injected a codescanning config");
});
});

test("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI config passing is enabled", async (t: ExecutionContext<unknown>) => {
await util.withTmpDir(async (tempDir) => {
const runnerConstructorStub = stubToolRunnerConstructor();
Expand All @@ -1084,13 +1085,41 @@ test("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI confi
const hasCodeScanningConfigArg = args.some((arg: string) =>
arg.startsWith("--codescanning-config=")
);
t.true(hasCodeScanningConfigArg, "Should NOT have injected a qlconfig");
t.true(
hasCodeScanningConfigArg,
"Should have injected a codescanning config"
);

// should have passed a qlconfig file
// should not have passed a qlconfig file
const hasQlconfigArg = args.some((arg: string) =>
arg.startsWith("--qlconfig=")
);
t.false(hasQlconfigArg, "should NOT have injected a qlconfig");
});
});

test("does not pass a qlconfig to the CLI when it is undefined", async (t: ExecutionContext<unknown>) => {
await util.withTmpDir(async (tempDir) => {
const runnerConstructorStub = stubToolRunnerConstructor();
const codeqlObject = await codeql.getCodeQLForTesting();
sinon
.stub(codeqlObject, "getVersion")
.resolves(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG);

await codeqlObject.databaseInitCluster(
{ ...stubConfig, tempDir },
"",
undefined,
createFeatures([Feature.CliConfigFileEnabled]),
undefined, // undefined qlconfigFile
getRunnerLogger(true)
);

const args = runnerConstructorStub.firstCall.args[1] as any[];
const hasQlconfigArg = args.some((arg: string) =>
arg.startsWith("--qlconfig=")
);
t.false(hasQlconfigArg, "Should have injected a codescanning config");
t.false(hasQlconfigArg, "should NOT have injected a qlconfig");
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@ export async function getCodeQLForCmd(
}

if (
await util.codeQlVersionAbove(this, CODEQL_VERSION_INIT_WITH_QLCONFIG)
qlconfigFile !== undefined &&
(await util.codeQlVersionAbove(this, CODEQL_VERSION_INIT_WITH_QLCONFIG))
) {
extraArgs.push(`--qlconfig=${qlconfigFile}`);
}
Expand Down

0 comments on commit 4366485

Please sign in to comment.