mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-01 20:08:26 +00:00
test(python): fix persistence_tests
[no changelog]
This commit is contained in:
parent
7fc0874d68
commit
0d7080102f
@ -1023,7 +1023,6 @@ message_filters = MessageFilterGenerator()
|
|||||||
|
|
||||||
|
|
||||||
class SessionDebugWrapper(Session):
|
class SessionDebugWrapper(Session):
|
||||||
session_version: int
|
|
||||||
CODEC_V1: t.Final[int] = 1
|
CODEC_V1: t.Final[int] = 1
|
||||||
THP_V2: t.Final[int] = 2
|
THP_V2: t.Final[int] = 2
|
||||||
|
|
||||||
@ -1031,14 +1030,18 @@ class SessionDebugWrapper(Session):
|
|||||||
self._session = session
|
self._session = session
|
||||||
self.reset_debug_features()
|
self.reset_debug_features()
|
||||||
if isinstance(session, SessionV1):
|
if isinstance(session, SessionV1):
|
||||||
self.session_version = 1
|
self.client.session_version = 1
|
||||||
elif isinstance(session, SessionV2):
|
elif isinstance(session, SessionV2):
|
||||||
self.session_version = 2
|
self.client.session_version = 2
|
||||||
elif isinstance(session, SessionDebugWrapper):
|
elif isinstance(session, SessionDebugWrapper):
|
||||||
raise Exception("Cannot wrap already wrapped session!")
|
raise Exception("Cannot wrap already wrapped session!")
|
||||||
else:
|
else:
|
||||||
self.session_version = -1 # UNKNOWN
|
self.session_version = -1 # UNKNOWN
|
||||||
|
|
||||||
|
@property
|
||||||
|
def session_version(self) -> int:
|
||||||
|
return self.client.session_version
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self) -> TrezorClientDebugLink:
|
def client(self) -> TrezorClientDebugLink:
|
||||||
assert isinstance(self._session.client, TrezorClientDebugLink)
|
assert isinstance(self._session.client, TrezorClientDebugLink)
|
||||||
@ -1279,6 +1282,7 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
# by the device.
|
# by the device.
|
||||||
|
|
||||||
def __init__(self, transport: "Transport", auto_interact: bool = True) -> None:
|
def __init__(self, transport: "Transport", auto_interact: bool = True) -> None:
|
||||||
|
self._session_version: int = -1
|
||||||
try:
|
try:
|
||||||
debug_transport = transport.find_debug()
|
debug_transport = transport.find_debug()
|
||||||
self.debug = DebugLink(debug_transport, auto_interact)
|
self.debug = DebugLink(debug_transport, auto_interact)
|
||||||
@ -1305,6 +1309,14 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
self.debug.version = self.version
|
self.debug.version = self.version
|
||||||
self.passphrase: str | None = None
|
self.passphrase: str | None = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def session_version(self) -> int:
|
||||||
|
return self._session_version
|
||||||
|
|
||||||
|
@session_version.setter
|
||||||
|
def session_version(self, value: int) -> None:
|
||||||
|
self._session_version = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def layout_type(self) -> LayoutType:
|
def layout_type(self) -> LayoutType:
|
||||||
return self.debug.layout_type
|
return self.debug.layout_type
|
||||||
|
@ -20,16 +20,18 @@ from ..upgrade_tests import core_only
|
|||||||
def test_safety_checks_level_after_reboot(
|
def test_safety_checks_level_after_reboot(
|
||||||
core_emulator: Emulator, set_level: SafetyCheckLevel, after_level: SafetyCheckLevel
|
core_emulator: Emulator, set_level: SafetyCheckLevel, after_level: SafetyCheckLevel
|
||||||
):
|
):
|
||||||
device.wipe(core_emulator.client)
|
device.wipe(core_emulator.client.get_management_session())
|
||||||
|
core_emulator.client = core_emulator.client.get_new_client()
|
||||||
debuglink.load_device(
|
debuglink.load_device(
|
||||||
core_emulator.client,
|
core_emulator.client.get_management_session(),
|
||||||
mnemonic=MNEMONIC12,
|
mnemonic=MNEMONIC12,
|
||||||
pin="",
|
pin="",
|
||||||
passphrase_protection=False,
|
passphrase_protection=False,
|
||||||
label="SAFETYLEVEL",
|
label="SAFETYLEVEL",
|
||||||
)
|
)
|
||||||
|
|
||||||
device.apply_settings(core_emulator.client, safety_checks=set_level)
|
device.apply_settings(core_emulator.client.get_session(), safety_checks=set_level)
|
||||||
|
core_emulator.client.refresh_features()
|
||||||
assert core_emulator.client.features.safety_checks == set_level
|
assert core_emulator.client.features.safety_checks == set_level
|
||||||
|
|
||||||
core_emulator.restart()
|
core_emulator.restart()
|
||||||
|
@ -17,8 +17,11 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import device
|
from trezorlib import device
|
||||||
from trezorlib.debuglink import DebugLink, LayoutType
|
from trezorlib import messages
|
||||||
from trezorlib.messages import RecoveryStatus
|
from trezorlib.debuglink import DebugLink, LayoutType, SessionDebugWrapper as Session
|
||||||
|
from trezorlib.messages import RecoveryStatus, WipeDevice
|
||||||
|
|
||||||
|
from tests import buttons
|
||||||
|
|
||||||
from ..click_tests import common, recovery
|
from ..click_tests import common, recovery
|
||||||
from ..common import MNEMONIC_SLIP39_ADVANCED_20, MNEMONIC_SLIP39_BASIC_20_3of6
|
from ..common import MNEMONIC_SLIP39_ADVANCED_20, MNEMONIC_SLIP39_BASIC_20_3of6
|
||||||
@ -45,7 +48,7 @@ def test_abort(core_emulator: Emulator):
|
|||||||
|
|
||||||
assert features.recovery_status == RecoveryStatus.Nothing
|
assert features.recovery_status == RecoveryStatus.Nothing
|
||||||
|
|
||||||
device_handler.run(device.recover, pin_protection=False)
|
device_handler.run_with_session(device.recover, pin_protection=False)
|
||||||
|
|
||||||
recovery.confirm_recovery(debug)
|
recovery.confirm_recovery(debug)
|
||||||
layout = debug.read_layout()
|
layout = debug.read_layout()
|
||||||
@ -82,7 +85,7 @@ def test_recovery_single_reset(core_emulator: Emulator):
|
|||||||
assert features.initialized is False
|
assert features.initialized is False
|
||||||
assert features.recovery_status == RecoveryStatus.Nothing
|
assert features.recovery_status == RecoveryStatus.Nothing
|
||||||
|
|
||||||
device_handler.run(device.recover, pin_protection=False)
|
device_handler.run_with_session(device.recover, pin_protection=False)
|
||||||
|
|
||||||
recovery.confirm_recovery(debug)
|
recovery.confirm_recovery(debug)
|
||||||
|
|
||||||
@ -129,7 +132,7 @@ def test_recovery_on_old_wallet(core_emulator: Emulator):
|
|||||||
assert features.recovery_status == RecoveryStatus.Nothing
|
assert features.recovery_status == RecoveryStatus.Nothing
|
||||||
|
|
||||||
# enter recovery mode
|
# enter recovery mode
|
||||||
device_handler.run(device.recover, pin_protection=False)
|
device_handler.run_with_session(device.recover, pin_protection=False)
|
||||||
|
|
||||||
recovery.confirm_recovery(debug)
|
recovery.confirm_recovery(debug)
|
||||||
|
|
||||||
@ -157,7 +160,8 @@ def test_recovery_on_old_wallet(core_emulator: Emulator):
|
|||||||
layout = debug.read_layout()
|
layout = debug.read_layout()
|
||||||
|
|
||||||
# while keyboard is open, hit the device with Initialize/GetFeatures
|
# while keyboard is open, hit the device with Initialize/GetFeatures
|
||||||
device_handler.client.init_device()
|
if device_handler.client.session_version == Session.CODEC_V1:
|
||||||
|
device_handler.client.get_management_session().call(messages.Initialize())
|
||||||
device_handler.client.refresh_features()
|
device_handler.client.refresh_features()
|
||||||
|
|
||||||
# try entering remaining 19 words
|
# try entering remaining 19 words
|
||||||
@ -207,7 +211,7 @@ def test_recovery_multiple_resets(core_emulator: Emulator):
|
|||||||
assert features.recovery_status == RecoveryStatus.Nothing
|
assert features.recovery_status == RecoveryStatus.Nothing
|
||||||
|
|
||||||
# start device and recovery
|
# start device and recovery
|
||||||
device_handler.run(device.recover, pin_protection=False)
|
device_handler.run_with_session(device.recover, pin_protection=False)
|
||||||
|
|
||||||
recovery.confirm_recovery(debug)
|
recovery.confirm_recovery(debug)
|
||||||
|
|
||||||
|
@ -11,46 +11,55 @@ WIPE_CODE = "9876"
|
|||||||
|
|
||||||
|
|
||||||
def setup_device_legacy(client: Client, pin: str, wipe_code: str) -> None:
|
def setup_device_legacy(client: Client, pin: str, wipe_code: str) -> None:
|
||||||
device.wipe(client)
|
device.wipe(client.get_management_session())
|
||||||
|
client = client.get_new_client()
|
||||||
debuglink.load_device(
|
debuglink.load_device(
|
||||||
client, MNEMONIC12, pin, passphrase_protection=False, label="WIPECODE"
|
client.get_management_session(),
|
||||||
|
MNEMONIC12,
|
||||||
|
pin,
|
||||||
|
passphrase_protection=False,
|
||||||
|
label="WIPECODE",
|
||||||
)
|
)
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.use_pin_sequence([PIN, WIPE_CODE, WIPE_CODE])
|
client.use_pin_sequence([PIN, WIPE_CODE, WIPE_CODE])
|
||||||
device.change_wipe_code(client)
|
device.change_wipe_code(client.get_management_session())
|
||||||
|
|
||||||
|
|
||||||
def setup_device_core(client: Client, pin: str, wipe_code: str) -> None:
|
def setup_device_core(client: Client, pin: str, wipe_code: str) -> None:
|
||||||
device.wipe(client)
|
device.wipe(client.get_management_session())
|
||||||
|
client = client.get_new_client()
|
||||||
debuglink.load_device(
|
debuglink.load_device(
|
||||||
client, MNEMONIC12, pin, passphrase_protection=False, label="WIPECODE"
|
client.get_management_session(),
|
||||||
|
MNEMONIC12,
|
||||||
|
pin,
|
||||||
|
passphrase_protection=False,
|
||||||
|
label="WIPECODE",
|
||||||
)
|
)
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.use_pin_sequence([pin, wipe_code, wipe_code])
|
client.use_pin_sequence([pin, wipe_code, wipe_code])
|
||||||
device.change_wipe_code(client)
|
device.change_wipe_code(client.get_management_session())
|
||||||
|
|
||||||
|
|
||||||
@core_only
|
@core_only
|
||||||
def test_wipe_code_activate_core(core_emulator: Emulator):
|
def test_wipe_code_activate_core(core_emulator: Emulator):
|
||||||
# set up device
|
# set up device
|
||||||
setup_device_core(core_emulator.client, PIN, WIPE_CODE)
|
setup_device_core(core_emulator.client, PIN, WIPE_CODE)
|
||||||
|
session = core_emulator.client.get_session()
|
||||||
core_emulator.client.init_device()
|
|
||||||
device_id = core_emulator.client.features.device_id
|
device_id = core_emulator.client.features.device_id
|
||||||
|
|
||||||
# Initiate Change pin process
|
# Initiate Change pin process
|
||||||
ret = core_emulator.client.call_raw(messages.ChangePin(remove=False))
|
ret = session.call_raw(messages.ChangePin(remove=False))
|
||||||
assert isinstance(ret, messages.ButtonRequest)
|
assert isinstance(ret, messages.ButtonRequest)
|
||||||
assert ret.name == "change_pin"
|
assert ret.name == "change_pin"
|
||||||
core_emulator.client.debug.press_yes()
|
core_emulator.client.debug.press_yes()
|
||||||
ret = core_emulator.client.call_raw(messages.ButtonAck())
|
ret = session.call_raw(messages.ButtonAck())
|
||||||
|
|
||||||
# Enter the wipe code instead of the current PIN
|
# Enter the wipe code instead of the current PIN
|
||||||
expected = message_filters.ButtonRequest(code=messages.ButtonRequestType.PinEntry)
|
expected = message_filters.ButtonRequest(code=messages.ButtonRequestType.PinEntry)
|
||||||
assert expected.match(ret)
|
assert expected.match(ret)
|
||||||
core_emulator.client._raw_write(messages.ButtonAck())
|
session._write(messages.ButtonAck())
|
||||||
core_emulator.client.debug.input(WIPE_CODE)
|
core_emulator.client.debug.input(WIPE_CODE)
|
||||||
|
|
||||||
# preserving screenshots even after it dies and starts again
|
# preserving screenshots even after it dies and starts again
|
||||||
@ -75,25 +84,26 @@ def test_wipe_code_activate_legacy():
|
|||||||
# set up device
|
# set up device
|
||||||
setup_device_legacy(emu.client, PIN, WIPE_CODE)
|
setup_device_legacy(emu.client, PIN, WIPE_CODE)
|
||||||
|
|
||||||
emu.client.init_device()
|
session = emu.client.get_session()
|
||||||
device_id = emu.client.features.device_id
|
device_id = emu.client.features.device_id
|
||||||
|
|
||||||
# Initiate Change pin process
|
# Initiate Change pin process
|
||||||
ret = emu.client.call_raw(messages.ChangePin(remove=False))
|
ret = session.call_raw(messages.ChangePin(remove=False))
|
||||||
assert isinstance(ret, messages.ButtonRequest)
|
assert isinstance(ret, messages.ButtonRequest)
|
||||||
emu.client.debug.press_yes()
|
emu.client.debug.press_yes()
|
||||||
ret = emu.client.call_raw(messages.ButtonAck())
|
ret = session.call_raw(messages.ButtonAck())
|
||||||
|
|
||||||
# Enter the wipe code instead of the current PIN
|
# Enter the wipe code instead of the current PIN
|
||||||
assert isinstance(ret, messages.PinMatrixRequest)
|
assert isinstance(ret, messages.PinMatrixRequest)
|
||||||
wipe_code_encoded = emu.client.debug.encode_pin(WIPE_CODE)
|
wipe_code_encoded = emu.client.debug.encode_pin(WIPE_CODE)
|
||||||
emu.client._raw_write(messages.PinMatrixAck(pin=wipe_code_encoded))
|
session._write(messages.PinMatrixAck(pin=wipe_code_encoded))
|
||||||
|
|
||||||
# wait 30 seconds for emulator to shut down
|
# wait 30 seconds for emulator to shut down
|
||||||
# this will raise a TimeoutError if the emulator doesn't die.
|
# this will raise a TimeoutError if the emulator doesn't die.
|
||||||
emu.wait(30)
|
emu.wait(30)
|
||||||
|
|
||||||
emu.start()
|
emu.start()
|
||||||
|
emu.client.refresh_features()
|
||||||
assert emu.client.features.initialized is False
|
assert emu.client.features.initialized is False
|
||||||
assert emu.client.features.pin_protection is False
|
assert emu.client.features.pin_protection is False
|
||||||
assert emu.client.features.wipe_code_protection is False
|
assert emu.client.features.wipe_code_protection is False
|
||||||
|
Loading…
Reference in New Issue
Block a user