diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2018-05-28 22:02:10 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2018-05-29 00:03:56 +0200 |
commit | 89b8a947e5c622272362e967847eb19337aa68da (patch) | |
tree | ccbd24b53b4a98312247a304b51774fac2e3b685 /src/tests/device.rs | |
parent | f58400a22986cdedf34f85dc17d1d59335ffb404 (diff) | |
download | nitrokey-rs-89b8a947e5c622272362e967847eb19337aa68da.tar.gz nitrokey-rs-89b8a947e5c622272362e967847eb19337aa68da.tar.bz2 |
Add rudimentary support for the Nitrokey Storage
This patch adds the Storage struct and the test-storage feature. It
also enables all currently supported Pro commands for the Storage.
Diffstat (limited to 'src/tests/device.rs')
-rw-r--r-- | src/tests/device.rs | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/tests/device.rs b/src/tests/device.rs index 394861c..80541d4 100644 --- a/src/tests/device.rs +++ b/src/tests/device.rs @@ -1,6 +1,6 @@ use std::ffi::CStr; -use {Authenticate, CommandError, CommandStatus, Config, Device, Pro}; -use tests::util::{ADMIN_PASSWORD, USER_PASSWORD}; +use {Authenticate, CommandError, CommandStatus, Config, Device}; +use tests::util::{Target, ADMIN_PASSWORD, USER_PASSWORD}; static ADMIN_NEW_PASSWORD: &str = "1234567890"; static USER_NEW_PASSWORD: &str = "abcdefghij"; @@ -10,17 +10,23 @@ static USER_NEW_PASSWORD: &str = "abcdefghij"; fn connect_no_device() { assert!(::connect().is_err()); assert!(::Pro::connect().is_err()); - // TODO: test storage - // assert!(::Storage::connect().is_err()); + assert!(::Storage::connect().is_err()); } #[test] #[cfg_attr(not(feature = "test-pro"), ignore)] fn connect_pro() { assert!(::connect().is_ok()); - assert!(Pro::connect().is_ok()); - // TODO: test storage - // assert!(::Storage::connect().is_err()); + assert!(::Pro::connect().is_ok()); + assert!(::Storage::connect().is_err()); +} + +#[test] +#[cfg_attr(not(feature = "test-storage"), ignore)] +fn connect_storage() { + assert!(::connect().is_ok()); + assert!(::Pro::connect().is_err()); + assert!(::Storage::connect().is_ok()); } fn assert_empty_serial_number() { @@ -33,16 +39,16 @@ fn assert_empty_serial_number() { } #[test] -#[cfg_attr(not(feature = "test-pro"), ignore)] +#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)] fn disconnect() { - ::connect().unwrap(); + Target::connect().unwrap(); assert_empty_serial_number(); - ::connect() + Target::connect() .unwrap() .authenticate_admin(ADMIN_PASSWORD) .unwrap(); assert_empty_serial_number(); - ::connect() + Target::connect() .unwrap() .authenticate_user(USER_PASSWORD) .unwrap(); @@ -50,9 +56,9 @@ fn disconnect() { } #[test] -#[cfg_attr(not(feature = "test-pro"), ignore)] +#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)] fn get_serial_number() { - let device = ::connect().unwrap(); + let device = Target::connect().unwrap(); let result = device.get_serial_number(); assert!(result.is_ok()); let serial_number = result.unwrap(); @@ -61,8 +67,9 @@ fn get_serial_number() { } #[test] #[cfg_attr(not(feature = "test-pro"), ignore)] +// TODO: adapt for storage fn get_firmware_version() { - let device = ::connect().unwrap(); + let device = Target::connect().unwrap(); assert_eq!(0, device.get_major_firmware_version()); let minor = device.get_minor_firmware_version(); assert!(minor == 7 || minor == 8); @@ -89,9 +96,9 @@ fn user_retry<T: Authenticate + Device>(device: T, suffix: &str, count: u8) -> T } #[test] -#[cfg_attr(not(feature = "test-pro"), ignore)] +#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)] fn get_retry_count() { - let device = ::connect().unwrap(); + let device = Target::connect().unwrap(); let device = admin_retry(device, "", 3); let device = admin_retry(device, "123", 2); @@ -105,9 +112,9 @@ fn get_retry_count() { } #[test] -#[cfg_attr(not(feature = "test-pro"), ignore)] +#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)] fn config() { - let device = ::connect().unwrap(); + 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)); @@ -132,9 +139,9 @@ fn config() { } #[test] -#[cfg_attr(not(feature = "test-pro"), ignore)] +#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)] fn change_user_pin() { - let device = ::connect().unwrap(); + let device = Target::connect().unwrap(); let device = device.authenticate_user(USER_PASSWORD).unwrap().device(); let device = device.authenticate_user(USER_NEW_PASSWORD).unwrap_err().0; @@ -158,9 +165,9 @@ fn change_user_pin() { } #[test] -#[cfg_attr(not(feature = "test-pro"), ignore)] +#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)] fn change_admin_pin() { - let device = ::connect().unwrap(); + let device = Target::connect().unwrap(); let device = device.authenticate_admin(ADMIN_PASSWORD).unwrap().device(); let device = device.authenticate_admin(ADMIN_NEW_PASSWORD).unwrap_err().0; |