aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-05-30 10:08:26 +0000
committerRobin Krahl <robin.krahl@ireas.org>2018-05-30 12:09:02 +0200
commitc37899dfee9057497f6622149e3b06ae8def55d5 (patch)
tree8b19af544ed4df041d978db54fa102ab428331e7 /src/tests
parent41dfe16047cd9f1a2accaacc3eff4c7e672f1e0d (diff)
downloadnitrokey-rs-c37899dfee9057497f6622149e3b06ae8def55d5.tar.gz
nitrokey-rs-c37899dfee9057497f6622149e3b06ae8def55d5.tar.bz2
Add test case for writing the HOTP counter
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/otp.rs31
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());
}