MCPcopy Create free account
hub / github.com/supabase/auth / TestVerifyValidOtp

Method TestVerifyValidOtp

internal/api/verify_test.go:877–1062  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

875}
876
877func (ts *VerifyTestSuite) TestVerifyValidOtp() {
878 ts.Config.Mailer.SecureEmailChangeEnabled = true
879 u, err := models.FindUserByEmailAndAudience(ts.API.db, "test@example.com", ts.Config.JWT.Aud)
880 require.NoError(ts.T(), err)
881 u.EmailChange = "new@example.com"
882 u.Phone = "12345678"
883 u.PhoneChange = "1234567890"
884 require.NoError(ts.T(), ts.API.db.Update(u))
885
886 type expected struct {
887 code int
888 tokenHash string
889 }
890
891 cases := []struct {
892 desc string
893 sentTime time.Time
894 body map[string]interface{}
895 expected
896 }{
897 {
898 desc: "Valid SMS OTP",
899 sentTime: time.Now(),
900 body: map[string]interface{}{
901 "type": smsVerification,
902 "token": "123456",
903 "phone": u.GetPhone(),
904 },
905 expected: expected{
906 code: http.StatusOK,
907 tokenHash: crypto.GenerateTokenHash(u.GetPhone(), "123456"),
908 },
909 },
910 {
911 desc: "Valid Confirmation OTP",
912 sentTime: time.Now(),
913 body: map[string]interface{}{
914 "type": mail.SignupVerification,
915 "token": "123456",
916 "email": u.GetEmail(),
917 },
918 expected: expected{
919 code: http.StatusOK,
920 tokenHash: crypto.GenerateTokenHash(u.GetEmail(), "123456"),
921 },
922 },
923 {
924 desc: "Valid Signup Token Hash",
925 sentTime: time.Now(),
926 body: map[string]interface{}{
927 "type": mail.SignupVerification,
928 "token_hash": crypto.GenerateTokenHash(u.GetEmail(), "123456"),
929 },
930 expected: expected{
931 code: http.StatusOK,
932 tokenHash: crypto.GenerateTokenHash(u.GetEmail(), "123456"),
933 },
934 },

Callers

nothing calls this directly

Calls 13

GenerateTokenHashFunction · 0.92
CreateOneTimeTokenFunction · 0.92
UpdateMethod · 0.80
NowMethod · 0.80
GetPhoneMethod · 0.80
EncodeMethod · 0.80
SetMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
GetEmailMethod · 0.45

Tested by

no test coverage detected