Show OTP code validity in frontends
This commit is contained in:
@@ -1028,8 +1028,8 @@ mod tests {
|
||||
entry: "otp/totp".to_owned(),
|
||||
field: Some(wrong_field),
|
||||
code: ironstorage::repository::SecretBytes::new(b"123456".to_vec()),
|
||||
remaining_seconds: Some(12),
|
||||
counter: None,
|
||||
validity: ironstorage::otp::OtpCodeValidity::Timed { valid_until: 72 },
|
||||
observed_at: 60,
|
||||
clipboard: false,
|
||||
tree: None,
|
||||
}),
|
||||
@@ -1042,8 +1042,8 @@ mod tests {
|
||||
entry: "otp/totp".to_owned(),
|
||||
field: Some(otp_field),
|
||||
code: ironstorage::repository::SecretBytes::new(b"123456".to_vec()),
|
||||
remaining_seconds: Some(12),
|
||||
counter: None,
|
||||
validity: ironstorage::otp::OtpCodeValidity::Timed { valid_until: 72 },
|
||||
observed_at: 60,
|
||||
clipboard: false,
|
||||
tree: None,
|
||||
}),
|
||||
@@ -1053,6 +1053,30 @@ mod tests {
|
||||
assert!(code.contains("12s remaining"));
|
||||
assert!(!code.contains("JBSWY3DPEHPK3PXP"));
|
||||
|
||||
app.observe_time(72);
|
||||
assert!(render(120, 20, &app).contains("0s remaining"));
|
||||
assert_eq!(
|
||||
app.begin_totp_refresh(),
|
||||
Some(("otp/totp".to_owned(), otp_field))
|
||||
);
|
||||
let token = app.begin_request();
|
||||
app.apply_result(crate::app::AsyncResult {
|
||||
token,
|
||||
payload: Ok(crate::app::AsyncPayload::OtpCodeFinished {
|
||||
entry: "otp/totp".to_owned(),
|
||||
field: Some(otp_field),
|
||||
code: ironstorage::repository::SecretBytes::new(b"654321".to_vec()),
|
||||
validity: ironstorage::otp::OtpCodeValidity::Timed { valid_until: 102 },
|
||||
observed_at: 72,
|
||||
clipboard: false,
|
||||
tree: None,
|
||||
}),
|
||||
});
|
||||
let refreshed = render(120, 20, &app);
|
||||
assert!(refreshed.contains("654321"));
|
||||
assert!(refreshed.contains("30s remaining"));
|
||||
assert!(!refreshed.contains("123456"));
|
||||
|
||||
let payload = ironstorage::repository::SecretBytes::new(
|
||||
b"otpauth://totp/test?secret=NEVER-RENDER".to_vec(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user