From 92ebc77597fc7504ebfaa1775ef3f603cf8e77e7 Mon Sep 17 00:00:00 2001 From: Gautam Aggarwal Date: Sun, 30 Mar 2025 16:19:56 +0000 Subject: [PATCH] 2nd Draft --- borgmatic/config/schema.yaml | 2 +- tests/unit/hooks/credential/test_keepassxc.py | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 33f0580c1..15c04ee3f 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -2683,7 +2683,7 @@ properties: description: | Command to use instead of "keepassxc-cli". example: /usr/local/bin/keepassxc-cli - key_file: + key-file: type: string description: | Path to a key file for unlocking the KeePassXC database. diff --git a/tests/unit/hooks/credential/test_keepassxc.py b/tests/unit/hooks/credential/test_keepassxc.py index 9fddf1331..c7c2306f1 100644 --- a/tests/unit/hooks/credential/test_keepassxc.py +++ b/tests/unit/hooks/credential/test_keepassxc.py @@ -181,3 +181,43 @@ def test_load_credential_with_yubikey(): ) == 'password' ) + + +def test_load_credential_with_key_file_and_yubikey(): + flexmock(module.os.path).should_receive('expanduser').with_args('database.kdbx').and_return( + 'database.kdbx' + ) + flexmock(module.os.path).should_receive('exists').and_return(True) + flexmock(module.borgmatic.execute).should_receive( + 'execute_command_and_capture_output' + ).with_args( + ( + 'keepassxc-cli', + 'show', + '--show-protected', + '--attributes', + 'Password', + 'database.kdbx', + 'mypassword', + '--key-file', + '/path/to/keyfile', + '--yubikey', + ) + ).and_return( + 'password' + ).once() + + assert ( + module.load_credential( + hook_config={}, + config={}, + credential_parameters=( + 'database.kdbx', + 'mypassword', + '--key-file', + '/path/to/keyfile', + '--yubikey', + ), + ) + == 'password' + )