aboutsummaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2020-01-17 18:19:45 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2020-02-26 12:26:07 +0100
commit9e1f590d5a929a21223bb39ae5123d27e69fda66 (patch)
treee1a68a7959c2183baa8993fbdd3374f128b80cea /unittest
parent2c52393d12dbb16ce1d643cf020aff964da6ec89 (diff)
downloadlibnitrokey-9e1f590d5a929a21223bb39ae5123d27e69fda66.tar.gz
libnitrokey-9e1f590d5a929a21223bb39ae5123d27e69fda66.tar.bz2
Add tests for Pro`s bootloader
Diffstat (limited to 'unittest')
-rw-r--r--unittest/constants.py3
-rw-r--r--unittest/test_pro.py31
2 files changed, 32 insertions, 2 deletions
diff --git a/unittest/constants.py b/unittest/constants.py
index 645ef6a..bf4f5b9 100644
--- a/unittest/constants.py
+++ b/unittest/constants.py
@@ -39,6 +39,9 @@ class DefaultPasswords:
USER_TEMP = b'234234234'
UPDATE = b'12345678'
UPDATE_TEMP = b'123update123'
+ UPDATE_LONG = b'1234567890'*2
+ UPDATE_TOO_LONG = UPDATE_LONG + b'x'
+ UPDATE_TOO_SHORT = b'1234567'
class DeviceErrorCode:
diff --git a/unittest/test_pro.py b/unittest/test_pro.py
index a8df7cd..3f1cb8d 100644
--- a/unittest/test_pro.py
+++ b/unittest/test_pro.py
@@ -978,20 +978,47 @@ def test_get_device_model(C):
@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(C):
+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
+@pytest.mark.firmware
+def test_bootloader_run_pro(C):
# Not enabled due to lack of side-effect removal at this point
- # assert C.NK_enable_firmware_update_pro(DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
+ assert C.NK_enable_firmware_update_pro(DefaultPasswords.UPDATE) == DeviceErrorCode.STATUS_OK
@pytest.mark.firmware