Skip to content

Commit

Permalink
fix: change how we check for success under the --json flag
Browse files Browse the repository at this point in the history
Co-authored-by: Ron Tal <ron.tal@snyk.io>
  • Loading branch information
teodora-sandu and rontalx committed Apr 29, 2021
1 parent 9984e4d commit 3048dcf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
11 changes: 1 addition & 10 deletions src/cli/commands/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,8 @@ async function test(...args: MethodArgs): Promise<TestCommandResult> {
} = extractDataToSendFromResults(results, jsonData, options);

if (options.json || options.sarif) {
// the new experimental IaC flow does not have the ok field because it returns vulnerabilities and errors separately
// the legacy IaC flow may return errors that get mapped into errorMappedResults, but that flow will be removed soon
const successfulIacScanning =
options.iac &&
!foundVulnerabilities &&
(!iacScanFailures || iacScanFailures.length === 0);

// if running iac and it was successful, or
// if all results are ok (.ok == true)
// then return the json
if (successfulIacScanning || errorMappedResults.every((res) => res.ok)) {
if (errorMappedResults.every((res) => res.ok)) {
return TestCommandResult.createJsonTestCommandResult(
stringifiedData,
stringifiedJsonData,
Expand Down
6 changes: 4 additions & 2 deletions src/lib/snyk-test/iac-test-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ export function mapIacTestResult(
};
}

const infrastructureAsCodeIssues =
iacTest?.result?.cloudConfigResults.map(mapIacIssue) || [];
const {
result: { projectType },
...filteredIacTest
} = iacTest;
return {
...filteredIacTest,
projectType,
[IAC_ISSUES_KEY]:
iacTest?.result?.cloudConfigResults.map(mapIacIssue) || [],
ok: infrastructureAsCodeIssues.length === 0,
[IAC_ISSUES_KEY]: infrastructureAsCodeIssues,
};
}

Expand Down

0 comments on commit 3048dcf

Please sign in to comment.