diff options
| author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-05 14:19:13 +0200 | 
|---|---|---|
| committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-05 14:20:27 +0200 | 
| commit | 3a8637b673d9d92aac2a933d70439e42b68c5cb8 (patch) | |
| tree | f1dca31c6de02ebbabab089d7c01d2f3845a8aea | |
| parent | f82d0574b133b23f69755ec854f8686282dd58ef (diff) | |
| download | libnitrokey-3a8637b673d9d92aac2a933d70439e42b68c5cb8.tar.gz libnitrokey-3a8637b673d9d92aac2a933d70439e42b68c5cb8.tar.bz2 | |
Test factory reset command
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
| -rw-r--r-- | unittest/test_bindings.py | 28 | 
1 files changed, 28 insertions, 0 deletions
| diff --git a/unittest/test_bindings.py b/unittest/test_bindings.py index ace0609..fc680c0 100644 --- a/unittest/test_bindings.py +++ b/unittest/test_bindings.py @@ -20,6 +20,7 @@ class DeviceErrorCode(Enum):      NOT_PROGRAMMED = 3      WRONG_PASSWORD = 4      STATUS_NOT_AUTHORIZED = 5 +    STATUS_AES_DEC_FAILED = 0xa  @pytest.fixture(scope="module") @@ -382,3 +383,30 @@ def test_read_write_config(C):      assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK      config = cast_pointer_to_tuple(config_raw_data, 'uint8_t', 5)      assert config == (255, 255, 255, False, True) + + +def wait(t): +    import time +    msg = 'Waiting for %d seconds' % t +    print(msg.center(40, '=')) +    time.sleep(t) + + +# @pytest.mark.skip() +def test_factory_reset(C): +    C.NK_set_debug(True) +    assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +    assert C.NK_write_config(255, 255, 255, False, True, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +    assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +    assert C.NK_write_hotp_slot(1, 'python_test', RFC_SECRET, 0, False, False, False, "", +                                DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +    assert C.NK_get_hotp_code(1) == 755224 +    assert C.NK_factory_reset(DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK +    wait(10) +    assert C.NK_get_hotp_code(1) != 287082 +    assert C.NK_get_last_command_status() == DeviceErrorCode.NOT_PROGRAMMED +    # restore AES key +    assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK +    assert C.NK_build_aes_key(DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK +    assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK +    assert C.NK_lock_device() == DeviceErrorCode.STATUS_OK | 
