diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/otp.rs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/tests/otp.rs b/src/tests/otp.rs index 077157f..de3b646 100644 --- a/src/tests/otp.rs +++ b/src/tests/otp.rs @@ -28,16 +28,18 @@ fn get_admin_test_device() -> Admin<Target> { .expect("Could not login as admin.") } -fn configure_hotp(admin: &ConfigureOtp) { +fn configure_hotp(admin: &ConfigureOtp, counter: u8) { let slot_data = OtpSlotData::new(1, "test-hotp", HOTP_SECRET, OtpMode::SixDigits); - assert_eq!(CommandStatus::Success, admin.write_hotp_slot(slot_data, 0)); + assert_eq!(CommandStatus::Success, admin.write_hotp_slot(slot_data, counter.into())); } -fn check_hotp_codes(device: &GenerateOtp) { - for code in HOTP_CODES { - let result = device.get_hotp_code(1); - assert_eq!(code, &result.unwrap()); - } +fn check_hotp_codes(device: &GenerateOtp, offset: u8) { + HOTP_CODES.iter().enumerate().for_each(|(i, code)| { + if i >= offset as usize { + let result = device.get_hotp_code(1); + assert_eq!(code, &result.unwrap()); + } + }); } #[test] @@ -47,11 +49,14 @@ fn hotp_no_pin() { let config = Config::new(None, None, None, false); assert_eq!(CommandStatus::Success, admin.write_config(config)); - configure_hotp(&admin); - check_hotp_codes(admin.deref()); + configure_hotp(&admin, 0); + check_hotp_codes(admin.deref(), 0); + + configure_hotp(&admin, 5); + check_hotp_codes(admin.deref(), 5); - configure_hotp(&admin); - check_hotp_codes(&admin.device()); + configure_hotp(&admin, 0); + check_hotp_codes(&admin.device(), 0); } #[test] @@ -61,9 +66,9 @@ fn hotp_pin() { let config = Config::new(None, None, None, true); assert_eq!(CommandStatus::Success, admin.write_config(config)); - configure_hotp(&admin); + configure_hotp(&admin, 0); let user = admin.device().authenticate_user(USER_PASSWORD).unwrap(); - check_hotp_codes(&user); + check_hotp_codes(&user, 0); assert!(user.device().get_hotp_code(1).is_err()); } |