diff options
Diffstat (limited to 'unittest')
| -rw-r--r-- | unittest/test_pro.py | 54 | 
1 files changed, 54 insertions, 0 deletions
| diff --git a/unittest/test_pro.py b/unittest/test_pro.py index 8c99f81..a9e9fa4 100644 --- a/unittest/test_pro.py +++ b/unittest/test_pro.py @@ -520,3 +520,57 @@ def test_OTP_secret_started_from_null(C, secret):          dev_res += (t, code_device)          lib_res += (t, lib_at(t))      assert dev_res == lib_res + + +@pytest.mark.parametrize("counter", [0, 3, 7, 0xffff] ) +def test_HOTP_slots_read_write_counter(C, counter): +    secret = RFC_SECRET +    oath = pytest.importorskip("oath") +    lib_at = lambda t: oath.hotp(secret, t, format='dec6') +    PIN_protection = False +    use_8_digits = False +    assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +    assert C.NK_write_config(255, 255, 255, PIN_protection, not PIN_protection, +                             DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +    dev_res = [] +    lib_res = [] +    for slot_number in range(3): +        assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +        assert C.NK_write_hotp_slot(slot_number, 'null_secret', secret, counter, use_8_digits, False, False, "", +                                    DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +        code_device = str(C.NK_get_hotp_code(slot_number)) +        code_device = '0'+code_device if len(code_device) < 6 else code_device +        dev_res += (counter, code_device) +        lib_res += (counter, lib_at(counter)) +    assert dev_res == lib_res + + +@pytest.mark.parametrize("period", [30,60] ) +@pytest.mark.parametrize("time", range(20,70,20) ) +def test_TOTP_slots_read_write_at_time_period(C, time, period): +    secret = RFC_SECRET +    oath = pytest.importorskip("oath") +    lib_at = lambda t: oath.totp(RFC_SECRET, t=t, period=period) +    PIN_protection = False +    use_8_digits = False +    T = 0 +    assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +    assert C.NK_write_config(255, 255, 255, PIN_protection, not PIN_protection, +                             DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +    dev_res = [] +    lib_res = [] +    for slot_number in range(15): +        assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +        assert C.NK_write_totp_slot(slot_number, 'null_secret', secret, period, use_8_digits, False, False, "", +                                    DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +        assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +        assert C.NK_totp_set_time(time) == DeviceErrorCode.STATUS_OK +        code_device = str(C.NK_get_totp_code(slot_number, T, 0, period)) +        code_device = '0'+code_device if len(code_device) < 6 else code_device +        dev_res += (time, code_device) +        lib_res += (time, lib_at(time)) +    assert dev_res == lib_res + + + + | 
