test: mock legacy choice prompts

This commit is contained in:
thePR0M3TH3AN
2025-08-03 19:34:27 -04:00
parent d7a39c88d3
commit cc077a9762
3 changed files with 14 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ def test_decrypt_data_password_fallback(tmp_path, monkeypatch):
monkeypatch.setattr(
enc_module, "prompt_existing_password", lambda *_a, **_k: TEST_PASSWORD
)
monkeypatch.setattr("builtins.input", lambda *_a, **_k: "1")
legacy_key = _fast_legacy_key(TEST_PASSWORD, iterations=50_000)
legacy_mgr = EncryptionManager(legacy_key, tmp_path)

View File

@@ -25,6 +25,7 @@ def test_legacy_password_only_fallback(monkeypatch, tmp_path, caplog):
monkeypatch.setattr(
enc_module, "prompt_existing_password", lambda *_a, **_k: TEST_PASSWORD
)
monkeypatch.setattr("builtins.input", lambda *_a, **_k: "2")
vault, enc_mgr = create_vault(tmp_path)
data = {"schema_version": 4, "entries": {}}

View File

@@ -9,6 +9,7 @@ import sys
sys.path.append(str(Path(__file__).resolve().parents[1]))
import seedpass.core.encryption as enc_module
from seedpass.core.encryption import EncryptionManager
from seedpass.core.vault import Vault
from seedpass.core.backup import BackupManager
@@ -71,6 +72,17 @@ def test_corruption_detection(monkeypatch):
content["payload"] = base64.b64encode(payload).decode()
path.write_text(json.dumps(content))
def _fast_legacy_key(password: str, iterations: int = 100_000) -> bytes:
return base64.urlsafe_b64encode(b"0" * 32)
monkeypatch.setattr(
enc_module, "_derive_legacy_key_from_password", _fast_legacy_key
)
monkeypatch.setattr(
enc_module, "prompt_existing_password", lambda *_a, **_k: PASSWORD
)
monkeypatch.setattr("builtins.input", lambda *_a, **_k: "1")
with pytest.raises(InvalidToken):
import_backup(vault, backup, path, parent_seed=SEED)