aboutsummaryrefslogtreecommitdiff
path: root/src/tests/pws.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/pws.rs')
-rw-r--r--src/tests/pws.rs69
1 files changed, 17 insertions, 52 deletions
diff --git a/src/tests/pws.rs b/src/tests/pws.rs
index 02e33cd..f581515 100644
--- a/src/tests/pws.rs
+++ b/src/tests/pws.rs
@@ -2,7 +2,7 @@ use device::Device;
use nitrokey_sys;
use pws::{GetPasswordSafe, PasswordSafe, SLOT_COUNT};
use tests::util::{Target, ADMIN_PASSWORD, USER_PASSWORD};
-use util::{result_from_string, CommandError, CommandStatus};
+use util::{result_from_string, CommandError};
fn get_pws(device: &Target) -> PasswordSafe {
device.get_password_safe(USER_PASSWORD).unwrap()
@@ -28,17 +28,14 @@ fn drop() {
let device = Target::connect().unwrap();
{
let pws = get_pws(&device);
- assert_eq!(
- CommandStatus::Success,
- pws.write_slot(1, "name", "login", "password")
- );
+ assert!(pws.write_slot(1, "name", "login", "password").is_ok());
assert_eq!("name", pws.get_slot_name(1).unwrap());
let result = result_from_string(unsafe { nitrokey_sys::NK_get_password_safe_slot_name(1) });
assert_eq!(Ok(String::from("name")), result);
}
let result = result_from_string(unsafe { nitrokey_sys::NK_get_password_safe_slot_name(1) });
assert_eq!(Ok(String::from("name")), result);
- device.lock();
+ assert!(device.lock().is_ok());
let result = result_from_string(unsafe { nitrokey_sys::NK_get_password_safe_slot_name(1) });
assert_eq!(Err(CommandError::NotAuthorized), result);
}
@@ -49,30 +46,19 @@ fn get_status() {
let device = Target::connect().unwrap();
let pws = get_pws(&device);
for i in 0..SLOT_COUNT {
- assert_eq!(
- CommandStatus::Success,
- pws.erase_slot(i),
- "Could not erase slot {}",
- i
- );
+ assert!(pws.erase_slot(i).is_ok(), "Could not erase slot {}", i);
}
let status = pws.get_slot_status().unwrap();
assert_eq!(status, [false; SLOT_COUNT as usize]);
- assert_eq!(
- CommandStatus::Success,
- pws.write_slot(1, "name", "login", "password")
- );
+ assert!(pws.write_slot(1, "name", "login", "password").is_ok());
let status = pws.get_slot_status().unwrap();
for i in 0..SLOT_COUNT {
assert_eq!(i == 1, status[i as usize]);
}
for i in 0..SLOT_COUNT {
- assert_eq!(
- CommandStatus::Success,
- pws.write_slot(i, "name", "login", "password")
- );
+ assert!(pws.write_slot(i, "name", "login", "password").is_ok());
}
let status = pws.get_slot_status().unwrap();
assert_eq!(status, [true; SLOT_COUNT as usize]);
@@ -83,15 +69,12 @@ fn get_status() {
fn get_data() {
let device = Target::connect().unwrap();
let pws = get_pws(&device);
- assert_eq!(
- CommandStatus::Success,
- pws.write_slot(1, "name", "login", "password")
- );
+ assert!(pws.write_slot(1, "name", "login", "password").is_ok());
assert_eq!("name", pws.get_slot_name(1).unwrap());
assert_eq!("login", pws.get_slot_login(1).unwrap());
assert_eq!("password", pws.get_slot_password(1).unwrap());
- assert_eq!(CommandStatus::Success, pws.erase_slot(1));
+ assert!(pws.erase_slot(1).is_ok());
// TODO: check error codes
assert_eq!(Err(CommandError::Unknown), pws.get_slot_name(1));
assert_eq!(Err(CommandError::Unknown), pws.get_slot_login(1));
@@ -100,10 +83,7 @@ fn get_data() {
let name = "with å";
let login = "pär@test.com";
let password = "'i3lJc[09?I:,[u7dWz9";
- assert_eq!(
- CommandStatus::Success,
- pws.write_slot(1, name, login, password)
- );
+ assert!(pws.write_slot(1, name, login, password).is_ok());
assert_eq!(name, pws.get_slot_name(1).unwrap());
assert_eq!(login, pws.get_slot_login(1).unwrap());
assert_eq!(password, pws.get_slot_password(1).unwrap());
@@ -129,30 +109,21 @@ fn write() {
let pws = get_pws(&device);
assert_eq!(
- CommandStatus::Error(CommandError::InvalidSlot),
+ Err(CommandError::InvalidSlot),
pws.write_slot(SLOT_COUNT, "name", "login", "password")
);
- assert_eq!(
- CommandStatus::Success,
- pws.write_slot(0, "", "login", "password")
- );
+ assert!(pws.write_slot(0, "", "login", "password").is_ok());
assert_eq!(Err(CommandError::Unknown), pws.get_slot_name(0));
assert_eq!(Ok(String::from("login")), pws.get_slot_login(0));
assert_eq!(Ok(String::from("password")), pws.get_slot_password(0));
- assert_eq!(
- CommandStatus::Success,
- pws.write_slot(0, "name", "", "password")
- );
+ assert!(pws.write_slot(0, "name", "", "password").is_ok());
assert_eq!(Ok(String::from("name")), pws.get_slot_name(0));
assert_eq!(Err(CommandError::Unknown), pws.get_slot_login(0));
assert_eq!(Ok(String::from("password")), pws.get_slot_password(0));
- assert_eq!(
- CommandStatus::Success,
- pws.write_slot(0, "name", "login", "")
- );
+ assert!(pws.write_slot(0, "name", "login", "").is_ok());
assert_eq!(Ok(String::from("name")), pws.get_slot_name(0));
assert_eq!(Ok(String::from("login")), pws.get_slot_login(0));
assert_eq!(Err(CommandError::Unknown), pws.get_slot_password(0));
@@ -163,16 +134,10 @@ fn write() {
fn erase() {
let device = Target::connect().unwrap();
let pws = get_pws(&device);
- assert_eq!(
- CommandStatus::Error(CommandError::InvalidSlot),
- pws.erase_slot(SLOT_COUNT)
- );
+ assert_eq!(Err(CommandError::InvalidSlot), pws.erase_slot(SLOT_COUNT));
- assert_eq!(
- CommandStatus::Success,
- pws.write_slot(0, "name", "login", "password")
- );
- assert_eq!(CommandStatus::Success, pws.erase_slot(0));
- assert_eq!(CommandStatus::Success, pws.erase_slot(0));
+ assert!(pws.write_slot(0, "name", "login", "password").is_ok());
+ assert!(pws.erase_slot(0).is_ok());
+ assert!(pws.erase_slot(0).is_ok());
assert_eq!(Err(CommandError::Unknown), pws.get_slot_name(0));
}