mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-09 06:12:28 +00:00
fix: harden legacy/tui3 non-tty flows and shutdown stability
This commit is contained in:
1 parent
d3fc572c4e
commit
033870f2df
9 files changed
+112
-4
No files matched your search
@@ -28,6 +28,16 @@ def test_prompt_existing_password(monkeypatch):
|
||||
assert password_prompt.prompt_existing_password() == "mypassword"
|
||||
|
||||
|
||||
def test_prompt_existing_password_non_tty(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
password_prompt,
|
||||
"masked_input",
|
||||
lambda _prompt: (_ for _ in ()).throw(EOFError("no tty")),
|
||||
)
|
||||
with pytest.raises(password_prompt.PasswordPromptError, match="requires a TTY"):
|
||||
password_prompt.prompt_existing_password()
|
||||
|
||||
|
||||
def test_confirm_action_yes_no(monkeypatch):
|
||||
monkeypatch.setattr(builtins, "input", lambda _: "Y")
|
||||
assert password_prompt.confirm_action()
|
||||
|
||||
@@ -5,6 +5,7 @@ from utils import seed_prompt
|
||||
|
||||
def test_masked_input_posix_backspace(monkeypatch, capsys):
|
||||
seq = iter(["a", "b", "\x7f", "c", "\n"])
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "isatty", lambda: True)
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "read", lambda n=1: next(seq))
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "fileno", lambda: 0)
|
||||
|
||||
@@ -36,6 +37,7 @@ def test_masked_input_posix_backspace(monkeypatch, capsys):
|
||||
|
||||
def test_masked_input_windows_space(monkeypatch, capsys):
|
||||
seq = iter(["x", "y", " ", "z", "\r"])
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "isatty", lambda: True)
|
||||
fake_msvcrt = types.SimpleNamespace(getwch=lambda: next(seq))
|
||||
monkeypatch.setattr(seed_prompt, "msvcrt", fake_msvcrt)
|
||||
monkeypatch.setattr(seed_prompt.sys, "platform", "win32", raising=False)
|
||||
@@ -49,6 +51,7 @@ def test_masked_input_windows_space(monkeypatch, capsys):
|
||||
|
||||
def test_masked_input_posix_ctrl_c(monkeypatch):
|
||||
seq = iter(["\x03"])
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "isatty", lambda: True)
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "read", lambda n=1: next(seq))
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "fileno", lambda: 0)
|
||||
|
||||
@@ -70,6 +73,7 @@ def test_masked_input_posix_ctrl_c(monkeypatch):
|
||||
|
||||
def test_masked_input_windows_ctrl_c(monkeypatch):
|
||||
seq = iter(["\x03"])
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "isatty", lambda: True)
|
||||
fake_msvcrt = types.SimpleNamespace(getwch=lambda: next(seq))
|
||||
monkeypatch.setattr(seed_prompt, "msvcrt", fake_msvcrt)
|
||||
monkeypatch.setattr(seed_prompt.sys, "platform", "win32", raising=False)
|
||||
@@ -93,6 +97,12 @@ def test_prompt_seed_words_valid(monkeypatch):
|
||||
assert result == phrase
|
||||
|
||||
|
||||
def test_masked_input_requires_tty(monkeypatch):
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "isatty", lambda: False)
|
||||
with pytest.raises(EOFError, match="requires a TTY"):
|
||||
seed_prompt.masked_input("Enter: ")
|
||||
|
||||
|
||||
def test_prompt_seed_words_invalid_word(monkeypatch):
|
||||
from mnemonic import Mnemonic
|
||||
|
||||
|
||||
@@ -1092,6 +1092,18 @@ def test_tui2_check(monkeypatch):
|
||||
assert payload["textual_available"] is True
|
||||
|
||||
|
||||
def test_tui3_check(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
cli,
|
||||
"check_tui2_runtime",
|
||||
lambda: {"status": "ok", "backend": "textual", "textual_available": True},
|
||||
)
|
||||
result = runner.invoke(app, ["tui3", "--check"])
|
||||
assert result.exit_code == 0
|
||||
payload = json.loads(result.stdout)
|
||||
assert "textual_available" in payload
|
||||
|
||||
|
||||
def test_tui2_unavailable_without_fallback(monkeypatch):
|
||||
monkeypatch.setattr(cli, "_get_entry_service", lambda _ctx: object())
|
||||
monkeypatch.setattr(cli, "launch_tui2", lambda **_: False)
|
||||
|
||||
Reference in new issue
Block a user