aboutsummaryrefslogtreecommitdiff
path: root/unittest/test_bindings.py
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-08-05 14:19:13 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-05 14:20:27 +0200
commit3a8637b673d9d92aac2a933d70439e42b68c5cb8 (patch)
treef1dca31c6de02ebbabab089d7c01d2f3845a8aea /unittest/test_bindings.py
parentf82d0574b133b23f69755ec854f8686282dd58ef (diff)
downloadlibnitrokey-3a8637b673d9d92aac2a933d70439e42b68c5cb8.tar.gz
libnitrokey-3a8637b673d9d92aac2a933d70439e42b68c5cb8.tar.bz2
Test factory reset command
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'unittest/test_bindings.py')
-rw-r--r--unittest/test_bindings.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/unittest/test_bindings.py b/unittest/test_bindings.py
index ace0609..fc680c0 100644
--- a/unittest/test_bindings.py
+++ b/unittest/test_bindings.py
@@ -20,6 +20,7 @@ class DeviceErrorCode(Enum):
NOT_PROGRAMMED = 3
WRONG_PASSWORD = 4
STATUS_NOT_AUTHORIZED = 5
+ STATUS_AES_DEC_FAILED = 0xa
@pytest.fixture(scope="module")
@@ -382,3 +383,30 @@ def test_read_write_config(C):
assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK
config = cast_pointer_to_tuple(config_raw_data, 'uint8_t', 5)
assert config == (255, 255, 255, False, True)
+
+
+def wait(t):
+ import time
+ msg = 'Waiting for %d seconds' % t
+ print(msg.center(40, '='))
+ time.sleep(t)
+
+
+# @pytest.mark.skip()
+def test_factory_reset(C):
+ C.NK_set_debug(True)
+ assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
+ assert C.NK_write_config(255, 255, 255, False, True, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
+ assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
+ assert C.NK_write_hotp_slot(1, 'python_test', RFC_SECRET, 0, False, False, False, "",
+ DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
+ assert C.NK_get_hotp_code(1) == 755224
+ assert C.NK_factory_reset(DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK
+ wait(10)
+ assert C.NK_get_hotp_code(1) != 287082
+ assert C.NK_get_last_command_status() == DeviceErrorCode.NOT_PROGRAMMED
+ # restore AES key
+ assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
+ assert C.NK_build_aes_key(DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK
+ assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK
+ assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK