|
@@ -5,6 +5,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.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential'
|
|
|
+ ).and_return(None)
|
|
|
flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
'get_passphrase_from_passcommand'
|
|
|
).and_return('passphrase')
|
|
@@ -21,12 +24,12 @@ def test_make_environment_with_passcommand_should_call_it_and_set_passphrase_fil
|
|
|
|
|
|
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.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
- ).and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
'resolve_credential'
|
|
|
).replace_with(lambda value, config: value)
|
|
|
+ flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
+ 'get_passphrase_from_passcommand'
|
|
|
+ ).and_return(None)
|
|
|
flexmock(module.os).should_receive('pipe').and_return((3, 4))
|
|
|
flexmock(module.os).should_receive('write')
|
|
|
flexmock(module.os).should_receive('close')
|
|
@@ -41,12 +44,12 @@ def test_make_environment_with_passphrase_should_set_passphrase_file_descriptor_
|
|
|
def test_make_environment_with_credential_tag_passphrase_should_load_it_and_set_passphrase_file_descriptor_in_environment():
|
|
|
flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
|
|
|
config = {'encryption_passphrase': '{credential systemd pass}'}
|
|
|
- flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
- ).and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
'resolve_credential',
|
|
|
).with_args('{credential systemd pass}', config).and_return('pass')
|
|
|
+ flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
+ 'get_passphrase_from_passcommand'
|
|
|
+ ).never()
|
|
|
flexmock(module.os).should_receive('pipe').and_return((3, 4))
|
|
|
flexmock(module.os).should_receive('write')
|
|
|
flexmock(module.os).should_receive('close')
|
|
@@ -60,8 +63,8 @@ def test_make_environment_with_credential_tag_passphrase_should_load_it_and_set_
|
|
|
|
|
|
def test_make_environment_with_ssh_command_should_set_environment():
|
|
|
flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
|
|
|
- flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential'
|
|
|
).and_return(None)
|
|
|
flexmock(module.os).should_receive('pipe').never()
|
|
|
environment = module.make_environment({'ssh_command': 'ssh -C'})
|
|
@@ -71,8 +74,8 @@ def test_make_environment_with_ssh_command_should_set_environment():
|
|
|
|
|
|
def test_make_environment_without_configuration_sets_certain_environment_variables():
|
|
|
flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
|
|
|
- flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential'
|
|
|
).and_return(None)
|
|
|
flexmock(module.os).should_receive('pipe').never()
|
|
|
environment = module.make_environment({})
|
|
@@ -94,8 +97,8 @@ def test_make_environment_without_configuration_passes_through_default_environme
|
|
|
'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK': 'nah',
|
|
|
}
|
|
|
)
|
|
|
- flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential'
|
|
|
).and_return(None)
|
|
|
flexmock(module.os).should_receive('pipe').never()
|
|
|
environment = module.make_environment({})
|
|
@@ -110,8 +113,8 @@ def test_make_environment_without_configuration_passes_through_default_environme
|
|
|
|
|
|
def test_make_environment_with_relocated_repo_access_true_should_set_environment_yes():
|
|
|
flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
|
|
|
- flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential'
|
|
|
).and_return(None)
|
|
|
flexmock(module.os).should_receive('pipe').never()
|
|
|
environment = module.make_environment({'relocated_repo_access_is_ok': True})
|
|
@@ -121,8 +124,8 @@ def test_make_environment_with_relocated_repo_access_true_should_set_environment
|
|
|
|
|
|
def test_make_environment_with_relocated_repo_access_false_should_set_environment_no():
|
|
|
flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
|
|
|
- flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential'
|
|
|
).and_return(None)
|
|
|
flexmock(module.os).should_receive('pipe').never()
|
|
|
environment = module.make_environment({'relocated_repo_access_is_ok': False})
|
|
@@ -132,8 +135,8 @@ def test_make_environment_with_relocated_repo_access_false_should_set_environmen
|
|
|
|
|
|
def test_make_environment_check_i_know_what_i_am_doing_true_should_set_environment_YES():
|
|
|
flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
|
|
|
- flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential'
|
|
|
).and_return(None)
|
|
|
flexmock(module.os).should_receive('pipe').never()
|
|
|
environment = module.make_environment({'check_i_know_what_i_am_doing': True})
|
|
@@ -143,8 +146,8 @@ def test_make_environment_check_i_know_what_i_am_doing_true_should_set_environme
|
|
|
|
|
|
def test_make_environment_check_i_know_what_i_am_doing_false_should_set_environment_NO():
|
|
|
flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
|
|
|
- flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential'
|
|
|
).and_return(None)
|
|
|
flexmock(module.os).should_receive('pipe').never()
|
|
|
environment = module.make_environment({'check_i_know_what_i_am_doing': False})
|
|
@@ -154,9 +157,10 @@ def test_make_environment_check_i_know_what_i_am_doing_false_should_set_environm
|
|
|
|
|
|
def test_make_environment_with_integer_variable_value():
|
|
|
flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
|
|
|
- flexmock(module.borgmatic.borg.passcommand).should_receive(
|
|
|
- 'get_passphrase_from_passcommand'
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential'
|
|
|
).and_return(None)
|
|
|
flexmock(module.os).should_receive('pipe').never()
|
|
|
environment = module.make_environment({'borg_files_cache_ttl': 40})
|
|
|
+
|
|
|
assert environment.get('BORG_FILES_CACHE_TTL') == '40'
|