Skip to content

Commit 91d3ea5

Browse files
authored
CM-29799 - Revert async flow for secrets (#181)
1 parent b4f510e commit 91d3ea5

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

cycode/cli/code_scanner.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,13 @@ def perform_scan(
546546
is_commit_range: bool,
547547
scan_parameters: dict,
548548
) -> ZippedFileScanResult:
549+
if scan_type in (consts.SCA_SCAN_TYPE, consts.SAST_SCAN_TYPE):
550+
return perform_scan_async(cycode_client, zipped_documents, scan_type, scan_parameters)
551+
549552
if is_commit_range:
550553
return cycode_client.commit_range_zipped_file_scan(scan_type, zipped_documents, scan_id)
551554

552-
if scan_type == consts.INFRA_CONFIGURATION_SCAN_TYPE:
553-
return cycode_client.zipped_file_scan(scan_type, zipped_documents, scan_id, scan_parameters, is_git_diff)
554-
555-
return perform_scan_async(cycode_client, zipped_documents, scan_type, scan_parameters)
555+
return cycode_client.zipped_file_scan(scan_type, zipped_documents, scan_id, scan_parameters, is_git_diff)
556556

557557

558558
def perform_scan_async(
@@ -1025,10 +1025,6 @@ def _map_detections_per_file(detections: List[dict]) -> List[DetectionsPerFile]:
10251025
def _get_file_name_from_detection(detection: dict) -> str:
10261026
if detection['category'] == 'SAST':
10271027
return detection['detection_details']['file_path']
1028-
if detection['category'] == 'SecretDetection':
1029-
file_path = detection['detection_details']['file_path']
1030-
file_name = detection['detection_details']['file_name']
1031-
return os.path.join(file_path, file_name)
10321028

10331029
return detection['detection_details']['file_name']
10341030

cycode/cyclient/scan_config_base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ def get_async_scan_type(scan_type: str) -> str:
1616
return scan_type.upper()
1717

1818
@staticmethod
19-
def get_async_entity_type(scan_type: str) -> str:
20-
if scan_type == 'secret':
21-
return 'zippedfile'
22-
19+
def get_async_entity_type(_: str) -> str:
20+
# we are migrating to "zippedfile" entity type. will be used later
2321
return 'repository'
2422

2523
@abstractmethod

tests/cli/test_main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import json
22
from typing import TYPE_CHECKING
3-
from uuid import UUID
3+
from uuid import uuid4
44

55
import pytest
66
import responses
77
from click.testing import CliRunner
88

99
from cycode.cli.main import main_cli
1010
from tests.conftest import CLI_ENV_VARS, TEST_FILES_PATH, ZIP_CONTENT_PATH
11-
from tests.cyclient.mocked_responses.scan_client import mock_scan_async_responses
11+
from tests.cyclient.mocked_responses.scan_client import mock_scan_responses
12+
from tests.cyclient.test_scan_client import get_zipped_file_scan_response, get_zipped_file_scan_url
1213

1314
_PATH_TO_SCAN = TEST_FILES_PATH.joinpath('zip_content').absolute()
1415

@@ -28,10 +29,11 @@ def _is_json(plain: str) -> bool:
2829
@pytest.mark.parametrize('output', ['text', 'json'])
2930
def test_passing_output_option(output: str, scan_client: 'ScanClient', api_token_response: responses.Response) -> None:
3031
scan_type = 'secret'
31-
scan_id = UUID('12345678-418f-47ee-abb0-012345678901')
32+
scan_id = uuid4()
3233

34+
mock_scan_responses(responses, scan_type, scan_client, scan_id, ZIP_CONTENT_PATH)
35+
responses.add(get_zipped_file_scan_response(get_zipped_file_scan_url(scan_type, scan_client), ZIP_CONTENT_PATH))
3336
responses.add(api_token_response)
34-
mock_scan_async_responses(responses, scan_type, scan_client, scan_id, ZIP_CONTENT_PATH)
3537

3638
args = ['--output', output, 'scan', '--soft-fail', 'path', str(_PATH_TO_SCAN)]
3739
result = CliRunner().invoke(main_cli, args, env=CLI_ENV_VARS)

tests/cyclient/mocked_responses/scan_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,12 @@ def mock_scan_async_responses(
156156
responses_module.add(get_scan_detections_count_response(get_scan_detections_count_url(scan_client)))
157157
responses_module.add(get_scan_detections_response(get_scan_detections_url(scan_client), scan_id, zip_content_path))
158158
responses_module.add(get_report_scan_status_response(get_report_scan_status_url(scan_type, scan_id, scan_client)))
159+
160+
161+
def mock_scan_responses(
162+
responses_module: responses, scan_type: str, scan_client: ScanClient, scan_id: UUID, zip_content_path: Path
163+
) -> None:
164+
responses_module.add(
165+
get_zipped_file_scan_response(get_zipped_file_scan_url(scan_type, scan_client), zip_content_path)
166+
)
167+
responses_module.add(get_report_scan_status_response(get_report_scan_status_url(scan_type, scan_id, scan_client)))

tests/cyclient/test_scan_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ def get_test_zip_file(scan_type: str) -> InMemoryZip:
3737
return zip_documents(scan_type, test_documents)
3838

3939

40+
def test_get_service_name(scan_client: ScanClient) -> None:
41+
# TODO(MarshalX): get_service_name should be removed from ScanClient? Because it exists in ScanConfig
42+
assert scan_client.get_service_name('secret') == 'secret'
43+
assert scan_client.get_service_name('iac') == 'iac'
44+
assert scan_client.get_service_name('sca') == 'scans'
45+
assert scan_client.get_service_name('sast') == 'scans'
46+
47+
4048
@pytest.mark.parametrize('scan_type', config['scans']['supported_scans'])
4149
@responses.activate
4250
def test_zipped_file_scan(scan_type: str, scan_client: ScanClient, api_token_response: responses.Response) -> None:

0 commit comments

Comments
 (0)