def _call_open_password(self, password_name): console_output = password_store.open_password( password_name, copy=self._config["settings"]["copy password to clipboard"]) if self._config["settings"]["quit after opening password"]: self._quit() else: self._search.edit_text = password_name self._search.edit_pos = len(password_name) self._console.set_output(console_output) self._refresh_right_column()
def test_open_multiline_password_copies_first_line_to_clipboard_displays_rest( mocker, mocked_pyperclip_copy, ): mocker.patch( "tpass.password_store.subprocess.run", return_value=proc(b"h3ll0 w0rld\nusername: foo\nurl: bar.org"), ) assert (password_store.open_password("greeting", copy=True) == "'greeting' copied to clipboard.\n\nusername: foo\nurl: bar.org") mocked_pyperclip_copy.assert_called()
def _get_otp(self): key_name = "2fa/" + self._listing.selected_password secret = password_store.open_password(key_name, copy=False) oathtool_cmd = "oathtool --totp --base32 " + secret proc = subprocess.run(oathtool_cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) otp = proc.stdout.decode().splitlines()[0] if otp.startswith("oathtool"): self._console.set_output("No OTP found for " + self._listing.selected_password) else: pyperclip.copy(otp) self._console.set_output("OTP copied for " + self._listing.selected_password) self._search.edit_text = self._listing.selected_password self._search.edit_pos = len(self._listing.selected_password) self._refresh_right_column()
def test_open_password_copied_to_clipboard_returns_console_output( mocked_open_password_subprocess, mocked_pyperclip_copy): assert (password_store.open_password( "greeting", copy=True) == "'greeting' copied to clipboard.")
def test_open_password_copied_to_clipboard_calls_pyperclip( mocked_open_password_subprocess, mocked_pyperclip_copy): password_store.open_password("greeting", copy=True) mocked_pyperclip_copy.assert_called_with("h3ll0 w0rld")
def test_open_password_not_copied_to_clipboard_returns_password( mocked_open_password_subprocess, ): assert password_store.open_password("greeting", copy=False) == "h3ll0 w0rld"