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 {
1162 totp::code_at(shared, totp::step_for(forge_core::time::now_unix()))1162 totp::code_at(shared, totp::step_for(forge_core::time::now_unix()))
1163 }1163 }
1164 1164
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+
1165 async fn enable_totp_directly(fx: &Fixture) -> Vec<u8> {1176 async fn enable_totp_directly(fx: &Fixture) -> Vec<u8> {
1166 let shared = totp::new_secret();1177 let shared = totp::new_secret();
1167 let sealed = secret::seal(&fx.state.key, &shared).unwrap();1178 let sealed = secret::seal(&fx.state.key, &shared).unwrap();
@@ -1491,7 +1502,7 @@ mod tests {
1491 "uri shown"1502 "uri shown"
1492 );1503 );
1493 1504
1494- let wrong = format!("csrf={CSRF}&code=000000");1505+ let wrong = format!("csrf={CSRF}&code={}", wrong_code(&shared));
1495 let reply = send(1506 let reply = send(
1496 &fx.router,1507 &fx.router,
1497 "POST",1508 "POST",