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 28, 2023
1 parent e0937a4 commit 15a785d
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 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 @@ -353,6 +354,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 @@ -369,8 +374,16 @@ def test_se050(ctx: TestContext, device: Nitrokey3Base) -> TestResult:

que: Queue[Optional[bytes]] = Queue()

def internal_se050_run(q: Queue[Optional[bytes]]) -> None:
q.put(AdminApp(device).se050_tests())
def internal_se050_run(q: Queue[Optional[bytes] | 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)
except:
q.put(None)

t = Thread(target=internal_se050_run, args=[que])
t.start()
Expand All @@ -394,7 +407,14 @@ def internal_se050_run(q: Queue[Optional[bytes]]) -> None:
bar.close()
result = que.get()

if result is None or len(result) < 11:
print(result)
if result is 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 or len(result) < 11:
return TestResult(TestStatus.FAILURE, "Did not get test run data")
major = result[0]
minor = result[1]
Expand Down

0 comments on commit 15a785d

Please sign in to comment.