package auth import ( "bytes" "testing" "time" ) func TestTOTPVerificationWindow(t *testing.T) { secret := "JBSWY3DPEHPK3PXP" now := time.Unix(1_700_000_000, 0) code := totpAt(secret, now.Unix()/totpPeriod) if !VerifyTOTP(secret, code, now) { t.Fatal("current TOTP code was rejected") } if VerifyTOTP(secret, "0000000", now) || VerifyTOTP(secret, "abcdef", now) { t.Fatal("malformed TOTP code was accepted") } } func TestRecoveryCodeHashNormalizesFormatting(t *testing.T) { if !bytes.Equal(RecoveryCodeHash("abcd-efgh-ijkl"), RecoveryCodeHash(" ABCDEFGHIJKL ")) { t.Fatal("equivalent recovery codes produced different hashes") } }