Skip to content

Commit b1b8516

Browse files
committed
Cleanup: replace magic numbers. Correct copyright dates.
Signed-off-by: Szczepan Zalega <[email protected]>
1 parent 77f9214 commit b1b8516

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

unittest/test_pro.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2015-2018 Nitrokey UG
2+
Copyright (c) 2015-2019 Nitrokey UG
33
44
This file is part of libnitrokey.
55
@@ -535,11 +535,11 @@ def test_get_slot_names(C):
535535
assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
536536
assert C.NK_erase_hotp_slot(0, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
537537

538-
for i in range(15):
538+
for i in range(TOTP_slot_count):
539539
name = ffi.string(C.NK_get_totp_slot_name(i))
540540
if name == '':
541541
assert C.NK_get_last_command_status() == DeviceErrorCode.NOT_PROGRAMMED
542-
for i in range(3):
542+
for i in range(HOTP_slot_count):
543543
name = ffi.string(C.NK_get_hotp_slot_name(i))
544544
if name == '':
545545
assert C.NK_get_last_command_status() == DeviceErrorCode.NOT_PROGRAMMED
@@ -549,12 +549,12 @@ def test_get_slot_names(C):
549549
def test_get_OTP_codes(C):
550550
assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
551551
assert C.NK_write_config(255, 255, 255, False, True, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
552-
for i in range(15):
552+
for i in range(TOTP_slot_count):
553553
code = gs(C.NK_get_totp_code(i, 0, 0, 0))
554554
if code == b'':
555555
assert C.NK_get_last_command_status() == DeviceErrorCode.NOT_PROGRAMMED
556556

557-
for i in range(3):
557+
for i in range(HOTP_slot_count):
558558
code = gs(C.NK_get_hotp_code(i))
559559
if code == b'':
560560
assert C.NK_get_last_command_status() == DeviceErrorCode.NOT_PROGRAMMED
@@ -788,7 +788,7 @@ def test_HOTP_slots_read_write_counter(C, counter):
788788
DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
789789
dev_res = []
790790
lib_res = []
791-
for slot_number in range(3):
791+
for slot_number in range(HOTP_slot_count):
792792
assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
793793
assert C.NK_write_hotp_slot(slot_number, b'HOTP rw' + bytes(slot_number), bb(secret), counter, use_8_digits, False, False, b"",
794794
DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
@@ -817,7 +817,7 @@ def test_TOTP_slots_read_write_at_time_period(C, time, period):
817817
DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
818818
dev_res = []
819819
lib_res = []
820-
for slot_number in range(15):
820+
for slot_number in range(TOTP_slot_count):
821821
assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
822822
assert C.NK_write_totp_slot(slot_number, b'TOTP rw' + bytes(slot_number), bb(secret), period, use_8_digits, False, False, b"",
823823
DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
@@ -1022,6 +1022,7 @@ def test_HOTP_counter_getter(C, counter_mid: int):
10221022
assert read_slot_st.slot_counter == counter
10231023

10241024

1025+
@pytest.mark.otp
10251026
def test_edge_OTP_slots(C):
10261027
# -> shows TOTP15 is not written
10271028
# -> assuming HOTP1 is written
@@ -1045,7 +1046,7 @@ def test_edge_OTP_slots(C):
10451046
DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
10461047
counter = 0
10471048
HOTP_slot_number = 1 -1
1048-
TOTP_slot_number = 15 -1 # 0 based
1049+
TOTP_slot_number = TOTP_slot_count -1 # 0 based
10491050
assert C.NK_write_totp_slot(TOTP_slot_number, b'python_test', bbRFC_SECRET, 30, False, False, False, b'',
10501051
DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
10511052
assert C.NK_write_hotp_slot(HOTP_slot_number, b'python_test', bbRFC_SECRET, counter, use_8_digits, False, False, b'', DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
@@ -1057,9 +1058,11 @@ def test_edge_OTP_slots(C):
10571058
assert read_slot_st.slot_counter == (i+1)
10581059
helper_set_time_on_device(C, 1)
10591060
code_totp = gs((C.NK_get_totp_code(TOTP_slot_number, 0, 0, 30)))
1061+
assert code_totp
10601062
assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK
10611063

10621064

1065+
@pytest.mark.otp
10631066
def test_OTP_all_rw(C):
10641067
"""
10651068
Write all OTP slots and read codes from them two times.

unittest/test_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2015-2018 Nitrokey UG
2+
Copyright (c) 2015-2019 Nitrokey UG
33
44
This file is part of libnitrokey.
55

0 commit comments

Comments
 (0)