2019-08-14 13:46:08 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from trezorlib import device, exceptions, messages
|
|
|
|
|
2019-09-02 08:20:51 +00:00
|
|
|
from .common import MNEMONIC_SHAMIR_20_2of3_2of3_GROUPS, recovery_enter_shares
|
2019-08-14 13:46:08 +00:00
|
|
|
|
2019-09-02 08:20:51 +00:00
|
|
|
pytestmark = pytest.mark.skip_t1
|
2019-08-14 13:46:08 +00:00
|
|
|
|
|
|
|
|
2019-08-28 15:05:01 +00:00
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
2019-08-14 13:46:08 +00:00
|
|
|
def test_recover_no_pin_no_passphrase(client):
|
|
|
|
debug = client.debug
|
|
|
|
|
|
|
|
def input_flow():
|
|
|
|
yield # Confirm Recovery
|
|
|
|
debug.press_yes()
|
|
|
|
# Proceed with recovery
|
2019-09-02 08:20:51 +00:00
|
|
|
yield from recovery_enter_shares(
|
|
|
|
debug, MNEMONIC_SHAMIR_20_2of3_2of3_GROUPS, groups=True
|
|
|
|
)
|
2019-08-14 13:46:08 +00:00
|
|
|
|
|
|
|
with client:
|
|
|
|
client.set_input_flow(input_flow)
|
|
|
|
ret = device.recover(
|
|
|
|
client, pin_protection=False, passphrase_protection=False, label="label"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Workflow succesfully ended
|
|
|
|
assert ret == messages.Success(message="Device recovered")
|
|
|
|
assert client.features.initialized is True
|
|
|
|
assert client.features.pin_protection is False
|
|
|
|
assert client.features.passphrase_protection is False
|
|
|
|
|
|
|
|
|
2019-08-28 15:05:01 +00:00
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
2019-08-14 13:46:08 +00:00
|
|
|
def test_abort(client):
|
|
|
|
debug = client.debug
|
|
|
|
|
|
|
|
def input_flow():
|
|
|
|
yield # Confirm Recovery
|
|
|
|
debug.press_yes()
|
|
|
|
yield # Homescreen - abort process
|
|
|
|
debug.press_no()
|
|
|
|
yield # Homescreen - confirm abort
|
|
|
|
debug.press_yes()
|
|
|
|
|
|
|
|
with client:
|
|
|
|
client.set_input_flow(input_flow)
|
|
|
|
with pytest.raises(exceptions.Cancelled):
|
|
|
|
device.recover(client, pin_protection=False, label="label")
|
|
|
|
client.init_device()
|
|
|
|
assert client.features.initialized is False
|
|
|
|
|
|
|
|
|
2019-08-28 15:05:01 +00:00
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
2019-08-14 13:46:08 +00:00
|
|
|
def test_noabort(client):
|
|
|
|
debug = client.debug
|
|
|
|
|
|
|
|
def input_flow():
|
|
|
|
yield # Confirm Recovery
|
|
|
|
debug.press_yes()
|
|
|
|
yield # Homescreen - abort process
|
|
|
|
debug.press_no()
|
|
|
|
yield # Homescreen - go back to process
|
|
|
|
debug.press_no()
|
2019-09-02 08:20:51 +00:00
|
|
|
yield from recovery_enter_shares(
|
|
|
|
debug, MNEMONIC_SHAMIR_20_2of3_2of3_GROUPS, groups=True
|
|
|
|
)
|
2019-08-14 13:46:08 +00:00
|
|
|
|
|
|
|
with client:
|
|
|
|
client.set_input_flow(input_flow)
|
|
|
|
device.recover(client, pin_protection=False, label="label")
|
|
|
|
client.init_device()
|
|
|
|
assert client.features.initialized is True
|