Skip to content

Commit

Permalink
fix: PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
j-luong committed Mar 13, 2024
1 parent 1b0ae09 commit e04c477
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/lib/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const debug = require('debug')('snyk-json');

/**
* Attempt to json-stringify an object which is potentially very large and might exceed the string limit.
* If it does exceed the string limit, try again without pretty-print to hopefully come out below the string limit.
* If it does exceed the string limit, return empty string.
* @param obj the object from which you want to get a JSON string
*/
export function jsonStringifyLargeObject(obj: any): string {
Expand Down
34 changes: 20 additions & 14 deletions test/jest/acceptance/cli-json-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,31 @@ describe('test --json', () => {
});

it('test --json handles responses larger than 512Mb string size limit in v8', async () => {
const project = await createProjectFromWorkspace('fail-on/no-fixable');
const response = await project.readJSON('vulns-result.json');
const remediation = response.result.remediation.unresolved[0];
response.result.remediation.unresolved = new Array(420000).fill(
remediation,
const project = await createProjectFromWorkspace(
'extra-large-response-payload',
);
const response = await project.readJSON('vulns-result.json');
const reference =
response.result.issuesData['SNYK-ALPINE319-OPENSSL-6148881']
.references[0];
response.result.issuesData[
'SNYK-ALPINE319-OPENSSL-6148881'
].references = new Array(420000).fill(reference);

server.setCustomResponse(response);

const {
code,
stdoutBuffer,
} = await runSnykCLI(`test --json`, {
cwd: project.path(),
env,
bufferOutput: true,
});
const imageName = 'hello-world:latest';
const { code, stdout, stderr } = await runSnykCLI(
`container test --platform=linux/amd64 ${imageName} --json`,
{
cwd: project.path(),
env,
},
);

if (stderr) console.debug(stderr);

expect(code).toEqual(1);
expect(stdoutBuffer).toBeDefined();
expect(JSON.parse(stdout)?.path).toEqual(imageName);
}, 120000);
});

0 comments on commit e04c477

Please sign in to comment.