diff --git a/cycode/cli/apps/scan/code_scanner.py b/cycode/cli/apps/scan/code_scanner.py index 8c321c56..6244103b 100644 --- a/cycode/cli/apps/scan/code_scanner.py +++ b/cycode/cli/apps/scan/code_scanner.py @@ -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( diff --git a/tests/cli/commands/scan/test_code_scanner.py b/tests/cli/commands/scan/test_code_scanner.py index 24f6a39f..3aa6cfae 100644 --- a/tests/cli/commands/scan/test_code_scanner.py +++ b/tests/cli/commands/scan/test_code_scanner.py @@ -10,6 +10,7 @@ _get_scan_documents_thread_func, _perform_scan, _run_presigned_upload_scan, + _should_use_sync_flow, scan_disk_files, scan_documents, ) @@ -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