summaryrefslogtreecommitdiff
path: root/src/tests/pws.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/pws.rs')
-rw-r--r--src/tests/pws.rs44
1 files changed, 15 insertions, 29 deletions
diff --git a/src/tests/pws.rs b/src/tests/pws.rs
index f45a81a..30d6853 100644
--- a/src/tests/pws.rs
+++ b/src/tests/pws.rs
@@ -2,46 +2,29 @@ use pws::{GetPasswordSafe, PasswordSafe, SLOT_COUNT};
use tests::util::{Target, ADMIN_PASSWORD, USER_PASSWORD};
use util::{CommandError, CommandStatus};
-fn get_pws() -> PasswordSafe<Target> {
- Target::connect()
- .unwrap()
- .get_password_safe(USER_PASSWORD)
- .unwrap()
+fn get_pws(device: &Target) -> PasswordSafe {
+ device.get_password_safe(USER_PASSWORD).unwrap()
}
#[test]
#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)]
fn enable() {
+ let device = Target::connect().unwrap();
assert!(
- Target::connect()
- .unwrap()
+ device
.get_password_safe(&(USER_PASSWORD.to_owned() + "123"))
.is_err()
);
- assert!(
- Target::connect()
- .unwrap()
- .get_password_safe(USER_PASSWORD)
- .is_ok()
- );
- assert!(
- Target::connect()
- .unwrap()
- .get_password_safe(ADMIN_PASSWORD)
- .is_err()
- );
- assert!(
- Target::connect()
- .unwrap()
- .get_password_safe(USER_PASSWORD)
- .is_ok()
- );
+ assert!(device.get_password_safe(USER_PASSWORD).is_ok());
+ assert!(device.get_password_safe(ADMIN_PASSWORD).is_err());
+ assert!(device.get_password_safe(USER_PASSWORD).is_ok());
}
#[test]
#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)]
fn get_status() {
- let pws = get_pws();
+ let device = Target::connect().unwrap();
+ let pws = get_pws(&device);
for i in 0..SLOT_COUNT {
assert_eq!(
CommandStatus::Success,
@@ -75,7 +58,8 @@ fn get_status() {
#[test]
#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)]
fn get_data() {
- let pws = get_pws();
+ let device = Target::connect().unwrap();
+ let pws = get_pws(&device);
assert_eq!(
CommandStatus::Success,
pws.write_slot(1, "name", "login", "password")
@@ -118,7 +102,8 @@ fn get_data() {
#[test]
#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)]
fn write() {
- let pws = get_pws();
+ let device = Target::connect().unwrap();
+ let pws = get_pws(&device);
assert_eq!(
CommandStatus::Error(CommandError::InvalidSlot),
@@ -153,7 +138,8 @@ fn write() {
#[test]
#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)]
fn erase() {
- let pws = get_pws();
+ let device = Target::connect().unwrap();
+ let pws = get_pws(&device);
assert_eq!(
CommandStatus::Error(CommandError::InvalidSlot),
pws.erase_slot(SLOT_COUNT)