Skip to content
Merged
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
3 changes: 1 addition & 2 deletions cycode/cli/apps/scan/scan_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,12 @@ def scan_command(

ctx.obj['show_secret'] = show_secret
ctx.obj['soft_fail'] = soft_fail
ctx.obj['stop_on_error'] = stop_on_error
ctx.obj['scan_type'] = scan_type
ctx.obj['sync'] = sync
ctx.obj['severity_threshold'] = severity_threshold
ctx.obj['monitor'] = monitor
ctx.obj['report'] = report
apply_sca_restore_options_to_context(ctx, no_restore, gradle_all_sub_projects, maven_settings_file)
apply_sca_restore_options_to_context(ctx, no_restore, gradle_all_sub_projects, maven_settings_file, stop_on_error)

scan_client = get_scan_cycode_client(ctx)
ctx.obj['client'] = scan_client
Expand Down
17 changes: 17 additions & 0 deletions tests/cli/commands/scan/test_scan_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import importlib
import re
from unittest.mock import patch

import click
import pytest
Expand All @@ -9,6 +11,8 @@
from cycode.cli.apps.scan.scan_command import scan_command_result_callback
from cycode.cli.consts import ISSUE_DETECTED_STATUS_CODE, NO_ISSUES_STATUS_CODE, SCAN_ERROR_STATUS_CODE

_scan_command_module = importlib.import_module('cycode.cli.apps.scan.scan_command')


def _strip_ansi(text: str) -> str:
return re.sub(r'\x1b\[[0-9;]*[mGKHF]', '', text)
Expand Down Expand Up @@ -47,6 +51,19 @@ def test_single_scan_type_accepted(self) -> None:
assert result.exit_code == 0
assert 'Error' not in result.output

@pytest.mark.parametrize(('args', 'expected'), [(['--stop-on-error'], True), ([], False)])
def test_stop_on_error_kept_in_context(self, args: list, expected: bool) -> None:
captured = {}

def _capture_ctx_and_stop(ctx: typer.Context) -> None:
captured.update(ctx.obj)
raise typer.Exit(0)

with patch.object(_scan_command_module, 'get_scan_cycode_client', side_effect=_capture_ctx_and_stop):
CliRunner().invoke(app, ['scan', '-t', 'sca', *args, 'path', '.'])

assert captured['stop_on_error'] is expected


class TestScanCommandResultCallback:
def test_no_issues_no_errors_exits_zero(self) -> None:
Expand Down
Loading