mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-05 21:10:57 +00:00
test: allow session to be locked by default
[no changelog]
This commit is contained in:
parent
147c4586b4
commit
987b92f888
@ -61,6 +61,7 @@ class TrezorClient:
|
||||
_management_session: Session | None = None
|
||||
_features: messages.Features | None = None
|
||||
_protocol_version: int
|
||||
_has_setup_pin: bool = False # Should by used only by conftest
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -368,6 +368,8 @@ def client(
|
||||
needs_backup=setup_params["needs_backup"], # type: ignore
|
||||
no_backup=setup_params["no_backup"], # type: ignore
|
||||
)
|
||||
if setup_params["pin"] is not None:
|
||||
_raw_client._has_setup_pin = True
|
||||
|
||||
if request.node.get_closest_marker("experimental"):
|
||||
apply_settings(session, experimental_features=True)
|
||||
@ -396,7 +398,10 @@ def session(
|
||||
derive_cardano=derive_cardano, passphrase=passphrase
|
||||
)
|
||||
try:
|
||||
yield SessionDebugWrapper(session)
|
||||
wrapped_session = SessionDebugWrapper(session)
|
||||
if client._has_setup_pin:
|
||||
wrapped_session.lock()
|
||||
yield wrapped_session
|
||||
finally:
|
||||
pass
|
||||
# TODO
|
||||
|
@ -62,7 +62,7 @@ SLIP25_PATH = parse_path("m/10025h")
|
||||
@pytest.mark.setup_client(pin=PIN)
|
||||
def test_sign_tx(session: Session, chunkify: bool):
|
||||
# NOTE: FAKE input tx
|
||||
|
||||
assert session.features.unlocked is False
|
||||
commitment_data = b"\x0fwww.example.com" + (1).to_bytes(ROUND_ID_LEN, "big")
|
||||
|
||||
with session.client as client:
|
||||
|
@ -52,7 +52,6 @@ def set_autolock_delay(session: Session, delay):
|
||||
|
||||
|
||||
def test_apply_auto_lock_delay(session: Session):
|
||||
session.lock()
|
||||
set_autolock_delay(session, 10 * 1000)
|
||||
|
||||
time.sleep(0.1) # sleep less than auto-lock delay
|
||||
@ -80,14 +79,11 @@ def test_apply_auto_lock_delay(session: Session):
|
||||
],
|
||||
)
|
||||
def test_apply_auto_lock_delay_valid(session: Session, seconds):
|
||||
session.lock()
|
||||
set_autolock_delay(session, seconds * 1000)
|
||||
assert session.features.auto_lock_delay_ms == seconds * 1000
|
||||
|
||||
|
||||
def test_autolock_default_value(session: Session):
|
||||
session.lock()
|
||||
|
||||
assert session.features.auto_lock_delay_ms is None
|
||||
with session, session.client as client:
|
||||
client.use_pin_sequence([PIN4])
|
||||
@ -101,7 +97,6 @@ def test_autolock_default_value(session: Session):
|
||||
[0, 1, 9, 536871, 2**22],
|
||||
)
|
||||
def test_apply_auto_lock_delay_out_of_range(session: Session, seconds):
|
||||
session.lock()
|
||||
|
||||
with session, session.client as client:
|
||||
client.use_pin_sequence([PIN4])
|
||||
@ -119,8 +114,6 @@ def test_apply_auto_lock_delay_out_of_range(session: Session, seconds):
|
||||
|
||||
@pytest.mark.models("core")
|
||||
def test_autolock_cancels_ui(session: Session):
|
||||
session.lock()
|
||||
|
||||
set_autolock_delay(session, 10 * 1000)
|
||||
|
||||
resp = session.call_raw(
|
||||
@ -144,7 +137,6 @@ def test_autolock_cancels_ui(session: Session):
|
||||
|
||||
|
||||
def test_autolock_ignores_initialize(session: Session):
|
||||
session.lock()
|
||||
client = session.client
|
||||
set_autolock_delay(session, 10 * 1000)
|
||||
|
||||
@ -162,7 +154,6 @@ def test_autolock_ignores_initialize(session: Session):
|
||||
|
||||
|
||||
def test_autolock_ignores_getaddress(session: Session):
|
||||
session.lock()
|
||||
|
||||
set_autolock_delay(session, 10 * 1000)
|
||||
|
||||
|
@ -40,7 +40,6 @@ def _assert_busy(session: Session, should_be_busy: bool, screen: str = "Homescre
|
||||
|
||||
@pytest.mark.setup_client(pin=PIN)
|
||||
def test_busy_state(session: Session):
|
||||
session.lock()
|
||||
_assert_busy(session, False, "Lockscreen")
|
||||
assert session.features.unlocked is False
|
||||
|
||||
@ -68,7 +67,6 @@ def test_busy_state(session: Session):
|
||||
|
||||
@pytest.mark.models("core")
|
||||
def test_busy_expiry_core(session: Session):
|
||||
session.lock()
|
||||
WAIT_TIME_MS = 1500
|
||||
TOLERANCE = 1000
|
||||
|
||||
|
@ -59,7 +59,6 @@ def _set_expected_responses(session: Session):
|
||||
|
||||
|
||||
def test_apply_settings(session: Session):
|
||||
session.lock()
|
||||
assert session.features.label == "test"
|
||||
|
||||
with session:
|
||||
@ -71,7 +70,6 @@ def test_apply_settings(session: Session):
|
||||
|
||||
@pytest.mark.models("core")
|
||||
def test_apply_settings_rotation(session: Session):
|
||||
session.lock()
|
||||
assert session.features.display_rotation is None
|
||||
|
||||
with session:
|
||||
@ -83,7 +81,6 @@ def test_apply_settings_rotation(session: Session):
|
||||
|
||||
@pytest.mark.setup_client(pin=PIN4, passphrase=False)
|
||||
def test_apply_settings_passphrase(session: Session):
|
||||
session.lock()
|
||||
with session:
|
||||
_set_expected_responses(session)
|
||||
device.apply_settings(session, use_passphrase=True)
|
||||
@ -390,7 +387,6 @@ def test_safety_checks(session: Session):
|
||||
|
||||
@pytest.mark.models("core")
|
||||
def test_experimental_features(session: Session):
|
||||
session.lock()
|
||||
|
||||
def experimental_call():
|
||||
misc.get_nonce(session)
|
||||
|
@ -60,7 +60,7 @@ def _ensure_unlocked(session: Session, pin: str):
|
||||
|
||||
@pytest.mark.setup_client(pin=PIN4)
|
||||
def test_set_remove_wipe_code(session: Session):
|
||||
session.lock()
|
||||
|
||||
# Test set wipe code.
|
||||
assert session.features.wipe_code_protection is None
|
||||
_ensure_unlocked(session, PIN4)
|
||||
|
@ -41,7 +41,6 @@ def test_no_protection(session: Session):
|
||||
def test_correct_pin(session: Session):
|
||||
with session, session.client as client:
|
||||
client.use_pin_sequence([PIN4])
|
||||
session.lock() # TODO is the lock here necessary/correctly?
|
||||
# Expected responses differ between T1 and TT
|
||||
is_t1 = session.model is models.T1B1
|
||||
session.set_expected_responses(
|
||||
@ -66,7 +65,6 @@ def test_incorrect_pin_t1(session: Session):
|
||||
|
||||
@pytest.mark.models("core")
|
||||
def test_incorrect_pin_t2(session: Session):
|
||||
session.lock() # TODO is the lock here necessary/correctly?
|
||||
with session, session.client as client:
|
||||
# After first incorrect attempt, TT will not raise an error, but instead ask for another attempt
|
||||
client.use_pin_sequence([BAD_PIN, PIN4])
|
||||
@ -95,5 +93,4 @@ def test_exponential_backoff_t2(session: Session):
|
||||
with session.client as client:
|
||||
IF = InputFlowPINBackoff(client, BAD_PIN, PIN4)
|
||||
client.set_input_flow(IF.get())
|
||||
session.lock()
|
||||
get_test_address(session)
|
||||
|
@ -443,7 +443,6 @@ def test_signtx(session: Session):
|
||||
|
||||
@pytest.mark.setup_client(pin=PIN4, passphrase=False)
|
||||
def test_unlocked(session: Session):
|
||||
session.lock()
|
||||
assert session.features.unlocked is False
|
||||
|
||||
session = _assert_protection(session, passphrase=False)
|
||||
|
@ -23,6 +23,8 @@ from trezorlib.messages import SdProtectOperationType as Op
|
||||
|
||||
from .. import translations as TR
|
||||
|
||||
PIN = "1234"
|
||||
|
||||
pytestmark = pytest.mark.models("core", skip="safe3")
|
||||
|
||||
|
||||
@ -51,17 +53,16 @@ def test_sd_no_format(session: Session):
|
||||
|
||||
|
||||
@pytest.mark.sd_card
|
||||
@pytest.mark.setup_client(pin="1234")
|
||||
@pytest.mark.setup_client(pin=PIN)
|
||||
def test_sd_protect_unlock(session: Session):
|
||||
debug = session.client.debug
|
||||
layout = debug.read_layout
|
||||
session.lock()
|
||||
|
||||
def input_flow_enable_sd_protect():
|
||||
# debug.press_yes()
|
||||
yield # Enter PIN to unlock device
|
||||
assert "PinKeyboard" in layout().all_components()
|
||||
debug.input("1234")
|
||||
debug.input(PIN)
|
||||
|
||||
yield # do you really want to enable SD protection
|
||||
assert TR.sd_card__enable in layout().text_content()
|
||||
@ -69,7 +70,7 @@ def test_sd_protect_unlock(session: Session):
|
||||
|
||||
yield # enter current PIN
|
||||
assert "PinKeyboard" in layout().all_components()
|
||||
debug.input("1234")
|
||||
debug.input(PIN)
|
||||
|
||||
yield # you have successfully enabled SD protection
|
||||
assert TR.sd_card__enabled in layout().text_content()
|
||||
@ -87,15 +88,15 @@ def test_sd_protect_unlock(session: Session):
|
||||
|
||||
yield # enter current PIN
|
||||
assert "PinKeyboard" in layout().all_components()
|
||||
debug.input("1234")
|
||||
debug.input(PIN)
|
||||
|
||||
yield # enter new PIN
|
||||
assert "PinKeyboard" in layout().all_components()
|
||||
debug.input("1234")
|
||||
debug.input(PIN)
|
||||
|
||||
yield # enter new PIN again
|
||||
assert "PinKeyboard" in layout().all_components()
|
||||
debug.input("1234")
|
||||
debug.input(PIN)
|
||||
|
||||
yield # Pin change successful
|
||||
assert TR.pin__changed in layout().text_content()
|
||||
@ -115,7 +116,7 @@ def test_sd_protect_unlock(session: Session):
|
||||
|
||||
yield # enter current PIN
|
||||
assert "PinKeyboard" in layout().all_components()
|
||||
debug.input("1234")
|
||||
debug.input(PIN)
|
||||
|
||||
yield # SD card problem
|
||||
assert (
|
||||
|
Loading…
Reference in New Issue
Block a user