def test_no_backup_fails(client: Client):
    client.ensure_unlocked()
    assert client.features.initialized is True
    assert client.features.no_backup is True
    assert client.features.needs_backup is False

    # backup attempt should fail because no_backup=True
    with pytest.raises(TrezorFailure, match=r".*Seed already backed up"):
        device.backup(client)
Пример #2
0
def _assert_protection(client: Client,
                       pin: bool = True,
                       passphrase: bool = True) -> None:
    """Make sure PIN and passphrase protection have expected values"""
    with client:
        client.use_pin_sequence([PIN4])
        client.ensure_unlocked()
        assert client.features.pin_protection is pin
        assert client.features.passphrase_protection is passphrase
    client.clear_session()
def test_set_wipe_code_mismatch(client: Client):
    # Check that there is no wipe code protection.
    client.ensure_unlocked()
    assert client.features.wipe_code_protection is False

    # Let's set a new wipe code.
    with client:
        client.use_pin_sequence([WIPE_CODE4, WIPE_CODE6])
        client.set_expected_responses([
            messages.ButtonRequest(),
            messages.PinMatrixRequest(type=PinType.WipeCodeFirst),
            messages.PinMatrixRequest(type=PinType.WipeCodeSecond),
            messages.Failure(code=messages.FailureType.WipeCodeMismatch),
        ])
        with pytest.raises(exceptions.TrezorFailure):
            device.change_wipe_code(client)

    # Check that there is no wipe code protection.
    client.init_device()
    assert client.features.wipe_code_protection is False
def test_set_wipe_code_invalid(client: Client, invalid_wipe_code):
    # Let's set the wipe code
    ret = client.call_raw(messages.ChangeWipeCode())
    assert isinstance(ret, messages.ButtonRequest)

    # Confirm
    client.debug.press_yes()
    ret = client.call_raw(messages.ButtonAck())

    # Enter a wipe code containing an invalid digit
    assert isinstance(ret, messages.PinMatrixRequest)
    assert ret.type == PinType.WipeCodeFirst
    ret = client.call_raw(messages.PinMatrixAck(pin=invalid_wipe_code))

    # Ensure the invalid wipe code is detected
    assert isinstance(ret, messages.Failure)

    # Check that there's still no wipe code protection.
    client.init_device()
    client.ensure_unlocked()
    assert client.features.wipe_code_protection is False
def test_interrupt_backup_fails(client: Client):
    client.ensure_unlocked()
    assert client.features.initialized is True
    assert client.features.needs_backup is True
    assert client.features.unfinished_backup is False
    assert client.features.no_backup is False

    # start backup
    client.call_raw(messages.BackupDevice())

    # interupt backup by sending initialize
    client.init_device()

    # check that device state is as expected
    assert client.features.initialized is True
    assert client.features.needs_backup is False
    assert client.features.unfinished_backup is True
    assert client.features.no_backup is False

    # Second attempt at backup should fail
    with pytest.raises(TrezorFailure, match=r".*Seed already backed up"):
        device.backup(client)
Пример #6
0
def test_mnemonic(client: Client):
    client.ensure_unlocked()
    mnemonic = client.debug.state().mnemonic_secret
    assert mnemonic == MNEMONIC12.encode()