mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-08 15:48:08 +00:00
WIP - fix device tests
This commit is contained in:
parent
a802cd0d6c
commit
a63bf72d08
@ -590,6 +590,7 @@ def _show_xpub(xpub: str, title: str, cancel: str) -> ui.Layout:
|
|||||||
trezorui2.confirm_text(
|
trezorui2.confirm_text(
|
||||||
title=title.upper(),
|
title=title.upper(),
|
||||||
data=xpub,
|
data=xpub,
|
||||||
|
description="",
|
||||||
# verb_cancel=cancel,
|
# verb_cancel=cancel,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -1254,8 +1255,6 @@ async def request_pin_on_device(
|
|||||||
allow_cancel: bool,
|
allow_cancel: bool,
|
||||||
shuffle: bool = False,
|
shuffle: bool = False,
|
||||||
) -> str:
|
) -> str:
|
||||||
await button_request(ctx, "pin_device", code=ButtonRequestType.PinEntry)
|
|
||||||
|
|
||||||
if attempts_remaining is None:
|
if attempts_remaining is None:
|
||||||
subprompt = ""
|
subprompt = ""
|
||||||
elif attempts_remaining == 1:
|
elif attempts_remaining == 1:
|
||||||
@ -1266,15 +1265,17 @@ async def request_pin_on_device(
|
|||||||
if attempts_remaining is not None:
|
if attempts_remaining is not None:
|
||||||
await confirm_action(
|
await confirm_action(
|
||||||
ctx,
|
ctx,
|
||||||
"pin_device",
|
"pin_device_info",
|
||||||
"PIN entry",
|
"PIN entry",
|
||||||
action=prompt,
|
action=prompt,
|
||||||
description=subprompt,
|
description=subprompt,
|
||||||
verb="BEGIN",
|
verb="BEGIN",
|
||||||
verb_cancel=None,
|
verb_cancel=None,
|
||||||
br_code=ButtonRequestType.PinEntry,
|
br_code=ButtonRequestType.Other, # cannot use BRT.PinEntry, as debuglink would be sending PIN to this screen
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await button_request(ctx, "pin_device", code=ButtonRequestType.PinEntry)
|
||||||
|
|
||||||
dialog = RustLayout(
|
dialog = RustLayout(
|
||||||
trezorui2.request_pin(
|
trezorui2.request_pin(
|
||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
|
@ -92,7 +92,8 @@ def do_recover_r(client: Client, mnemonic: List[str], **kwargs: Any):
|
|||||||
layout = client.debug.wait_layout
|
layout = client.debug.wait_layout
|
||||||
|
|
||||||
def input_flow():
|
def input_flow():
|
||||||
pytest.fail("Freezes")
|
if client.features.model == "R":
|
||||||
|
pytest.skip("Freezes")
|
||||||
yield
|
yield
|
||||||
assert "check the recovery seed" in layout().text
|
assert "check the recovery seed" in layout().text
|
||||||
client.debug.press_right()
|
client.debug.press_right()
|
||||||
@ -222,6 +223,11 @@ def test_invalid_seed_core(client: Client):
|
|||||||
assert "Enter recovery seed" in layout().text
|
assert "Enter recovery seed" in layout().text
|
||||||
client.debug.press_right()
|
client.debug.press_right()
|
||||||
|
|
||||||
|
yield
|
||||||
|
layout = client.debug.wait_layout()
|
||||||
|
assert "WORD ENTERING" in layout.text
|
||||||
|
client.debug.press_right()
|
||||||
|
|
||||||
yield
|
yield
|
||||||
for _ in range(12):
|
for _ in range(12):
|
||||||
yield
|
yield
|
||||||
|
@ -65,15 +65,21 @@ def test_tt_pin_passphrase(client: Client):
|
|||||||
|
|
||||||
def input_flow_tr():
|
def input_flow_tr():
|
||||||
yield
|
yield
|
||||||
assert "Do you really want to recover a wallet?" in layout().text
|
assert "By continuing you agree" in layout().text
|
||||||
|
client.debug.press_right()
|
||||||
|
assert "trezor.io/tos" in layout().text
|
||||||
client.debug.press_yes()
|
client.debug.press_yes()
|
||||||
|
|
||||||
yield
|
yield
|
||||||
assert "PIN" in layout().text
|
assert "ENTER" in layout().text
|
||||||
client.debug.input("654")
|
client.debug.input("654")
|
||||||
|
|
||||||
yield
|
yield
|
||||||
assert "PIN" in layout().text
|
assert "re-enter to confirm" in layout().text
|
||||||
|
client.debug.press_right()
|
||||||
|
|
||||||
|
yield
|
||||||
|
assert "ENTER" in layout().text
|
||||||
client.debug.input("654")
|
client.debug.input("654")
|
||||||
|
|
||||||
yield
|
yield
|
||||||
@ -89,6 +95,10 @@ def test_tt_pin_passphrase(client: Client):
|
|||||||
assert "Enter recovery seed" in layout().text
|
assert "Enter recovery seed" in layout().text
|
||||||
client.debug.press_yes()
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
yield
|
||||||
|
assert "WORD ENTERING" in layout().text
|
||||||
|
client.debug.press_right()
|
||||||
|
|
||||||
yield
|
yield
|
||||||
for word in mnemonic:
|
for word in mnemonic:
|
||||||
yield
|
yield
|
||||||
@ -154,7 +164,9 @@ def test_tt_nopin_nopassphrase(client: Client):
|
|||||||
|
|
||||||
def input_flow_tr():
|
def input_flow_tr():
|
||||||
yield
|
yield
|
||||||
assert "Do you really want to recover a wallet?" in layout().text
|
assert "By continuing you agree" in layout().text
|
||||||
|
client.debug.press_right()
|
||||||
|
assert "trezor.io/tos" in layout().text
|
||||||
client.debug.press_yes()
|
client.debug.press_yes()
|
||||||
|
|
||||||
yield
|
yield
|
||||||
@ -170,6 +182,10 @@ def test_tt_nopin_nopassphrase(client: Client):
|
|||||||
assert "Enter recovery seed" in layout().text
|
assert "Enter recovery seed" in layout().text
|
||||||
client.debug.press_yes()
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
yield
|
||||||
|
assert "WORD ENTERING" in layout().text
|
||||||
|
client.debug.press_right()
|
||||||
|
|
||||||
yield
|
yield
|
||||||
for word in mnemonic:
|
for word in mnemonic:
|
||||||
yield
|
yield
|
||||||
|
@ -200,7 +200,8 @@ VECTORS = [
|
|||||||
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
|
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_skip_backup_msg(client: Client, backup_type, backup_flow):
|
def test_skip_backup_msg(client: Client, backup_type, backup_flow):
|
||||||
pytest.fail("Freezes")
|
if client.features.model == "R":
|
||||||
|
pytest.skip("Freezes")
|
||||||
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
|
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
|
||||||
with mock.patch("os.urandom", os_urandom), client:
|
with mock.patch("os.urandom", os_urandom), client:
|
||||||
device.reset(
|
device.reset(
|
||||||
@ -236,7 +237,8 @@ def test_skip_backup_msg(client: Client, backup_type, backup_flow):
|
|||||||
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
|
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_skip_backup_manual(client: Client, backup_type, backup_flow):
|
def test_skip_backup_manual(client: Client, backup_type, backup_flow):
|
||||||
pytest.fail("Freezes")
|
if client.features.model == "R":
|
||||||
|
pytest.skip("Freezes")
|
||||||
|
|
||||||
def reset_skip_input_flow():
|
def reset_skip_input_flow():
|
||||||
yield # Confirm Recovery
|
yield # Confirm Recovery
|
||||||
|
@ -118,19 +118,22 @@ def reset_device(client: Client, strength):
|
|||||||
|
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_reset_device(client: Client):
|
def test_reset_device(client: Client):
|
||||||
pytest.fail("Freezes")
|
if client.features.model == "R":
|
||||||
|
pytest.skip("Freezes")
|
||||||
reset_device(client, 128) # 12 words
|
reset_device(client, 128) # 12 words
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_reset_device_192(client: Client):
|
def test_reset_device_192(client: Client):
|
||||||
pytest.fail("Freezes")
|
if client.features.model == "R":
|
||||||
|
pytest.skip("Freezes")
|
||||||
reset_device(client, 192) # 18 words
|
reset_device(client, 192) # 18 words
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_reset_device_pin(client: Client):
|
def test_reset_device_pin(client: Client):
|
||||||
pytest.fail("Freezes")
|
if client.features.model == "R":
|
||||||
|
pytest.skip("Freezes")
|
||||||
mnemonic = None
|
mnemonic = None
|
||||||
strength = 256 # 24 words
|
strength = 256 # 24 words
|
||||||
|
|
||||||
@ -234,7 +237,8 @@ def test_reset_device_pin(client: Client):
|
|||||||
|
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_reset_failed_check(client: Client):
|
def test_reset_failed_check(client: Client):
|
||||||
pytest.fail("Freezes")
|
if client.features.model == "R":
|
||||||
|
pytest.skip("Freezes")
|
||||||
mnemonic = None
|
mnemonic = None
|
||||||
strength = 256 # 24 words
|
strength = 256 # 24 words
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ from ...common import (
|
|||||||
@pytest.mark.skip_t1
|
@pytest.mark.skip_t1
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_reset_recovery(client: Client):
|
def test_reset_recovery(client: Client):
|
||||||
pytest.fail("Freezes")
|
if client.features.model == "R":
|
||||||
|
pytest.skip("Freezes")
|
||||||
mnemonic = reset(client)
|
mnemonic = reset(client)
|
||||||
address_before = btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"))
|
address_before = btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"))
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ def set_autolock_delay(client: Client, delay):
|
|||||||
[
|
[
|
||||||
pin_request(client),
|
pin_request(client),
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
|
(client.features.model == "R", messages.ButtonRequest),
|
||||||
messages.Success,
|
messages.Success,
|
||||||
messages.Features,
|
messages.Features,
|
||||||
]
|
]
|
||||||
@ -63,7 +64,13 @@ def test_apply_auto_lock_delay(client: Client):
|
|||||||
time.sleep(10.5) # sleep more than auto-lock delay
|
time.sleep(10.5) # sleep more than auto-lock delay
|
||||||
with client:
|
with client:
|
||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses([pin_request(client), messages.Address])
|
client.set_expected_responses(
|
||||||
|
[
|
||||||
|
pin_request(client),
|
||||||
|
(client.features.model == "R", messages.ButtonRequest),
|
||||||
|
messages.Address,
|
||||||
|
]
|
||||||
|
)
|
||||||
get_test_address(client)
|
get_test_address(client)
|
||||||
|
|
||||||
|
|
||||||
@ -102,6 +109,7 @@ def test_apply_auto_lock_delay_out_of_range(client: Client, seconds):
|
|||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
pin_request(client),
|
pin_request(client),
|
||||||
|
(client.features.model == "R", messages.ButtonRequest),
|
||||||
messages.Failure(code=messages.FailureType.ProcessError),
|
messages.Failure(code=messages.FailureType.ProcessError),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -26,6 +26,10 @@ EXPECTED_RESPONSES_NOPIN = [
|
|||||||
messages.Features,
|
messages.Features,
|
||||||
]
|
]
|
||||||
EXPECTED_RESPONSES_PIN_T1 = [messages.PinMatrixRequest()] + EXPECTED_RESPONSES_NOPIN
|
EXPECTED_RESPONSES_PIN_T1 = [messages.PinMatrixRequest()] + EXPECTED_RESPONSES_NOPIN
|
||||||
|
EXPECTED_RESPONSES_PIN_TR = [
|
||||||
|
messages.ButtonRequest(),
|
||||||
|
messages.ButtonRequest(),
|
||||||
|
] + EXPECTED_RESPONSES_NOPIN
|
||||||
EXPECTED_RESPONSES_PIN_TT = [messages.ButtonRequest()] + EXPECTED_RESPONSES_NOPIN
|
EXPECTED_RESPONSES_PIN_TT = [messages.ButtonRequest()] + EXPECTED_RESPONSES_NOPIN
|
||||||
|
|
||||||
PIN4 = "1234"
|
PIN4 = "1234"
|
||||||
@ -37,6 +41,8 @@ def _set_expected_responses(client: Client):
|
|||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
if client.features.model == "1":
|
if client.features.model == "1":
|
||||||
client.set_expected_responses(EXPECTED_RESPONSES_PIN_T1)
|
client.set_expected_responses(EXPECTED_RESPONSES_PIN_T1)
|
||||||
|
elif client.features.model == "R":
|
||||||
|
client.set_expected_responses(EXPECTED_RESPONSES_PIN_TR)
|
||||||
else:
|
else:
|
||||||
client.set_expected_responses(EXPECTED_RESPONSES_PIN_TT)
|
client.set_expected_responses(EXPECTED_RESPONSES_PIN_TT)
|
||||||
|
|
||||||
@ -386,7 +392,10 @@ def test_experimental_features(client: Client):
|
|||||||
client.lock()
|
client.lock()
|
||||||
with client:
|
with client:
|
||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses([messages.ButtonRequest, messages.Nonce])
|
tr = client.features.model == "R"
|
||||||
|
client.set_expected_responses(
|
||||||
|
[messages.ButtonRequest, (tr, messages.ButtonRequest), messages.Nonce]
|
||||||
|
)
|
||||||
experimental_call()
|
experimental_call()
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +42,8 @@ def click_info_button(debug):
|
|||||||
@pytest.mark.skip_t1 # TODO we want this for t1 too
|
@pytest.mark.skip_t1 # TODO we want this for t1 too
|
||||||
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC12)
|
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC12)
|
||||||
def test_backup_bip39(client: Client):
|
def test_backup_bip39(client: Client):
|
||||||
pytest.fail("Freezes")
|
if client.features.model == "R":
|
||||||
|
pytest.skip("Freezes")
|
||||||
assert client.features.needs_backup is True
|
assert client.features.needs_backup is True
|
||||||
mnemonic = None
|
mnemonic = None
|
||||||
|
|
||||||
|
@ -33,11 +33,13 @@ def _check_wipe_code(client: Client, pin: str, wipe_code: str):
|
|||||||
client.init_device()
|
client.init_device()
|
||||||
assert client.features.wipe_code_protection is True
|
assert client.features.wipe_code_protection is True
|
||||||
|
|
||||||
|
tr = client.features.model == "R"
|
||||||
|
|
||||||
# Try to change the PIN to the current wipe code value. The operation should fail.
|
# Try to change the PIN to the current wipe code value. The operation should fail.
|
||||||
with client, pytest.raises(TrezorFailure):
|
with client, pytest.raises(TrezorFailure):
|
||||||
client.use_pin_sequence([pin, wipe_code, wipe_code])
|
client.use_pin_sequence([pin, wipe_code, wipe_code])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 5
|
[messages.ButtonRequest()] * (7 if tr else 5)
|
||||||
+ [messages.Failure(code=messages.FailureType.PinInvalid)]
|
+ [messages.Failure(code=messages.FailureType.PinInvalid)]
|
||||||
)
|
)
|
||||||
device.change_pin(client)
|
device.change_pin(client)
|
||||||
@ -56,12 +58,15 @@ def test_set_remove_wipe_code(client: Client):
|
|||||||
# Test set wipe code.
|
# Test set wipe code.
|
||||||
assert client.features.wipe_code_protection is None
|
assert client.features.wipe_code_protection is None
|
||||||
|
|
||||||
|
tr = client.features.model == "R"
|
||||||
|
|
||||||
_ensure_unlocked(client, PIN4)
|
_ensure_unlocked(client, PIN4)
|
||||||
assert client.features.wipe_code_protection is False
|
assert client.features.wipe_code_protection is False
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 5 + [messages.Success, messages.Features]
|
[messages.ButtonRequest()] * (6 if tr else 5)
|
||||||
|
+ [messages.Success, messages.Features]
|
||||||
)
|
)
|
||||||
client.use_pin_sequence([PIN4, WIPE_CODE_MAX, WIPE_CODE_MAX])
|
client.use_pin_sequence([PIN4, WIPE_CODE_MAX, WIPE_CODE_MAX])
|
||||||
device.change_wipe_code(client)
|
device.change_wipe_code(client)
|
||||||
@ -73,7 +78,8 @@ def test_set_remove_wipe_code(client: Client):
|
|||||||
# Test change wipe code.
|
# Test change wipe code.
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 5 + [messages.Success, messages.Features]
|
[messages.ButtonRequest()] * (6 if tr else 5)
|
||||||
|
+ [messages.Success, messages.Features]
|
||||||
)
|
)
|
||||||
client.use_pin_sequence([PIN4, WIPE_CODE6, WIPE_CODE6])
|
client.use_pin_sequence([PIN4, WIPE_CODE6, WIPE_CODE6])
|
||||||
device.change_wipe_code(client)
|
device.change_wipe_code(client)
|
||||||
@ -85,7 +91,8 @@ def test_set_remove_wipe_code(client: Client):
|
|||||||
# Test remove wipe code.
|
# Test remove wipe code.
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 3 + [messages.Success, messages.Features]
|
[messages.ButtonRequest()] * (4 if tr else 3)
|
||||||
|
+ [messages.Success, messages.Features]
|
||||||
)
|
)
|
||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
device.change_wipe_code(client, remove=True)
|
device.change_wipe_code(client, remove=True)
|
||||||
@ -125,9 +132,12 @@ def test_set_wipe_code_mismatch(client: Client):
|
|||||||
def test_set_wipe_code_to_pin(client: Client):
|
def test_set_wipe_code_to_pin(client: Client):
|
||||||
_ensure_unlocked(client, PIN4)
|
_ensure_unlocked(client, PIN4)
|
||||||
|
|
||||||
|
tr = client.features.model == "R"
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 6 + [messages.Success, messages.Features]
|
[messages.ButtonRequest()] * (7 if tr else 6)
|
||||||
|
+ [messages.Success, messages.Features]
|
||||||
)
|
)
|
||||||
client.use_pin_sequence([PIN4, PIN4, WIPE_CODE4, WIPE_CODE4])
|
client.use_pin_sequence([PIN4, PIN4, WIPE_CODE4, WIPE_CODE4])
|
||||||
device.change_wipe_code(client)
|
device.change_wipe_code(client)
|
||||||
@ -138,6 +148,8 @@ def test_set_wipe_code_to_pin(client: Client):
|
|||||||
|
|
||||||
|
|
||||||
def test_set_pin_to_wipe_code(client: Client):
|
def test_set_pin_to_wipe_code(client: Client):
|
||||||
|
tr = client.features.model == "R"
|
||||||
|
|
||||||
# Set wipe code.
|
# Set wipe code.
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
@ -149,7 +161,7 @@ def test_set_pin_to_wipe_code(client: Client):
|
|||||||
# Try to set the PIN to the current wipe code value.
|
# Try to set the PIN to the current wipe code value.
|
||||||
with client, pytest.raises(TrezorFailure):
|
with client, pytest.raises(TrezorFailure):
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest()] * 4
|
[messages.ButtonRequest()] * (6 if tr else 4)
|
||||||
+ [messages.Failure(code=messages.FailureType.PinInvalid)]
|
+ [messages.Failure(code=messages.FailureType.PinInvalid)]
|
||||||
)
|
)
|
||||||
client.use_pin_sequence([WIPE_CODE4, WIPE_CODE4])
|
client.use_pin_sequence([WIPE_CODE4, WIPE_CODE4])
|
||||||
|
@ -33,9 +33,13 @@ def _check_pin(client: Client, pin):
|
|||||||
assert client.features.pin_protection is True
|
assert client.features.pin_protection is True
|
||||||
assert client.features.unlocked is False
|
assert client.features.unlocked is False
|
||||||
|
|
||||||
|
tr = client.features.model == "R"
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.use_pin_sequence([pin])
|
client.use_pin_sequence([pin])
|
||||||
client.set_expected_responses([messages.ButtonRequest, messages.Address])
|
client.set_expected_responses(
|
||||||
|
[messages.ButtonRequest, (tr, messages.ButtonRequest), messages.Address]
|
||||||
|
)
|
||||||
btc.get_address(client, "Testnet", PASSPHRASE_TEST_PATH)
|
btc.get_address(client, "Testnet", PASSPHRASE_TEST_PATH)
|
||||||
|
|
||||||
|
|
||||||
@ -51,6 +55,8 @@ def _check_no_pin(client: Client):
|
|||||||
def test_set_pin(client: Client):
|
def test_set_pin(client: Client):
|
||||||
assert client.features.pin_protection is False
|
assert client.features.pin_protection is False
|
||||||
|
|
||||||
|
tr = client.features.model == "R"
|
||||||
|
|
||||||
# Check that there's no PIN protection
|
# Check that there's no PIN protection
|
||||||
_check_no_pin(client)
|
_check_no_pin(client)
|
||||||
|
|
||||||
@ -58,7 +64,8 @@ def test_set_pin(client: Client):
|
|||||||
with client:
|
with client:
|
||||||
client.use_pin_sequence([PIN_MAX, PIN_MAX])
|
client.use_pin_sequence([PIN_MAX, PIN_MAX])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest] * 4 + [messages.Success, messages.Features]
|
[messages.ButtonRequest] * (6 if tr else 4)
|
||||||
|
+ [messages.Success, messages.Features]
|
||||||
)
|
)
|
||||||
device.change_pin(client)
|
device.change_pin(client)
|
||||||
|
|
||||||
@ -71,6 +78,8 @@ def test_set_pin(client: Client):
|
|||||||
def test_change_pin(client: Client):
|
def test_change_pin(client: Client):
|
||||||
assert client.features.pin_protection is True
|
assert client.features.pin_protection is True
|
||||||
|
|
||||||
|
tr = client.features.model == "R"
|
||||||
|
|
||||||
# Check current PIN value
|
# Check current PIN value
|
||||||
_check_pin(client, PIN4)
|
_check_pin(client, PIN4)
|
||||||
|
|
||||||
@ -78,7 +87,8 @@ def test_change_pin(client: Client):
|
|||||||
with client:
|
with client:
|
||||||
client.use_pin_sequence([PIN4, PIN_MAX, PIN_MAX])
|
client.use_pin_sequence([PIN4, PIN_MAX, PIN_MAX])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest] * 5 + [messages.Success, messages.Features]
|
[messages.ButtonRequest] * (7 if tr else 5)
|
||||||
|
+ [messages.Success, messages.Features]
|
||||||
)
|
)
|
||||||
device.change_pin(client)
|
device.change_pin(client)
|
||||||
|
|
||||||
@ -93,6 +103,8 @@ def test_change_pin(client: Client):
|
|||||||
def test_remove_pin(client: Client):
|
def test_remove_pin(client: Client):
|
||||||
assert client.features.pin_protection is True
|
assert client.features.pin_protection is True
|
||||||
|
|
||||||
|
tr = client.features.model == "R"
|
||||||
|
|
||||||
# Check current PIN value
|
# Check current PIN value
|
||||||
_check_pin(client, PIN4)
|
_check_pin(client, PIN4)
|
||||||
|
|
||||||
@ -100,7 +112,8 @@ def test_remove_pin(client: Client):
|
|||||||
with client:
|
with client:
|
||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[messages.ButtonRequest] * 3 + [messages.Success, messages.Features]
|
[messages.ButtonRequest] * (4 if tr else 3)
|
||||||
|
+ [messages.Success, messages.Features]
|
||||||
)
|
)
|
||||||
device.change_pin(client, remove=True)
|
device.change_pin(client, remove=True)
|
||||||
|
|
||||||
@ -145,11 +158,13 @@ def test_set_failed(client: Client):
|
|||||||
def test_change_failed(client: Client):
|
def test_change_failed(client: Client):
|
||||||
assert client.features.pin_protection is True
|
assert client.features.pin_protection is True
|
||||||
|
|
||||||
|
tr = client.features.model == "R"
|
||||||
|
|
||||||
# Check current PIN value
|
# Check current PIN value
|
||||||
_check_pin(client, PIN4)
|
_check_pin(client, PIN4)
|
||||||
|
|
||||||
# Let's set new PIN
|
# Let's set new PIN
|
||||||
def input_flow():
|
def input_flow_tt():
|
||||||
yield # do you want to change pin?
|
yield # do you want to change pin?
|
||||||
client.debug.press_yes()
|
client.debug.press_yes()
|
||||||
yield # enter current pin
|
yield # enter current pin
|
||||||
@ -163,9 +178,28 @@ def test_change_failed(client: Client):
|
|||||||
yield # enter current pin again
|
yield # enter current pin again
|
||||||
client.cancel()
|
client.cancel()
|
||||||
|
|
||||||
|
# Let's set new PIN
|
||||||
|
def input_flow_tr():
|
||||||
|
yield # do you want to change pin?
|
||||||
|
client.debug.press_yes()
|
||||||
|
yield # Enter old PIN?
|
||||||
|
client.debug.press_yes()
|
||||||
|
yield # enter current pin
|
||||||
|
client.debug.input(PIN4)
|
||||||
|
yield # enter new pin
|
||||||
|
client.debug.input("457891")
|
||||||
|
yield # enter new pin again (but different)
|
||||||
|
client.debug.input("381847")
|
||||||
|
|
||||||
|
# failed retry
|
||||||
|
yield # enter current pin again
|
||||||
|
client.cancel()
|
||||||
|
|
||||||
with client, pytest.raises(Cancelled):
|
with client, pytest.raises(Cancelled):
|
||||||
client.set_expected_responses([messages.ButtonRequest] * 5 + [messages.Failure])
|
client.set_expected_responses(
|
||||||
client.set_input_flow(input_flow)
|
[messages.ButtonRequest] * (6 if tr else 5) + [messages.Failure]
|
||||||
|
)
|
||||||
|
client.set_input_flow(input_flow_tr if tr else input_flow_tt)
|
||||||
|
|
||||||
device.change_pin(client)
|
device.change_pin(client)
|
||||||
|
|
||||||
|
@ -42,17 +42,21 @@ def test_correct_pin(client: Client):
|
|||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
# Expected responses differ between T1 and TT
|
# Expected responses differ between T1 and TT
|
||||||
is_t1 = client.features.model == "1"
|
is_t1 = client.features.model == "1"
|
||||||
|
is_tr = client.features.model == "R"
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
(is_t1, messages.PinMatrixRequest),
|
(is_t1, messages.PinMatrixRequest),
|
||||||
(
|
(
|
||||||
not is_t1,
|
is_tr,
|
||||||
|
messages.ButtonRequest(code=messages.ButtonRequestType.Other),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
not is_t1 or is_tr,
|
||||||
messages.ButtonRequest(code=messages.ButtonRequestType.PinEntry),
|
messages.ButtonRequest(code=messages.ButtonRequestType.PinEntry),
|
||||||
),
|
),
|
||||||
messages.Address,
|
messages.Address,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
# client.set_expected_responses([messages.ButtonRequest, messages.Address])
|
|
||||||
get_test_address(client)
|
get_test_address(client)
|
||||||
|
|
||||||
|
|
||||||
@ -68,10 +72,13 @@ def test_incorrect_pin_t1(client: Client):
|
|||||||
def test_incorrect_pin_t2(client: Client):
|
def test_incorrect_pin_t2(client: Client):
|
||||||
with client:
|
with client:
|
||||||
# After first incorrect attempt, TT will not raise an error, but instead ask for another attempt
|
# After first incorrect attempt, TT will not raise an error, but instead ask for another attempt
|
||||||
|
is_tr = client.features.model == "R"
|
||||||
client.use_pin_sequence([BAD_PIN, PIN4])
|
client.use_pin_sequence([BAD_PIN, PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
|
(is_tr, messages.ButtonRequest(code=messages.ButtonRequestType.Other)),
|
||||||
messages.ButtonRequest(code=messages.ButtonRequestType.PinEntry),
|
messages.ButtonRequest(code=messages.ButtonRequestType.PinEntry),
|
||||||
|
(is_tr, messages.ButtonRequest(code=messages.ButtonRequestType.Other)),
|
||||||
messages.ButtonRequest(code=messages.ButtonRequestType.PinEntry),
|
messages.ButtonRequest(code=messages.ButtonRequestType.PinEntry),
|
||||||
messages.Address,
|
messages.Address,
|
||||||
]
|
]
|
||||||
@ -99,7 +106,7 @@ def test_exponential_backoff_t1(client: Client):
|
|||||||
|
|
||||||
@pytest.mark.skip_t1
|
@pytest.mark.skip_t1
|
||||||
def test_exponential_backoff_t2(client: Client):
|
def test_exponential_backoff_t2(client: Client):
|
||||||
def input_flow():
|
def input_flow_tt():
|
||||||
"""Inputting some bad PINs and finally the correct one"""
|
"""Inputting some bad PINs and finally the correct one"""
|
||||||
yield # PIN entry
|
yield # PIN entry
|
||||||
for attempt in range(3):
|
for attempt in range(3):
|
||||||
@ -109,6 +116,21 @@ def test_exponential_backoff_t2(client: Client):
|
|||||||
_check_backoff_time(attempt, start)
|
_check_backoff_time(attempt, start)
|
||||||
client.debug.input(PIN4)
|
client.debug.input(PIN4)
|
||||||
|
|
||||||
|
def input_flow_tr():
|
||||||
|
"""Inputting some bad PINs and finally the correct one"""
|
||||||
|
yield # Enter your PIN
|
||||||
|
client.debug.press_yes()
|
||||||
|
yield # PIN entry
|
||||||
|
for attempt in range(3):
|
||||||
|
start = time.time()
|
||||||
|
client.debug.input(BAD_PIN)
|
||||||
|
yield # PIN entry
|
||||||
|
client.debug.press_yes()
|
||||||
|
yield # Wrong PIN, enter again
|
||||||
|
_check_backoff_time(attempt, start)
|
||||||
|
client.debug.input(PIN4)
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.set_input_flow(input_flow)
|
tr = client.features.model == "R"
|
||||||
|
client.set_input_flow(input_flow_tr if tr else input_flow_tt)
|
||||||
get_test_address(client)
|
get_test_address(client)
|
||||||
|
@ -44,12 +44,17 @@ PIN4 = "1234"
|
|||||||
pytestmark = pytest.mark.setup_client(pin=PIN4, passphrase=True)
|
pytestmark = pytest.mark.setup_client(pin=PIN4, passphrase=True)
|
||||||
|
|
||||||
|
|
||||||
def _pin_request(client: Client):
|
def _pin_requests(client: Client) -> list:
|
||||||
"""Get appropriate PIN request for each model"""
|
"""Get appropriate PIN requests for each model"""
|
||||||
if client.features.model == "1":
|
if client.features.model == "1":
|
||||||
return messages.PinMatrixRequest
|
return [messages.PinMatrixRequest]
|
||||||
|
elif client.features.model == "R":
|
||||||
|
return [
|
||||||
|
messages.ButtonRequest(code=B.Other),
|
||||||
|
messages.ButtonRequest(code=B.PinEntry),
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
return messages.ButtonRequest(code=B.PinEntry)
|
return [messages.ButtonRequest(code=B.PinEntry)]
|
||||||
|
|
||||||
|
|
||||||
def _assert_protection(
|
def _assert_protection(
|
||||||
@ -103,7 +108,7 @@ def test_apply_settings(client: Client):
|
|||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
messages.Success,
|
messages.Success,
|
||||||
messages.Features,
|
messages.Features,
|
||||||
@ -121,9 +126,9 @@ def test_change_pin_t1(client: Client):
|
|||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.Success,
|
messages.Success,
|
||||||
messages.Features,
|
messages.Features,
|
||||||
]
|
]
|
||||||
@ -138,11 +143,11 @@ def test_change_pin_t2(client: Client):
|
|||||||
client.use_pin_sequence([PIN4, PIN4, PIN4, PIN4])
|
client.use_pin_sequence([PIN4, PIN4, PIN4, PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
_pin_request(client),
|
messages.ButtonRequest(code=B.PinEntry),
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
messages.Success,
|
messages.Success,
|
||||||
messages.Features,
|
messages.Features,
|
||||||
@ -165,7 +170,7 @@ def test_get_entropy(client: Client):
|
|||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.ButtonRequest(code=B.ProtectCall),
|
messages.ButtonRequest(code=B.ProtectCall),
|
||||||
messages.Entropy,
|
messages.Entropy,
|
||||||
]
|
]
|
||||||
@ -179,7 +184,7 @@ def test_get_public_key(client: Client):
|
|||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.PassphraseRequest,
|
messages.PassphraseRequest,
|
||||||
messages.PublicKey,
|
messages.PublicKey,
|
||||||
]
|
]
|
||||||
@ -193,7 +198,7 @@ def test_get_address(client: Client):
|
|||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.PassphraseRequest,
|
messages.PassphraseRequest,
|
||||||
messages.Address,
|
messages.Address,
|
||||||
]
|
]
|
||||||
@ -288,7 +293,7 @@ def test_sign_message(client: Client):
|
|||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.PassphraseRequest,
|
messages.PassphraseRequest,
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
@ -331,7 +336,7 @@ def test_verify_message_t2(client: Client):
|
|||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
messages.ButtonRequest,
|
messages.ButtonRequest,
|
||||||
@ -371,7 +376,7 @@ def test_signtx(client: Client):
|
|||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
_pin_request(client),
|
*_pin_requests(client),
|
||||||
messages.PassphraseRequest,
|
messages.PassphraseRequest,
|
||||||
request_input(0),
|
request_input(0),
|
||||||
request_output(0),
|
request_output(0),
|
||||||
@ -407,7 +412,7 @@ def test_unlocked(client: Client):
|
|||||||
_assert_protection(client, passphrase=False)
|
_assert_protection(client, passphrase=False)
|
||||||
with client:
|
with client:
|
||||||
client.use_pin_sequence([PIN4])
|
client.use_pin_sequence([PIN4])
|
||||||
client.set_expected_responses([_pin_request(client), messages.Address])
|
client.set_expected_responses([*_pin_requests(client), messages.Address])
|
||||||
get_test_address(client)
|
get_test_address(client)
|
||||||
|
|
||||||
client.init_device()
|
client.init_device()
|
||||||
|
@ -35,6 +35,7 @@ def test_clear_session(client: Client):
|
|||||||
is_trezor1 = client.features.model == "1"
|
is_trezor1 = client.features.model == "1"
|
||||||
init_responses = [
|
init_responses = [
|
||||||
messages.PinMatrixRequest if is_trezor1 else messages.ButtonRequest,
|
messages.PinMatrixRequest if is_trezor1 else messages.ButtonRequest,
|
||||||
|
(client.features.model == "R", messages.ButtonRequest),
|
||||||
messages.PassphraseRequest,
|
messages.PassphraseRequest,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user