def test_sd_no_format(client): def input_flow(): yield # enable SD protection? client.debug.press_yes() yield # format SD card client.debug.press_no() with pytest.raises(TrezorFailure) as e, client: client.set_input_flow(input_flow) device.sd_protect(client, Op.ENABLE) assert e.value.failure.code == messages.FailureType.ProcessError
def sd_protect(hw_client, operation: Literal["enable", "disable", "refresh"]): if hw_client: op_code = { "enable": messages.SdProtectOperationType.ENABLE, "disable": messages.SdProtectOperationType.DISABLE, "refresh": messages.SdProtectOperationType.REFRESH, }.get(operation) if op_code is not None: try: device.sd_protect(hw_client, op_code) except exceptions.Cancelled: pass except exceptions.TrezorFailure as e: if e.failure.message == 'Device not initialized': raise HwNotInitialized(e.failure.message) else: raise else: raise Exception('Invalid operation code.') else: raise Exception('HW client not set.')
def test_refresh(client): assert client.features.sd_protection is False # Enable SD protection device.sd_protect(client, Op.ENABLE) assert client.features.sd_protection is True # Refresh SD protection device.sd_protect(client, Op.REFRESH) assert client.features.sd_protection is True # Disable SD protection device.sd_protect(client, Op.DISABLE) assert client.features.sd_protection is False # Refreshing SD protection should fail with pytest.raises(TrezorFailure): device.sd_protect(client, Op.REFRESH) assert client.features.sd_protection is False
def test_enable_disable(client): assert client.features.sd_protection is False # Disabling SD protection should fail with pytest.raises(TrezorFailure): device.sd_protect(client, Op.DISABLE) # Enable SD protection device.sd_protect(client, Op.ENABLE) assert client.features.sd_protection is True # Enabling SD protection should fail with pytest.raises(TrezorFailure): device.sd_protect(client, Op.ENABLE) assert client.features.sd_protection is True # Disable SD protection device.sd_protect(client, Op.DISABLE) assert client.features.sd_protection is False
def test_wipe(client): # Enable SD protection device.sd_protect(client, Op.ENABLE) assert client.features.sd_protection is True # Wipe device (this wipes internal storage) device.wipe(client) assert client.features.sd_protection is False # Restore device to working status debuglink.load_device_by_mnemonic( client, mnemonic=MNEMONIC12, pin=None, passphrase_protection=False, label="test" ) assert client.features.sd_protection is False # Enable SD protection device.sd_protect(client, Op.ENABLE) assert client.features.sd_protection is True # Refresh SD protection device.sd_protect(client, Op.REFRESH)
def test_sd_protect_unlock(client): def input_flow_enable_sd_protect(): yield # do you really want to enable SD protection assert "SD card protection" in client.debug.wait_layout().text client.debug.press_yes() yield # enter current PIN assert "PinDialog" == client.debug.wait_layout().text client.debug.input("1234") yield # you have successfully enabled SD protection assert "Success" in client.debug.wait_layout().text client.debug.press_yes() with client: client.set_input_flow(input_flow_enable_sd_protect) device.sd_protect(client, Op.ENABLE) def input_flow_change_pin(): yield # do you really want to change PIN? assert "Change PIN" in client.debug.wait_layout().text client.debug.press_yes() yield # enter current PIN assert "PinDialog" == client.debug.wait_layout().text client.debug.input("1234") yield # enter new PIN assert "PinDialog" == client.debug.wait_layout().text client.debug.input("1234") yield # enter new PIN again assert "PinDialog" == client.debug.wait_layout().text client.debug.input("1234") yield # Pin change successful assert "Success" in client.debug.wait_layout().text client.debug.press_yes() with client: client.set_input_flow(input_flow_change_pin) device.change_pin(client) client.debug.erase_sd_card(format=False) def input_flow_change_pin_format(): yield # do you really want to change PIN? assert "Change PIN" in client.debug.wait_layout().text client.debug.press_yes() yield # SD card problem assert "SD card problem" in client.debug.wait_layout().text client.debug.press_yes() # retry yield # still SD card problem assert "SD card problem" in client.debug.wait_layout().text client.debug.press_no() # do not retry with client, pytest.raises(TrezorFailure) as e: client.set_input_flow(input_flow_change_pin_format) device.change_pin(client) assert e.value.failure.code == messages.FailureType.ProcessError
def test_sd_format(client): device.sd_protect(client, Op.ENABLE) assert client.features.sd_protection is True
def test_sd_protect(self, client): # Disabling SD protection should fail with pytest.raises(TrezorFailure): device.sd_protect(client, proto.SdProtectOperationType.DISABLE) # Enable SD protection device.sd_protect(client, proto.SdProtectOperationType.ENABLE) # Enabling SD protection should fail with pytest.raises(TrezorFailure): device.sd_protect(client, proto.SdProtectOperationType.ENABLE) # Wipe device.wipe(client) debuglink.load_device_by_mnemonic( client, mnemonic=MNEMONIC12, pin="", passphrase_protection=False, label="test", ) # Enable SD protection device.sd_protect(client, proto.SdProtectOperationType.ENABLE) # Refresh SD protection device.sd_protect(client, proto.SdProtectOperationType.REFRESH) # Disable SD protection device.sd_protect(client, proto.SdProtectOperationType.DISABLE) # Refreshing SD protection should fail with pytest.raises(TrezorFailure): device.sd_protect(client, proto.SdProtectOperationType.REFRESH)