Skip to content

Commit

Permalink
Fix cli copy_to_clipboard wrong passphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwebbie committed Jan 10, 2015
1 parent 9061567 commit 1e151c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pysswords/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ def copy_to_clipboard(self, fullname):
)
elif len(self.display) == 1:
credential = self.display[0]
self.display = []
passphrase = self.get_passphrase()
if passphrase is None:
return self.write("Wrong passphrase", error=True)

password = self.database.gpg.decrypt(
credential.password,
passphrase=passphrase
Expand All @@ -175,7 +179,6 @@ def copy_to_clipboard(self, fullname):
asfullname(credential.name, credential.login)
)
self.write(cred_string)
self.display = []
elif len(self.display) > 1:
print("-- Multiple credentials were found: try fullname syntax"
"\nfor example: login@name")
Expand Down
11 changes: 11 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,17 @@ def test_get_passphrase_returns_good_passphrase(self, _):
with patch("pysswords.cli.getpass", return_value=passphrase):
self.assertEqual(interface.get_passphrase(), passphrase)

@timethis
def test_copy_to_clipboard_writes_error_when_bad_passphrase(self, _):
interface = pysswords.cli.CLI("some path", show_password=False)
interface.database.get.return_value = [some_credential()]
interface.get_passphrase = Mock(return_value=None)
interface.write = Mock()
interface.copy_to_clipboard("fullname")
interface.write.assert_called_once_with(
"Wrong passphrase",
error=True
)

if __name__ == "__main__":
if sys.version_info >= (3,):
Expand Down

0 comments on commit 1e151c7

Please sign in to comment.