瀏覽代碼

When both "encryption_passcommand" and "encryption_passphrase" are configured, prefer "encryption_passphrase" even if it's an empty value (#987).

Dan Helfman 4 月之前
父節點
當前提交
23009e22aa
共有 3 個文件被更改,包括 19 次插入1 次删除
  1. 2 0
      NEWS
  2. 1 1
      borgmatic/borg/passcommand.py
  3. 16 0
      tests/unit/borg/test_passcommand.py

+ 2 - 0
NEWS

@@ -1,5 +1,7 @@
 1.9.10.dev0
  * #987: Fix a "list" action error when the "encryption_passcommand" option is set.
+ * #987: When both "encryption_passcommand" and "encryption_passphrase" are configured, prefer
+   "encryption_passphrase" even if it's an empty value.
 
 1.9.9
  * #635: Log the repository path or label on every relevant log message, not just some logs.

+ 1 - 1
borgmatic/borg/passcommand.py

@@ -47,4 +47,4 @@ def get_passphrase_from_passcommand(config):
     passphrase = config.get('encryption_passphrase')
     working_directory = borgmatic.config.paths.get_working_directory(config)
 
-    return run_passcommand(passcommand, bool(passphrase), working_directory)
+    return run_passcommand(passcommand, bool(passphrase is not None), working_directory)

+ 16 - 0
tests/unit/borg/test_passcommand.py

@@ -53,3 +53,19 @@ def test_get_passphrase_from_passcommand_with_configured_passphrase_and_passcomm
         )
         is None
     )
+
+
+def test_get_passphrase_from_passcommand_with_configured_blank_passphrase_and_passcommand_detects_passphrase():
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
+        '/working'
+    )
+    flexmock(module).should_receive('run_passcommand').with_args(
+        'command', True, '/working'
+    ).and_return(None).once()
+
+    assert (
+        module.get_passphrase_from_passcommand(
+            {'encryption_passphrase': '', 'encryption_passcommand': 'command'},
+        )
+        is None
+    )