Browse Source

Ignore the BORG_PASSCOMMAND environment variable when the "encryption_passphase" option is set.

Dan Helfman 3 months ago
parent
commit
ad3392ca15
2 changed files with 9 additions and 2 deletions
  1. 1 0
      borgmatic/borg/environment.py
  2. 8 2
      tests/unit/borg/test_environment.py

+ 1 - 0
borgmatic/borg/environment.py

@@ -55,6 +55,7 @@ def make_environment(config):
 
 
     if 'encryption_passphrase' in config:
     if 'encryption_passphrase' in config:
         environment.pop('BORG_PASSPHRASE', None)
         environment.pop('BORG_PASSPHRASE', None)
+        environment.pop('BORG_PASSCOMMAND', None)
 
 
     if 'encryption_passcommand' in config:
     if 'encryption_passcommand' in config:
         environment.pop('BORG_PASSCOMMAND', None)
         environment.pop('BORG_PASSCOMMAND', None)

+ 8 - 2
tests/unit/borg/test_environment.py

@@ -4,7 +4,9 @@ from borgmatic.borg import environment as module
 
 
 
 
 def test_make_environment_with_passcommand_should_call_it_and_set_passphrase_file_descriptor_in_environment():
 def test_make_environment_with_passcommand_should_call_it_and_set_passphrase_file_descriptor_in_environment():
-    flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.os).should_receive('environ').and_return(
+        {'USER': 'root', 'BORG_PASSCOMMAND': 'nope'}
+    )
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential'
         'resolve_credential'
     ).and_return(None)
     ).and_return(None)
@@ -18,12 +20,15 @@ def test_make_environment_with_passcommand_should_call_it_and_set_passphrase_fil
 
 
     environment = module.make_environment({'encryption_passcommand': 'command'})
     environment = module.make_environment({'encryption_passcommand': 'command'})
 
 
+    assert environment.get('BORG_PASSPHRASE') is None
     assert environment.get('BORG_PASSCOMMAND') is None
     assert environment.get('BORG_PASSCOMMAND') is None
     assert environment.get('BORG_PASSPHRASE_FD') == '3'
     assert environment.get('BORG_PASSPHRASE_FD') == '3'
 
 
 
 
 def test_make_environment_with_passphrase_should_set_passphrase_file_descriptor_in_environment():
 def test_make_environment_with_passphrase_should_set_passphrase_file_descriptor_in_environment():
-    flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.os).should_receive('environ').and_return(
+        {'USER': 'root', 'BORG_PASSPHRASE': 'nope', 'BORG_PASSCOMMAND': 'nope'}
+    )
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential'
         'resolve_credential'
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
@@ -38,6 +43,7 @@ def test_make_environment_with_passphrase_should_set_passphrase_file_descriptor_
     environment = module.make_environment({'encryption_passphrase': 'pass'})
     environment = module.make_environment({'encryption_passphrase': 'pass'})
 
 
     assert environment.get('BORG_PASSPHRASE') is None
     assert environment.get('BORG_PASSPHRASE') is None
+    assert environment.get('BORG_PASSCOMMAND') is None
     assert environment.get('BORG_PASSPHRASE_FD') == '3'
     assert environment.get('BORG_PASSPHRASE_FD') == '3'