From 262434ea1ba30d46f8c877af064298358cfd67c5 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Sun, 1 Sep 2019 20:12:49 +0200 Subject: [PATCH] python/tests: Add SD protection device test. --- core/src/boot.py | 15 +++++- tests/device_tests/test_msg_sd_protect.py | 62 +++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/device_tests/test_msg_sd_protect.py diff --git a/core/src/boot.py b/core/src/boot.py index cbcf31065..a9f48d6ad 100644 --- a/core/src/boot.py +++ b/core/src/boot.py @@ -1,4 +1,4 @@ -from trezor import config, log, loop, res, ui +from trezor import config, io, log, loop, res, ui, utils from trezor.pin import pin_to_int, show_pin_timeout from apps.common import storage @@ -72,6 +72,19 @@ async def lockscreen() -> None: await ui.click() +if utils.EMULATOR: + # Ensure the emulated SD card is FAT32 formatted. + sd = io.SDCard() + fs = io.FatFS() + sd.power(True) + try: + fs.mount() + except OSError: + fs.mkfs() + else: + fs.unmount() + sd.power(False) + ui.display.backlight(ui.BACKLIGHT_NONE) ui.backlight_fade(ui.BACKLIGHT_NORMAL) config.init(show_pin_timeout) diff --git a/tests/device_tests/test_msg_sd_protect.py b/tests/device_tests/test_msg_sd_protect.py new file mode 100644 index 000000000..943d968fc --- /dev/null +++ b/tests/device_tests/test_msg_sd_protect.py @@ -0,0 +1,62 @@ +# 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 . + +import pytest + +from trezorlib import debuglink, device, messages as proto +from trezorlib.exceptions import TrezorFailure + +from ..common import MNEMONIC12 + + +@pytest.mark.skip_t1 +class TestMsgSdProtect: + @pytest.mark.setup_client(mnemonic=MNEMONIC12) + 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)