Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: validate applied policy rules in json output #5167

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test/jest/acceptance/cli-json-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fakeServer } from '../../acceptance/fake-server';
import { createProjectFromWorkspace } from '../util/createProject';
import { getServerPort } from '../util/getServerPort';
import { runSnykCLI } from '../util/runSnykCLI';
import { AppliedPolicyRules } from '../../../src/lib/formatters/types';
import * as Parser from 'jsonparse';

jest.setTimeout(1000 * 60);
Expand Down Expand Up @@ -133,4 +134,35 @@ describe('test --json', () => {
expect(hasReferenceCount).toBeTruthy();
}, 120000);
});

describe('when policy data is available', () => {
it('includes a user note and reason', async () => {
const project = await createProjectFromWorkspace(
'npm-package-single-vuln',
);
server.setCustomResponse(
await project.readJSON('test-graph-results-with-annotation.json'),
);

const { code, stdout } = await runSnykCLI(`test --json`, {
cwd: project.path(),
env,
});

const expectedPolicyData: AppliedPolicyRules = {
annotation: {
value: 'This is a test user note',
reason: 'This vulnerability is a papercut and can be ignored',
},
};

const returnedJson = JSON.parse(stdout);
const actualPolicyData =
returnedJson.vulnerabilities[0].appliedPolicyRules;

expect(actualPolicyData).toStrictEqual(expectedPolicyData);
expect(code).toEqual(1);
expect(server.getRequests().length).toBeGreaterThanOrEqual(1);
});
});
});
Loading