mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Implement password prompt steps in pytest-bdd
- Scaffold some tests that will be added later - Add fixtures for journal name and keyring type - Add "we should be prompted for a password" step - Add "we should not be prompted for a password" step Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
parent
d0f92113f4
commit
6b27126c37
2 changed files with 69 additions and 7 deletions
|
@ -22,3 +22,41 @@ Feature: Using the installed keyring
|
||||||
Then we should get no error
|
Then we should get no error
|
||||||
And the output should not contain "Failed to retrieve keyring"
|
And the output should not contain "Failed to retrieve keyring"
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Encrypt journal with no keyring backend and do store in keyring
|
||||||
|
Given we use the config "simple.yaml"
|
||||||
|
When we run "jrnl test entry"
|
||||||
|
And we run "jrnl --encrypt" and enter
|
||||||
|
password
|
||||||
|
password
|
||||||
|
y
|
||||||
|
Then we should get no error
|
||||||
|
And the output should not contain "Failed to retrieve keyring"
|
||||||
|
# @todo add step to check contents of keyring
|
||||||
|
|
||||||
|
|
||||||
|
@todo
|
||||||
|
Scenario: Open an encrypted journal with wrong password in keyring
|
||||||
|
# This should ask the user for the password after the keyring fails
|
||||||
|
|
||||||
|
|
||||||
|
@todo
|
||||||
|
Scenario: Decrypt journal with password in keyring
|
||||||
|
|
||||||
|
|
||||||
|
@todo
|
||||||
|
Scenario: Decrypt journal without a keyring
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Encrypt journal when keyring exists but fails
|
||||||
|
Given we use the config "simple.yaml"
|
||||||
|
And we have a failed keyring
|
||||||
|
When we run "jrnl --encrypt" and enter
|
||||||
|
this password will not be saved in keyring
|
||||||
|
this password will not be saved in keyring
|
||||||
|
y
|
||||||
|
Then we should see the message "Failed to retrieve keyring"
|
||||||
|
And we should get no error
|
||||||
|
And we should be prompted for a password
|
||||||
|
And the config for journal "default" should have "encrypt" set to "bool:True"
|
||||||
|
|
||||||
|
|
|
@ -133,15 +133,28 @@ def keyring():
|
||||||
set_keyring(NoKeyring())
|
set_keyring(NoKeyring())
|
||||||
|
|
||||||
|
|
||||||
|
@fixture
|
||||||
|
def keyring_type():
|
||||||
|
return "default"
|
||||||
|
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
def config_data(config_path):
|
def config_data(config_path):
|
||||||
return load_config(config_path)
|
return load_config(config_path)
|
||||||
|
|
||||||
|
|
||||||
|
@fixture
|
||||||
|
def journal_name():
|
||||||
|
return None
|
||||||
|
|
||||||
# ----- STEPS ----- #
|
# ----- STEPS ----- #
|
||||||
@given("we have a keyring", target_fixture="keyring")
|
@given("we have a keyring", target_fixture="keyring")
|
||||||
def we_have_keyring():
|
@given(parse("we have a {keyring_type} keyring"), target_fixture="keyring")
|
||||||
set_keyring(FailedKeyring())
|
def we_have_type_of_keyring(keyring_type):
|
||||||
|
if keyring_type == "failed":
|
||||||
|
set_keyring(FailedKeyring())
|
||||||
|
else:
|
||||||
|
set_keyring(TestKeyring())
|
||||||
|
|
||||||
|
|
||||||
@given(parse('we use the config "{config_file}"'), target_fixture="config_path")
|
@given(parse('we use the config "{config_file}"'), target_fixture="config_path")
|
||||||
|
@ -270,15 +283,26 @@ def should_see_the_message(text, cli_run):
|
||||||
assert text in out, [text, out]
|
assert text in out, [text, out]
|
||||||
|
|
||||||
|
|
||||||
@then(parse('the config should have "{key}" set to'))
|
@then(parse('the config should have "{key}" set to\n{value}'))
|
||||||
@then(parse('the config should have "{key}" set to "{value}"'))
|
@then(parse('the config should have "{key}" set to "{value}"'))
|
||||||
@then(parse('the config for journal "{journal}" should have "{key}" set to "{value}"'))
|
@then(parse('the config for journal "{journal_name}" should have "{key}" set to "{value}"'))
|
||||||
def config_var(config_data, key, value="", journal=None):
|
def config_var(config_data, key, value, journal_name):
|
||||||
value = read_value_from_string(value)
|
value = read_value_from_string(value)
|
||||||
|
|
||||||
configuration = config_data
|
configuration = config_data
|
||||||
if journal:
|
if journal_name:
|
||||||
configuration = configuration["journals"][journal]
|
configuration = configuration["journals"][journal_name]
|
||||||
|
|
||||||
assert key in configuration
|
assert key in configuration
|
||||||
assert configuration[key] == value
|
assert configuration[key] == value
|
||||||
|
|
||||||
|
|
||||||
|
@then("we should be prompted for a password")
|
||||||
|
def password_was_called(cli_run):
|
||||||
|
assert cli_run["mocks"]["getpass"].called
|
||||||
|
|
||||||
|
|
||||||
|
@then("we should not be prompted for a password")
|
||||||
|
def password_was_not_called(cli_run):
|
||||||
|
assert not cli_run["mocks"]["getpass"].called
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue