aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/device.rs4
-rw-r--r--tests/otp.rs28
-rw-r--r--tests/pws.rs16
-rw-r--r--tests/util/mod.rs7
4 files changed, 32 insertions, 23 deletions
diff --git a/tests/device.rs b/tests/device.rs
index 174624f..ee5dae1 100644
--- a/tests/device.rs
+++ b/tests/device.rs
@@ -6,7 +6,7 @@ use std::{thread, time};
use nitrokey::{
Authenticate, CommandError, Config, ConfigureOtp, Device, Error, GenerateOtp, GetPasswordSafe,
- OtpMode, OtpSlotData, Storage, VolumeMode,
+ LibraryError, OtpMode, OtpSlotData, Storage, VolumeMode,
};
use nitrokey_test::test as test_device;
@@ -130,7 +130,7 @@ fn config(device: DeviceWrapper) {
assert_eq!(config, get_config);
let config = Config::new(None, Some(9), None, true);
- assert_cmd_err!(CommandError::InvalidSlot, admin.write_config(config));
+ assert_lib_err!(LibraryError::InvalidSlot, admin.write_config(config));
let config = Config::new(Some(1), None, Some(0), false);
assert_ok!((), admin.write_config(config));
diff --git a/tests/otp.rs b/tests/otp.rs
index d328351..51a6539 100644
--- a/tests/otp.rs
+++ b/tests/otp.rs
@@ -4,8 +4,8 @@ use std::fmt::Debug;
use std::ops::Deref;
use nitrokey::{
- Admin, Authenticate, CommandError, Config, ConfigureOtp, Device, GenerateOtp, OtpMode,
- OtpSlotData,
+ Admin, Authenticate, CommandError, Config, ConfigureOtp, Device, GenerateOtp, LibraryError,
+ OtpMode, OtpSlotData,
};
use nitrokey_test::test as test_device;
@@ -106,7 +106,7 @@ fn hotp_slot_name(device: DeviceWrapper) {
let result = device.get_hotp_slot_name(1);
assert_eq!("test-hotp", result.unwrap());
let result = device.get_hotp_slot_name(4);
- assert_cmd_err!(CommandError::InvalidSlot, result);
+ assert_lib_err!(LibraryError::InvalidSlot, result);
}
#[test_device]
@@ -115,17 +115,17 @@ fn hotp_error(device: DeviceWrapper) {
let slot_data = OtpSlotData::new(1, "", HOTP_SECRET, OtpMode::SixDigits);
assert_cmd_err!(CommandError::NoName, admin.write_hotp_slot(slot_data, 0));
let slot_data = OtpSlotData::new(4, "test", HOTP_SECRET, OtpMode::SixDigits);
- assert_cmd_err!(
- CommandError::InvalidSlot,
+ assert_lib_err!(
+ LibraryError::InvalidSlot,
admin.write_hotp_slot(slot_data, 0)
);
let slot_data = OtpSlotData::new(1, "test", "foobar", OtpMode::SixDigits);
- assert_cmd_err!(
- CommandError::InvalidHexString,
+ assert_lib_err!(
+ LibraryError::InvalidHexString,
admin.write_hotp_slot(slot_data, 0)
);
let code = admin.get_hotp_code(4);
- assert_cmd_err!(CommandError::InvalidSlot, code);
+ assert_lib_err!(LibraryError::InvalidSlot, code);
}
#[test_device]
@@ -249,7 +249,7 @@ fn totp_slot_name(device: DeviceWrapper) {
assert!(result.is_ok());
assert_eq!("test-totp", result.unwrap());
let result = device.get_totp_slot_name(16);
- assert_cmd_err!(CommandError::InvalidSlot, result);
+ assert_lib_err!(LibraryError::InvalidSlot, result);
}
#[test_device]
@@ -258,17 +258,17 @@ fn totp_error(device: DeviceWrapper) {
let slot_data = OtpSlotData::new(1, "", TOTP_SECRET, OtpMode::SixDigits);
assert_cmd_err!(CommandError::NoName, admin.write_totp_slot(slot_data, 0));
let slot_data = OtpSlotData::new(20, "test", TOTP_SECRET, OtpMode::SixDigits);
- assert_cmd_err!(
- CommandError::InvalidSlot,
+ assert_lib_err!(
+ LibraryError::InvalidSlot,
admin.write_totp_slot(slot_data, 0)
);
let slot_data = OtpSlotData::new(4, "test", "foobar", OtpMode::SixDigits);
- assert_cmd_err!(
- CommandError::InvalidHexString,
+ assert_lib_err!(
+ LibraryError::InvalidHexString,
admin.write_totp_slot(slot_data, 0)
);
let code = admin.get_totp_code(20);
- assert_cmd_err!(CommandError::InvalidSlot, code);
+ assert_lib_err!(LibraryError::InvalidSlot, code);
}
#[test_device]
diff --git a/tests/pws.rs b/tests/pws.rs
index a4647bd..51e6189 100644
--- a/tests/pws.rs
+++ b/tests/pws.rs
@@ -3,7 +3,9 @@ mod util;
use std::ffi::CStr;
use libc::{c_int, c_void, free};
-use nitrokey::{CommandError, Device, Error, GetPasswordSafe, PasswordSafe, SLOT_COUNT};
+use nitrokey::{
+ CommandError, Device, Error, GetPasswordSafe, LibraryError, PasswordSafe, SLOT_COUNT,
+};
use nitrokey_sys;
use nitrokey_test::test as test_device;
@@ -104,17 +106,17 @@ fn get_data(device: DeviceWrapper) {
assert_eq!(login, pws.get_slot_login(1).unwrap());
assert_eq!(password, pws.get_slot_password(1).unwrap());
- assert_cmd_err!(CommandError::InvalidSlot, pws.get_slot_name(SLOT_COUNT));
- assert_cmd_err!(CommandError::InvalidSlot, pws.get_slot_login(SLOT_COUNT));
- assert_cmd_err!(CommandError::InvalidSlot, pws.get_slot_password(SLOT_COUNT));
+ assert_lib_err!(LibraryError::InvalidSlot, pws.get_slot_name(SLOT_COUNT));
+ assert_lib_err!(LibraryError::InvalidSlot, pws.get_slot_login(SLOT_COUNT));
+ assert_lib_err!(LibraryError::InvalidSlot, pws.get_slot_password(SLOT_COUNT));
}
#[test_device]
fn write(device: DeviceWrapper) {
let pws = get_pws(&device);
- assert_cmd_err!(
- CommandError::InvalidSlot,
+ assert_lib_err!(
+ LibraryError::InvalidSlot,
pws.write_slot(SLOT_COUNT, "name", "login", "password")
);
@@ -137,7 +139,7 @@ fn write(device: DeviceWrapper) {
#[test_device]
fn erase(device: DeviceWrapper) {
let pws = get_pws(&device);
- assert_cmd_err!(CommandError::InvalidSlot, pws.erase_slot(SLOT_COUNT));
+ assert_lib_err!(LibraryError::InvalidSlot, pws.erase_slot(SLOT_COUNT));
assert_ok!((), pws.write_slot(0, "name", "login", "password"));
assert_ok!((), pws.erase_slot(0));
diff --git a/tests/util/mod.rs b/tests/util/mod.rs
index f0d0bb5..b1d3ea3 100644
--- a/tests/util/mod.rs
+++ b/tests/util/mod.rs
@@ -67,3 +67,10 @@ macro_rules! assert_cmd_err {
assert_err!(::nitrokey::Error::CommandError, $left, $right);
};
}
+
+#[macro_export]
+macro_rules! assert_lib_err {
+ ($left:expr, $right:expr) => {
+ assert_err!(::nitrokey::Error::LibraryError, $left, $right);
+ };
+}