test_keepassxc.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import pytest
  2. from flexmock import flexmock
  3. from borgmatic.hooks.credential import keepassxc as module
  4. @pytest.mark.parametrize('credential_parameters', ((), ('foo',), ('foo', 'bar', 'baz')))
  5. def test_load_credential_with_invalid_credential_parameters_raises(credential_parameters):
  6. flexmock(module.borgmatic.execute).should_receive('execute_command_and_capture_output').never()
  7. with pytest.raises(ValueError):
  8. module.load_credential(
  9. hook_config={}, config={}, credential_parameters=credential_parameters
  10. )
  11. def test_load_credential_with_missing_database_raises():
  12. flexmock(module.os.path).should_receive('exists').and_return(False)
  13. flexmock(module.borgmatic.execute).should_receive('execute_command_and_capture_output').never()
  14. with pytest.raises(ValueError):
  15. module.load_credential(
  16. hook_config={}, config={}, credential_parameters=('database.kdbx', 'mypassword')
  17. )
  18. def test_load_credential_with_present_database_fetches_password_from_keepassxc():
  19. flexmock(module.os.path).should_receive('exists').and_return(True)
  20. flexmock(module.borgmatic.execute).should_receive(
  21. 'execute_command_and_capture_output'
  22. ).and_return('password').once()
  23. assert (
  24. module.load_credential(
  25. hook_config={}, config={}, credential_parameters=('database.kdbx', 'mypassword')
  26. )
  27. == 'password'
  28. )