Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow prod pki usage in Ragger #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/ragger/conftest/base_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def pytest_addoption(parser):
default=False,
help="Do not compare the snapshots during testing, but instead save the live "
"ones. Will only work with 'speculos' as the backend")
parser.addoption("--pki_prod",
action="store_true",
default=False,
help="Have Speculos accept prod PKI certificates instead of test")
parser.addoption("--log_apdu_file", action="store", default=None, help="Log the APDU in a file")
parser.addoption("--seed", action="store", default=None, help="Set a custom seed")

Expand Down Expand Up @@ -68,6 +72,11 @@ def cli_user_seed(pytestconfig):
return pytestconfig.getoption("seed")


@pytest.fixture(scope="session")
def pki_prod(pytestconfig):
return pytestconfig.getoption("pki_prod")


@pytest.fixture(scope="session")
def root_pytest_dir(request) -> Path:
return Path(request.config.rootpath).resolve()
Expand Down Expand Up @@ -142,12 +151,14 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize("firmware", fw_list, ids=ids, scope="session")


def prepare_speculos_args(root_pytest_dir: Path, firmware: Firmware, display: bool,
def prepare_speculos_args(root_pytest_dir: Path, firmware: Firmware, display: bool, pki_prod: bool,
cli_user_seed: str, additional_args: List[str]):
speculos_args = additional_args.copy()

if display:
speculos_args += ["--display", "qt"]
if pki_prod:
speculos_args += ["-p"]

device = firmware.name
if device == "nanosp":
Expand Down Expand Up @@ -206,7 +217,7 @@ def prepare_speculos_args(root_pytest_dir: Path, firmware: Firmware, display: bo
# instantiated, and the tests will either run on Speculos or on a physical
# device depending on the backend
def create_backend(root_pytest_dir: Path, backend_name: str, firmware: Firmware, display: bool,
log_apdu_file: Optional[Path], cli_user_seed: str,
pki_prod: bool, log_apdu_file: Optional[Path], cli_user_seed: str,
additional_speculos_arguments: List[str]) -> BackendInterface:
if backend_name.lower() == "ledgercomm":
return LedgerCommBackend(firmware=firmware,
Expand All @@ -217,7 +228,7 @@ def create_backend(root_pytest_dir: Path, backend_name: str, firmware: Firmware,
return LedgerWalletBackend(firmware=firmware, log_apdu_file=log_apdu_file, with_gui=display)
elif backend_name.lower() == "speculos":
main_app_path, speculos_args = prepare_speculos_args(root_pytest_dir, firmware, display,
cli_user_seed,
pki_prod, cli_user_seed,
additional_speculos_arguments)
return SpeculosBackend(main_app_path,
firmware=firmware,
Expand All @@ -232,9 +243,10 @@ def create_backend(root_pytest_dir: Path, backend_name: str, firmware: Firmware,
# before trying to find the binary
@pytest.fixture(scope=conf.OPTIONAL.BACKEND_SCOPE)
def backend(skip_tests_for_unsupported_devices, root_pytest_dir: Path, backend_name: str,
firmware: Firmware, display: bool, log_apdu_file: Optional[Path], cli_user_seed: str,
firmware: Firmware, display: bool, pki_prod: bool, log_apdu_file: Optional[Path],
cli_user_seed: str,
additional_speculos_arguments: List[str]) -> Generator[BackendInterface, None, None]:
with create_backend(root_pytest_dir, backend_name, firmware, display, log_apdu_file,
with create_backend(root_pytest_dir, backend_name, firmware, display, pki_prod, log_apdu_file,
cli_user_seed, additional_speculos_arguments) as b:
if backend_name.lower() != "speculos" and conf.OPTIONAL.APP_NAME:
# Make sure the app is restarted as this is what is requested by the fixture scope
Expand Down
Loading