def client(): client = get_device() wipe_device(client) client.open() yield client client.close()
def client(): client = get_device() wipe_device(client) client.open() yield client client.close()
def client(): wirelink = get_device() client = TrezorClientDebugLink(wirelink) wipe_device(client) client.open() yield client client.close()
def client(): wirelink = get_device() client = TrezorClientDebugLink(wirelink) wipe_device(client) client.transport.session_begin() yield client client.transport.session_end() # XXX debuglink session must also be closed # client.close accomplishes that for now; going forward, there should # also be proper session handling for debuglink client.close()
def load_client(): try: client = get_device() except RuntimeError: request.session.shouldstop = "No debuggable Trezor is available" pytest.fail("No debuggable Trezor is available") wipe_device(client) debuglink.load_device_by_mnemonic( client, mnemonic=" ".join(["all"] * 12), pin=None, passphrase_protection=False, label="test", language="en-US", ) client.clear_session() client.open() return client
def client(request): client = get_device() wipe_device(client) client.open() # fmt: off setup_params = dict( uninitialized=False, mnemonic=" ".join(["all"] * 12), pin=None, passphrase=False, ) # fmt: on marker = request.node.get_closest_marker("setup_client") if marker: setup_params.update(marker.kwargs) if not setup_params["uninitialized"]: if setup_params["pin"] is True: setup_params["pin"] = "1234" debuglink.load_device_by_mnemonic( client, mnemonic=setup_params["mnemonic"], pin=setup_params["pin"], passphrase_protection=setup_params["passphrase"], label="test", language="english", ) client.clear_session() if setup_params["passphrase"] and client.features.model != "1": apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST) yield client client.close()
def load_client(): devices = enumerate_devices() for device in devices: try: client = TrezorClientDebugLink(device) break except Exception: pass else: raise RuntimeError("No debuggable device found") wipe_device(client) debuglink.load_device_by_mnemonic( client, mnemonic=" ".join(["all"] * 12), pin=None, passphrase_protection=False, label="test", language="english", ) client.clear_session() client.open() return client
def client(request): """Client fixture. Every test function that requires a client instance will get it from here. If we can't connect to a debuggable device, the test will fail. If 'skip_t2' is used and TT is connected, the test is skipped. Vice versa with T1 and 'skip_t1'. The client instance is wiped and preconfigured with "all all all..." mnemonic, no password and no pin. It is possible to customize this with the `setup_client` marker. To specify a custom mnemonic and/or custom pin and/or enable passphrase: @pytest.mark.setup_client(mnemonic=MY_MNEMONIC, pin="9999", passphrase=True) To receive a client instance that was not initialized: @pytest.mark.setup_client(uninitialized=True) """ try: client = get_device() except RuntimeError: pytest.fail("No debuggable Trezor is available") if request.node.get_closest_marker( "skip_t2") and client.features.model == "T": pytest.skip("Test excluded on Trezor T") if request.node.get_closest_marker( "skip_t1") and client.features.model == "1": pytest.skip("Test excluded on Trezor 1") if (request.node.get_closest_marker("sd_card") and not client.features.sd_card_present): raise RuntimeError("This test requires SD card.\n" "To skip all such tests, run:\n" " pytest -m 'not sd_card' <test path>") test_ui = request.config.getoption("ui") if test_ui not in ("", "record", "test"): raise ValueError("Invalid ui option.") run_ui_tests = not request.node.get_closest_marker("skip_ui") and test_ui client.open() if run_ui_tests: # we need to reseed before the wipe client.debug.reseed(0) wipe_device(client) setup_params = dict( uninitialized=False, mnemonic=" ".join(["all"] * 12), pin=None, passphrase=False, needs_backup=False, no_backup=False, ) marker = request.node.get_closest_marker("setup_client") if marker: setup_params.update(marker.kwargs) if not setup_params["uninitialized"]: if setup_params["pin"] is True: setup_params["pin"] = "1234" debuglink.load_device( client, mnemonic=setup_params["mnemonic"], pin=setup_params["pin"], passphrase_protection=setup_params["passphrase"], label="test", language="en-US", needs_backup=setup_params["needs_backup"], no_backup=setup_params["no_backup"], ) if setup_params["passphrase"] and client.features.model != "1": apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST) if setup_params["pin"]: # ClearSession locks the device. We only do that if the PIN is set. client.clear_session() if run_ui_tests: with ui_tests.screen_recording(client, request): yield client else: yield client client.close()
def client(request, _raw_client): """Client fixture. Every test function that requires a client instance will get it from here. If we can't connect to a debuggable device, the test will fail. If 'skip_t2' is used and TT is connected, the test is skipped. Vice versa with T1 and 'skip_t1'. The client instance is wiped and preconfigured with "all all all..." mnemonic, no password and no pin. It is possible to customize this with the `setup_client` marker. To specify a custom mnemonic and/or custom pin and/or enable passphrase: @pytest.mark.setup_client(mnemonic=MY_MNEMONIC, pin="9999", passphrase=True) To receive a client instance that was not initialized: @pytest.mark.setup_client(uninitialized=True) """ if request.node.get_closest_marker( "skip_t2") and _raw_client.features.model == "T": pytest.skip("Test excluded on Trezor T") if request.node.get_closest_marker( "skip_t1") and _raw_client.features.model == "1": pytest.skip("Test excluded on Trezor 1") sd_marker = request.node.get_closest_marker("sd_card") if sd_marker and not _raw_client.features.sd_card_present: raise RuntimeError("This test requires SD card.\n" "To skip all such tests, run:\n" " pytest -m 'not sd_card' <test path>") test_ui = request.config.getoption("ui") run_ui_tests = not request.node.get_closest_marker("skip_ui") and test_ui _raw_client.reset_debug_features() _raw_client.open() try: _raw_client.init_device() except Exception: request.session.shouldstop = "Failed to communicate with Trezor" pytest.fail("Failed to communicate with Trezor") if run_ui_tests: # we need to reseed before the wipe _raw_client.debug.reseed(0) if sd_marker: should_format = sd_marker.kwargs.get("formatted", True) _raw_client.debug.erase_sd_card(format=should_format) wipe_device(_raw_client) setup_params = dict( uninitialized=False, mnemonic=" ".join(["all"] * 12), pin=None, passphrase=False, needs_backup=False, no_backup=False, ) marker = request.node.get_closest_marker("setup_client") if marker: setup_params.update(marker.kwargs) use_passphrase = setup_params["passphrase"] is True or isinstance( setup_params["passphrase"], str) if not setup_params["uninitialized"]: debuglink.load_device( _raw_client, mnemonic=setup_params["mnemonic"], pin=setup_params["pin"], passphrase_protection=use_passphrase, label="test", language="en-US", needs_backup=setup_params["needs_backup"], no_backup=setup_params["no_backup"], ) if _raw_client.features.model == "T": apply_settings(_raw_client, experimental_features=True) if use_passphrase and isinstance(setup_params["passphrase"], str): _raw_client.use_passphrase(setup_params["passphrase"]) _raw_client.clear_session() if run_ui_tests: with ui_tests.screen_recording(_raw_client, request): yield _raw_client else: yield _raw_client _raw_client.close()
def client(request): """Client fixture. Every test function that requires a client instance will get it from here. If we can't connect to a debuggable device, the test will fail. If 'skip_t2' is used and TT is connected, the test is skipped. Vice versa with T1 and 'skip_t1'. The client instance is wiped and preconfigured with "all all all..." mnemonic, no password and no pin. It is possible to customize this with the `setup_client` marker. To specify a custom mnemonic and/or custom pin and/or enable passphrase: @pytest.mark.setup_client(mnemonic=MY_MNEMONIC, pin="9999", passphrase=True) To receive a client instance that was not initialized: @pytest.mark.setup_client(uninitialized=True) """ try: client = get_device() except RuntimeError: pytest.fail("No debuggable Trezor is available") if request.node.get_closest_marker( "skip_t2") and client.features.model == "T": pytest.skip("Test excluded on Trezor T") if request.node.get_closest_marker( "skip_t1") and client.features.model == "1": pytest.skip("Test excluded on Trezor 1") if (request.node.get_closest_marker("sd_card") and not client.features.sd_card_present): raise RuntimeError("This test requires SD card.\n" "To skip all such tests, run:\n" " pytest -m 'not sd_card' <test path>") wipe_device(client) # fmt: off setup_params = dict( uninitialized=False, mnemonic=" ".join(["all"] * 12), pin=None, passphrase=False, ) # fmt: on marker = request.node.get_closest_marker("setup_client") if marker: setup_params.update(marker.kwargs) if not setup_params["uninitialized"]: if setup_params["pin"] is True: setup_params["pin"] = "1234" debuglink.load_device_by_mnemonic( client, mnemonic=setup_params["mnemonic"], pin=setup_params["pin"], passphrase_protection=setup_params["passphrase"], label="test", language="english", ) client.clear_session() if setup_params["passphrase"] and client.features.model != "1": apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST) client.open() yield client client.close()