mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 15:58:48 +00:00
Show details after list selection
This commit is contained in:
@@ -19,6 +19,7 @@ from typing import Optional
|
|||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
import select
|
import select
|
||||||
|
import builtins
|
||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
|
|
||||||
from password_manager.encryption import EncryptionManager
|
from password_manager.encryption import EncryptionManager
|
||||||
@@ -1213,6 +1214,26 @@ class PasswordManager:
|
|||||||
logging.error(f"Error during Nostr key setup: {e}", exc_info=True)
|
logging.error(f"Error during Nostr key setup: {e}", exc_info=True)
|
||||||
print(colored(f"Error: Failed to add Nostr key: {e}", "red"))
|
print(colored(f"Error: Failed to add Nostr key: {e}", "red"))
|
||||||
|
|
||||||
|
def show_entry_details_by_index(self, index: int) -> None:
|
||||||
|
"""Display entry details using :meth:`handle_retrieve_entry` for the
|
||||||
|
given index without prompting for it again."""
|
||||||
|
|
||||||
|
original_input = builtins.input
|
||||||
|
first_call = True
|
||||||
|
|
||||||
|
def patched_input(prompt: str = "") -> str:
|
||||||
|
nonlocal first_call
|
||||||
|
if first_call:
|
||||||
|
first_call = False
|
||||||
|
return str(index)
|
||||||
|
return original_input(prompt)
|
||||||
|
|
||||||
|
try:
|
||||||
|
builtins.input = patched_input
|
||||||
|
self.handle_retrieve_entry()
|
||||||
|
finally:
|
||||||
|
builtins.input = original_input
|
||||||
|
|
||||||
def handle_retrieve_entry(self) -> None:
|
def handle_retrieve_entry(self) -> None:
|
||||||
"""
|
"""
|
||||||
Handles retrieving a password from the index by prompting the user for the index number
|
Handles retrieving a password from the index by prompting the user for the index number
|
||||||
@@ -1885,7 +1906,7 @@ class PasswordManager:
|
|||||||
if not idx_input.isdigit():
|
if not idx_input.isdigit():
|
||||||
print(colored("Invalid index.", "red"))
|
print(colored("Invalid index.", "red"))
|
||||||
continue
|
continue
|
||||||
self.display_entry_details(int(idx_input))
|
self.show_entry_details_by_index(int(idx_input))
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to list entries: {e}", exc_info=True)
|
logging.error(f"Failed to list entries: {e}", exc_info=True)
|
||||||
|
@@ -41,3 +41,44 @@ def test_handle_list_entries(monkeypatch, capsys):
|
|||||||
out = capsys.readouterr().out
|
out = capsys.readouterr().out
|
||||||
assert "Example" in out
|
assert "Example" in out
|
||||||
assert "example.com" in out
|
assert "example.com" in out
|
||||||
|
|
||||||
|
|
||||||
|
def test_list_entries_show_details(monkeypatch, capsys):
|
||||||
|
with TemporaryDirectory() as tmpdir:
|
||||||
|
tmp_path = Path(tmpdir)
|
||||||
|
vault, enc_mgr = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD)
|
||||||
|
cfg_mgr = ConfigManager(vault, tmp_path)
|
||||||
|
backup_mgr = BackupManager(tmp_path, cfg_mgr)
|
||||||
|
entry_mgr = EntryManager(vault, backup_mgr)
|
||||||
|
|
||||||
|
pm = PasswordManager.__new__(PasswordManager)
|
||||||
|
pm.encryption_mode = EncryptionMode.SEED_ONLY
|
||||||
|
pm.encryption_manager = enc_mgr
|
||||||
|
pm.vault = vault
|
||||||
|
pm.entry_manager = entry_mgr
|
||||||
|
pm.backup_manager = backup_mgr
|
||||||
|
pm.parent_seed = TEST_SEED
|
||||||
|
pm.nostr_client = SimpleNamespace()
|
||||||
|
pm.fingerprint_dir = tmp_path
|
||||||
|
pm.secret_mode_enabled = False
|
||||||
|
|
||||||
|
entry_mgr.add_totp("Example", TEST_SEED)
|
||||||
|
|
||||||
|
monkeypatch.setattr(pm.entry_manager, "get_totp_code", lambda *a, **k: "123456")
|
||||||
|
monkeypatch.setattr(
|
||||||
|
pm.entry_manager, "get_totp_time_remaining", lambda *a, **k: 1
|
||||||
|
)
|
||||||
|
monkeypatch.setattr("password_manager.manager.time.sleep", lambda *a, **k: None)
|
||||||
|
monkeypatch.setattr(sys.stdin, "readline", lambda *a, **k: "b\n")
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"password_manager.manager.select.select",
|
||||||
|
lambda *a, **k: ([sys.stdin], [], []),
|
||||||
|
)
|
||||||
|
|
||||||
|
inputs = iter(["1", "0"])
|
||||||
|
monkeypatch.setattr("builtins.input", lambda *_: next(inputs))
|
||||||
|
|
||||||
|
pm.handle_list_entries()
|
||||||
|
out = capsys.readouterr().out
|
||||||
|
assert "Retrieved 2FA Code" in out
|
||||||
|
assert "123456" in out
|
||||||
|
Reference in New Issue
Block a user