From 39b9aff27f1d534e994978b25baa61a242297592 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Tue, 4 Feb 2025 15:01:55 +0100 Subject: [PATCH] test: update device tests [no changelog] --- tests/device_tests/test_cancel.py | 1 + tests/device_tests/test_debuglink.py | 3 +++ tests/device_tests/test_msg_applysettings.py | 5 +++++ tests/device_tests/test_protection_levels.py | 3 +++ tests/device_tests/test_session.py | 10 ++++++++++ .../device_tests/test_session_id_and_passphrase.py | 13 +++++++++++++ 6 files changed, 35 insertions(+) diff --git a/tests/device_tests/test_cancel.py b/tests/device_tests/test_cancel.py index a7fa64a454..9ab7e9165e 100644 --- a/tests/device_tests/test_cancel.py +++ b/tests/device_tests/test_cancel.py @@ -58,6 +58,7 @@ def test_cancel_message_via_cancel(session: Session, message): ), ], ) +@pytest.mark.protocol("protocol_v1") def test_cancel_message_via_initialize(session: Session, message): resp = session.call_raw(message) assert isinstance(resp, m.ButtonRequest) diff --git a/tests/device_tests/test_debuglink.py b/tests/device_tests/test_debuglink.py index 4123b5e1b4..d9445fddec 100644 --- a/tests/device_tests/test_debuglink.py +++ b/tests/device_tests/test_debuglink.py @@ -17,6 +17,7 @@ import pytest from trezorlib import debuglink, device, messages, misc +from trezorlib.client import ProtocolVersion from trezorlib.debuglink import SessionDebugWrapper as Session from trezorlib.debuglink import TrezorClientDebugLink as Client from trezorlib.tools import parse_path @@ -62,6 +63,8 @@ def test_pin(session: Session): @pytest.mark.models("core") def test_softlock_instability(session: Session): + if session.protocol_version == ProtocolVersion.PROTOCOL_V2: + raise Exception("THIS NEEDS TO BE CHANGED FOR THP") def load_device(): debuglink.load_device( diff --git a/tests/device_tests/test_msg_applysettings.py b/tests/device_tests/test_msg_applysettings.py index 40c18d2cab..ff5776a546 100644 --- a/tests/device_tests/test_msg_applysettings.py +++ b/tests/device_tests/test_msg_applysettings.py @@ -19,6 +19,7 @@ from pathlib import Path import pytest from trezorlib import btc, device, exceptions, messages, misc, models +from trezorlib.client import ProtocolVersion from trezorlib.debuglink import SessionDebugWrapper as Session from trezorlib.tools import parse_path @@ -205,6 +206,10 @@ def test_apply_homescreen_toif(session: Session): @pytest.mark.models(skip=["legacy", "safe3"]) def test_apply_homescreen_jpeg(session: Session): + if session.protocol_version is ProtocolVersion.PROTOCOL_V2: + raise Exception( + "FAILS BECAUSE THE MESSAGE IS BIGGER THAN THE INTERNAL READ BUFFER" + ) with open(HERE / "test_bg.jpg", "rb") as f: img = f.read() # raise Exception("FAILS FOR SOME REASON ") diff --git a/tests/device_tests/test_protection_levels.py b/tests/device_tests/test_protection_levels.py index 19bfe77934..1eaf327391 100644 --- a/tests/device_tests/test_protection_levels.py +++ b/tests/device_tests/test_protection_levels.py @@ -62,6 +62,8 @@ def _assert_protection( client.refresh_features() assert client.features.pin_protection is pin assert client.features.passphrase_protection is passphrase + if session.protocol_version == ProtocolVersion.PROTOCOL_V2: + new_session = session.client.get_session() session.lock() # session.end() if session.protocol_version == ProtocolVersion.PROTOCOL_V1: @@ -69,6 +71,7 @@ def _assert_protection( return Session(new_session) +@pytest.mark.protocol("protocol_v1") def test_initialize(session: Session): with session, session.client as client: client.use_pin_sequence([PIN4]) diff --git a/tests/device_tests/test_session.py b/tests/device_tests/test_session.py index e8df254129..378e16506f 100644 --- a/tests/device_tests/test_session.py +++ b/tests/device_tests/test_session.py @@ -31,6 +31,16 @@ XPUB = "xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7 PIN4 = "1234" +@pytest.mark.protocol("protocol_v2") +def test_thp_end_session(client: Client): + session = Session(client.get_session()) + + msg = session.call(messages.EndSession()) + assert isinstance(msg, messages.Success) + with pytest.raises(TrezorFailure, match="ThpUnallocatedSession"): + session.call(messages.GetFeatures()) + + @pytest.mark.setup_client(pin=PIN4, passphrase="") def test_clear_session(client: Client): is_t1 = client.model is models.T1B1 diff --git a/tests/device_tests/test_session_id_and_passphrase.py b/tests/device_tests/test_session_id_and_passphrase.py index 93ce1eeb45..4806b068d5 100644 --- a/tests/device_tests/test_session_id_and_passphrase.py +++ b/tests/device_tests/test_session_id_and_passphrase.py @@ -72,6 +72,7 @@ def _get_xpub( @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_session_with_passphrase(client: Client): session = Session(client.get_session(passphrase="A")) @@ -101,6 +102,7 @@ def test_session_with_passphrase(client: Client): @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_multiple_sessions(client: Client): # start SESSIONS_STORED sessions session_ids = [] @@ -143,6 +145,7 @@ def test_multiple_sessions(client: Client): @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_multiple_passphrases(client: Client): # start a session session_a = Session(client.get_session(passphrase="A")) @@ -179,6 +182,7 @@ def test_multiple_passphrases(client: Client): @pytest.mark.slow @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_max_sessions_with_passphrases(client: Client): # for the following tests, we are using as many passphrases as there are available sessions assert len(XPUB_PASSPHRASES) == SESSIONS_STORED @@ -224,6 +228,7 @@ def test_max_sessions_with_passphrases(client: Client): ) # passphrase is prompted +@pytest.mark.protocol("protocol_v1") def test_session_enable_passphrase(client: Client): # Let's start the communication by calling Initialize. session = Session(client.get_session(passphrase="")) @@ -250,6 +255,7 @@ def test_session_enable_passphrase(client: Client): @pytest.mark.models("core") @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_passphrase_on_device(client: Client): # _init_session(client) session = client.get_session(passphrase="A") @@ -289,6 +295,7 @@ def test_passphrase_on_device(client: Client): @pytest.mark.models("core") @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_passphrase_always_on_device(client: Client): # Let's start the communication by calling Initialize. session = client.get_session() @@ -324,6 +331,7 @@ def test_passphrase_always_on_device(client: Client): @pytest.mark.models("legacy") @pytest.mark.setup_client(passphrase="") +@pytest.mark.protocol("protocol_v1") def test_passphrase_on_device_not_possible_on_t1(client: Client): # This setting makes no sense on T1. response = client.call_raw(messages.ApplySettings(passphrase_always_on_device=True)) @@ -339,6 +347,7 @@ def test_passphrase_on_device_not_possible_on_t1(client: Client): @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_passphrase_ack_mismatch(session: Session): response = session.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) @@ -348,6 +357,7 @@ def test_passphrase_ack_mismatch(session: Session): @pytest.mark.setup_client(passphrase="") +@pytest.mark.protocol("protocol_v1") def test_passphrase_missing(session: Session): response = session.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) @@ -365,6 +375,7 @@ def test_passphrase_missing(session: Session): @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_passphrase_length(client: Client): def call(passphrase: str, expected_result: bool): session = client.get_session(passphrase=passphrase) @@ -390,6 +401,7 @@ def test_passphrase_length(client: Client): @pytest.mark.models("core") @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_hide_passphrase_from_host(client: Client): # Without safety checks, turning it on fails session = client.get_seedless_session() @@ -485,6 +497,7 @@ def _get_xpub_cardano(session: Session, expected_passphrase_req: bool = False): @pytest.mark.models("core") @pytest.mark.altcoin @pytest.mark.setup_client(passphrase=True) +@pytest.mark.protocol("protocol_v1") def test_cardano_passphrase(client: Client): # Cardano has a separate derivation method that needs to access the plaintext # of the passphrase.