From f2099ec00b8bfd62dd585e828ace674391935463 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Wed, 30 Jun 2021 18:05:02 +0200 Subject: [PATCH] [MM-33538] Trims space from user email when sanitizing user input (#17168) Automatic Merge --- api4/user_test.go | 15 +++++++++++++++ model/user.go | 1 + 2 files changed, 16 insertions(+) diff --git a/api4/user_test.go b/api4/user_test.go index cdd6a733c2..c821774553 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -92,6 +92,21 @@ func TestCreateUser(t *testing.T) { require.NotNil(t, err, "should have errored") assert.Equal(t, http.StatusBadRequest, r.StatusCode) }) + + th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { + email := th.GenerateTestEmail() + user2 := &model.User{Email: email, Password: "Password1", Username: GenerateTestUsername(), EmailVerified: true} + _, resp := client.CreateUser(user2) + CheckNoError(t, resp) + _, appErr := th.App.GetUserByUsername(user2.Username) + require.Nil(t, appErr) + + user3 := &model.User{Email: fmt.Sprintf(" %s ", email), Password: "Password1", Username: GenerateTestUsername(), EmailVerified: true} + _, resp = client.CreateUser(user3) + CheckBadRequestStatus(t, resp) + _, appErr = th.App.GetUserByUsername(user3.Username) + require.NotNil(t, appErr) + }, "Should not be able to create two users with the same email but spaces in it") } func TestCreateUserInputFilter(t *testing.T) { diff --git a/model/user.go b/model/user.go index 7c6789feaf..1745d7267a 100644 --- a/model/user.go +++ b/model/user.go @@ -581,6 +581,7 @@ func (u *User) SanitizeInput(isAdmin bool) { u.FailedAttempts = 0 u.MfaActive = false u.MfaSecret = "" + u.Email = strings.TrimSpace(u.Email) } func (u *User) ClearNonProfileFields() {