aboutsummaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-25 17:39:29 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:57 +0200
commitdcd30dea651bad424219ae0f486fc6d49f534ee3 (patch)
treeadaeece2c2d829b12bf3f02c4e936f759c79e290 /unittest
parent8f4fb5d6320241a27d4d8c93d819daba40c58867 (diff)
downloadlibnitrokey-dcd30dea651bad424219ae0f486fc6d49f534ee3.tar.gz
libnitrokey-dcd30dea651bad424219ae0f486fc6d49f534ee3.tar.bz2
Add test for changing PINs
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'unittest')
-rw-r--r--unittest/test_bindings.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/unittest/test_bindings.py b/unittest/test_bindings.py
index 5da2bc0..34bd21b 100644
--- a/unittest/test_bindings.py
+++ b/unittest/test_bindings.py
@@ -1,5 +1,18 @@
import pytest
import cffi
+from enum import Enum
+
+RFC_SECRET = '12345678901234567890'
+
+class DefaultPasswords(Enum):
+ ADMIN = '12345678'
+ USER = '123456'
+
+class DeviceErrorCode(Enum):
+ STATUS_OK = 0
+ NOT_PROGRAMMED = 3
+ WRONG_PASSWORD = 4
+
ffi = cffi.FFI()
@@ -24,11 +37,28 @@ def C(request):
# C.NK_set_debug(True)
def fin():
C.NK_logout()
- request.addfinalizer(fin)
+
+ request.addfinalizer(fin)
return C
+def test_admin_PIN_change(C):
+ C.NK_set_debug(True)
+ assert C.NK_change_admin_PIN('wrong_password', '123123123') == DeviceErrorCode.WRONG_PASSWORD
+ assert C.NK_change_admin_PIN(DefaultPasswords.ADMIN, '123123123') == DeviceErrorCode.STATUS_OK
+ assert C.NK_change_admin_PIN('123123123', DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK
+ C.NK_set_debug(False)
+
+
+def test_user_PIN_change(C):
+ C.NK_set_debug(True)
+ assert C.NK_change_user_PIN('wrong_password', '123123123') == DeviceErrorCode.WRONG_PASSWORD
+ assert C.NK_change_user_PIN(DefaultPasswords.USER, '123123123') == DeviceErrorCode.STATUS_OK
+ assert C.NK_change_user_PIN('123123123', DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK
+ C.NK_set_debug(False)
+
+
def test_HOTP_RFC(C):
# https://tools.ietf.org/html/rfc4226#page-32
C.NK_write_hotp_slot(1, 'python_test', '12345678901234567890', 0, '123123123')