Skip to content

Commit

Permalink
fix: wrong 2x count of iac issues with --report -multi-doc yaml
Browse files Browse the repository at this point in the history
this is to fix a bug where we mutated the "results" in the formatAndShareResults and these were used again in the formatScanResults below, resulting in double count of issues.
note: this happened only in multi-YAML documents
  • Loading branch information
Ilianna Papastefanou committed Aug 10, 2022
1 parent 7a46414 commit 06da34e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Expand Up @@ -109,7 +109,7 @@ export {
measurableScanFiles as scanFiles,
measurableGetIacOrgSettings as getIacOrgSettings,
measurableApplyCustomSeverities as applyCustomSeverities,
measurableFormatScanResults as formatScanResultsV2,
measurableFormatScanResults as formatScanResults,
measurableTrackUsage as trackUsage,
measurableCleanLocalCache as cleanLocalCache,
measurableLocalTest as localTest,
Expand Down
@@ -1,6 +1,7 @@
import { filterIgnoredIssues } from './policy';
import { formatAndShareResults } from './share-results';
import { formatScanResultsV2 } from '../measurable-methods';
import { formatScanResults } from '../measurable-methods';
import * as cloneDeep from 'lodash.clonedeep';
import { Policy } from '../../../../../../lib/policy/find-and-load-policy';
import {
IacOutputMeta,
Expand Down Expand Up @@ -33,7 +34,11 @@ export async function processResults(

if (options.report) {
({ projectPublicIds, gitRemoteUrl } = await formatAndShareResults({
results: resultsWithCustomSeverities,
// this is to fix a bug where we mutated the "results" in the formatAndShareResults
// and these were used again in the formatScanResults below
// resulting in double count of issues
// note: this happened only in multi-YAML documents
results: cloneDeep(resultsWithCustomSeverities),
options,
orgPublicId,
policy,
Expand All @@ -44,7 +49,7 @@ export async function processResults(
}));
}

const formattedResults = formatScanResultsV2(
const formattedResults = formatScanResults(
resultsWithCustomSeverities,
options,
iacOrgSettings.meta,
Expand Down
Expand Up @@ -27,12 +27,12 @@ export function formatScanResults(
options: IaCTestFlags,
meta: TestMeta,
projectPublicIds: Record<string, string>,
porjectRoot: string,
projectRoot: string,
gitRemoteUrl?: string,
): FormattedResult[] {
try {
const groupedByFile = scanResults.reduce((memo, scanResult) => {
const res = formatScanResult(scanResult, meta, options, porjectRoot);
const res = formatScanResult(scanResult, meta, options, projectRoot);

if (memo[scanResult.filePath]) {
memo[scanResult.filePath].result.cloudConfigResults.push(
Expand Down

0 comments on commit 06da34e

Please sign in to comment.