aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-01 23:38:14 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-02 00:43:32 +0100
commit52afed9c6a17ec9c120a5a91b445afa74be87f0e (patch)
treef2c177d068c61aea4ed85b134110bac25f027332 /tests
parentbf1e181a1bbbc8e42d1313e80676c1955499b87c (diff)
downloadnitrokey-rs-52afed9c6a17ec9c120a5a91b445afa74be87f0e.tar.gz
nitrokey-rs-52afed9c6a17ec9c120a5a91b445afa74be87f0e.tar.bz2
Add force argument to ConfigureOtp::set_time
This patch adds the force argument to the set_time method in the ConfigureOtp trait that allows the user to choose whether jumps to the past are allowed when updating the time. It is implemented by using the NK_totp_set_time_soft function. Previously, jumps where unconditionally allowed.
Diffstat (limited to 'tests')
-rw-r--r--tests/otp.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/otp.rs b/tests/otp.rs
index 8e7ae08..c7d6e68 100644
--- a/tests/otp.rs
+++ b/tests/otp.rs
@@ -55,6 +55,16 @@ fn check_hotp_codes(device: &GenerateOtp, offset: u8) {
#[test]
#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)]
+fn set_time() {
+ let device = Target::connect().expect("Could not connect to the Nitrokey.");
+ assert_eq!(Ok(()), device.set_time(1546385382, true));
+ assert_eq!(Ok(()), device.set_time(1546385392, false));
+ assert_eq!(Err(CommandError::Timestamp), device.set_time(1546385292, false));
+ assert_eq!(Ok(()), device.set_time(1546385382, true));
+}
+
+#[test]
+#[cfg_attr(not(any(feature = "test-pro", feature = "test-storage")), ignore)]
fn hotp_no_pin() {
let admin = get_admin_test_device();
let config = Config::new(None, None, None, false);
@@ -152,7 +162,7 @@ fn check_totp_codes(device: &GenerateOtp, factor: u64, timestamp_size: TotpTimes
continue;
}
- assert!(device.set_time(time).is_ok());
+ assert!(device.set_time(time, true).is_ok());
let result = device.get_totp_code(1);
assert!(result.is_ok());
let result_code = result.unwrap();