*: fix tests that care about email case sensitivity
This commit is contained in:
parent
2a0cc47419
commit
01a24542e9
6 changed files with 13 additions and 12 deletions
|
@ -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,
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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?",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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] {
|
||||
|
|
Reference in a new issue