diff --git a/functional/repo/user_repo_test.go b/functional/repo/user_repo_test.go index 3dda44cc..17071490 100644 --- a/functional/repo/user_repo_test.go +++ b/functional/repo/user_repo_test.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "reflect" + "strings" "testing" "time" @@ -220,6 +221,7 @@ func TestUpdateUser(t *testing.T) { t.Errorf("case %d: want nil err, got %q", i, err) } + tt.user.Email = strings.ToLower(tt.user.Email) if diff := pretty.Compare(tt.user, gotUser); diff != "" { t.Errorf("case %d: Compare(want, got) = %v", i, diff) @@ -436,12 +438,12 @@ func TestGetByEmail(t *testing.T) { }{ { email: "Email-1@example.com", - wantEmail: "Email-1@example.com", + wantEmail: "email-1@example.com", wantErr: nil, }, { email: "EMAIL-1@example.com", // Emails should be case insensitive. - wantEmail: "Email-1@example.com", + wantEmail: "email-1@example.com", wantErr: nil, }, { diff --git a/server/email_verification.go b/server/email_verification.go index 2bc01fa9..64fd3689 100644 --- a/server/email_verification.go +++ b/server/email_verification.go @@ -223,7 +223,7 @@ func handleEmailVerifyFunc(verifiedTpl *template.Template, issuer url.URL, keysF Error: "Invalid Verification Link", Message: "Your email link has expired or has already been verified.", }, http.StatusBadRequest) - case manager.ErrorEVEmailDoesntMatch: + case user.ErrorNotFound: execTemplateWithStatus(w, verifiedTpl, emailVerifiedTemplateData{ Error: "Invalid Verification Link", Message: "Your email link does not match the email address on file. Perhaps you have a more recent verification link?", diff --git a/server/invitation.go b/server/invitation.go index c70e3291..032f7ed9 100644 --- a/server/invitation.go +++ b/server/invitation.go @@ -62,7 +62,7 @@ func (h *InvitationHandler) handleGET(w http.ResponseWriter, r *http.Request) { // never be able to set their passwords. log.Debugf("error attempting to verify email: %v", err) switch err { - case manager.ErrorEVEmailDoesntMatch: + case user.ErrorNotFound: writeAPIError(w, http.StatusBadRequest, newAPIError(errorInvalidRequest, "Your email does not match the email address on file")) return diff --git a/server/password_test.go b/server/password_test.go index 9f5ac606..a5f7e6d3 100644 --- a/server/password_test.go +++ b/server/password_test.go @@ -100,7 +100,7 @@ func TestSendResetPasswordEmailHandler(t *testing.T) { wantCode: http.StatusOK, wantEmailer: &testEmailer{ - to: str("Email-1@example.com"), + to: str("email-1@example.com"), from: "noreply@example.com", subject: "Reset Your Password", }, @@ -136,7 +136,7 @@ func TestSendResetPasswordEmailHandler(t *testing.T) { wantCode: http.StatusOK, wantEmailer: &testEmailer{ - to: str("Email-1@example.com"), + to: str("email-1@example.com"), from: "noreply@example.com", subject: "Reset Your Password", }, diff --git a/user/manager/manager.go b/user/manager/manager.go index a37ca8b1..b77b7b15 100644 --- a/user/manager/manager.go +++ b/user/manager/manager.go @@ -13,9 +13,7 @@ import ( ) var ( - ErrorEVEmailDoesntMatch = errors.New("email in EV doesn't match user email") - ErrorEmailAlreadyVerified = errors.New("email already verified") - + ErrorEmailAlreadyVerified = errors.New("email already verified") ErrorPasswordAlreadyChanged = errors.New("password has already been changed") ) @@ -228,15 +226,15 @@ func (m *UserManager) VerifyEmail(ev EmailVerifiable) (*url.URL, error) { return nil, err } - usr, err := m.userRepo.Get(tx, ev.UserID()) + usr, err := m.userRepo.GetByEmail(tx, ev.Email()) if err != nil { rollback(tx) return nil, err } - if usr.Email != ev.Email() { + if usr.ID != ev.UserID() { rollback(tx) - return nil, ErrorEVEmailDoesntMatch + return nil, user.ErrorNotFound } if usr.EmailVerified { diff --git a/user/manager/manager_test.go b/user/manager/manager_test.go index 819bab2b..1b90384c 100644 --- a/user/manager/manager_test.go +++ b/user/manager/manager_test.go @@ -311,6 +311,7 @@ func TestVerifyEmail(t *testing.T) { if err != nil { t.Errorf("case %d: want err=nil got=%q", i, err) + continue } if cb.String() != tt.evClaims[user.ClaimEmailVerificationCallback] {