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

fix: make dotnet acceptance test resilient to system lib vulns #5358

Merged
merged 1 commit into from
Jul 11, 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
19 changes: 16 additions & 3 deletions test/jest/acceptance/snyk-test/basic-test-all-languages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,32 @@ describe('`snyk test` of basic projects for each language/ecosystem', () => {
}

const { code, stderr, stdout } = await runSnykCLI(
'test -d --dotnet-runtime-resolution',
'test --dotnet-runtime-resolution --json',
{
cwd: project.path(),
},
);

if (code !== 0) {
// Debug output on an unexpected exit code
if (code !== 0 && code !== 1) {
console.debug(stderr);
console.debug('---------------------------');
console.debug(stdout);
}

expect(code).toEqual(0);
// Expect an exit code of 0 or 1. Exit code 1 is possible if a new
// vulnerability is discovered in the installed version of dotnet's system
// libraries.
expect([0, 1]).toContain(code);

// Note: dotnet plugin can print a warning about runtime resolution, which breaks JSON output.
// This replacement regex is a temporary workaround until the dotnet plugin can be fixed.
const sanitizedStdout = stdout.replace(/^[\s\S]*?{/, '{');
const result = JSON.parse(sanitizedStdout);
expect(result?.ok).toBeDefined();

// Expect 'ok' to be true if exit 0, false if exit 1.
expect(result.ok).toBe(code === 0);
},
);

Expand Down
Loading