The 2FA enrollment test picks a code that is wrong at every step near now
Browse files at this commit7c33646494e128c02d858bccead669ba5307a14dParent: 28e3143All checks have passed
Show checks
ci/buildSucceededDetails
- 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
1 changed file +12 -1
crates/forge-web-account/src/pages/settings_security.rsmodified+12 -1
| @@ -1162,6 +1162,17 @@ mod tests { | ||
| 1162 | 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 | 1176 | async fn enable_totp_directly(fx: &Fixture) -> Vec<u8> { |
| 1166 | 1177 | let shared = totp::new_secret(); |
| 1167 | 1178 | let sealed = secret::seal(&fx.state.key, &shared).unwrap(); |
| @@ -1491,7 +1502,7 @@ mod tests { | ||
| 1491 | 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 | 1506 | let reply = send( |
| 1496 | 1507 | &fx.router, |
| 1497 | 1508 | "POST", |