Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt for password change when using 'jrnl --encrypt' on already encrypted journal #1477

Merged
merged 11 commits into from
May 21, 2022
Merged
10 changes: 8 additions & 2 deletions jrnl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from jrnl.messages import Message
from jrnl.messages import MsgText
from jrnl.messages import MsgType
from jrnl.prompt import create_password


def preconfig_diagnostic(_):
Expand Down Expand Up @@ -84,9 +85,14 @@ def postconfig_encrypt(args, config, original_config, **kwargs):
)
)

journal.config["encrypt"] = True

new_journal = EncryptedJournal.from_journal(journal)

# If journal is encrypted, create new password
if journal.config["encrypt"] is True:
print(f"Journal {journal.name} is already encrypted. Create a new password.")
new_journal.password = create_password(new_journal.name)

journal.config["encrypt"] = True
new_journal.write(args.filename)

print(
Expand Down
7 changes: 4 additions & 3 deletions tests/bdd/features/encrypt.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ Feature: Encrypting and decrypting journals
2013-06-10 15:40 Life is good.


@todo
Scenario: Trying to encrypt an already encrypted journal
# This should warn the user that the journal is already encrypted

Given we use the config "encrypted.yaml"
When we run "jrnl --encrypt" and enter "bad doggie no biscuit"
Then the output should contain "already encrypted. Create a new password."
Then we should be prompted for a password

Scenario Outline: Encrypting a journal
Given we use the config "simple.yaml"
Expand Down