Skip to content
Open
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
19 changes: 5 additions & 14 deletions cycode/cli/apps/scan/code_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,17 @@ def _should_use_sync_flow(command_scan_type: str, scan_type: str, sync_option: b
Passing `--sync` option does not mean that sync flow will be used in all cases.

The logic:
- for IAC scan, sync flow is always used
- for SAST scan, sync flow is not supported
- for SCA and Secrets scan, sync flow is supported only for path/repository scan
- for IaC and SAST scans, the async flow is always used
- for SCA and Secrets scans, sync flow is used only with `--sync` on path/repository scans

"""
if not sync_option and scan_type != consts.IAC_SCAN_TYPE:
if scan_type in {consts.IAC_SCAN_TYPE, consts.SAST_SCAN_TYPE}:
return False

if command_scan_type not in {'path', 'repository', 'ai_guardrails'}:
if not sync_option:
return False

if scan_type == consts.IAC_SCAN_TYPE:
# sync in the only available flow for IAC scan; we do not use detector directly anymore
return True

if scan_type is consts.SAST_SCAN_TYPE: # noqa: SIM103
# SAST does not support sync flow
return False

return True
return command_scan_type in {'path', 'repository', 'ai_guardrails'}


def _get_scan_documents_thread_func(
Expand Down
21 changes: 21 additions & 0 deletions tests/cli/commands/scan/test_code_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
_get_scan_documents_thread_func,
_perform_scan,
_run_presigned_upload_scan,
_should_use_sync_flow,
scan_disk_files,
scan_documents,
)
Expand All @@ -19,6 +20,26 @@
from cycode.cli.models import Document


@pytest.mark.parametrize(
('command_scan_type', 'scan_type', 'sync_option', 'expected'),
[
# IaC and SAST always use the async flow, regardless of --sync.
('path', consts.IAC_SCAN_TYPE, False, False),
('path', consts.IAC_SCAN_TYPE, True, False),
('repository', consts.IAC_SCAN_TYPE, True, False),
('path', consts.SAST_SCAN_TYPE, False, False),
('path', consts.SAST_SCAN_TYPE, True, False),
# SCA/Secrets use the sync flow only with --sync on path/repository.
('path', consts.SCA_SCAN_TYPE, True, True),
('repository', consts.SECRET_SCAN_TYPE, True, True),
('path', consts.SCA_SCAN_TYPE, False, False),
('commit_history', consts.SCA_SCAN_TYPE, True, False),
],
)
def test_should_use_sync_flow(command_scan_type: str, scan_type: str, sync_option: bool, expected: bool) -> None:
assert _should_use_sync_flow(command_scan_type, scan_type, sync_option) is expected


def test_is_file_relevant_for_sca_scan() -> None:
path = os.path.join('some_package', 'node_modules', 'package.json')
assert _is_file_relevant_for_sca_scan(path) is False
Expand Down
Loading