|
|
|
@ -17,13 +17,15 @@
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from trezorlib import device, messages
|
|
|
|
|
from trezorlib.client import MAX_PIN_LENGTH
|
|
|
|
|
from trezorlib.exceptions import TrezorFailure
|
|
|
|
|
|
|
|
|
|
from ..common import get_test_address
|
|
|
|
|
|
|
|
|
|
PIN4 = "1234"
|
|
|
|
|
PIN6 = "789456"
|
|
|
|
|
|
|
|
|
|
PIN_MAX = "".join(chr((i % 9) + ord("1")) for i in range(MAX_PIN_LENGTH))
|
|
|
|
|
PIN_TOO_LONG = PIN_MAX + "1"
|
|
|
|
|
|
|
|
|
|
pytestmark = pytest.mark.skip_t2
|
|
|
|
|
|
|
|
|
@ -51,7 +53,7 @@ def test_set_pin(client):
|
|
|
|
|
|
|
|
|
|
# Let's set new PIN
|
|
|
|
|
with client:
|
|
|
|
|
client.use_pin_sequence([PIN6, PIN6])
|
|
|
|
|
client.use_pin_sequence([PIN_MAX, PIN_MAX])
|
|
|
|
|
client.set_expected_responses(
|
|
|
|
|
[
|
|
|
|
|
messages.ButtonRequest(code=messages.ButtonRequestType.ProtectCall),
|
|
|
|
@ -66,7 +68,7 @@ def test_set_pin(client):
|
|
|
|
|
# Check that there's PIN protection now
|
|
|
|
|
assert client.features.pin_protection is True
|
|
|
|
|
# Check that the PIN is correct
|
|
|
|
|
_check_pin(client, PIN6)
|
|
|
|
|
_check_pin(client, PIN_MAX)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.setup_client(pin=PIN4)
|
|
|
|
@ -77,7 +79,7 @@ def test_change_pin(client):
|
|
|
|
|
|
|
|
|
|
# Let's change PIN
|
|
|
|
|
with client:
|
|
|
|
|
client.use_pin_sequence([PIN4, PIN6, PIN6])
|
|
|
|
|
client.use_pin_sequence([PIN4, PIN_MAX, PIN_MAX])
|
|
|
|
|
client.set_expected_responses(
|
|
|
|
|
[
|
|
|
|
|
messages.ButtonRequest(code=messages.ButtonRequestType.ProtectCall),
|
|
|
|
@ -93,7 +95,7 @@ def test_change_pin(client):
|
|
|
|
|
# Check that there's still PIN protection now
|
|
|
|
|
assert client.features.pin_protection is True
|
|
|
|
|
# Check that the PIN is correct
|
|
|
|
|
_check_pin(client, PIN6)
|
|
|
|
|
_check_pin(client, PIN_MAX)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.setup_client(pin=PIN4)
|
|
|
|
@ -128,7 +130,7 @@ def test_set_mismatch(client):
|
|
|
|
|
# Let's set new PIN
|
|
|
|
|
with pytest.raises(TrezorFailure, match="PIN mismatch"), client:
|
|
|
|
|
# use different PINs for first and second attempt. This will fail.
|
|
|
|
|
client.use_pin_sequence([PIN4, PIN6])
|
|
|
|
|
client.use_pin_sequence([PIN4, PIN_MAX])
|
|
|
|
|
client.set_expected_responses(
|
|
|
|
|
[
|
|
|
|
|
messages.ButtonRequest(code=messages.ButtonRequestType.ProtectCall),
|
|
|
|
@ -169,7 +171,7 @@ def test_change_mismatch(client):
|
|
|
|
|
_check_pin(client, PIN4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("invalid_pin", ("1204", "", "1234567891"))
|
|
|
|
|
@pytest.mark.parametrize("invalid_pin", ("1204", "", PIN_TOO_LONG))
|
|
|
|
|
def test_set_invalid(client, invalid_pin):
|
|
|
|
|
assert client.features.pin_protection is False
|
|
|
|
|
|
|
|
|
@ -194,7 +196,7 @@ def test_set_invalid(client, invalid_pin):
|
|
|
|
|
_check_no_pin(client)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("invalid_pin", ("1204", "", "1234567891"))
|
|
|
|
|
@pytest.mark.parametrize("invalid_pin", ("1204", "", PIN_TOO_LONG))
|
|
|
|
|
@pytest.mark.setup_client(pin=PIN4)
|
|
|
|
|
def test_enter_invalid(client, invalid_pin):
|
|
|
|
|
assert client.features.pin_protection is True
|
|
|
|
|