package server import ( "fmt" "testing" ) // RFC 6238 appendix B, SHA1 rows (8 digits). func TestTOTPVectors(t *testing.T) { key := []byte("12345678901234567890") for ts, want := range map[int64]string{ 59: "94287082", 1111111109: "07081804", 1111111111: "14050471", 1234567890: "89005924", 2000000000: "69279037", 20000000000: "65353130", } { if got := fmt.Sprintf("%08d", hotp(key, uint64(ts/30))%100000000); got != want { t.Errorf("T=%d: got %s, want %s", ts, got, want) } if got := totpCode(key, ts/30); got != want[2:] { t.Errorf("T=%d 6-digit: got %s, want %s", ts, got, want[2:]) } } } func TestNormCode(t *testing.T) { for in, want := range map[string]string{" 123 456 ": "123456", "ABCD-efgh-2345-6789": "abcdefgh23456789"} { if got := normCode(in); got != want { t.Errorf("normCode(%q) = %q, want %q", in, got, want) } } }