Skip to content
Draft
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions cliv2/cmd/cliv2/behavior/legacy/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ func unknownCommandError(details string) error {

// SetupTestMonitorCommand configures command for test/monitor to ensure parity with legacy behavior
func SetupTestMonitorCommand(cmd *cobra.Command) {
// Relax flag validation for backwards compatibility by suppressing cobra's default error
cmd.SetFlagErrorFunc(func(_ *cobra.Command, _ error) error {
return unknownCommandError("")
})
// Disable flag parsing for test/monitor so that cli-extension-os-flows
// can manually route to the legacy CLI and handle flag validation.
cmd.DisableFlagParsing = true

cmd.PreRunE = func(c *cobra.Command, args []string) error {
if err := validateFlagsCompatibilityWithLegacy(os.Args[1:]); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ describe('snyk test --reachability', () => {
expect(code).toBe(EXIT_CODES.VULNS_FOUND);
});

test('emits a valid json output when unknown flags are passed', async () => {
const { stdout, stderr } = await runSnykCLI(
`test ${TEMP_LOCAL_PATH} --reachability --json --foo-bar`,
{
env: {
...process.env,
...ReachabilityIntegrationEnv.env,
},
},
);

expect(stdout).not.toBe('');
expect(stderr).toBe('');

const jsonOutput = JSON.parse(stdout);

const allVulnsHaveReachabilitySignal = jsonOutput.vulnerabilities.every(
(vuln: { reachability: string }) => !!vuln.reachability,
);

expect(allVulnsHaveReachabilitySignal).toBeTruthy();
});

test('emits a valid json output and fails the test if vulnerabilies are upgradable', async () => {
const { stdout, code, stderr } = await runSnykCLI(
`test ${TEMP_LOCAL_PATH} --reachability --fail-on=upgradable --json`,
Expand Down