diff options
Diffstat (limited to 'src/tests/device.rs')
-rw-r--r-- | src/tests/device.rs | 89 |
1 files changed, 48 insertions, 41 deletions
diff --git a/src/tests/device.rs b/src/tests/device.rs index 22423fa..60ca33a 100644 --- a/src/tests/device.rs +++ b/src/tests/device.rs @@ -2,7 +2,7 @@ use std::ffi::CStr; use std::process::Command; use std::{thread, time}; use tests::util::{Target, ADMIN_PASSWORD, USER_PASSWORD}; -use {Authenticate, CommandError, CommandStatus, Config, Device}; +use {Authenticate, CommandError, Config, Device, Storage}; static ADMIN_NEW_PASSWORD: &str = "1234567890"; static USER_NEW_PASSWORD: &str = "abcdefghij"; @@ -130,23 +130,20 @@ fn config() { let device = Target::connect().unwrap(); let admin = device.authenticate_admin(ADMIN_PASSWORD).unwrap(); let config = Config::new(None, None, None, true); - assert_eq!(CommandStatus::Success, admin.write_config(config)); + assert!(admin.write_config(config).is_ok()); let get_config = admin.get_config().unwrap(); assert_eq!(config, get_config); let config = Config::new(None, Some(9), None, true); - assert_eq!( - CommandStatus::Error(CommandError::InvalidSlot), - admin.write_config(config) - ); + assert_eq!(Err(CommandError::InvalidSlot), admin.write_config(config)); let config = Config::new(Some(1), None, Some(0), false); - assert_eq!(CommandStatus::Success, admin.write_config(config)); + assert!(admin.write_config(config).is_ok()); let get_config = admin.get_config().unwrap(); assert_eq!(config, get_config); let config = Config::new(None, None, None, false); - assert_eq!(CommandStatus::Success, admin.write_config(config)); + assert!(admin.write_config(config).is_ok()); let get_config = admin.get_config().unwrap(); assert_eq!(config, get_config); } @@ -158,8 +155,11 @@ fn change_user_pin() { let device = device.authenticate_user(USER_PASSWORD).unwrap().device(); let device = device.authenticate_user(USER_NEW_PASSWORD).unwrap_err().0; - let result = device.change_user_pin(USER_PASSWORD, USER_NEW_PASSWORD); - assert_eq!(CommandStatus::Success, result); + assert!( + device + .change_user_pin(USER_PASSWORD, USER_NEW_PASSWORD) + .is_ok() + ); let device = device.authenticate_user(USER_PASSWORD).unwrap_err().0; let device = device @@ -168,13 +168,16 @@ fn change_user_pin() { .device(); let result = device.change_user_pin(USER_PASSWORD, USER_PASSWORD); - assert_eq!(CommandStatus::Error(CommandError::WrongPassword), result); + assert_eq!(Err(CommandError::WrongPassword), result); - let result = device.change_user_pin(USER_NEW_PASSWORD, USER_PASSWORD); - assert_eq!(CommandStatus::Success, result); + assert!( + device + .change_user_pin(USER_NEW_PASSWORD, USER_PASSWORD) + .is_ok() + ); let device = device.authenticate_user(USER_PASSWORD).unwrap().device(); - device.authenticate_user(USER_NEW_PASSWORD).unwrap_err(); + assert!(device.authenticate_user(USER_NEW_PASSWORD).is_err()); } #[test] @@ -184,8 +187,11 @@ fn change_admin_pin() { let device = device.authenticate_admin(ADMIN_PASSWORD).unwrap().device(); let device = device.authenticate_admin(ADMIN_NEW_PASSWORD).unwrap_err().0; - let result = device.change_admin_pin(ADMIN_PASSWORD, ADMIN_NEW_PASSWORD); - assert_eq!(CommandStatus::Success, result); + assert!( + device + .change_admin_pin(ADMIN_PASSWORD, ADMIN_NEW_PASSWORD) + .is_ok() + ); let device = device.authenticate_admin(ADMIN_PASSWORD).unwrap_err().0; let device = device @@ -193,11 +199,16 @@ fn change_admin_pin() { .unwrap() .device(); - let result = device.change_admin_pin(ADMIN_PASSWORD, ADMIN_PASSWORD); - assert_eq!(CommandStatus::Error(CommandError::WrongPassword), result); + assert_eq!( + Err(CommandError::WrongPassword), + device.change_admin_pin(ADMIN_PASSWORD, ADMIN_PASSWORD) + ); - let result = device.change_admin_pin(ADMIN_NEW_PASSWORD, ADMIN_PASSWORD); - assert_eq!(CommandStatus::Success, result); + assert!( + device + .change_admin_pin(ADMIN_NEW_PASSWORD, ADMIN_PASSWORD) + .is_ok() + ); let device = device.authenticate_admin(ADMIN_PASSWORD).unwrap().device(); device.authenticate_admin(ADMIN_NEW_PASSWORD).unwrap_err(); @@ -216,12 +227,13 @@ fn require_failed_user_login(device: Target, password: &str, error: CommandError 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!( + device + .unlock_user_pin(ADMIN_PASSWORD, USER_PASSWORD) + .is_ok() ); assert_eq!( - CommandStatus::Error(CommandError::WrongPassword), + Err(CommandError::WrongPassword), device.unlock_user_pin(USER_PASSWORD, USER_PASSWORD) ); @@ -232,12 +244,13 @@ fn unlock_user_pin() { let device = require_failed_user_login(device, USER_PASSWORD, CommandError::WrongPassword); assert_eq!( - CommandStatus::Error(CommandError::WrongPassword), + Err(CommandError::WrongPassword), device.unlock_user_pin(USER_PASSWORD, USER_PASSWORD) ); - assert_eq!( - CommandStatus::Success, - device.unlock_user_pin(ADMIN_PASSWORD, USER_PASSWORD) + assert!( + device + .unlock_user_pin(ADMIN_PASSWORD, USER_PASSWORD) + .is_ok() ); device.authenticate_user(USER_PASSWORD).unwrap(); } @@ -246,22 +259,19 @@ fn unlock_user_pin() { #[cfg_attr(not(feature = "test-storage"), ignore)] fn encrypted_volume() { let device = Storage::connect().unwrap(); - assert_eq!(CommandStatus::Success, device.lock()); + assert!(device.lock().is_ok()); assert_eq!(1, count_nitrokey_block_devices()); - assert_eq!(CommandStatus::Success, device.disable_encrypted_volume()); + assert!(device.disable_encrypted_volume().is_ok()); assert_eq!(1, count_nitrokey_block_devices()); assert_eq!( - CommandStatus::Error(CommandError::WrongPassword), + Err(CommandError::WrongPassword), device.enable_encrypted_volume("123") ); assert_eq!(1, count_nitrokey_block_devices()); - assert_eq!( - CommandStatus::Success, - device.enable_encrypted_volume(USER_PASSWORD) - ); + assert!(device.enable_encrypted_volume(USER_PASSWORD).is_ok()); assert_eq!(2, count_nitrokey_block_devices()); - assert_eq!(CommandStatus::Success, device.disable_encrypted_volume()); + assert!(device.disable_encrypted_volume().is_ok()); assert_eq!(1, count_nitrokey_block_devices()); } @@ -270,10 +280,7 @@ fn encrypted_volume() { fn lock() { let device = Storage::connect().unwrap(); - assert_eq!( - CommandStatus::Success, - device.enable_encrypted_volume(USER_PASSWORD) - ); - assert_eq!(CommandStatus::Success, device.lock()); + assert!(device.enable_encrypted_volume(USER_PASSWORD).is_ok()); + assert!(device.lock().is_ok()); assert_eq!(1, count_nitrokey_block_devices()); } |