From 75803e41da73e50e6911758690fe29f4fea967e1 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Wed, 27 Nov 2024 18:15:19 +0100 Subject: [PATCH] test: fix handling of PASSPHRASE_ON_DEVICE [no changelog] --- python/src/trezorlib/client.py | 3 ++- python/src/trezorlib/debuglink.py | 4 ++-- python/src/trezorlib/transport/session.py | 5 ++++- tests/click_tests/test_autolock.py | 13 +++++++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index a80c44f6a6..8cf3e4bc02 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -126,7 +126,7 @@ class TrezorClient: def get_session( self, - passphrase: str | None = None, + passphrase: str | object | None = None, derive_cardano: bool = False, ) -> Session: """ @@ -141,6 +141,7 @@ class TrezorClient: passphrase = "" return SessionV1.new(self, passphrase, derive_cardano) if isinstance(self.protocol, ProtocolV2): + assert isinstance(passphrase, str) or passphrase is None return SessionV2.new(self, passphrase, derive_cardano) raise NotImplementedError # TODO diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index 7920d08ea9..38fdfd754f 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -1457,10 +1457,10 @@ class TrezorClientDebugLink(TrezorClient): def get_session( self, - passphrase: str | None = "", + passphrase: str | object | None = "", derive_cardano: bool = False, ) -> Session: - if passphrase is not None: + if isinstance(passphrase, str): passphrase = Mnemonic.normalize_string(passphrase) return super().get_session(passphrase, derive_cardano) diff --git a/python/src/trezorlib/transport/session.py b/python/src/trezorlib/transport/session.py index 9be4083194..2ac47115c5 100644 --- a/python/src/trezorlib/transport/session.py +++ b/python/src/trezorlib/transport/session.py @@ -93,7 +93,10 @@ class SessionV1(Session): @classmethod def new( - cls, client: TrezorClient, passphrase: str = "", derive_cardano: bool = False + cls, + client: TrezorClient, + passphrase: str | object = "", + derive_cardano: bool = False, ) -> SessionV1: assert isinstance(client.protocol, ProtocolV1) session_id = client.features.session_id diff --git a/tests/click_tests/test_autolock.py b/tests/click_tests/test_autolock.py index 25926df1c0..80d7fc1765 100644 --- a/tests/click_tests/test_autolock.py +++ b/tests/click_tests/test_autolock.py @@ -21,6 +21,7 @@ from typing import TYPE_CHECKING import pytest from trezorlib import btc, device, exceptions, messages +from trezorlib.client import PASSPHRASE_ON_DEVICE from trezorlib.debuglink import LayoutType from trezorlib.debuglink import SessionDebugWrapper as Session from trezorlib.protobuf import MessageType @@ -210,8 +211,10 @@ def test_autolock_passphrase_keyboard(device_handler: "BackgroundDeviceHandler") debug = device_handler.debuglink() # get address - device_handler.run_with_session(common.get_test_address) # type: ignore - + session = Session( + device_handler.client.get_session(passphrase=PASSPHRASE_ON_DEVICE) + ) + device_handler.run_with_provided_session(session, common.get_test_address) # type: ignore assert "PassphraseKeyboard" in debug.read_layout().all_components() if debug.layout_type is LayoutType.TR: @@ -252,8 +255,10 @@ def test_autolock_interrupts_passphrase(device_handler: "BackgroundDeviceHandler debug = device_handler.debuglink() # get address - device_handler.run_with_session(common.get_test_address) # type: ignore - + session = Session( + device_handler.client.get_session(passphrase=PASSPHRASE_ON_DEVICE) + ) + device_handler.run_with_provided_session(session, common.get_test_address) # type: ignore assert "PassphraseKeyboard" in debug.read_layout().all_components() if debug.layout_type is LayoutType.TR: