()
| 875 | } |
| 876 | |
| 877 | func (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 | }, |
nothing calls this directly
no test coverage detected