Skip to content

Commit

Permalink
Show test as skipped when not supported by the device
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Sep 29, 2023
1 parent 0b1035e commit 41797f1
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions pynitrokey/cli/nk3/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from types import TracebackType
from typing import Any, Callable, Iterable, Optional, Tuple, Type, Union

from fido2.ctap import CtapError
from tqdm import tqdm

from pynitrokey.cli.exceptions import CliException
Expand Down Expand Up @@ -354,6 +355,10 @@ def select(conn: CardConnection, aid: list[int]) -> bool:
]


class NotSupported:
pass


@test_case("se050", "SE050")
def test_se050(ctx: TestContext, device: Nitrokey3Base) -> TestResult:
from queue import Queue
Expand All @@ -368,10 +373,18 @@ def test_se050(ctx: TestContext, device: Nitrokey3Base) -> TestResult:
):
return TestResult(TestStatus.SKIPPED)

que: Queue[Optional[bytes]] = Queue()
que: Queue[Union[bytes, None, NotSupported]] = Queue()

def internal_se050_run(q: Queue[Optional[bytes]]) -> None:
q.put(AdminApp(device).se050_tests())
def internal_se050_run(
q: Queue[Union[bytes, None, NotSupported]],
) -> None:
try:
q.put(AdminApp(device).se050_tests())
except CtapError as e:
if e.code == CtapError.ERR.INVALID_LENGTH:
q.put(NotSupported())
else:
q.put(None)

t = Thread(target=internal_se050_run, args=[que])
t.start()
Expand All @@ -395,8 +408,17 @@ def internal_se050_run(q: Queue[Optional[bytes]]) -> None:
bar.close()
result = que.get()

if result is None or len(result) < 11:
return TestResult(TestStatus.FAILURE, "Did not get test run data")
if isinstance(result, NotSupported):
# This means that the device responded with `NotAvailable`, so either it is a version that doesn't support this feature or it was disabled at compile time
return TestResult(
TestStatus.SKIPPED,
"Testing SE050 functionality is not supported by the device",
)
elif result is None:
return TestResult(TestStatus.FAILURE, "Failed to get test run data")

if len(result) < 11:
return TestResult(TestStatus.FAILURE, "Did not get full test run data")
major = result[0]
minor = result[1]
patch = result[2]
Expand Down

0 comments on commit 41797f1

Please sign in to comment.