mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Tests for storing password in keychain
This commit is contained in:
parent
ab12294777
commit
13b7d1c1df
3 changed files with 31 additions and 9 deletions
|
@ -9,6 +9,7 @@
|
|||
"password": "",
|
||||
"journals": {
|
||||
"default": "features/journals/simple.journal",
|
||||
"simple": "features/journals/simple.journal",
|
||||
"work": "features/journals/work.journal",
|
||||
"ideas": "features/journals/nothing.journal"
|
||||
},
|
||||
|
|
|
@ -9,15 +9,24 @@
|
|||
Scenario: Decrypting a journal
|
||||
Given we use the config "encrypted.json"
|
||||
When we run "jrnl --decrypt" and enter "bad doggie no biscuit"
|
||||
Then the config for journal "default" should have "encrypt" set to "bool:False"
|
||||
Then we should see the message "Journal decrypted"
|
||||
and the journal should have 2 entries
|
||||
and the config should have "encrypt" set to "bool:False"
|
||||
|
||||
Scenario: Encrypting a journal
|
||||
Given we use the config "basic.json"
|
||||
When we run "jrnl --encrypt" and enter "swordfish"
|
||||
Then we should see the message "Journal encrypted"
|
||||
and the config should have "encrypt" set to "bool:True"
|
||||
and the config for journal "default" should have "encrypt" set to "bool:True"
|
||||
When we run "jrnl -n 1" and enter "swordfish"
|
||||
Then we should see the message "Password"
|
||||
and the output should contain "2013-06-10 15:40 Life is good"
|
||||
|
||||
Scenario: Storing a password in Keychain
|
||||
Given we use the config "multiple.json"
|
||||
When we run "jrnl simple --encrypt" and enter "sabertooth"
|
||||
When we set the keychain password of "simple" to "sabertooth"
|
||||
Then the config for journal "simple" should have "encrypt" set to "bool:True"
|
||||
When we run "jrnl simple -n 1"
|
||||
Then we should not see the message "Password"
|
||||
and the output should contain "2013-06-10 15:40 Life is good"
|
||||
|
|
|
@ -5,6 +5,7 @@ import os
|
|||
import sys
|
||||
import json
|
||||
import pytz
|
||||
import keyring
|
||||
try:
|
||||
from io import StringIO
|
||||
except ImportError:
|
||||
|
@ -34,11 +35,11 @@ def read_journal(journal_name="default"):
|
|||
def open_journal(journal_name="default"):
|
||||
with open(jrnl.CONFIG_PATH) as config_file:
|
||||
config = json.load(config_file)
|
||||
journals = config['journals']
|
||||
if type(journals) is dict: # We can override the default config on a by-journal basis
|
||||
config['journal'] = journals.get(journal_name)
|
||||
journal_conf = config['journals'][journal_name]
|
||||
if type(journal_conf) is dict: # We can override the default config on a by-journal basis
|
||||
config.update(journal_conf)
|
||||
else: # But also just give them a string to point to the journal file
|
||||
config['journal'] = journal
|
||||
config['journal'] = journal_conf
|
||||
return Journal.Journal(**config)
|
||||
|
||||
@given('we use the config "{config_file}"')
|
||||
|
@ -68,6 +69,10 @@ def run(context, command):
|
|||
except SystemExit as e:
|
||||
context.exit_status = e.code
|
||||
|
||||
@when('we set the keychain password of "{journal}" to "{password}"')
|
||||
def set_keychain(context, journal, password):
|
||||
keyring.set_password('jrnl', journal, password)
|
||||
|
||||
@then('we should get an error')
|
||||
def has_error(context):
|
||||
assert context.exit_status != 0, context.exit_status
|
||||
|
@ -134,6 +139,11 @@ def check_message(context, text):
|
|||
out = context.messages.getvalue()
|
||||
assert text in out, [text, out]
|
||||
|
||||
@then('we should not see the message "{text}"')
|
||||
def check_not_message(context, text):
|
||||
out = context.messages.getvalue()
|
||||
assert text not in out, [text, out]
|
||||
|
||||
@then('the journal should contain "{text}"')
|
||||
@then('journal "{journal_name}" should contain "{text}"')
|
||||
def check_journal_content(context, text, journal_name="default"):
|
||||
|
@ -148,7 +158,8 @@ def journal_doesnt_exist(context, journal_name="default"):
|
|||
assert not os.path.exists(journal_path)
|
||||
|
||||
@then('the config should have "{key}" set to "{value}"')
|
||||
def config_var(context, key, value):
|
||||
@then('the config for journal "{journal}" should have "{key}" set to "{value}"')
|
||||
def config_var(context, key, value, journal=None):
|
||||
t, value = value.split(":")
|
||||
value = {
|
||||
"bool": lambda v: v.lower() == "true",
|
||||
|
@ -157,6 +168,8 @@ def config_var(context, key, value):
|
|||
}[t](value)
|
||||
with open(jrnl.CONFIG_PATH) as config_file:
|
||||
config = json.load(config_file)
|
||||
if journal:
|
||||
config = config["journals"][journal]
|
||||
assert key in config
|
||||
assert config[key] == value
|
||||
|
||||
|
@ -171,4 +184,3 @@ def check_journal_content(context, number, journal_name="default"):
|
|||
@then('fail')
|
||||
def debug_fail(context):
|
||||
assert False
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue