diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-01-03 00:39:22 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-01-03 01:40:12 +0100 |
commit | 9af5d8d894563f34d063035607bc39a5e8239fa7 (patch) | |
tree | 360448f8f0a17aa2594dd07968075f6c4a8a286d /tests | |
parent | 248f8b209b0150e70e82ab15b73bf32b0f47341d (diff) | |
download | nitrokey-rs-9af5d8d894563f34d063035607bc39a5e8239fa7.tar.gz nitrokey-rs-9af5d8d894563f34d063035607bc39a5e8239fa7.tar.bz2 |
Extend unlock_user_pin tests
This patch adds a test case that changes the PIN when calling
unlock_user_pin. The previous test case only unlocked the current user
PIN.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/device.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/device.rs b/tests/device.rs index 26afa62..4551534 100644 --- a/tests/device.rs +++ b/tests/device.rs @@ -256,12 +256,14 @@ fn unlock_user_pin() { device.unlock_user_pin(USER_PASSWORD, USER_PASSWORD) ); + // block user PIN let wrong_password = USER_PASSWORD.to_owned() + "foo"; let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); let device = require_failed_user_login(device, USER_PASSWORD, CommandError::WrongPassword); + // unblock with current PIN assert_eq!( Err(CommandError::WrongPassword), device.unlock_user_pin(USER_PASSWORD, USER_PASSWORD) @@ -269,7 +271,27 @@ fn unlock_user_pin() { assert!(device .unlock_user_pin(ADMIN_PASSWORD, USER_PASSWORD) .is_ok()); - device.authenticate_user(USER_PASSWORD).unwrap(); + let device = device.authenticate_user(USER_PASSWORD).unwrap().device(); + + // block user PIN + let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); + let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); + let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); + let device = require_failed_user_login(device, USER_PASSWORD, CommandError::WrongPassword); + + // unblock with new PIN + assert_eq!( + Err(CommandError::WrongPassword), + device.unlock_user_pin(USER_PASSWORD, USER_PASSWORD) + ); + assert!(device + .unlock_user_pin(ADMIN_PASSWORD, USER_NEW_PASSWORD) + .is_ok()); + + // reset user PIN + assert!(device + .change_user_pin(USER_NEW_PASSWORD, USER_PASSWORD) + .is_ok()); } #[test] |