1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 08:38:07 +00:00

test: Use long PIN values in device tests.

This commit is contained in:
Andrew Kozlik 2020-08-14 11:03:49 +02:00 committed by Andrew Kozlik
parent 885b6f7214
commit 602761694f
4 changed files with 28 additions and 21 deletions

View File

@ -17,12 +17,15 @@
import pytest import pytest
from trezorlib import device, exceptions, messages from trezorlib import device, exceptions, messages
from trezorlib.client import MAX_PIN_LENGTH
PinType = messages.PinMatrixRequestType PinType = messages.PinMatrixRequestType
PIN4 = "1234" PIN4 = "1234"
WIPE_CODE4 = "4321" WIPE_CODE4 = "4321"
WIPE_CODE6 = "456789" WIPE_CODE6 = "456789"
WIPE_CODE_MAX = "".join(chr((i % 9) + ord("1")) for i in range(MAX_PIN_LENGTH))
WIPE_CODE_TOO_LONG = WIPE_CODE_MAX + "1"
pytestmark = pytest.mark.skip_t2 pytestmark = pytest.mark.skip_t2
@ -75,14 +78,14 @@ def test_set_remove_wipe_code(client):
assert client.features.wipe_code_protection is None assert client.features.wipe_code_protection is None
# Test set wipe code. # Test set wipe code.
_set_wipe_code(client, PIN4, WIPE_CODE4) _set_wipe_code(client, PIN4, WIPE_CODE_MAX)
# Check that there's wipe code protection now. # Check that there's wipe code protection now.
client.init_device() client.init_device()
assert client.features.wipe_code_protection is True assert client.features.wipe_code_protection is True
# Check that the wipe code is correct. # Check that the wipe code is correct.
_check_wipe_code(client, PIN4, WIPE_CODE4) _check_wipe_code(client, PIN4, WIPE_CODE_MAX)
# Test change wipe code. # Test change wipe code.
_set_wipe_code(client, PIN4, WIPE_CODE6) _set_wipe_code(client, PIN4, WIPE_CODE6)
@ -177,7 +180,7 @@ def test_set_pin_to_wipe_code(client):
assert isinstance(resp, messages.Address) assert isinstance(resp, messages.Address)
@pytest.mark.parametrize("invalid_wipe_code", ("1204", "", "1234567891")) @pytest.mark.parametrize("invalid_wipe_code", ("1204", "", WIPE_CODE_TOO_LONG))
def test_set_wipe_code_invalid(client, invalid_wipe_code): def test_set_wipe_code_invalid(client, invalid_wipe_code):
# Let's set the wipe code # Let's set the wipe code
ret = client.call_raw(messages.ChangeWipeCode()) ret = client.call_raw(messages.ChangeWipeCode())

View File

@ -17,12 +17,13 @@
import pytest import pytest
from trezorlib import btc, device, messages from trezorlib import btc, device, messages
from trezorlib.client import PASSPHRASE_TEST_PATH from trezorlib.client import MAX_PIN_LENGTH, PASSPHRASE_TEST_PATH
from trezorlib.exceptions import Cancelled, TrezorFailure from trezorlib.exceptions import Cancelled, TrezorFailure
PIN4 = "1234" PIN4 = "1234"
WIPE_CODE4 = "4321" WIPE_CODE4 = "4321"
WIPE_CODE6 = "456789" WIPE_CODE6 = "456789"
WIPE_CODE_MAX = "".join(chr((i % 10) + ord("0")) for i in range(MAX_PIN_LENGTH))
pytestmark = pytest.mark.skip_t1 pytestmark = pytest.mark.skip_t1
@ -61,12 +62,12 @@ def test_set_remove_wipe_code(client):
client.set_expected_responses( client.set_expected_responses(
[messages.ButtonRequest()] * 5 + [messages.Success, messages.Features] [messages.ButtonRequest()] * 5 + [messages.Success, messages.Features]
) )
client.use_pin_sequence([PIN4, WIPE_CODE4, WIPE_CODE4]) client.use_pin_sequence([PIN4, WIPE_CODE_MAX, WIPE_CODE_MAX])
device.change_wipe_code(client) device.change_wipe_code(client)
client.init_device() client.init_device()
assert client.features.wipe_code_protection is True assert client.features.wipe_code_protection is True
_check_wipe_code(client, PIN4, WIPE_CODE4) _check_wipe_code(client, PIN4, WIPE_CODE_MAX)
# Test change wipe code. # Test change wipe code.
with client: with client:

View File

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

View File

@ -17,11 +17,12 @@
import pytest import pytest
from trezorlib import btc, device, messages from trezorlib import btc, device, messages
from trezorlib.client import PASSPHRASE_TEST_PATH from trezorlib.client import MAX_PIN_LENGTH, PASSPHRASE_TEST_PATH
from trezorlib.exceptions import Cancelled from trezorlib.exceptions import Cancelled
PIN4 = "1234" PIN4 = "1234"
PIN6 = "789456" PIN60 = "789456" * 10
PIN_MAX = "".join(chr((i % 10) + ord("0")) for i in range(MAX_PIN_LENGTH))
pytestmark = pytest.mark.skip_t1 pytestmark = pytest.mark.skip_t1
@ -54,7 +55,7 @@ def test_set_pin(client):
# Let's set new PIN # Let's set new PIN
with client: with client:
client.use_pin_sequence([PIN6, PIN6]) client.use_pin_sequence([PIN_MAX, PIN_MAX])
client.set_expected_responses( client.set_expected_responses(
[messages.ButtonRequest] * 4 + [messages.Success, messages.Features] [messages.ButtonRequest] * 4 + [messages.Success, messages.Features]
) )
@ -62,7 +63,7 @@ def test_set_pin(client):
client.init_device() client.init_device()
assert client.features.pin_protection is True assert client.features.pin_protection is True
_check_pin(client, PIN6) _check_pin(client, PIN_MAX)
@pytest.mark.setup_client(pin=PIN4) @pytest.mark.setup_client(pin=PIN4)
@ -74,7 +75,7 @@ def test_change_pin(client):
# Let's change PIN # Let's change PIN
with client: with client:
client.use_pin_sequence([PIN4, PIN6, PIN6]) client.use_pin_sequence([PIN4, PIN_MAX, PIN_MAX])
client.set_expected_responses( client.set_expected_responses(
[messages.ButtonRequest] * 5 + [messages.Success, messages.Features] [messages.ButtonRequest] * 5 + [messages.Success, messages.Features]
) )
@ -84,7 +85,7 @@ def test_change_pin(client):
client.init_device() client.init_device()
assert client.features.pin_protection is True assert client.features.pin_protection is True
# Check that the PIN is correct # Check that the PIN is correct
_check_pin(client, PIN6) _check_pin(client, PIN_MAX)
@pytest.mark.setup_client(pin=PIN4) @pytest.mark.setup_client(pin=PIN4)
@ -121,7 +122,7 @@ def test_set_failed(client):
yield # enter new pin yield # enter new pin
client.debug.input(PIN4) client.debug.input(PIN4)
yield # enter new pin again (but different) yield # enter new pin again (but different)
client.debug.input(PIN6) client.debug.input(PIN60)
# failed retry # failed retry
yield # enter new pin yield # enter new pin