From 663f1519740c9e18f33af3cfbb5f573e8bdd6fbb Mon Sep 17 00:00:00 2001 From: Jonathan van der Steege Date: Sat, 21 May 2022 23:11:55 +0200 Subject: [PATCH] Prompt for password change when using 'jrnl --encrypt' on already encrypted journal (#1477) * Create new password if journal already encrypted. * Add test for encrypting already encrypted journal. --- jrnl/commands.py | 10 ++++++++-- tests/bdd/features/encrypt.feature | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/jrnl/commands.py b/jrnl/commands.py index c795402a..87d3981d 100644 --- a/jrnl/commands.py +++ b/jrnl/commands.py @@ -17,6 +17,7 @@ from jrnl.exception import JrnlException from jrnl.messages import Message from jrnl.messages import MsgText from jrnl.messages import MsgType +from jrnl.prompt import create_password def preconfig_diagnostic(_): @@ -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( diff --git a/tests/bdd/features/encrypt.feature b/tests/bdd/features/encrypt.feature index 7f466c1d..78b21188 100644 --- a/tests/bdd/features/encrypt.feature +++ b/tests/bdd/features/encrypt.feature @@ -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"