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

This commit is contained in:
Dan Helfman
2025-02-22 09:55:07 -08:00
parent 087b7f5c7b
commit ad3392ca15
2 changed files with 9 additions and 2 deletions
+1
View File
@@ -55,6 +55,7 @@ def make_environment(config):
if 'encryption_passphrase' in config:
environment.pop('BORG_PASSPHRASE', None)
environment.pop('BORG_PASSCOMMAND', None)
if 'encryption_passcommand' in config:
environment.pop('BORG_PASSCOMMAND', None)
+8 -2
View File
@@ -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():
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(
'resolve_credential'
).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'})
assert environment.get('BORG_PASSPHRASE') is None
assert environment.get('BORG_PASSCOMMAND') is None
assert environment.get('BORG_PASSPHRASE_FD') == '3'
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(
'resolve_credential'
).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'})
assert environment.get('BORG_PASSPHRASE') is None
assert environment.get('BORG_PASSCOMMAND') is None
assert environment.get('BORG_PASSPHRASE_FD') == '3'