summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2020-01-28 14:53:41 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2020-02-26 12:26:32 +0100
commit2fa7e29b725085e62dd647da6e0dd28bcfe91e43 (patch)
treea7095277b92ce6357483251588620962f5cbb0e6
parent59ca679eeb272163e4ebbb2f01231adc4820cda1 (diff)
downloadlibnitrokey-2fa7e29b725085e62dd647da6e0dd28bcfe91e43.tar.gz
libnitrokey-2fa7e29b725085e62dd647da6e0dd28bcfe91e43.tar.bz2
Refactor move 2
-rw-r--r--unittest/test_pro.py69
-rw-r--r--unittest/test_pro_bootloader.py73
2 files changed, 73 insertions, 69 deletions
diff --git a/unittest/test_pro.py b/unittest/test_pro.py
index 233d4d2..13efd28 100644
--- a/unittest/test_pro.py
+++ b/unittest/test_pro.py
@@ -962,75 +962,6 @@ def test_get_device_model(C):
# assert C.NK_get_device_model() != C.NK_DISCONNECTED
-@pytest.mark.firmware
-def test_bootloader_password_change_pro_length(C):
- skip_if_device_version_lower_than({'P': 11})
-
- # Test whether the correct password is set
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
- # Change to the longest possible password
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE_LONG) == DeviceErrorCode.STATUS_OK
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE_LONG, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
- # Use longer or shorter passwords than possible
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE_TOO_LONG) == LibraryErrors.TOO_LONG_STRING
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE_TOO_SHORT) == DeviceErrorCode.WRONG_PASSWORD
-
-
-
-@pytest.mark.firmware
-def test_bootloader_password_change_pro(C):
- skip_if_device_version_lower_than({'P': 11})
- assert C.NK_change_firmware_password_pro(b'zxcasd', b'zxcasd') == DeviceErrorCode.WRONG_PASSWORD
-
- # Revert effects of broken test run, if needed
- C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE_TEMP, DefaultPasswords.UPDATE)
-
- # Change to the same password
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
- # Change password
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE_TEMP) == DeviceErrorCode.STATUS_OK
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE_TEMP, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
-
-
-@pytest.mark.firmware
-def test_bootloader_run_pro_wrong_password(C):
- skip_if_device_version_lower_than({'P': 11})
- assert C.NK_enable_firmware_update_pro(DefaultPasswords.UPDATE_TEMP) == DeviceErrorCode.WRONG_PASSWORD
-
-
-@pytest.mark.skip_by_default
-@pytest.mark.firmware
-def test_bootloader_run_pro_real(C):
- # Not enabled due to lack of side-effect removal at this point
- assert C.NK_enable_firmware_update_pro(DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_DISCONNECTED
-
-
-@pytest.mark.firmware
-def test_bootloader_password_change_pro_too_long(C):
- skip_if_device_version_lower_than({'P': 11})
- long_string = b'a' * 100
- assert C.NK_change_firmware_password_pro(long_string, long_string) == LibraryErrors.TOO_LONG_STRING
- assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, long_string) == LibraryErrors.TOO_LONG_STRING
-
-
-@pytest.mark.skip_by_default
-@pytest.mark.firmware
-def test_bootloader_data_rention_test(C):
- skip_if_device_version_lower_than({'P': 11})
-
- def populate_device():
- return False
-
- def check_data_on_device():
- return False
-
- assert populate_device()
- assert C.NK_enable_firmware_update_pro(DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_DISCONNECTED
- input('Please press ENTER after uploading new firmware to the device')
- assert check_data_on_device()
-
-
@pytest.mark.otp
@pytest.mark.parametrize('counter_mid', [10**3-1, 10**4-1, 10**7-1, 10**8-10, 2**16, 2**31-1, 2**32-1, 2**33, 2**50, 2**60, 2**63]) # 2**64-1
def test_HOTP_counter_getter(C, counter_mid: int):
diff --git a/unittest/test_pro_bootloader.py b/unittest/test_pro_bootloader.py
new file mode 100644
index 0000000..4a6b272
--- /dev/null
+++ b/unittest/test_pro_bootloader.py
@@ -0,0 +1,73 @@
+import pytest
+
+from conftest import skip_if_device_version_lower_than
+from constants import DefaultPasswords, DeviceErrorCode, LibraryErrors
+
+
+@pytest.mark.firmware
+def test_bootloader_password_change_pro_length(C):
+ skip_if_device_version_lower_than({'P': 11})
+
+ # Test whether the correct password is set
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
+ # Change to the longest possible password
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE_LONG) == DeviceErrorCode.STATUS_OK
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE_LONG, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
+ # Use longer or shorter passwords than possible
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE_TOO_LONG) == LibraryErrors.TOO_LONG_STRING
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE_TOO_SHORT) == DeviceErrorCode.WRONG_PASSWORD
+
+
+
+@pytest.mark.firmware
+def test_bootloader_password_change_pro(C):
+ skip_if_device_version_lower_than({'P': 11})
+ assert C.NK_change_firmware_password_pro(b'zxcasd', b'zxcasd') == DeviceErrorCode.WRONG_PASSWORD
+
+ # Revert effects of broken test run, if needed
+ C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE_TEMP, DefaultPasswords.UPDATE)
+
+ # Change to the same password
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
+ # Change password
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, DefaultPasswords.UPDATE_TEMP) == DeviceErrorCode.STATUS_OK
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE_TEMP, DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
+
+
+@pytest.mark.firmware
+def test_bootloader_run_pro_wrong_password(C):
+ skip_if_device_version_lower_than({'P': 11})
+ assert C.NK_enable_firmware_update_pro(DefaultPasswords.UPDATE_TEMP) == DeviceErrorCode.WRONG_PASSWORD
+
+
+@pytest.mark.skip_by_default
+@pytest.mark.firmware
+def test_bootloader_run_pro_real(C):
+ # Not enabled due to lack of side-effect removal at this point
+ assert C.NK_enable_firmware_update_pro(DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_DISCONNECTED
+
+
+@pytest.mark.firmware
+def test_bootloader_password_change_pro_too_long(C):
+ skip_if_device_version_lower_than({'P': 11})
+ long_string = b'a' * 100
+ assert C.NK_change_firmware_password_pro(long_string, long_string) == LibraryErrors.TOO_LONG_STRING
+ assert C.NK_change_firmware_password_pro(DefaultPasswords.UPDATE, long_string) == LibraryErrors.TOO_LONG_STRING
+
+
+@pytest.mark.skip_by_default
+@pytest.mark.firmware
+def test_bootloader_data_rention_test(C):
+ skip_if_device_version_lower_than({'P': 11})
+
+ def populate_device():
+ return False
+
+ def check_data_on_device():
+ return False
+
+ assert populate_device()
+ assert C.NK_enable_firmware_update_pro(DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_DISCONNECTED
+ input('Please press ENTER after uploading new firmware to the device')
+ assert check_data_on_device()