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

Fix set_keychain errors #964

Merged
merged 8 commits into from
May 30, 2020
Merged

Fix set_keychain errors #964

merged 8 commits into from
May 30, 2020

Conversation

eshrh
Copy link
Contributor

@eshrh eshrh commented May 26, 2020

This is intended to close #851.

There are two problems with the current keyring system:

  1. The program tries to delete a password even if a password hasn't been set yet
  2. Disgracefully crashes when there's no keyring backend.

This pull request solves both of those problems.
Do note that that the new mechanism does not exit if a keyring backend is not found. This is because for whatever reason, the password seems to get corrupted/missing after the program crashes due to keyring.errors.KeyringError.

The problem with not exiting is that if the editor is queued to pop up, the user never had an opportunity to see that their password didn't get saved. I would have just asked the user whether they wanted to continue or not, but this leads to the problem of what happens if they Ctrl-C out of that prompt. It also leads to some probably nasty scenario where you'd have to set a flag that we need to quit if the user chooses no, and then somehow finish the program without adding any text. I thought this was far too messy to be worth it.

This is very easy to test for me. The default poetry shell does not have a keyring. Perhaps we should include the keyrings.cryptfile package as a dev dependency?

Checklist

  • I have read the contributing doc.
  • I have included a link to the relevant issue number.
  • I have tested this code locally.
  • I have checked to ensure there aren't other open pull requests
    for the same issue.
  • I have written new tests for these changes, as needed.
  • All tests pass.

@eshrh eshrh changed the title Keychain error Fix set_keychain errors May 26, 2020
@wren
Copy link
Member

wren commented May 27, 2020

I'm not as familiar with the keyring functionality, so I'll have to go through this with some more detail (I'm not sure I know why we are attempting to delete a password if one hasn't been set).

As for adding a keyring dev dependency, I'm open to that (it seems like a good improvement for testing, too). Do you have suggestions for what the best keyring would be for devs and testing?

Copy link
Member

@wren wren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with the error message, but not sure about the change in functionality without adding some tests.

@eshrh
Copy link
Contributor Author

eshrh commented May 28, 2020

@wren
I have an idea as to why it might have been written this way. set_keychain(keychain,None) is also used in decrypt_content. That function first tries the password from the keychain, and if it doesn't work, deletes the key. I think this makes sense. However, it used twice for two different purposes.

The author must have realized this problem, and caught the exception if there was no password(namely PasswordDeleteError). They didn't realize that if they keychain doesn't exist at all there will be an entirely different error.

I figured out a way to test with an environment with no keychain. I just made my own keyring backend and made is raise an exception every time the program tries to do anything with it.

As for keyrings, including keyrings.cryptfile should do it.

Copy link
Member

@wren wren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@wren wren merged commit 52eaef2 into jrnl-org:develop May 30, 2020
@wren wren added the bug Something isn't working label May 30, 2020
@eshrh eshrh deleted the keychain-error branch May 30, 2020 21:57
wren pushed a commit that referenced this pull request Jul 25, 2020
* fix keyring problems
* black
* remove else and use stderr
* black
* add tests
* black
* change description of nokeyring
* dumb syntax error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing error message when user does not have a keyring backend installed
2 participants