aboutsummaryrefslogtreecommitdiff
path: root/unittest/helpers.py
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2020-02-25 14:10:30 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2020-02-26 12:26:39 +0100
commit55f9b7293c22bbedd5a972fa8f1946dfd57d9c7a (patch)
tree9eb28a9c2dd53f29280972d1fe2499e3ae8e5537 /unittest/helpers.py
parentb0550556c02625e59c11212421c4b81d9cddc961 (diff)
downloadlibnitrokey-55f9b7293c22bbedd5a972fa8f1946dfd57d9c7a.tar.gz
libnitrokey-55f9b7293c22bbedd5a972fa8f1946dfd57d9c7a.tar.bz2
Data retention test. Refactoring. Helper functions.
Diffstat (limited to 'unittest/helpers.py')
-rw-r--r--unittest/helpers.py35
1 files changed, 32 insertions, 3 deletions
diff --git a/unittest/helpers.py b/unittest/helpers.py
index 79f4e1e..90c818e 100644
--- a/unittest/helpers.py
+++ b/unittest/helpers.py
@@ -1,5 +1,5 @@
-def bb(x):
- return bytes(x, encoding='ascii')
+from constants import DeviceErrorCode, PWS_SLOT_COUNT, DefaultPasswords
+from misc import gs, bb
def helper_fill(str_to_fill, target_width):
@@ -19,4 +19,33 @@ def helper_PWS_get_loginname(suffix):
def helper_PWS_get_slotname(suffix):
- return helper_fill('slotname' + suffix, 11) \ No newline at end of file
+ return helper_fill('slotname' + suffix, 11)
+
+
+def helper_check_device_for_data(C):
+ assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK
+ assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK
+
+ for i in range(0, PWS_SLOT_COUNT):
+ iss = str(i)
+ assert gs(C.NK_get_password_safe_slot_name(i)) == helper_PWS_get_slotname(iss)
+ assert gs(C.NK_get_password_safe_slot_login(i)) == helper_PWS_get_loginname(iss)
+ assert gs(C.NK_get_password_safe_slot_password(i)) == helper_PWS_get_pass(iss)
+ return True
+
+
+def helper_populate_device(C):
+ # FIXME use object with random data, and check against it
+ # FIXME generate OTP as well, and check codes against its secrets
+ assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK
+ res = C.NK_enable_password_safe(DefaultPasswords.USER)
+ if res != 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
+
+ for i in range(0, PWS_SLOT_COUNT):
+ iss = str(i)
+ assert C.NK_write_password_safe_slot(i,
+ helper_PWS_get_slotname(iss), helper_PWS_get_loginname(iss),
+ helper_PWS_get_pass(iss)) == DeviceErrorCode.STATUS_OK
+ return True