From dcd30dea651bad424219ae0f486fc6d49f534ee3 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 25 Jul 2016 17:39:29 +0200 Subject: Add test for changing PINs Signed-off-by: Szczepan Zalega --- unittest/test_bindings.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'unittest') 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') -- cgit v1.2.3