-
-
Notifications
You must be signed in to change notification settings - Fork 5
option to disable md5 #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mlapaglia
wants to merge
2
commits into
develop
Choose a base branch
from
disable-md5
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| import pytest | ||
| from unittest.mock import AsyncMock, MagicMock | ||
| from borgitory.protocols.file_protocols import FileServiceProtocol | ||
| from borgitory.services.cloud_providers.storage.sftp_storage import ( | ||
| SFTPStorageConfig, | ||
| SFTPStorage, | ||
| ) | ||
| from borgitory.services.cloud_providers.types import SyncEvent | ||
|
|
||
|
|
||
| class TestSFTPStorage: | ||
| """Test SFTP storage runtime behavior""" | ||
|
|
||
| @pytest.fixture | ||
| def mock_command_executor(self) -> AsyncMock: | ||
| return AsyncMock() | ||
|
|
||
| @pytest.fixture | ||
| def mock_file_service(self) -> AsyncMock: | ||
| return AsyncMock(spec=FileServiceProtocol) | ||
|
|
||
| @pytest.fixture | ||
| def storage_config(self) -> SFTPStorageConfig: | ||
| return SFTPStorageConfig( | ||
| host="nas.example.com", | ||
| username="backup", | ||
| remote_path="/backups", | ||
| password="secret", | ||
| port=22, | ||
| ) | ||
|
|
||
| @pytest.fixture | ||
| def storage( | ||
| self, | ||
| storage_config: SFTPStorageConfig, | ||
| mock_command_executor: AsyncMock, | ||
| mock_file_service: AsyncMock, | ||
| ) -> SFTPStorage: | ||
| return SFTPStorage(storage_config, mock_command_executor, mock_file_service) | ||
|
|
||
| def _make_mock_process(self, return_code: int = 0) -> AsyncMock: | ||
| mock_process = AsyncMock() | ||
| mock_process.pid = 12345 | ||
| mock_process.wait.return_value = return_code | ||
| mock_process.stdout = AsyncMock() | ||
| mock_process.stderr = AsyncMock() | ||
| mock_process.stdout.readline = AsyncMock(return_value=b"") | ||
| mock_process.stderr.readline = AsyncMock(return_value=b"") | ||
| return mock_process | ||
|
|
||
| def test_get_sensitive_fields(self, storage: SFTPStorage) -> None: | ||
| assert "password" in storage.get_sensitive_fields() | ||
| assert "private_key" in storage.get_sensitive_fields() | ||
|
|
||
| def test_get_connection_info(self, storage: SFTPStorage) -> None: | ||
| info = storage.get_connection_info() | ||
| assert info.provider == "sftp" | ||
| assert info.details["host"] == "nas.example.com" | ||
| assert info.details["port"] == 22 | ||
| assert info.details["username"] == "backup" | ||
| assert info.details["remote_path"] == "/backups" | ||
| assert info.details["auth_method"] == "password" | ||
|
|
||
| def test_get_connection_info_private_key( | ||
| self, mock_command_executor: AsyncMock, mock_file_service: AsyncMock | ||
| ) -> None: | ||
| config = SFTPStorageConfig( | ||
| host="nas.example.com", | ||
| username="backup", | ||
| remote_path="/backups", | ||
| private_key="-----BEGIN OPENSSH PRIVATE KEY-----\nfakekey\n-----END OPENSSH PRIVATE KEY-----", | ||
| ) | ||
| storage = SFTPStorage(config, mock_command_executor, mock_file_service) | ||
| info = storage.get_connection_info() | ||
| assert info.details["auth_method"] == "private_key" | ||
|
|
||
| async def test_upload_repository_success( | ||
| self, storage: SFTPStorage, mock_command_executor: AsyncMock | ||
| ) -> None: | ||
| mock_command_executor.create_subprocess.return_value = self._make_mock_process( | ||
| 0 | ||
| ) | ||
|
|
||
| progress_events = [] | ||
|
|
||
| def progress_callback(event: SyncEvent) -> None: | ||
| progress_events.append(event) | ||
|
|
||
| await storage.upload_repository( | ||
| repository_path="/path/to/repo", | ||
| remote_path="backups/test", | ||
| progress_callback=progress_callback, | ||
| ) | ||
|
|
||
| assert any(event.type.value == "started" for event in progress_events) | ||
| assert any(event.type.value == "completed" for event in progress_events) | ||
|
|
||
| async def test_upload_repository_failure( | ||
| self, storage: SFTPStorage, mock_command_executor: AsyncMock | ||
| ) -> None: | ||
| mock_command_executor.create_subprocess.return_value = self._make_mock_process( | ||
| 1 | ||
| ) | ||
|
|
||
| with pytest.raises(Exception, match="SFTP sync failed"): | ||
| await storage.upload_repository( | ||
| repository_path="/path/to/repo", | ||
| remote_path="backups/test", | ||
| progress_callback=lambda e: None, | ||
| ) | ||
|
|
||
| async def test_sync_does_not_include_hashcheck_flag_by_default( | ||
| self, storage: SFTPStorage, mock_command_executor: AsyncMock | ||
| ) -> None: | ||
| mock_command_executor.create_subprocess.return_value = self._make_mock_process( | ||
| 0 | ||
| ) | ||
|
|
||
| async for _ in storage.sync_repository_to_sftp( | ||
| repository=MagicMock(path="/repo"), | ||
| host="nas.example.com", | ||
| username="backup", | ||
| remote_path="/backups", | ||
| password="secret", | ||
| disable_hashcheck=False, | ||
| ): | ||
| pass | ||
|
|
||
| call_args = mock_command_executor.create_subprocess.call_args | ||
| command = call_args.kwargs.get("command") or call_args.args[0] | ||
| assert "--sftp-disable-hashcheck" not in command | ||
|
|
||
| async def test_sync_includes_hashcheck_flag_when_disabled( | ||
| self, storage: SFTPStorage, mock_command_executor: AsyncMock | ||
| ) -> None: | ||
| mock_command_executor.create_subprocess.return_value = self._make_mock_process( | ||
| 0 | ||
| ) | ||
|
|
||
| async for _ in storage.sync_repository_to_sftp( | ||
| repository=MagicMock(path="/repo"), | ||
| host="nas.example.com", | ||
| username="backup", | ||
| remote_path="/backups", | ||
| password="secret", | ||
| disable_hashcheck=True, | ||
| ): | ||
| pass | ||
|
|
||
| call_args = mock_command_executor.create_subprocess.call_args | ||
| command = call_args.kwargs.get("command") or call_args.args[0] | ||
| assert "--sftp-disable-hashcheck" in command | ||
|
|
||
| async def test_upload_repository_with_disable_checksums_config( | ||
| self, mock_command_executor: AsyncMock, mock_file_service: AsyncMock | ||
| ) -> None: | ||
| config = SFTPStorageConfig( | ||
| host="nas.example.com", | ||
| username="backup", | ||
| remote_path="/backups", | ||
| password="secret", | ||
| disable_server_side_checksums=True, | ||
| ) | ||
| storage = SFTPStorage(config, mock_command_executor, mock_file_service) | ||
| mock_command_executor.create_subprocess.return_value = self._make_mock_process( | ||
| 0 | ||
| ) | ||
|
|
||
| await storage.upload_repository( | ||
| repository_path="/path/to/repo", | ||
| remote_path="backups/test", | ||
| ) | ||
|
|
||
| call_args = mock_command_executor.create_subprocess.call_args | ||
| command = call_args.kwargs.get("command") or call_args.args[0] | ||
| assert "--sftp-disable-hashcheck" in command | ||
|
|
||
| async def test_upload_repository_without_disable_checksums_config( | ||
| self, storage: SFTPStorage, mock_command_executor: AsyncMock | ||
| ) -> None: | ||
| mock_command_executor.create_subprocess.return_value = self._make_mock_process( | ||
| 0 | ||
| ) | ||
|
|
||
| await storage.upload_repository( | ||
| repository_path="/path/to/repo", | ||
| remote_path="backups/test", | ||
| ) | ||
|
|
||
| call_args = mock_command_executor.create_subprocess.call_args | ||
| command = call_args.kwargs.get("command") or call_args.args[0] | ||
| assert "--sftp-disable-hashcheck" not in command | ||
|
|
||
| async def test_test_connection_success( | ||
| self, storage: SFTPStorage, mock_command_executor: AsyncMock | ||
| ) -> None: | ||
| mock_result = AsyncMock() | ||
| mock_result.success = True | ||
| mock_result.stdout = "" | ||
| mock_result.stderr = "" | ||
| mock_command_executor.execute_command.return_value = mock_result | ||
|
|
||
| result = await storage.test_connection() | ||
| assert result is True | ||
|
|
||
| async def test_test_connection_failure( | ||
| self, storage: SFTPStorage, mock_command_executor: AsyncMock | ||
| ) -> None: | ||
| mock_command_executor.execute_command.side_effect = Exception( | ||
| "Connection refused" | ||
| ) | ||
|
|
||
| result = await storage.test_connection() | ||
| assert result is False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.