forge
Explore
Log in

Don't you dare go Hollow

The 2FA enrollment test picks a code that is wrong at every step near now

Browse files at this commit

7c33646494e128c02d858bccead669ba5307a14dAhmet Kaan GümüşParent: 28e3143
All checks have passed
Show checks
  • fix
    • the 2FA enrollment test picks a code that is wrong at every step near now
    • 000000 was valid about once in 300 000 runs and failed CI #189
Show full message
🐛 fix: the 2FA enrollment test picks a code that is wrong at every step near now; 000000 was valid about once in 300 000 runs and failed CI #189
crates/forge-web-account/src/pages/settings_security.rsmodified+12 -1
@@ -1162,6 +1162,17 @@ mod tests {
11621162 totp::code_at(shared, totp::step_for(forge_core::time::now_unix()))
11631163 }
11641164
1165+ fn wrong_code(shared: &[u8]) -> String {
1166+ let now = totp::step_for(forge_core::time::now_unix());
1167+ let near: Vec<String> = (now - 2..=now + 2)
1168+ .map(|step| totp::code_at(shared, step))
1169+ .collect();
1170+ (0..)
1171+ .map(|n| format!("{n:06}"))
1172+ .find(|code| !near.contains(code))
1173+ .unwrap()
1174+ }
1175+
11651176 async fn enable_totp_directly(fx: &Fixture) -> Vec<u8> {
11661177 let shared = totp::new_secret();
11671178 let sealed = secret::seal(&fx.state.key, &shared).unwrap();
@@ -1491,7 +1502,7 @@ mod tests {
14911502 "uri shown"
14921503 );
14931504
1494- let wrong = format!("csrf={CSRF}&code=000000");
1505+ let wrong = format!("csrf={CSRF}&code={}", wrong_code(&shared));
14951506 let reply = send(
14961507 &fx.router,
14971508 "POST",