diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2018-06-05 22:19:53 +0200 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2018-06-05 22:19:53 +0200 |
commit | 95d18c5b06399fa4109de808f70b1048d4494d39 (patch) | |
tree | 4b7cc832b85e9eeeb96a814dae7de598e16bd94c /src/tests/pws.rs | |
parent | 7a89b3dbf2f8d8f882edb6298d011cdd3d7add3c (diff) | |
download | nitrokey-rs-95d18c5b06399fa4109de808f70b1048d4494d39.tar.gz nitrokey-rs-95d18c5b06399fa4109de808f70b1048d4494d39.tar.bz2 |
Use a Device reference in PasswordSafe
Instead of wrapping an owned Device instance, PasswordSafe now only
requires a reference to a Device. The lifetime parameter makes sure
that the device lives at least as long as the password safe. Using a
reference instead of an owned device allows us to implement Drop on
PasswordSafe to make sure that the password safe is disabled once it is
destructed.
Diffstat (limited to 'src/tests/pws.rs')
-rw-r--r-- | src/tests/pws.rs | 44 |
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) |