From 1a0fa8267768d6dc2e71f0cfbd567caff2bf8194 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Thu, 28 May 2020 00:38:14 -0400 Subject: [PATCH] add tests --- features/encryption.feature | 24 ++++++++++++++++++++++++ features/steps/core.py | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/features/encryption.feature b/features/encryption.feature index 787fa850..02f8b423 100644 --- a/features/encryption.feature +++ b/features/encryption.feature @@ -55,3 +55,27 @@ Then the config for journal "simple" should have "encrypt" set to "bool:True" When we run "jrnl simple -n 1" 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 diff --git a/features/steps/core.py b/features/steps/core.py index 99ac9859..82581f9c 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -40,6 +40,21 @@ class TestKeyring(keyring.backend.KeyringBackend): def delete_password(self, servicename, username): self.keys[servicename][username] = None +class NoKeyring(keyring.backend.KeyringBackend): + """A test keyring that just stores its values in a hash""" + + 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 keyring.set_keyring(TestKeyring()) @@ -201,6 +216,10 @@ def set_keychain(context, 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") def has_error(context): assert context.exit_status != 0, context.exit_status