mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-10 14:52:29 +00:00
Handle Ctrl-C in masked input
This commit is contained in:
1 parent
d9f76ee668
commit
c0a6187478
2 files changed
+38
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import types
|
||||
import pytest
|
||||
from utils import seed_prompt
|
||||
|
||||
|
||||
@@ -46,6 +47,37 @@ def test_masked_input_windows_space(monkeypatch, capsys):
|
||||
assert out.count("*") == 4
|
||||
|
||||
|
||||
def test_masked_input_posix_ctrl_c(monkeypatch):
|
||||
seq = iter(["\x03"])
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "read", lambda n=1: next(seq))
|
||||
monkeypatch.setattr(seed_prompt.sys.stdin, "fileno", lambda: 0)
|
||||
|
||||
calls: list[tuple[str, int]] = []
|
||||
fake_termios = types.SimpleNamespace(
|
||||
tcgetattr=lambda fd: "old",
|
||||
tcsetattr=lambda fd, *_: calls.append(("tcsetattr", fd)),
|
||||
TCSADRAIN=1,
|
||||
)
|
||||
fake_tty = types.SimpleNamespace(setraw=lambda fd: calls.append(("setraw", fd)))
|
||||
monkeypatch.setattr(seed_prompt, "termios", fake_termios)
|
||||
monkeypatch.setattr(seed_prompt, "tty", fake_tty)
|
||||
monkeypatch.setattr(seed_prompt.sys, "platform", "linux", raising=False)
|
||||
|
||||
with pytest.raises(KeyboardInterrupt):
|
||||
seed_prompt.masked_input("Enter: ")
|
||||
assert calls == [("setraw", 0), ("tcsetattr", 0)]
|
||||
|
||||
|
||||
def test_masked_input_windows_ctrl_c(monkeypatch):
|
||||
seq = iter(["\x03"])
|
||||
fake_msvcrt = types.SimpleNamespace(getwch=lambda: next(seq))
|
||||
monkeypatch.setattr(seed_prompt, "msvcrt", fake_msvcrt)
|
||||
monkeypatch.setattr(seed_prompt.sys, "platform", "win32", raising=False)
|
||||
|
||||
with pytest.raises(KeyboardInterrupt):
|
||||
seed_prompt.masked_input("Password: ")
|
||||
|
||||
|
||||
def test_prompt_seed_words_valid(monkeypatch):
|
||||
from mnemonic import Mnemonic
|
||||
|
||||
|
||||
Reference in new issue
Block a user