package auth import ( "testing" "time" ) func TestVerifyTOTPRFC6238SHA1Vectors(t *testing.T) { secret := "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ" cases := []struct { unix int64 code string }{ {unix: 59, code: "287082"}, {unix: 1111111109, code: "081804"}, {unix: 1111111111, code: "050471"}, {unix: 1234567890, code: "005924"}, {unix: 2000000000, code: "279037"}, } for _, testCase := range cases { if !VerifyTOTP(secret, testCase.code, time.Unix(testCase.unix, 0)) { t.Errorf("VerifyTOTP(%d, %q) = false", testCase.unix, testCase.code) } } } func TestTOTPProvisioningURI(t *testing.T) { uri := TOTPProvisioningURI("Example App", "admin@example.com", "abc123") if uri == "" || len(uri) < len("otpauth://totp/") || uri[:15] != "otpauth://totp/" { t.Fatalf("unexpected provisioning URI: %q", uri) } }