Rework Encryption to enable future support of other encryption methods (#1602)

- initial pass through to rework encryption into separate module
- little more cleanup
- rename function, fix some linting issues
- more cleaning
- fix password bug in encryption
- fix linting issue
- more cleanup
- move prompt into prompt.py
- more cleanup
- update the upgrade process for new encryption classes
- general cleanup
- turn into enum instead of strings
- store status code so tests don't fail
- standardize the load and store methods in journals
- get rid of old PlainJournal class
- typing cleanup
- more cleanup
- format
- fix linting issue
- Fix obscure Windows line ending issue with decode
  See https://bugs.python.org/issue40863
- fix for python 3.11
- add more typing
- don't use class variables because that's not what we want
- fix more type hints
- jrnlv1 encryption doesn't support encryption anymore (it's deprecated)
- keep logic for password attemps inside the class that uses it
- take out old line of code
- add some more logging
- update logging statements
- clean up logging statements
- run linters
- fix typo
- Fix for new test from develop branch
  There was a new test added for re-encrypting a journal. This updates the
  refactor to match the old (previously untested) behavior of jrnl.

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
Jonathan Wren 2022-11-19 13:39:39 -08:00 committed by GitHub
parent e6e08e5d3e
commit fcc8d8e3fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 437 additions and 267 deletions

View file

@ -48,6 +48,7 @@ Feature: Encrypting and decrypting journals
Scenario: Encrypt journal twice and get prompted each time
Given we use the config "simple.yaml"
And we don't have a keyring
When we run "jrnl --encrypt" and enter
swordfish
swordfish
@ -56,7 +57,26 @@ Feature: Encrypting and decrypting journals
And the output should contain "Journal encrypted"
When we run "jrnl --encrypt" and enter
swordfish
tuna
tuna
y
Then we should get no error
And the output should contain "Journal default is already encrypted. Create a new password."
And we should be prompted for a password
And the config for journal "default" should contain "encrypt: true"
Scenario: Encrypt journal twice and get prompted each time with keyring
Given we use the config "simple.yaml"
And we have a keyring
When we run "jrnl --encrypt" and enter
swordfish
swordfish
y
Then we should get no error
And the output should contain "Journal encrypted"
When we run "jrnl --encrypt" and enter
tuna
tuna
y
Then we should get no error
And the output should contain "Journal default is already encrypted. Create a new password."

View file

@ -17,6 +17,7 @@ from pytest_bdd.parsers import parse
from jrnl import __version__
from jrnl.time import __get_pdt_calendar
from tests.lib.fixtures import FailedKeyring
from tests.lib.fixtures import NoKeyring
from tests.lib.fixtures import TestKeyring
from tests.lib.helpers import get_fixture
@ -67,13 +68,20 @@ def now_is_str(date_str, mock_factories):
)
@given("we don't have a keyring", target_fixture="keyring")
def we_dont_have_keyring(keyring_type):
return NoKeyring()
@given("we have a keyring", target_fixture="keyring")
@given(parse("we have a {keyring_type} keyring"), target_fixture="keyring")
def we_have_type_of_keyring(keyring_type):
if keyring_type == "failed":
return FailedKeyring()
else:
return TestKeyring()
match keyring_type:
case "failed":
return FailedKeyring()
case _:
return TestKeyring()
@given(parse('we use the config "{config_file}"'), target_fixture="config_path")

View file

@ -44,7 +44,7 @@ def we_run_jrnl(cli_run, capsys, keyring):
mocks[id] = stack.enter_context(factories[id]())
try:
cli()
cli_run["status"] = cli() or 0
except StopIteration:
# This happens when input is expected, but don't have any input left
pass