Skip to content

Commit

Permalink
fix: none custom policies severity issues should be filtered out befo…
Browse files Browse the repository at this point in the history
…re sending them to registry
  • Loading branch information
wbeuil committed Aug 18, 2022
1 parent 43dcec6 commit 4acacd2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function formatShareResults(
filePath: result.filePath,
fileType: result.fileType,
projectType: result.projectType,
violatedPolicies: result.violatedPolicies,
violatedPolicies: result.violatedPolicies.filter(
(violatedPolicy) => violatedPolicy.severity !== 'none',
),
};
});
}
Expand Down
9 changes: 9 additions & 0 deletions test/acceptance/fake-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,15 @@ export const fakeServer = (basePath: string, snykToken: string): FakeServer => {
});
}

if (req.query.org === 'custom-policies') {
return res.status(200).send({
...baseResponse,
customPolicies: {
'SNYK-CC-AZURE-543': { severity: 'none' },
},
});
}

res.status(200).send(baseResponse);
});

Expand Down
36 changes: 36 additions & 0 deletions test/jest/acceptance/iac/cli-share-results.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,42 @@ describe('CLI Share Results', () => {
expect(exitCode).toEqual(2);
});

it('should filter out NONE custom policies severity issues and then forward', async () => {
const { exitCode } = await run(
'snyk iac test ./iac/arm/rule_test.json --report --org=custom-policies',
);

const requests = server
.getRequests()
.filter((request) => request.url?.includes('/iac-cli-share-results'));

expect(requests.length).toEqual(1);
const [request] = requests;
expect(request.body).toEqual(
expect.objectContaining({
contributors: expect.any(Array),
scanResults: [
{
identity: {
type: 'armconfig',
targetFile: 'iac/arm/rule_test.json',
},
facts: [],
findings: expect.any(Array),
policy: '',
name: 'fixtures',
target: {
name: 'fixtures',
},
},
],
}),
);
// The other SNYK-CC-AZURE-543 issue has been filtered out
expect(request.body.scanResults[0].findings.length).toEqual(1);
expect(exitCode).toEqual(1);
});

describe('with target reference', () => {
it('forwards the target reference to iac-cli-share-results endpoint', async () => {
const testTargetRef = 'test-target-ref';
Expand Down

0 comments on commit 4acacd2

Please sign in to comment.