Skip to content

Commit

Permalink
feat: Added message for no issues found
Browse files Browse the repository at this point in the history
  • Loading branch information
ofekatr committed Apr 19, 2022
1 parent 8eb74cf commit 96dbc7c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -87,6 +87,7 @@
"jsondiffpatch": "^0.4.1",
"lodash.assign": "^4.2.0",
"lodash.camelcase": "^4.3.0",
"lodash.capitalize": "^4.2.1",
"lodash.clonedeep": "^4.5.0",
"lodash.flatten": "^4.4.0",
"lodash.get": "^4.4.2",
Expand Down
16 changes: 13 additions & 3 deletions src/lib/formatters/iac-output/v2/issues-list.ts
@@ -1,6 +1,7 @@
import { EOL } from 'os';
import capitalize = require('lodash/capitalize');
import debug = require('debug');
import * as capitalize from 'lodash.capitalize';
import * as isEmpty from 'lodash.isempty';
import * as debug from 'debug';

import { FormattedResult } from '../../../../cli/commands/test/iac/local-execution/types';
import { IacOutputMeta } from '../../../types';
Expand All @@ -12,9 +13,18 @@ export function getIacDisplayedIssues(
results: FormattedResult[],
outputMeta: IacOutputMeta,
): string {
let output = EOL + colors.info.bold('Issues') + EOL;

const formattedResults = formatScanResultsNewOutput(results, outputMeta);

let output = EOL + colors.info.bold('Issues') + EOL;
if (isEmpty(formattedResults.results)) {
return (
output +
EOL +
' '.repeat(2) +
colors.success.bold('No vulnerable paths were found!')
);
}

['low', 'medium', 'high', 'critical'].forEach((severity) => {
if (formattedResults.results[severity]) {
Expand Down
13 changes: 13 additions & 0 deletions test/jest/acceptance/iac/iac-output.spec.ts
Expand Up @@ -244,6 +244,19 @@ https://support.snyk.io/hc/en-us/articles/360013723877-Test-your-Terraform-files
expect(stdout).not.toContain('Test Summary');
});
});

describe('with no issues', () => {
it('it should display an appropriate message in the issues section', async () => {
// Arrange
const filePath = 'iac/terraform/vars.tf';

// Act
const { stdout } = await run(`snyk iac test ${filePath}`);

// Assert
expect(stdout).toContain('No vulnerable paths were found!');
});
});
});

describe(`without the '${IAC_CLI_OUTPUT_FF}' feature flag`, () => {
Expand Down
43 changes: 43 additions & 0 deletions test/jest/unit/lib/formatters/iac-output/v2/issues-list.spec.ts
Expand Up @@ -47,4 +47,47 @@ describe('getIacDisplayedIssues', () => {
);
expect(result).toContain(colors.severities.high(`High Severity Issues: 5`));
});

describe('with no issues', () => {
let resultsWithNoIssues: FormattedResult[];

beforeAll(() => {
resultsWithNoIssues = resultFixtures.map((resultFixture) => ({
...resultFixture,
result: {
...resultFixture.result,
cloudConfigResults: [],
},
}));
});

it('should display an appropriate message', () => {
// Act
const result = getIacDisplayedIssues(resultsWithNoIssues, outputMeta);

// Assert
expect(result).toContain(
colors.success.bold('No vulnerable paths were found!'),
);
});

it('should not display any severity sections', () => {
// Act
const result = getIacDisplayedIssues(resultsWithNoIssues, outputMeta);

// Assert
expect(result).not.toContain(
colors.severities.low('Low Severity Issues'),
);
expect(result).not.toContain(
colors.severities.medium('Medium Severity Issues'),
);
expect(result).not.toContain(
colors.severities.high('High Severity Issues'),
);
expect(result).not.toContain(
colors.severities.critical('Critical Severity Issues'),
);
});
});
});

0 comments on commit 96dbc7c

Please sign in to comment.