1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-22 20:42:03 +00:00

test: update device tests

[no changelog]
This commit is contained in:
M1nd3r 2025-02-04 15:01:55 +01:00
parent 6a3ee2f70f
commit 7d4aceb9cd
6 changed files with 35 additions and 0 deletions

View File

@ -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)

View File

@ -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(

View File

@ -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 ")

View File

@ -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])

View File

@ -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

View File

@ -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.