Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to pass additional arguments when running tests #785

Merged
merged 1 commit into from
Mar 16, 2021

Conversation

edoardopirovano
Copy link
Contributor

This PR addresses #606 by adding a configuration option to pass additional arguments to the CLI when running tests. By default, this option is empty and no additional arguments are passed.

extensions/ql-vscode/package.json Outdated Show resolved Hide resolved
extensions/ql-vscode/src/cli.ts Outdated Show resolved Hide resolved
@edoardopirovano
Copy link
Contributor Author

Tested after the changes and can confirm the option works as expected. In particular, I tried the --slice and --show-extractor-output options and observed the corresponding changes in output which confirm that the options are being picked up.

@@ -182,6 +182,12 @@
"default": "%q on %d - %s, %r result count [%t]",
"description": "Default string for how to label query history items. %t is the time of the query, %q is the query name, %d is the database name, %r is the number of results, and %s is a status string."
},
"codeQL.runningTests.additionalTestArguments": {
"scope": "window",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest making this more restrictive: use machine just like we do for codeql.cli.executablePath. This ensure the setting can only be configured at the user level and prevents malicious workspaces from executing arbitrary code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really a danger in this case? Can the run test command invoke arbitrary commands? I guess it would if you can specify a build command for a test database, but not sure if that's possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly being cautious. Saves us revisiting this in future if we introduce such an option. Right now, I think it's only potentially vulnerable through some indirection, e.g. if the controlled workspace points the test/extractor to a different folder it controls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine by me, probably best to avoid. I just wanted to make sure there wasn't a specific flaw we need to prevent.

@@ -509,12 +509,12 @@ export class CodeQLCliServer implements Disposable {
testPaths: string[], workspaces: string[], options: TestRunOptions
): AsyncGenerator<TestCompleted, void, unknown> {

const subcommandArgs = [
const subcommandArgs = this.cliConfig.additionalTestArguments.toString().split(/\s+/).concat([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment from @henrymercer. This will fail things like --string-arg "hello world". We will need some more sophisticated parsing here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could change the type of the setting to array and each arg is one string element of the array, but then they can only be editted in the settings.json see: https://code.visualstudio.com/api/references/contribution-points#Configuration-property-schema

This may not be so bad as long as you have a proper description in the text.

@@ -509,12 +509,12 @@ export class CodeQLCliServer implements Disposable {
testPaths: string[], workspaces: string[], options: TestRunOptions
): AsyncGenerator<TestCompleted, void, unknown> {

const subcommandArgs = [
const subcommandArgs = this.cliConfig.additionalTestArguments.toString().split(/\s+/).concat([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could change the type of the setting to array and each arg is one string element of the array, but then they can only be editted in the settings.json see: https://code.visualstudio.com/api/references/contribution-points#Configuration-property-schema

This may not be so bad as long as you have a proper description in the text.

@edoardopirovano
Copy link
Contributor Author

Have addressed the above comments and squashed into one commit.

Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@aeisenberg aeisenberg dismissed adityasharad’s stale review March 16, 2021 20:44

Comment was addressed.

@aeisenberg aeisenberg merged commit 6830bdd into github:main Mar 16, 2021
@edoardopirovano edoardopirovano deleted the qltest-config branch March 17, 2021 08:45
@aeisenberg
Copy link
Contributor

@github/docs-content-dsp We probably need to add some documentation for this new functionality.

@shati-patel
Copy link
Contributor

@github/docs-content-dsp We probably need to add some documentation for this new functionality.

Thanks! I've opened an internal docs issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants