summaryrefslogtreecommitdiff
path: root/tests/otp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/otp.rs')
-rw-r--r--tests/otp.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/tests/otp.rs b/tests/otp.rs
index 51a6539..96da371 100644
--- a/tests/otp.rs
+++ b/tests/otp.rs
@@ -93,7 +93,7 @@ fn hotp_pin(device: DeviceWrapper) {
let user = admin.device().authenticate_user(USER_PASSWORD).unwrap();
check_hotp_codes(&user, 0);
- assert!(user.device().get_hotp_code(1).is_err());
+ assert_cmd_err!(CommandError::NotAuthorized, user.device().get_hotp_code(1));
}
#[test_device]
@@ -156,7 +156,7 @@ fn configure_totp(admin: &ConfigureOtp, factor: u64) {
}
fn check_totp_codes(device: &GenerateOtp, factor: u64, timestamp_size: TotpTimestampSize) {
- for (i, &(base_time, code)) in TOTP_CODES.iter().enumerate() {
+ for (base_time, code) in TOTP_CODES {
let time = base_time.checked_mul(factor).unwrap();
let is_u64 = time > u32::max_value() as u64;
if is_u64 != (timestamp_size == TotpTimestampSize::U64) {
@@ -164,14 +164,7 @@ fn check_totp_codes(device: &GenerateOtp, factor: u64, timestamp_size: TotpTimes
}
assert_ok!((), device.set_time(time, true));
- let result = device.get_totp_code(1);
- assert!(result.is_ok());
- let result_code = result.unwrap();
- assert_eq!(
- code, result_code,
- "TOTP code {} should be {} but is {}",
- i, code, result_code
- );
+ assert_ok!(code.to_string(), device.get_totp_code(1));
}
}
@@ -221,7 +214,7 @@ fn totp_pin(device: DeviceWrapper) {
let user = admin.device().authenticate_user(USER_PASSWORD).unwrap();
check_totp_codes(&user, 1, TotpTimestampSize::U32);
- assert!(user.device().get_totp_code(1).is_err());
+ assert_cmd_err!(CommandError::NotAuthorized, user.device().get_totp_code(1));
}
#[test_device]
@@ -235,7 +228,7 @@ fn totp_pin_64(device: Pro) {
let user = admin.device().authenticate_user(USER_PASSWORD).unwrap();
check_totp_codes(&user, 1, TotpTimestampSize::U64);
- assert!(user.device().get_totp_code(1).is_err());
+ assert_cmd_err!(CommandError::NotAuthorized, user.device().get_totp_code(1));
}
#[test_device]
@@ -246,8 +239,7 @@ fn totp_slot_name(device: DeviceWrapper) {
let device = admin.device();
let result = device.get_totp_slot_name(1);
- assert!(result.is_ok());
- assert_eq!("test-totp", result.unwrap());
+ assert_ok!("test-totp", result);
let result = device.get_totp_slot_name(16);
assert_lib_err!(LibraryError::InvalidSlot, result);
}