Skip to content

Commit

Permalink
Merge pull request #153 from snyk/develop
Browse files Browse the repository at this point in the history
Merge develop into master for release
  • Loading branch information
michelkaporin authored Nov 17, 2022
2 parents 60fbca5 + 8716fff commit f50264b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions snykTask/src/__tests__/test-task-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions snykTask/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down Expand Up @@ -228,6 +229,7 @@ async function runSnykMonitor(
): Promise<SnykOutput> {
let errorMsg = '';
const fileArg = taskArgs.getFileParameter();
const projectNameArg = taskArgs.getProjectNameParameter();
const options = getOptionsToExecuteSnykCLICommand(
taskArgs,
taskNameForAnalytics,
Expand All @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions snykTask/src/task-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit f50264b

Please sign in to comment.