mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-16 17:42:02 +00:00
python/debuglink: make pin sequences configurable
This commit is contained in:
parent
f947fe97cc
commit
94b85efba1
@ -221,8 +221,12 @@ class DebugUI:
|
|||||||
self.input_flow = self.INPUT_FLOW_DONE
|
self.input_flow = self.INPUT_FLOW_DONE
|
||||||
|
|
||||||
def get_pin(self, code=None):
|
def get_pin(self, code=None):
|
||||||
if self.pin:
|
if isinstance(self.pin, str):
|
||||||
return self.pin
|
return self.debuglink.encode_pin(self.pin)
|
||||||
|
elif self.pin == []:
|
||||||
|
raise AssertionError("PIN sequence ended prematurely")
|
||||||
|
elif self.pin:
|
||||||
|
return self.debuglink.encode_pin(self.pin.pop(0))
|
||||||
else:
|
else:
|
||||||
return self.debuglink.read_pin_encoded()
|
return self.debuglink.read_pin_encoded()
|
||||||
|
|
||||||
@ -261,9 +265,6 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
|
|
||||||
self.filters = {}
|
self.filters = {}
|
||||||
|
|
||||||
# Always press Yes and provide correct pin
|
|
||||||
self.setup_debuglink(True, True)
|
|
||||||
|
|
||||||
# Do not expect any specific response from device
|
# Do not expect any specific response from device
|
||||||
self.expected_responses = None
|
self.expected_responses = None
|
||||||
self.current_response = None
|
self.current_response = None
|
||||||
@ -342,12 +343,11 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
self.expected_responses = expected
|
self.expected_responses = expected
|
||||||
self.current_response = 0
|
self.current_response = 0
|
||||||
|
|
||||||
def setup_debuglink(self, button, pin_correct):
|
def set_pin(self, pin):
|
||||||
# self.button = button # True -> YES button, False -> NO button
|
if isinstance(pin, str):
|
||||||
if pin_correct:
|
self.ui.pin = pin
|
||||||
self.ui.pin = None
|
|
||||||
else:
|
else:
|
||||||
self.ui.pin = "444222"
|
self.ui.pin = list(pin)
|
||||||
|
|
||||||
def set_passphrase(self, passphrase):
|
def set_passphrase(self, passphrase):
|
||||||
self.ui.passphrase = Mnemonic.normalize_string(passphrase)
|
self.ui.passphrase = Mnemonic.normalize_string(passphrase)
|
||||||
|
@ -41,25 +41,18 @@ class TestProtectCall:
|
|||||||
def test_pin(self, client):
|
def test_pin(self, client):
|
||||||
with client:
|
with client:
|
||||||
assert client.debug.read_pin()[0] == "1234"
|
assert client.debug.read_pin()[0] == "1234"
|
||||||
client.setup_debuglink(button=True, pin_correct=True)
|
|
||||||
client.set_expected_responses([proto.PinMatrixRequest(), proto.Address()])
|
client.set_expected_responses([proto.PinMatrixRequest(), proto.Address()])
|
||||||
self._some_protected_call(client)
|
self._some_protected_call(client)
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin="1234")
|
@pytest.mark.setup_client(pin="1234")
|
||||||
def test_incorrect_pin(self, client):
|
def test_incorrect_pin(self, client):
|
||||||
client.setup_debuglink(button=True, pin_correct=False)
|
client.set_pin("5678")
|
||||||
with pytest.raises(PinException):
|
|
||||||
self._some_protected_call(client)
|
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin="1234")
|
|
||||||
def test_cancelled_pin(self, client):
|
|
||||||
client.setup_debuglink(button=True, pin_correct=False) # PIN cancel
|
|
||||||
with pytest.raises(PinException):
|
with pytest.raises(PinException):
|
||||||
self._some_protected_call(client)
|
self._some_protected_call(client)
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
||||||
def test_exponential_backoff_with_reboot(self, client):
|
def test_exponential_backoff_with_reboot(self, client):
|
||||||
client.setup_debuglink(button=True, pin_correct=False)
|
client.set_pin("5678")
|
||||||
|
|
||||||
def test_backoff(attempts, start):
|
def test_backoff(attempts, start):
|
||||||
if attempts <= 1:
|
if attempts <= 1:
|
||||||
|
Loading…
Reference in New Issue
Block a user