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

feat: add init-script argument to CLI for gradle #1647

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions help/commands-docs/_SNYK_COMMAND_OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ Below are flags that are influencing CLI behavior for specific projects, languag

Default: 300 (5 minutes).

- `--init-script`=<FILE>
For projects that contain a gradle initialization script.

### .Net & NuGet options

- `--assets-project-name`:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"snyk-cpp-plugin": "2.2.1",
"snyk-docker-plugin": "4.17.2",
"snyk-go-plugin": "1.16.5",
"snyk-gradle-plugin": "3.12.5",
"snyk-gradle-plugin": "3.13.0",
"snyk-module": "3.1.0",
"snyk-mvn-plugin": "2.25.3",
"snyk-nodejs-lockfile-parser": "1.30.2",
Expand Down
1 change: 1 addition & 0 deletions src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export function args(rawArgv: string[]): Args {
'reachable-vulns',
'reachable-timeout',
'reachable-vulns-timeout',
'init-script',
'integration-name',
'integration-version',
'prune-repeated-subdependencies',
Expand Down
3 changes: 3 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface TestOptions {
failOn?: FailOn;
reachableVulns?: boolean;
reachableVulnsTimeout?: number;
initScript?: string;
yarnWorkspaces?: boolean;
testDepGraphDockerEndpoint?: string | null;
isDockerUser?: boolean;
Expand Down Expand Up @@ -100,6 +101,7 @@ export interface MonitorOptions {
'app-vulns'?: boolean;
reachableVulns?: boolean;
reachableVulnsTimeout?: number;
initScript?: string;
yarnWorkspaces?: boolean;
}

Expand Down Expand Up @@ -179,6 +181,7 @@ export type SupportedUserReachableFacingCliArgs =
| 'reachable-vulns'
| 'reachable-timeout'
| 'reachable-vulns-timeout'
| 'init-script'
Copy link
Contributor

Choose a reason for hiding this comment

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

So you don't need to pass this option, it'll just be picked from the global options?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite certain what you mean. Should I remove it then? As far as I understand it's better to have types set here for documentation concerns.

| 'integration-name'
| 'integration-version';

Expand Down
60 changes: 60 additions & 0 deletions test/acceptance/cli-test/cli-test.gradle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,66 @@ export const GradleTests: AcceptanceTests = {
);
},

'`test gradle-app --reachable-vulns and --init-script` sends call graph': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
const callGraphPayload = require('../fixtures/call-graphs/maven.json');
const callGraph = createCallGraph(callGraphPayload);
const plugin = {
async inspect() {
return {
package: {},
plugin: { name: 'testplugin', runtime: 'testruntime' },
callGraph,
};
},
};
const spyPlugin = sinon.spy(plugin, 'inspect');
const loadPlugin = sinon.stub(params.plugins, 'loadPlugin');
t.teardown(loadPlugin.restore);
loadPlugin.withArgs('gradle').returns(plugin);
await params.cli.test('gradle-app', {
reachableVulns: true,
initScript: 'somescript.gradle',
});
const req = params.server.popRequest();
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
params.versionNumber,
'sends version number',
);
t.match(req.url, '/test-dep-graph', 'posts to correct url');
t.match(req.body.targetFile, undefined, 'target is undefined');
t.equal(req.body.depGraph.pkgManager.name, 'gradle');
t.deepEqual(
req.body.callGraph,
callGraphPayload,
'correct call graph sent',
);
t.same(
spyPlugin.getCall(0).args,
[
'gradle-app',
'build.gradle',
{
args: null,
file: 'build.gradle',
org: null,
projectName: null,
packageManager: 'gradle',
path: 'gradle-app',
showVulnPaths: 'some',
reachableVulns: true,
initScript: 'somescript.gradle',
},
],
'calls gradle plugin',
);
},

'`test gradle-app --all-sub-projects` sends `allSubProjects` argument to plugin': (
params,
utils,
Expand Down