|
7 | 7 | from click.testing import CliRunner
|
8 | 8 |
|
9 | 9 | from cycode.cli.commands.main_cli import main_cli
|
| 10 | +from cycode.cli.utils.git_proxy import git_proxy |
10 | 11 | from tests.conftest import CLI_ENV_VARS, TEST_FILES_PATH, ZIP_CONTENT_PATH
|
11 | 12 | from tests.cyclient.mocked_responses.scan_client import mock_scan_responses
|
12 | 13 | from tests.cyclient.test_scan_client import get_zipped_file_scan_response, get_zipped_file_scan_url
|
@@ -47,3 +48,39 @@ def test_passing_output_option(output: str, scan_client: 'ScanClient', api_token
|
47 | 48 | assert 'scan_id' in output
|
48 | 49 | else:
|
49 | 50 | assert 'Scan ID' in result.output
|
| 51 | + |
| 52 | + |
| 53 | +@responses.activate |
| 54 | +def test_optional_git_with_path_scan(scan_client: 'ScanClient', api_token_response: responses.Response) -> None: |
| 55 | + mock_scan_responses(responses, 'secret', scan_client, uuid4(), ZIP_CONTENT_PATH) |
| 56 | + responses.add(get_zipped_file_scan_response(get_zipped_file_scan_url('secret', scan_client), ZIP_CONTENT_PATH)) |
| 57 | + responses.add(api_token_response) |
| 58 | + |
| 59 | + # fake env without Git executable |
| 60 | + git_proxy._set_dummy_git_proxy() |
| 61 | + |
| 62 | + args = ['--output', 'json', 'scan', 'path', str(_PATH_TO_SCAN)] |
| 63 | + result = CliRunner().invoke(main_cli, args, env=CLI_ENV_VARS) |
| 64 | + |
| 65 | + # do NOT expect error about not found Git executable |
| 66 | + assert 'GIT_PYTHON_GIT_EXECUTABLE' not in result.output |
| 67 | + |
| 68 | + # reset the git proxy |
| 69 | + git_proxy._set_git_proxy() |
| 70 | + |
| 71 | + |
| 72 | +@responses.activate |
| 73 | +def test_required_git_with_path_repository(scan_client: 'ScanClient', api_token_response: responses.Response) -> None: |
| 74 | + responses.add(api_token_response) |
| 75 | + |
| 76 | + # fake env without Git executable |
| 77 | + git_proxy._set_dummy_git_proxy() |
| 78 | + |
| 79 | + args = ['--output', 'json', 'scan', 'repository', str(_PATH_TO_SCAN)] |
| 80 | + result = CliRunner().invoke(main_cli, args, env=CLI_ENV_VARS) |
| 81 | + |
| 82 | + # expect error about not found Git executable |
| 83 | + assert 'GIT_PYTHON_GIT_EXECUTABLE' in result.output |
| 84 | + |
| 85 | + # reset the git proxy |
| 86 | + git_proxy._set_git_proxy() |
0 commit comments