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:
Jonathan Wren 2021-03-02 21:09:33 -08:00
parent d0f92113f4
commit 6b27126c37
2 changed files with 69 additions and 7 deletions

View file

@ -22,3 +22,41 @@ Feature: Using the installed keyring
Then we should get no error
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"

View file

@ -133,15 +133,28 @@ def keyring():
set_keyring(NoKeyring())
@fixture
def keyring_type():
return "default"
@fixture
def config_data(config_path):
return load_config(config_path)
@fixture
def journal_name():
return None
# ----- STEPS ----- #
@given("we have a keyring", target_fixture="keyring")
def we_have_keyring():
@given(parse("we have a {keyring_type} keyring"), target_fixture="keyring")
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")
@ -270,15 +283,26 @@ def should_see_the_message(text, cli_run):
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 for journal "{journal}" should have "{key}" set to "{value}"'))
def config_var(config_data, key, value="", journal=None):
@then(parse('the config for journal "{journal_name}" should have "{key}" set to "{value}"'))
def config_var(config_data, key, value, journal_name):
value = read_value_from_string(value)
configuration = config_data
if journal:
configuration = configuration["journals"][journal]
if journal_name:
configuration = configuration["journals"][journal_name]
assert key in configuration
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