mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 15:58:48 +00:00
Merge pull request #310 from PR0M3TH3AN/codex/add-option-to-view-details-or-return-to-menu
Improve search interaction
This commit is contained in:
@@ -1846,7 +1846,7 @@ class PasswordManager:
|
||||
print(colored(f"Error: Failed to modify entry: {e}", "red"))
|
||||
|
||||
def handle_search_entries(self) -> None:
|
||||
"""Prompt for a query and display matching entries."""
|
||||
"""Prompt for a query, list matches and optionally show details."""
|
||||
try:
|
||||
clear_screen()
|
||||
query = input("Enter search string: ").strip()
|
||||
@@ -1861,10 +1861,27 @@ class PasswordManager:
|
||||
pause()
|
||||
return
|
||||
|
||||
print(colored("\n[+] Search Results:\n", "green"))
|
||||
for match in results:
|
||||
self.display_entry_details(match[0])
|
||||
pause()
|
||||
while True:
|
||||
clear_screen()
|
||||
print(colored("\n[+] Search Results:\n", "green"))
|
||||
for idx, label, username, _url, _b in results:
|
||||
display_label = label
|
||||
if username:
|
||||
display_label += f" ({username})"
|
||||
print(colored(f"{idx}. {display_label}", "cyan"))
|
||||
|
||||
idx_input = input(
|
||||
"Enter index to view details or press Enter to go back: "
|
||||
).strip()
|
||||
if not idx_input:
|
||||
break
|
||||
if not idx_input.isdigit() or int(idx_input) not in [
|
||||
r[0] for r in results
|
||||
]:
|
||||
print(colored("Invalid index.", "red"))
|
||||
pause()
|
||||
continue
|
||||
self.show_entry_details_by_index(int(idx_input))
|
||||
except Exception as e:
|
||||
logging.error(f"Failed to search entries: {e}", exc_info=True)
|
||||
print(colored(f"Error: Failed to search entries: {e}", "red"))
|
||||
|
@@ -13,7 +13,7 @@ from password_manager.manager import PasswordManager, EncryptionMode
|
||||
from password_manager.config_manager import ConfigManager
|
||||
|
||||
|
||||
def test_search_entries_shows_totp_details(monkeypatch, capsys):
|
||||
def test_search_entries_prompt_for_details(monkeypatch, capsys):
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
tmp_path = Path(tmpdir)
|
||||
vault, enc_mgr = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD)
|
||||
@@ -27,15 +27,25 @@ def test_search_entries_shows_totp_details(monkeypatch, capsys):
|
||||
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("builtins.input", lambda *a, **k: "Example")
|
||||
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("password_manager.manager.timed_input", lambda *a, **k: "b")
|
||||
|
||||
inputs = iter(["Example", "0", ""])
|
||||
monkeypatch.setattr("builtins.input", lambda *a, **k: next(inputs))
|
||||
|
||||
pm.handle_search_entries()
|
||||
out = capsys.readouterr().out
|
||||
assert "Label: Example" in out
|
||||
assert "Derivation Index" in out
|
||||
assert "0. Example" in out
|
||||
assert "Retrieved 2FA Code" in out
|
||||
assert "123456" in out
|
||||
|
Reference in New Issue
Block a user