aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-05-24 20:36:46 +0000
committerRobin Krahl <robin.krahl@ireas.org>2018-05-28 20:08:23 +0200
commit5f956b8e2a7f1fbf8e968154f55fadb71e8b521a (patch)
tree4a820312740cfaf6259c152bdecd02aca301c51b /src/tests
parent2ec913fdcadef73281ec30f96c0fc7cd00a4ed26 (diff)
downloadnitrokey-rs-5f956b8e2a7f1fbf8e968154f55fadb71e8b521a.tar.gz
nitrokey-rs-5f956b8e2a7f1fbf8e968154f55fadb71e8b521a.tar.bz2
Introduce DeviceWrapper to abstract over devices
DeviceWrapper abstracts over the supported devices. It implements the traits that are implemented by all supported devices. The previous UnauthenticatedDevice is renamed to Pro to prepare Storage support. connect_model is moved to Pro::connect.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/no_device.rs7
-rw-r--r--src/tests/pro.rs27
2 files changed, 17 insertions, 17 deletions
diff --git a/src/tests/no_device.rs b/src/tests/no_device.rs
index 04c5c8a..4118bcd 100644
--- a/src/tests/no_device.rs
+++ b/src/tests/no_device.rs
@@ -1,9 +1,8 @@
-use Model;
-
#[test]
#[cfg_attr(not(feature = "test-no-device"), ignore)]
fn connect() {
assert!(::connect().is_err());
- assert!(::connect_model(Model::Storage).is_err());
- assert!(::connect_model(Model::Pro).is_err());
+ assert!(::Pro::connect().is_err());
+ // TODO: test storage
+ // assert!(::Storage::connect().is_err());
}
diff --git a/src/tests/pro.rs b/src/tests/pro.rs
index 8476451..915b45b 100644
--- a/src/tests/pro.rs
+++ b/src/tests/pro.rs
@@ -1,6 +1,6 @@
use std::ffi::CStr;
-use {AdminAuthenticatedDevice, Authenticate, CommandError, CommandStatus, Config, ConfigureOtp,
- Device, GenerateOtp, Model, OtpMode, OtpSlotData, UnauthenticatedDevice};
+use {Admin, Authenticate, CommandError, CommandStatus, Config, ConfigureOtp, Device, GenerateOtp,
+ OtpMode, OtpSlotData, Pro};
static ADMIN_PASSWORD: &str = "12345678";
static ADMIN_NEW_PASSWORD: &str = "1234567890";
@@ -25,11 +25,11 @@ static TOTP_CODES: &[(u64, &str)] = &[
(20000000000, "65353130"),
];
-fn get_test_device() -> UnauthenticatedDevice {
- ::connect_model(Model::Pro).expect("Could not connect to the Nitrokey Pro.")
+fn get_test_device() -> Pro {
+ Pro::connect().expect("Could not connect to the Nitrokey Pro.")
}
-fn get_admin_test_device() -> AdminAuthenticatedDevice {
+fn get_admin_test_device() -> Admin<Pro> {
get_test_device()
.authenticate_admin(ADMIN_PASSWORD)
.expect("Could not login as admin.")
@@ -39,8 +39,9 @@ fn get_admin_test_device() -> AdminAuthenticatedDevice {
#[cfg_attr(not(feature = "test-pro"), ignore)]
fn connect() {
assert!(::connect().is_ok());
- assert!(::connect_model(Model::Pro).is_ok());
- assert!(::connect_model(Model::Storage).is_err());
+ assert!(Pro::connect().is_ok());
+ // TODO: test storage
+ // assert!(::Storage::connect().is_err());
}
fn assert_empty_serial_number() {
@@ -55,14 +56,14 @@ fn assert_empty_serial_number() {
#[test]
#[cfg_attr(not(feature = "test-pro"), ignore)]
fn disconnect() {
- ::connect().unwrap();
+ Pro::connect().unwrap();
assert_empty_serial_number();
- ::connect()
+ Pro::connect()
.unwrap()
.authenticate_admin(ADMIN_PASSWORD)
.unwrap();
assert_empty_serial_number();
- ::connect()
+ Pro::connect()
.unwrap()
.authenticate_user(USER_PASSWORD)
.unwrap();
@@ -85,7 +86,7 @@ fn configure_hotp(admin: &ConfigureOtp) {
assert_eq!(CommandStatus::Success, admin.write_hotp_slot(slot_data, 0));
}
-fn check_hotp_codes<T: GenerateOtp>(device: &T) {
+fn check_hotp_codes(device: &GenerateOtp) {
for code in HOTP_CODES {
let result = device.get_hotp_code(1);
assert_eq!(code, &result.unwrap());
@@ -287,7 +288,7 @@ fn get_firmware_version() {
assert!(minor == 7 || minor == 8);
}
-fn admin_retry(device: UnauthenticatedDevice, suffix: &str, count: u8) -> UnauthenticatedDevice {
+fn admin_retry(device: Pro, suffix: &str, count: u8) -> Pro {
let result = device.authenticate_admin(&(ADMIN_PASSWORD.to_owned() + suffix));
let device = match result {
Ok(admin) => admin.device(),
@@ -297,7 +298,7 @@ fn admin_retry(device: UnauthenticatedDevice, suffix: &str, count: u8) -> Unauth
return device;
}
-fn user_retry(device: UnauthenticatedDevice, suffix: &str, count: u8) -> UnauthenticatedDevice {
+fn user_retry(device: Pro, suffix: &str, count: u8) -> Pro {
let result = device.authenticate_user(&(USER_PASSWORD.to_owned() + suffix));
let device = match result {
Ok(admin) => admin.device(),