From 279a310d6710908943237f5528d64a94ecd45885 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 6 Dec 2016 20:00:42 +0100 Subject: Tests: check are long OTP secrets supported Signed-off-by: Szczepan Zalega --- unittest/test_library.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'unittest/test_library.py') diff --git a/unittest/test_library.py b/unittest/test_library.py index d0eef80..7b05c58 100644 --- a/unittest/test_library.py +++ b/unittest/test_library.py @@ -1,6 +1,6 @@ import pytest -from misc import ffi, gs, to_hex +from misc import ffi, gs, to_hex, is_pro_rtm_07, is_long_OTP_secret_handled from constants import DefaultPasswords, DeviceErrorCode, RFC_SECRET, LibraryErrors def test_too_long_strings(C): @@ -50,6 +50,8 @@ def test_invalid_secret_hex_string_for_OTP_write(C, invalid_hex_string): def test_warning_binary_bigger_than_secret_buffer(C): invalid_hex_string = to_hex('1234567890') * 3 + 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, '', DefaultPasswords.ADMIN_TEMP) == LibraryErrors.TARGET_BUFFER_SIZE_SMALLER_THAN_SOURCE -- cgit v1.2.1 From 4ab91aae6c101b72a94d3785dbdad117354b87d5 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 6 Dec 2016 20:22:37 +0100 Subject: Check maximum OTP secret size in new authorization style commands Authenticate before testing invalid hex strings Remove invalid test for empty string for writing otp slot (empty string allows editing) Signed-off-by: Szczepan Zalega --- unittest/test_library.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'unittest/test_library.py') diff --git a/unittest/test_library.py b/unittest/test_library.py index 7b05c58..bd44e89 100644 --- a/unittest/test_library.py +++ b/unittest/test_library.py @@ -36,12 +36,13 @@ def test_invalid_slot(C): assert C.NK_get_last_command_status() == LibraryErrors.INVALID_SLOT @pytest.mark.parametrize("invalid_hex_string", - ['text', '00 ', '0xff', 'zzzzzzzzzzzz', 'fff', '', 'f' * 257, 'f' * 258]) + ['text', '00 ', '0xff', 'zzzzzzzzzzzz', 'fff', 'f' * 257, 'f' * 258]) 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. """ + 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, '', DefaultPasswords.ADMIN_TEMP) == LibraryErrors.INVALID_HEX_STRING assert C.NK_write_totp_slot(1, 'python_test', invalid_hex_string, 30, True, False, False, "", -- cgit v1.2.1 From e75f9a54e0a696de47f00dce980b1a3b9feddee2 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 9 Dec 2016 11:09:45 +0100 Subject: Code reformat in library test Signed-off-by: Szczepan Zalega --- unittest/test_library.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'unittest/test_library.py') diff --git a/unittest/test_library.py b/unittest/test_library.py index bd44e89..ec00a5a 100644 --- a/unittest/test_library.py +++ b/unittest/test_library.py @@ -3,6 +3,7 @@ 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 + def test_too_long_strings(C): new_password = '123123123' long_string = 'a' * 100 @@ -35,6 +36,7 @@ def test_invalid_slot(C): assert gs(C.NK_get_password_safe_slot_login(invalid_slot)) == '' assert C.NK_get_last_command_status() == LibraryErrors.INVALID_SLOT + @pytest.mark.parametrize("invalid_hex_string", ['text', '00 ', '0xff', 'zzzzzzzzzzzz', 'fff', 'f' * 257, 'f' * 258]) def test_invalid_secret_hex_string_for_OTP_write(C, invalid_hex_string): @@ -48,7 +50,6 @@ def test_invalid_secret_hex_string_for_OTP_write(C, invalid_hex_string): assert C.NK_write_totp_slot(1, 'python_test', invalid_hex_string, 30, True, False, False, "", DefaultPasswords.ADMIN_TEMP) == LibraryErrors.INVALID_HEX_STRING - def test_warning_binary_bigger_than_secret_buffer(C): invalid_hex_string = to_hex('1234567890') * 3 if is_long_OTP_secret_handled(C): -- cgit v1.2.1 From 87eaf78c7c7290764ccaebe67726b77a44f21240 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 9 Dec 2016 12:44:33 +0100 Subject: Remove old skipping code. Feature comment. Signed-off-by: Szczepan Zalega --- unittest/test_library.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'unittest/test_library.py') diff --git a/unittest/test_library.py b/unittest/test_library.py index ec00a5a..b24c72a 100644 --- a/unittest/test_library.py +++ b/unittest/test_library.py @@ -58,11 +58,6 @@ def test_warning_binary_bigger_than_secret_buffer(C): DefaultPasswords.ADMIN_TEMP) == LibraryErrors.TARGET_BUFFER_SIZE_SMALLER_THAN_SOURCE -@pytest.mark.xfail(reason="TODO") -def test_OTP_secret_started_from_null(C): - assert False - - @pytest.mark.skip(reason='Experimental') def test_clear(C): d = 'asdasdasd' -- cgit v1.2.1