summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-12-29 13:15:04 +0100
committerRobin Krahl <robin.krahl@ireas.org>2020-01-07 11:33:34 +0100
commit97c772724dd1fe395e7154e0d71c3b2408436082 (patch)
tree816248fbb3cb398f8b98294a14abee3300f14ae7 /tests
parentc74b8b3ea8dc4fe7c6891ae120540f8da5623227 (diff)
downloadnitrokey-rs-97c772724dd1fe395e7154e0d71c3b2408436082.tar.gz
nitrokey-rs-97c772724dd1fe395e7154e0d71c3b2408436082.tar.bz2
Add the connect_path function to the Manager struct
This patch adds the connect_path function to the Manager struct that uses NK_connect_with_path to connect to a Nitrokey device at a given USB path.
Diffstat (limited to 'tests')
-rw-r--r--tests/device.rs47
1 files changed, 45 insertions, 2 deletions
diff --git a/tests/device.rs b/tests/device.rs
index 5e60002..509763b 100644
--- a/tests/device.rs
+++ b/tests/device.rs
@@ -49,10 +49,10 @@ fn list_devices(_device: DeviceWrapper) {
let serial_number = device.serial_number.unwrap();
assert!(!serial_number.is_empty());
assert_valid_serial_number(&serial_number);
- },
+ }
nitrokey::Model::Storage => {
assert_eq!(None, device.serial_number);
- },
+ }
}
}
}
@@ -105,6 +105,49 @@ fn assert_empty_serial_number() {
}
#[test_device]
+fn connect_path_no_device() {
+ let mut manager = unwrap_ok!(nitrokey::take());
+
+ assert_cmu_err!(CommunicationError::NotConnected, manager.connect_path(""));
+ assert_cmu_err!(
+ CommunicationError::NotConnected,
+ manager.connect_path("foobar")
+ );
+ // TODO: add realistic path
+}
+
+#[test_device]
+fn connect_path(device: DeviceWrapper) {
+ let manager = device.into_manager();
+
+ assert_cmu_err!(CommunicationError::NotConnected, manager.connect_path(""));
+ assert_cmu_err!(
+ CommunicationError::NotConnected,
+ manager.connect_path("foobar")
+ );
+ // TODO: add realistic path
+
+ let devices = unwrap_ok!(nitrokey::list_devices());
+ assert!(!devices.is_empty());
+ for device in devices {
+ let connected_device = unwrap_ok!(manager.connect_path(device.path));
+ assert_eq!(device.model, Some(connected_device.get_model()));
+ match device.model.unwrap() {
+ nitrokey::Model::Pro => {
+ assert!(device.serial_number.is_some());
+ assert_ok!(
+ device.serial_number.unwrap(),
+ connected_device.get_serial_number()
+ );
+ }
+ nitrokey::Model::Storage => {
+ assert_eq!(None, device.serial_number);
+ }
+ }
+ }
+}
+
+#[test_device]
fn disconnect(device: DeviceWrapper) {
drop(device);
assert_empty_serial_number();