Skip to content

Commit

Permalink
Add import-export tests and a progress bar (test is looong)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Aug 16, 2023
1 parent c83d23a commit 00de18b
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion pynitrokey/cli/nk3/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from struct import unpack
from types import TracebackType
from typing import Any, Callable, Iterable, Optional, Tuple, Type, Union
from threading import Thread
from tqdm import tqdm

from pynitrokey.cli.exceptions import CliException
from pynitrokey.fido2 import device_path_to_str
Expand Down Expand Up @@ -334,6 +336,19 @@ def select(conn: CardConnection, aid: list[int]) -> bool:
"AesSessionReadBinary2",
"AesSessionDeleteBinary",
"AesSessionDeleteKey",
"Pbkdf2WritePin",
"Pbkdf2Calculate",
"Pbkdf2Compare",
"Pbkdf2DeletePin",
"ImportWrite",
"ImportCipher",
"ImportExport",
"ImportDelete",
"ImportDeletionWorked",
"ImportImport",
"ImportCipher2",
"ImportComp",
"ImportDeleteFinal",
]


Expand All @@ -344,7 +359,30 @@ def test_se050(ctx: TestContext, device: Nitrokey3Base) -> TestResult:
firmware_version = ctx.firmware_version or device.version()
if firmware_version.core() < Version(1, 5, 0):
return TestResult(TestStatus.SKIPPED)
result = AdminApp(device).se050_tests()

result = None
def internal_se050_run():
result = AdminApp(device).se050_tests()
print(result)

t = Thread(target = internal_se050_run)
t.start()
bar = tqdm(desc="Running SE050 test", unit="%", bar_format="{l_bar}{bar}", total=900)
# 1m30 in increments of 0.1 second
for i in range(900):
t.join(0.1)
bar.update(1)
if not t.is_alive():
break
if i == 900-1:
bar.close()
return TestResult(
TestStatus.FAILURE,
f"Test timed out after 1m30",
)

bar.close()

if result is None or len(result) < 11:
return TestResult(TestStatus.FAILURE, "Did not get test run data")
major = result[0]
Expand Down

0 comments on commit 00de18b

Please sign in to comment.