mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Fix set_keychain errors (#964)
* fix keyring problems * black * remove else and use stderr * black * add tests * black * change description of nokeyring * dumb syntax error
This commit is contained in:
parent
ca482b0a46
commit
0b9137c17d
3 changed files with 52 additions and 4 deletions
|
@ -55,3 +55,27 @@
|
||||||
Then the config for journal "simple" should have "encrypt" set to "bool:True"
|
Then the config for journal "simple" should have "encrypt" set to "bool:True"
|
||||||
When we run "jrnl simple -n 1"
|
When we run "jrnl simple -n 1"
|
||||||
Then the output should contain "2013-06-10 15:40 Life is good"
|
Then the output should contain "2013-06-10 15:40 Life is good"
|
||||||
|
|
||||||
|
Scenario: Encrypt journal with no keyring backend and do not store in keyring
|
||||||
|
Given we use the config "basic.yaml"
|
||||||
|
When we disable the keychain
|
||||||
|
and we run "jrnl test entry"
|
||||||
|
and we run "jrnl --encrypt" and enter
|
||||||
|
"""
|
||||||
|
password
|
||||||
|
password
|
||||||
|
n
|
||||||
|
"""
|
||||||
|
Then we should get no error
|
||||||
|
|
||||||
|
Scenario: Encrypt journal with no keyring backend and do store in keyring
|
||||||
|
Given we use the config "basic.yaml"
|
||||||
|
When we disable the keychain
|
||||||
|
and we run "jrnl test entry"
|
||||||
|
and we run "jrnl --encrypt" and enter
|
||||||
|
"""
|
||||||
|
password
|
||||||
|
password
|
||||||
|
y
|
||||||
|
"""
|
||||||
|
Then we should get no error
|
||||||
|
|
|
@ -41,6 +41,22 @@ class TestKeyring(keyring.backend.KeyringBackend):
|
||||||
self.keys[servicename][username] = None
|
self.keys[servicename][username] = None
|
||||||
|
|
||||||
|
|
||||||
|
class NoKeyring(keyring.backend.KeyringBackend):
|
||||||
|
"""A keyring that simulated an environment with no keyring backend."""
|
||||||
|
|
||||||
|
priority = 2
|
||||||
|
keys = defaultdict(dict)
|
||||||
|
|
||||||
|
def set_password(self, servicename, username, password):
|
||||||
|
raise keyring.errors.NoKeyringError
|
||||||
|
|
||||||
|
def get_password(self, servicename, username):
|
||||||
|
raise keyring.errors.NoKeyringError
|
||||||
|
|
||||||
|
def delete_password(self, servicename, username):
|
||||||
|
raise keyring.errors.NoKeyringError
|
||||||
|
|
||||||
|
|
||||||
# set the keyring for keyring lib
|
# set the keyring for keyring lib
|
||||||
keyring.set_keyring(TestKeyring())
|
keyring.set_keyring(TestKeyring())
|
||||||
|
|
||||||
|
@ -208,6 +224,11 @@ def set_keychain(context, journal, password):
|
||||||
keyring.set_password("jrnl", journal, password)
|
keyring.set_password("jrnl", journal, password)
|
||||||
|
|
||||||
|
|
||||||
|
@when("we disable the keychain")
|
||||||
|
def disable_keychain(context):
|
||||||
|
keyring.core.set_keyring(NoKeyring())
|
||||||
|
|
||||||
|
|
||||||
@then("we should get an error")
|
@then("we should get an error")
|
||||||
def has_error(context):
|
def has_error(context):
|
||||||
assert context.exit_status != 0, context.exit_status
|
assert context.exit_status != 0, context.exit_status
|
||||||
|
|
11
jrnl/util.py
11
jrnl/util.py
|
@ -59,9 +59,6 @@ def create_password(
|
||||||
|
|
||||||
if yesno("Do you want to store the password in your keychain?", default=True):
|
if yesno("Do you want to store the password in your keychain?", default=True):
|
||||||
set_keychain(journal_name, pw)
|
set_keychain(journal_name, pw)
|
||||||
else:
|
|
||||||
set_keychain(journal_name, None)
|
|
||||||
|
|
||||||
return pw
|
return pw
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,7 +104,13 @@ def set_keychain(journal_name, password):
|
||||||
except keyring.errors.PasswordDeleteError:
|
except keyring.errors.PasswordDeleteError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
keyring.set_password("jrnl", journal_name, password)
|
try:
|
||||||
|
keyring.set_password("jrnl", journal_name, password)
|
||||||
|
except keyring.errors.NoKeyringError:
|
||||||
|
print(
|
||||||
|
"Keyring backend not found. Please install one of the supported backends by visiting: https://pypi.org/project/keyring/",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def yesno(prompt, default=True):
|
def yesno(prompt, default=True):
|
||||||
|
|
Loading…
Add table
Reference in a new issue