aboutsummaryrefslogtreecommitdiff
path: root/unittest/test_library.py
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-10-10 18:25:32 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2017-10-10 18:25:32 +0200
commit343e4b1e6d53f042df84e951209b5a33b9a617c3 (patch)
treeba771942520fe6649d6e47a223814a260b9c5f31 /unittest/test_library.py
parentfa871ecba4333ffe9a96b0a662b9d77089cf69b7 (diff)
parentbe675e293fe94a4a6926125a61e67e92e8788d8a (diff)
downloadlibnitrokey-343e4b1e6d53f042df84e951209b5a33b9a617c3.tar.gz
libnitrokey-343e4b1e6d53f042df84e951209b5a33b9a617c3.tar.bz2
Merge branch 'test_organize'
Improve test organization Disable CRC check Improve log
Diffstat (limited to 'unittest/test_library.py')
-rw-r--r--unittest/test_library.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/unittest/test_library.py b/unittest/test_library.py
index b24c72a..7012619 100644
--- a/unittest/test_library.py
+++ b/unittest/test_library.py
@@ -1,12 +1,12 @@
import pytest
from misc import ffi, gs, to_hex, is_pro_rtm_07, is_long_OTP_secret_handled
-from constants import DefaultPasswords, DeviceErrorCode, RFC_SECRET, LibraryErrors
+from constants import DefaultPasswords, DeviceErrorCode, RFC_SECRET, LibraryErrors, bbRFC_SECRET
def test_too_long_strings(C):
- new_password = '123123123'
- long_string = 'a' * 100
+ new_password = b'123123123'
+ long_string = b'a' * 100
assert C.NK_change_user_PIN(long_string, new_password) == LibraryErrors.TOO_LONG_STRING
assert C.NK_change_user_PIN(new_password, long_string) == LibraryErrors.TOO_LONG_STRING
assert C.NK_change_admin_PIN(long_string, new_password) == LibraryErrors.TOO_LONG_STRING
@@ -14,26 +14,26 @@ def test_too_long_strings(C):
assert C.NK_first_authenticate(long_string, DefaultPasswords.ADMIN_TEMP) == LibraryErrors.TOO_LONG_STRING
assert C.NK_erase_totp_slot(0, long_string) == LibraryErrors.TOO_LONG_STRING
digits = False
- assert C.NK_write_hotp_slot(1, long_string, RFC_SECRET, 0, digits, False, False, "",
+ assert C.NK_write_hotp_slot(1, long_string, bbRFC_SECRET, 0, digits, False, False, b"",
DefaultPasswords.ADMIN_TEMP) == LibraryErrors.TOO_LONG_STRING
- assert C.NK_write_hotp_slot(1, 'long_test', RFC_SECRET, 0, digits, False, False, "",
+ assert C.NK_write_hotp_slot(1, b'long_test', bbRFC_SECRET, 0, digits, False, False, b"",
long_string) == LibraryErrors.TOO_LONG_STRING
- assert C.NK_get_hotp_code_PIN(0, long_string) == 0
+ assert gs(C.NK_get_hotp_code_PIN(0, long_string)) == b""
assert C.NK_get_last_command_status() == LibraryErrors.TOO_LONG_STRING
def test_invalid_slot(C):
invalid_slot = 255
- assert C.NK_erase_totp_slot(invalid_slot, 'some password') == LibraryErrors.INVALID_SLOT
- assert C.NK_write_hotp_slot(invalid_slot, 'long_test', RFC_SECRET, 0, False, False, False, "",
- 'aaa') == LibraryErrors.INVALID_SLOT
- assert C.NK_get_hotp_code_PIN(invalid_slot, 'some password') == 0
+ assert C.NK_erase_totp_slot(invalid_slot, b'some password') == LibraryErrors.INVALID_SLOT
+ assert C.NK_write_hotp_slot(invalid_slot, b'long_test', bbRFC_SECRET, 0, False, False, False, b"",
+ b'aaa') == LibraryErrors.INVALID_SLOT
+ assert gs(C.NK_get_hotp_code_PIN(invalid_slot, b'some password')) == b""
assert C.NK_get_last_command_status() == LibraryErrors.INVALID_SLOT
assert C.NK_erase_password_safe_slot(invalid_slot) == LibraryErrors.INVALID_SLOT
assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK
- assert gs(C.NK_get_password_safe_slot_name(invalid_slot)) == ''
+ assert gs(C.NK_get_password_safe_slot_name(invalid_slot)) == b''
assert C.NK_get_last_command_status() == LibraryErrors.INVALID_SLOT
- assert gs(C.NK_get_password_safe_slot_login(invalid_slot)) == ''
+ assert gs(C.NK_get_password_safe_slot_login(invalid_slot)) == b''
assert C.NK_get_last_command_status() == LibraryErrors.INVALID_SLOT
@@ -44,17 +44,19 @@ def test_invalid_secret_hex_string_for_OTP_write(C, invalid_hex_string):
Tests for invalid secret hex string during writing to OTP slot. Invalid strings are not hexadecimal number,
empty or longer than 255 characters.
"""
+ invalid_hex_string = invalid_hex_string.encode('ascii')
assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
- assert C.NK_write_hotp_slot(1, 'slot_name', invalid_hex_string, 0, True, False, False, '',
+ assert C.NK_write_hotp_slot(1, b'slot_name', invalid_hex_string, 0, True, False, False, b'',
DefaultPasswords.ADMIN_TEMP) == LibraryErrors.INVALID_HEX_STRING
- assert C.NK_write_totp_slot(1, 'python_test', invalid_hex_string, 30, True, False, False, "",
+ assert C.NK_write_totp_slot(1, b'python_test', invalid_hex_string, 30, True, False, False, b"",
DefaultPasswords.ADMIN_TEMP) == LibraryErrors.INVALID_HEX_STRING
def test_warning_binary_bigger_than_secret_buffer(C):
invalid_hex_string = to_hex('1234567890') * 3
+ invalid_hex_string = invalid_hex_string.encode('ascii')
if is_long_OTP_secret_handled(C):
invalid_hex_string *= 2
- assert C.NK_write_hotp_slot(1, 'slot_name', invalid_hex_string, 0, True, False, False, '',
+ assert C.NK_write_hotp_slot(1, b'slot_name', invalid_hex_string, 0, True, False, False, b'',
DefaultPasswords.ADMIN_TEMP) == LibraryErrors.TARGET_BUFFER_SIZE_SMALLER_THAN_SOURCE