*: fix tests that care about email case sensitivity

This commit is contained in:
Eric Chiang 2016-03-01 14:09:10 -08:00
parent 2a0cc47419
commit 01a24542e9
6 changed files with 13 additions and 12 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"reflect" "reflect"
"strings"
"testing" "testing"
"time" "time"
@ -220,6 +221,7 @@ func TestUpdateUser(t *testing.T) {
t.Errorf("case %d: want nil err, got %q", i, err) 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 != "" { if diff := pretty.Compare(tt.user, gotUser); diff != "" {
t.Errorf("case %d: Compare(want, got) = %v", i, t.Errorf("case %d: Compare(want, got) = %v", i,
diff) diff)
@ -436,12 +438,12 @@ func TestGetByEmail(t *testing.T) {
}{ }{
{ {
email: "Email-1@example.com", email: "Email-1@example.com",
wantEmail: "Email-1@example.com", wantEmail: "email-1@example.com",
wantErr: nil, wantErr: nil,
}, },
{ {
email: "EMAIL-1@example.com", // Emails should be case insensitive. email: "EMAIL-1@example.com", // Emails should be case insensitive.
wantEmail: "Email-1@example.com", wantEmail: "email-1@example.com",
wantErr: nil, wantErr: nil,
}, },
{ {

View file

@ -223,7 +223,7 @@ func handleEmailVerifyFunc(verifiedTpl *template.Template, issuer url.URL, keysF
Error: "Invalid Verification Link", Error: "Invalid Verification Link",
Message: "Your email link has expired or has already been verified.", Message: "Your email link has expired or has already been verified.",
}, http.StatusBadRequest) }, http.StatusBadRequest)
case manager.ErrorEVEmailDoesntMatch: case user.ErrorNotFound:
execTemplateWithStatus(w, verifiedTpl, emailVerifiedTemplateData{ execTemplateWithStatus(w, verifiedTpl, emailVerifiedTemplateData{
Error: "Invalid Verification Link", Error: "Invalid Verification Link",
Message: "Your email link does not match the email address on file. Perhaps you have a more recent verification link?", Message: "Your email link does not match the email address on file. Perhaps you have a more recent verification link?",

View file

@ -62,7 +62,7 @@ func (h *InvitationHandler) handleGET(w http.ResponseWriter, r *http.Request) {
// never be able to set their passwords. // never be able to set their passwords.
log.Debugf("error attempting to verify email: %v", err) log.Debugf("error attempting to verify email: %v", err)
switch err { switch err {
case manager.ErrorEVEmailDoesntMatch: case user.ErrorNotFound:
writeAPIError(w, http.StatusBadRequest, newAPIError(errorInvalidRequest, writeAPIError(w, http.StatusBadRequest, newAPIError(errorInvalidRequest,
"Your email does not match the email address on file")) "Your email does not match the email address on file"))
return return

View file

@ -100,7 +100,7 @@ func TestSendResetPasswordEmailHandler(t *testing.T) {
wantCode: http.StatusOK, wantCode: http.StatusOK,
wantEmailer: &testEmailer{ wantEmailer: &testEmailer{
to: str("Email-1@example.com"), to: str("email-1@example.com"),
from: "noreply@example.com", from: "noreply@example.com",
subject: "Reset Your Password", subject: "Reset Your Password",
}, },
@ -136,7 +136,7 @@ func TestSendResetPasswordEmailHandler(t *testing.T) {
wantCode: http.StatusOK, wantCode: http.StatusOK,
wantEmailer: &testEmailer{ wantEmailer: &testEmailer{
to: str("Email-1@example.com"), to: str("email-1@example.com"),
from: "noreply@example.com", from: "noreply@example.com",
subject: "Reset Your Password", subject: "Reset Your Password",
}, },

View file

@ -13,9 +13,7 @@ import (
) )
var ( 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") ErrorPasswordAlreadyChanged = errors.New("password has already been changed")
) )
@ -228,15 +226,15 @@ func (m *UserManager) VerifyEmail(ev EmailVerifiable) (*url.URL, error) {
return nil, err return nil, err
} }
usr, err := m.userRepo.Get(tx, ev.UserID()) usr, err := m.userRepo.GetByEmail(tx, ev.Email())
if err != nil { if err != nil {
rollback(tx) rollback(tx)
return nil, err return nil, err
} }
if usr.Email != ev.Email() { if usr.ID != ev.UserID() {
rollback(tx) rollback(tx)
return nil, ErrorEVEmailDoesntMatch return nil, user.ErrorNotFound
} }
if usr.EmailVerified { if usr.EmailVerified {

View file

@ -311,6 +311,7 @@ func TestVerifyEmail(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("case %d: want err=nil got=%q", i, err) t.Errorf("case %d: want err=nil got=%q", i, err)
continue
} }
if cb.String() != tt.evClaims[user.ClaimEmailVerificationCallback] { if cb.String() != tt.evClaims[user.ClaimEmailVerificationCallback] {