diff --git a/snykTask/src/__tests__/test-task-args.ts b/snykTask/src/__tests__/test-task-args.ts index dd9a366d..48febfb7 100644 --- a/snykTask/src/__tests__/test-task-args.ts +++ b/snykTask/src/__tests__/test-task-args.ts @@ -89,6 +89,15 @@ test('if dockerImageName is set and both targetFile and dockerfilePath are set, expect(fileArg).toBe('good/Dockerfile'); }); +test('project name is wrapped in quotes, if project name contains space', () => { + const args = defaultTaskArgs(); + args.projectName = 'my project'; + + const projectNameArg = args.getProjectNameParameter(); + + expect(projectNameArg).toBe('"my project"'); +}); + test('ensure that ignoreUnknownCA is false by default', () => { const args = defaultTaskArgs(); expect(args.ignoreUnknownCA).toBe(false); diff --git a/snykTask/src/index.ts b/snykTask/src/index.ts index ffd6fe3d..5f3b0f5f 100644 --- a/snykTask/src/index.ts +++ b/snykTask/src/index.ts @@ -138,6 +138,7 @@ async function runSnykTest( let errorMsg = ''; let code = 0; const fileArg = taskArgs.getFileParameter(); + const projectNameArg = taskArgs.getProjectNameParameter(); const snykTestToolRunner = tl .tool(snykPath) @@ -151,7 +152,7 @@ async function runSnykTest( .argIf(fileArg, `--file=${fileArg}`) .argIf(taskArgs.ignoreUnknownCA, `--insecure`) .argIf(taskArgs.organization, `--org=${taskArgs.organization}`) - .argIf(taskArgs.projectName, `--project-name=${taskArgs.projectName}`) + .argIf(taskArgs.projectName, `--project-name=${projectNameArg}`) .arg(`--json-file-output=${jsonReportOutputPath}`) .line(taskArgs.additionalArguments); @@ -228,6 +229,7 @@ async function runSnykMonitor( ): Promise { let errorMsg = ''; const fileArg = taskArgs.getFileParameter(); + const projectNameArg = taskArgs.getProjectNameParameter(); const options = getOptionsToExecuteSnykCLICommand( taskArgs, taskNameForAnalytics, @@ -241,7 +243,7 @@ async function runSnykMonitor( .argIf(taskArgs.dockerImageName, `${taskArgs.dockerImageName}`) .argIf(fileArg, `--file=${fileArg}`) .argIf(taskArgs.organization, `--org=${taskArgs.organization}`) - .argIf(taskArgs.projectName, `--project-name=${taskArgs.projectName}`) + .argIf(taskArgs.projectName, `--project-name=${projectNameArg}`) .argIf(taskArgs.ignoreUnknownCA, `--insecure`) .line(taskArgs.additionalArguments); diff --git a/snykTask/src/task-args.ts b/snykTask/src/task-args.ts index 31732904..92bda899 100644 --- a/snykTask/src/task-args.ts +++ b/snykTask/src/task-args.ts @@ -89,6 +89,19 @@ class TaskArgs { } } + getProjectNameParameter() { + if (!this.projectName) { + return undefined; + } + + if (this.projectName.indexOf(' ') >= 0) { + console.log('project name contains space'); + return `"${this.projectName}"`; + } + + return this.projectName; + } + public validate() { if (this.failOnThreshold) { if (this.isNotValidThreshold(this.failOnThreshold)) {