From 23efbb8df36ba81bf8e00f95100f390c9f51e3b0 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 25 Mar 2025 22:31:50 -0700 Subject: [PATCH] Fix line wrapping / code style (#837). --- borgmatic/config/schema.yaml | 15 ++++++++------- tests/unit/hooks/data_source/test_mongodb.py | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index ffbde0534..bb0dc7949 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -1729,20 +1729,21 @@ properties: mongodump_command: type: string description: | - Command to use instead of "mongodump". This can be used to - run a specific mongodump version (e.g., one inside a + Command to use instead of "mongodump". This can be used + to run a specific mongodump version (e.g., one inside a running container). If you run it from within a container, make sure to mount the path in the "user_runtime_directory" option from the host into the - container at the same location. Defaults to "mongodump". + container at the same location. Defaults to + "mongodump". example: docker exec mongodb_container mongodump mongorestore_command: type: string description: | - Command to run when restoring a database instead - of "mongorestore". This can be used to run a specific - mongorestore version (e.g., one inside a running container). - Defaults to "mongorestore". + Command to run when restoring a database instead of + "mongorestore". This can be used to run a specific + mongorestore version (e.g., one inside a running + container). Defaults to "mongorestore". example: docker exec mongodb_container mongorestore description: | List of one or more MongoDB databases to dump before creating a diff --git a/tests/unit/hooks/data_source/test_mongodb.py b/tests/unit/hooks/data_source/test_mongodb.py index 7ae036c9f..3cd0aff35 100644 --- a/tests/unit/hooks/data_source/test_mongodb.py +++ b/tests/unit/hooks/data_source/test_mongodb.py @@ -681,6 +681,8 @@ def test_restore_data_source_dump_without_extract_process_restores_from_disk(): }, borgmatic_runtime_directory='/run/borgmatic', ) + + def test_dump_data_sources_uses_custom_mongodump_command(): flexmock(module.borgmatic.hooks.command).should_receive('Before_after_hooks').and_return( flexmock() @@ -714,7 +716,8 @@ def test_dump_data_sources_uses_custom_mongodump_command(): patterns=[], dry_run=False, ) == [process] - + + def test_build_dump_command_prevents_shell_injection(): database = { 'name': 'testdb; rm -rf /', # Malicious input @@ -733,8 +736,11 @@ def test_build_dump_command_prevents_shell_injection(): # Ensure the malicious input is properly escaped and does not execute assert 'testdb; rm -rf /' not in command - assert any('testdb' in part for part in command) # Check if 'testdb' is in any part of the tuple - + assert any( + 'testdb' in part for part in command + ) # Check if 'testdb' is in any part of the tuple + + def test_restore_data_source_dump_uses_custom_mongorestore_command(): hook_config = [ { @@ -777,7 +783,8 @@ def test_restore_data_source_dump_uses_custom_mongorestore_command(): }, borgmatic_runtime_directory='/run/borgmatic', ) - + + def test_build_restore_command_prevents_shell_injection(): database = { 'name': 'testdb; rm -rf /', # Malicious input @@ -801,11 +808,8 @@ def test_build_restore_command_prevents_shell_injection(): command = module.build_restore_command( extract_process, database, config, dump_filename, connection_params ) - + # print(command) # Ensure the malicious input is properly escaped and does not execute assert 'rm -rf /' not in command assert ';' not in command - - -