diff --git a/crates/forge-web-account/src/pages/settings_security.rs b/crates/forge-web-account/src/pages/settings_security.rs index cee7f8d..31c529e 100644 --- a/crates/forge-web-account/src/pages/settings_security.rs +++ b/crates/forge-web-account/src/pages/settings_security.rs @@ -1162,6 +1162,17 @@ mod tests { totp::code_at(shared, totp::step_for(forge_core::time::now_unix())) } + fn wrong_code(shared: &[u8]) -> String { + let now = totp::step_for(forge_core::time::now_unix()); + let near: Vec = (now - 2..=now + 2) + .map(|step| totp::code_at(shared, step)) + .collect(); + (0..) + .map(|n| format!("{n:06}")) + .find(|code| !near.contains(code)) + .unwrap() + } + async fn enable_totp_directly(fx: &Fixture) -> Vec { let shared = totp::new_secret(); let sealed = secret::seal(&fx.state.key, &shared).unwrap(); @@ -1491,7 +1502,7 @@ mod tests { "uri shown" ); - let wrong = format!("csrf={CSRF}&code=000000"); + let wrong = format!("csrf={CSRF}&code={}", wrong_code(&shared)); let reply = send( &fx.router, "POST",