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 df845c9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pynitrokey/cli/nk3/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from threading import Thread
from types import TracebackType
from typing import Any, Callable, Iterable, Optional, Tuple, Type, Union
from fido2.ctap import CtapError

from tqdm import tqdm

Expand Down Expand Up @@ -352,6 +353,8 @@ def select(conn: CardConnection, aid: list[int]) -> bool:
"ImportDeleteFinal",
]

class NotSupported:
pass

@test_case("se050", "SE050")
def test_se050(ctx: TestContext, device: Nitrokey3Base) -> TestResult:
Expand All @@ -369,8 +372,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 +405,11 @@ 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 df845c9

Please sign in to comment.