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

nk3 test: Add --deny-skipped option #375

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions pynitrokey/cli/nk3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ def rng(ctx: Context, length: int) -> None:
default=False,
help="List the selected tests instead of running them",
)
@click.option(
"--deny-skipped",
"deny_skipped",
is_flag=True,
default=False,
help="Return an error if one or more tests have been skipped",
)
@click.pass_obj
def test(
ctx: Context,
Expand All @@ -254,6 +261,7 @@ def test(
include: Optional[str],
exclude: Optional[str],
list_: bool,
deny_skipped: bool,
) -> None:
"""Run some tests on all connected Nitrokey 3 devices."""
from .test import (
Expand Down Expand Up @@ -296,7 +304,7 @@ def test(
results = []
test_ctx = TestContext(pin=pin)
for device in devices:
results.append(run_tests(test_ctx, device, test_selector))
results.append(run_tests(test_ctx, device, test_selector, deny_skipped))

n = len(devices)
success = sum(results)
Expand Down Expand Up @@ -551,7 +559,7 @@ def provision_fido2(ctx: Context, key_file: BinaryIO, cert_file: BinaryIO) -> No
raise CliException(f"Missing subject {name} in certificate")
if subject_attrs["OU"] != "Authenticator Attestation":
raise CliException(
f"Unexpected certificate subject OU {subject_attrs['OU']} (expected "
f"Unexpected certificate subject OU {subject_attrs['OU']!r} (expected "
"Authenticator Attestation)"
)

Expand Down
9 changes: 7 additions & 2 deletions pynitrokey/cli/nk3/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ def list_tests(selector: TestSelector) -> None:
print(f"- {test_case.name}: {test_case.description}")


def run_tests(ctx: TestContext, device: Nitrokey3Base, selector: TestSelector) -> bool:
def run_tests(
ctx: TestContext, device: Nitrokey3Base, selector: TestSelector, deny_skipped: bool
) -> bool:
test_cases = selector.select()
if not test_cases:
raise CliException("No test cases selected", support_hint=False)
Expand Down Expand Up @@ -388,4 +390,7 @@ def run_tests(ctx: TestContext, device: Nitrokey3Base, selector: TestSelector) -
local_print("")
local_print(f"{n} tests, {success} successful, {skipped} skipped, {failed} failed")

return all([result.status != TestStatus.FAILURE for result in results])
if deny_skipped:
return all([result.status == TestStatus.SUCCESS for result in results])
else:
return all([result.status != TestStatus.FAILURE for result in results])