summaryrefslogtreecommitdiff
path: root/tests/device.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-07-09 10:49:16 +0200
committerRobin Krahl <robin.krahl@ireas.org>2019-07-09 10:49:16 +0200
commit7ce751225f12c295c6e33dd46cfb5dcb88f8fbb3 (patch)
tree910e7fcae5b2b502900c67782b4db22d9c242f21 /tests/device.rs
parent445e920986db276d0c5c39709aa76dd290773e8f (diff)
parent62e8ee8f5d02511d6eb5dc179b087b04e88c1b94 (diff)
downloadnitrokey-rs-7ce751225f12c295c6e33dd46cfb5dcb88f8fbb3.tar.gz
nitrokey-rs-7ce751225f12c295c6e33dd46cfb5dcb88f8fbb3.tar.bz2
Merge branch 'connection-manager-mut' into next
Refactor the connection management to prevent multiple device connections at the same time. RFC: https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20190126174327.tbuyk2s535kfiqm4%40localhost%3E
Diffstat (limited to 'tests/device.rs')
-rw-r--r--tests/device.rs45
1 files changed, 26 insertions, 19 deletions
diff --git a/tests/device.rs b/tests/device.rs
index 5c52024..bb71eb4 100644
--- a/tests/device.rs
+++ b/tests/device.rs
@@ -33,20 +33,19 @@ fn count_nitrokey_block_devices() -> usize {
#[test_device]
fn connect_no_device() {
- assert_cmu_err!(CommunicationError::NotConnected, nitrokey::connect());
- assert_cmu_err!(
- CommunicationError::NotConnected,
- nitrokey::connect_model(nitrokey::Model::Pro)
- );
+ let mut manager = nitrokey::take().unwrap();
+
+ assert_cmu_err!(CommunicationError::NotConnected, manager.connect());
assert_cmu_err!(
CommunicationError::NotConnected,
- nitrokey::connect_model(nitrokey::Model::Storage)
+ manager.connect_model(nitrokey::Model::Pro)
);
- assert_cmu_err!(CommunicationError::NotConnected, nitrokey::Pro::connect());
assert_cmu_err!(
CommunicationError::NotConnected,
- nitrokey::Storage::connect()
+ manager.connect_model(nitrokey::Model::Storage)
);
+ assert_cmu_err!(CommunicationError::NotConnected, manager.connect_pro());
+ assert_cmu_err!(CommunicationError::NotConnected, manager.connect_storage());
}
#[test_device]
@@ -54,9 +53,10 @@ fn connect_pro(device: Pro) {
assert_eq!(device.get_model(), nitrokey::Model::Pro);
drop(device);
- assert_any_ok!(nitrokey::connect());
- assert_any_ok!(nitrokey::connect_model(nitrokey::Model::Pro));
- assert_any_ok!(nitrokey::Pro::connect());
+ let mut manager = nitrokey::take().unwrap();
+ assert_any_ok!(manager.connect());
+ assert_any_ok!(manager.connect_model(nitrokey::Model::Pro));
+ assert_any_ok!(manager.connect_pro());
}
#[test_device]
@@ -64,9 +64,10 @@ fn connect_storage(device: Storage) {
assert_eq!(device.get_model(), nitrokey::Model::Storage);
drop(device);
- assert_any_ok!(nitrokey::connect());
- assert_any_ok!(nitrokey::connect_model(nitrokey::Model::Storage));
- assert_any_ok!(nitrokey::Storage::connect());
+ let mut manager = nitrokey::take().unwrap();
+ assert_any_ok!(manager.connect());
+ assert_any_ok!(manager.connect_model(nitrokey::Model::Storage));
+ assert_any_ok!(manager.connect_storage());
}
fn assert_empty_serial_number() {
@@ -97,7 +98,10 @@ fn get_firmware_version(device: Pro) {
assert!(version.minor > 0);
}
-fn admin_retry<T: Authenticate + Device>(device: T, suffix: &str, count: u8) -> T {
+fn admin_retry<'a, T>(device: T, suffix: &str, count: u8) -> T
+where
+ T: Authenticate<'a> + Device<'a> + 'a,
+{
let result = device.authenticate_admin(&(DEFAULT_ADMIN_PIN.to_owned() + suffix));
let device = match result {
Ok(admin) => admin.device(),
@@ -107,7 +111,10 @@ fn admin_retry<T: Authenticate + Device>(device: T, suffix: &str, count: u8) ->
return device;
}
-fn user_retry<T: Authenticate + Device>(device: T, suffix: &str, count: u8) -> T {
+fn user_retry<'a, T>(device: T, suffix: &str, count: u8) -> T
+where
+ T: Authenticate<'a> + Device<'a> + 'a,
+{
let result = device.authenticate_user(&(DEFAULT_USER_PIN.to_owned() + suffix));
let device = match result {
Ok(admin) => admin.device(),
@@ -216,10 +223,10 @@ fn change_admin_pin(device: DeviceWrapper) {
device.authenticate_admin(ADMIN_NEW_PASSWORD).unwrap_err();
}
-fn require_failed_user_login<D>(device: D, password: &str, error: CommandError) -> D
+fn require_failed_user_login<'a, D>(device: D, password: &str, error: CommandError) -> D
where
- D: Device + Authenticate,
- nitrokey::User<D>: std::fmt::Debug,
+ D: Device<'a> + Authenticate<'a> + 'a,
+ nitrokey::User<'a, D>: std::fmt::Debug,
{
let result = device.authenticate_user(password);
assert!(result.is_err());