Refactor manager to accept provided credentials

This commit is contained in:
thePR0M3TH3AN
2025-07-18 08:25:07 -04:00
parent ae26190928
commit d679d52b66
9 changed files with 88 additions and 50 deletions

View File

@@ -22,9 +22,6 @@ def test_switch_fingerprint_triggers_bg_sync(monkeypatch, tmp_path):
pm.config_manager = SimpleNamespace(get_quick_unlock=lambda: False)
monkeypatch.setattr("builtins.input", lambda *_a, **_k: "1")
monkeypatch.setattr(
"seedpass.core.manager.prompt_existing_password", lambda *_a, **_k: "pw"
)
monkeypatch.setattr(
PasswordManager, "setup_encryption_manager", lambda *a, **k: True
)
@@ -39,7 +36,7 @@ def test_switch_fingerprint_triggers_bg_sync(monkeypatch, tmp_path):
monkeypatch.setattr(PasswordManager, "start_background_sync", fake_bg)
assert pm.handle_switch_fingerprint()
assert pm.handle_switch_fingerprint(password="pw")
assert calls["count"] == 1

View File

@@ -43,7 +43,7 @@ class DummyPM:
self.change_password = lambda *a, **kw: None
self.lock_vault = lambda: None
self.get_profile_stats = lambda: {"n": 1}
self.handle_backup_reveal_parent_seed = lambda path=None: None
self.handle_backup_reveal_parent_seed = lambda path=None, **_: None
self.handle_verify_checksum = lambda: None
self.handle_update_script_checksum = lambda: None
self.add_new_fingerprint = lambda: None
@@ -76,7 +76,7 @@ class DummyPM:
)
self.secret_mode_enabled = True
self.clipboard_clear_delay = 30
self.select_fingerprint = lambda fp: None
self.select_fingerprint = lambda fp, **_: None
def load_doc_commands() -> list[str]:

View File

@@ -36,7 +36,7 @@ def test_setup_existing_seed_words(monkeypatch):
monkeypatch.setattr(builtins, "input", lambda *_: "y")
pm = PasswordManager.__new__(PasswordManager)
monkeypatch.setattr(pm, "_finalize_existing_seed", lambda seed: seed)
monkeypatch.setattr(pm, "_finalize_existing_seed", lambda seed, **_: seed)
result = pm.setup_existing_seed(method="words")
assert result == phrase
@@ -60,8 +60,32 @@ def test_setup_existing_seed_paste(monkeypatch):
)
pm = PasswordManager.__new__(PasswordManager)
monkeypatch.setattr(pm, "_finalize_existing_seed", lambda seed: seed)
monkeypatch.setattr(pm, "_finalize_existing_seed", lambda seed, **_: seed)
result = pm.setup_existing_seed(method="paste")
assert result == phrase
assert called["prompt"].startswith("Enter your 12-word BIP-85 seed")
def test_setup_existing_seed_with_args(monkeypatch):
m = Mnemonic("english")
phrase = m.generate(strength=128)
called = {}
monkeypatch.setattr(
"seedpass.core.manager.masked_input",
lambda *_: (_ for _ in ()).throw(RuntimeError("prompt")),
)
def finalize(seed, *, password=None):
called["seed"] = seed
called["pw"] = password
return "fp"
pm = PasswordManager.__new__(PasswordManager)
monkeypatch.setattr(pm, "_finalize_existing_seed", finalize)
result = pm.setup_existing_seed(method="paste", seed=phrase, password="pw")
assert result == "fp"
assert called["seed"] == phrase
assert called["pw"] == "pw"

View File

@@ -24,9 +24,6 @@ def _make_pm(tmp_path: Path) -> PasswordManager:
def test_handle_backup_reveal_parent_seed_confirm(monkeypatch, tmp_path, capsys):
pm = _make_pm(tmp_path)
monkeypatch.setattr(
"seedpass.core.manager.prompt_existing_password", lambda *_: "pw"
)
confirms = iter([True, True])
monkeypatch.setattr(
"seedpass.core.manager.confirm_action", lambda *_a, **_k: next(confirms)
@@ -39,7 +36,7 @@ def test_handle_backup_reveal_parent_seed_confirm(monkeypatch, tmp_path, capsys)
pm.encryption_manager = SimpleNamespace(encrypt_and_save_file=fake_save)
monkeypatch.setattr(builtins, "input", lambda *_: "mybackup.enc")
pm.handle_backup_reveal_parent_seed()
pm.handle_backup_reveal_parent_seed(password="pw")
out = capsys.readouterr().out
assert "seed phrase" in out
@@ -50,16 +47,13 @@ def test_handle_backup_reveal_parent_seed_confirm(monkeypatch, tmp_path, capsys)
def test_handle_backup_reveal_parent_seed_cancel(monkeypatch, tmp_path, capsys):
pm = _make_pm(tmp_path)
monkeypatch.setattr(
"seedpass.core.manager.prompt_existing_password", lambda *_: "pw"
)
monkeypatch.setattr("seedpass.core.manager.confirm_action", lambda *_a, **_k: False)
saved = []
pm.encryption_manager = SimpleNamespace(
encrypt_and_save_file=lambda data, path: saved.append((data, path))
)
pm.handle_backup_reveal_parent_seed()
pm.handle_backup_reveal_parent_seed(password="pw")
out = capsys.readouterr().out
assert "seed phrase" not in out

View File

@@ -31,10 +31,6 @@ def test_add_and_switch_fingerprint(monkeypatch):
pm.current_fingerprint = None
monkeypatch.setattr("builtins.input", lambda *_args, **_kwargs: "1")
monkeypatch.setattr(
"seedpass.core.manager.prompt_existing_password",
lambda *_a, **_k: "pass",
)
monkeypatch.setattr(
PasswordManager,
"setup_encryption_manager",
@@ -50,7 +46,7 @@ def test_add_and_switch_fingerprint(monkeypatch):
"seedpass.core.manager.NostrClient", lambda *a, **kw: object()
)
assert pm.handle_switch_fingerprint()
assert pm.handle_switch_fingerprint(password="pass")
assert pm.current_fingerprint == fingerprint
assert fm.current_fingerprint == fingerprint
assert pm.fingerprint_dir == expected_dir

View File

@@ -156,7 +156,7 @@ def test_vault_lock(monkeypatch):
def test_vault_reveal_parent_seed(monkeypatch, tmp_path):
called = {}
def reveal(path=None):
def reveal(path=None, **_):
called["path"] = path
pm = SimpleNamespace(
@@ -165,7 +165,9 @@ def test_vault_reveal_parent_seed(monkeypatch, tmp_path):
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
out_path = tmp_path / "seed.enc"
result = runner.invoke(
app, ["vault", "reveal-parent-seed", "--file", str(out_path)]
app,
["vault", "reveal-parent-seed", "--file", str(out_path)],
input="pw\n",
)
assert result.exit_code == 0
assert called["path"] == out_path
@@ -231,14 +233,14 @@ def test_fingerprint_remove(monkeypatch):
def test_fingerprint_switch(monkeypatch):
called = {}
def switch(fp):
def switch(fp, **_):
called["fp"] = fp
pm = SimpleNamespace(
select_fingerprint=switch, fingerprint_manager=SimpleNamespace()
)
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
result = runner.invoke(app, ["fingerprint", "switch", "def"])
result = runner.invoke(app, ["fingerprint", "switch", "def"], input="pw\n")
assert result.exit_code == 0
assert called.get("fp") == "def"