aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-05-31 12:26:36 +0200
committerRobin Krahl <robin.krahl@ireas.org>2018-05-31 12:26:36 +0200
commitd61a89e08b6d1d807e26329538f358130a22b4e2 (patch)
tree225466bf48b7b74790ec784f2fbd79918a723bf6 /src/tests
parente7e9ee25eb0ed798558848714408404ef2163ac7 (diff)
downloadnitrokey-rs-d61a89e08b6d1d807e26329538f358130a22b4e2.tar.gz
nitrokey-rs-d61a89e08b6d1d807e26329538f358130a22b4e2.tar.bz2
Add support for unlock_user_password command
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/device.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/tests/device.rs b/src/tests/device.rs
index 6c24025..6f88bf5 100644
--- a/src/tests/device.rs
+++ b/src/tests/device.rs
@@ -189,3 +189,42 @@ fn change_admin_pin() {
let device = device.authenticate_admin(ADMIN_PASSWORD).unwrap().device();
device.authenticate_admin(ADMIN_NEW_PASSWORD).unwrap_err();
}
+
+fn require_failed_user_login(device: Target, password: &str, error: CommandError) -> Target {
+ let result = device.authenticate_user(password);
+ assert!(result.is_err());
+ let err = result.unwrap_err();
+ assert_eq!(error, err.1);
+ err.0
+}
+
+#[test]
+#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)]
+fn unlock_user_pin() {
+ let device = Target::connect().unwrap();
+ let device = device.authenticate_user(USER_PASSWORD).unwrap().device();
+ assert_eq!(
+ CommandStatus::Success,
+ device.unlock_user_pin(ADMIN_PASSWORD, USER_PASSWORD)
+ );
+ assert_eq!(
+ CommandStatus::Error(CommandError::WrongPassword),
+ device.unlock_user_pin(USER_PASSWORD, USER_PASSWORD)
+ );
+
+ 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);
+
+ assert_eq!(
+ CommandStatus::Error(CommandError::WrongPassword),
+ device.unlock_user_pin(USER_PASSWORD, USER_PASSWORD)
+ );
+ assert_eq!(
+ CommandStatus::Success,
+ device.unlock_user_pin(ADMIN_PASSWORD, USER_PASSWORD)
+ );
+ device.authenticate_user(USER_PASSWORD).unwrap();
+}