From b37e5990aa409689e5d6162776583616ac03e0ac Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 25 Jul 2016 18:32:59 +0200 Subject: Enabling password safe and password safe status (latter not working yet) Signed-off-by: Szczepan Zalega --- unittest/test_bindings.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'unittest') diff --git a/unittest/test_bindings.py b/unittest/test_bindings.py index 6e87c65..ac77140 100644 --- a/unittest/test_bindings.py +++ b/unittest/test_bindings.py @@ -4,10 +4,12 @@ from enum import Enum RFC_SECRET = '12345678901234567890' + class DefaultPasswords(Enum): ADMIN = '12345678' USER = '123456' + class DeviceErrorCode(Enum): STATUS_OK = 0 NOT_PROGRAMMED = 3 @@ -16,6 +18,7 @@ class DeviceErrorCode(Enum): ffi = cffi.FFI() + @pytest.fixture(scope="module") def C(request): fp = '../NK_C_API.h' @@ -32,31 +35,41 @@ def C(request): ffi.cdef(declaration) C = ffi.dlopen("../build/libnitrokey.so") + C.NK_set_debug(False) C.NK_login('12345678', '123123123') # C.NK_set_debug(True) def fin(): + print ('\nFinishing connection to device') C.NK_logout() + print ('Finished') request.addfinalizer(fin) return C -def test_admin_PIN_change(C): +def test_enable_password_safe(C): + assert C.NK_enable_password_safe('wrong_password') == DeviceErrorCode.WRONG_PASSWORD + assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK + + +def test_password_safe_slot_status(C): C.NK_set_debug(True) + assert C.NK_get_password_safe_slot_status() == DeviceErrorCode.STATUS_OK + C.NK_set_debug(False) + + +def test_admin_PIN_change(C): 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): -- cgit v1.2.3