From 98ccc1ccf50a5c11cb0d9867e82186c8a9f71a21 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Sun, 1 Mar 2020 19:52:16 +0100 Subject: [PATCH] [MM-22572] Modify get user by email route to accept the / character in the email (#13897) Automatic Merge --- api4/api.go | 2 +- api4/user_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/api4/api.go b/api4/api.go index 63d5ad2e09..88cc69941f 100644 --- a/api4/api.go +++ b/api4/api.go @@ -133,7 +133,7 @@ func Init(configservice configservice.ConfigService, globalOptionsFunc app.AppOp api.BaseRoutes.Users = api.BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter() api.BaseRoutes.User = api.BaseRoutes.ApiRoot.PathPrefix("/users/{user_id:[A-Za-z0-9]+}").Subrouter() api.BaseRoutes.UserByUsername = api.BaseRoutes.Users.PathPrefix("/username/{username:[A-Za-z0-9\\_\\-\\.]+}").Subrouter() - api.BaseRoutes.UserByEmail = api.BaseRoutes.Users.PathPrefix("/email/{email}").Subrouter() + api.BaseRoutes.UserByEmail = api.BaseRoutes.Users.PathPrefix("/email/{email:.+}").Subrouter() api.BaseRoutes.Bots = api.BaseRoutes.ApiRoot.PathPrefix("/bots").Subrouter() api.BaseRoutes.Bot = api.BaseRoutes.ApiRoot.PathPrefix("/bots/{bot_user_id:[A-Za-z0-9]+}").Subrouter() diff --git a/api4/user_test.go b/api4/user_test.go index 6f6b0d8656..9a158d66a6 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -675,6 +675,21 @@ func TestGetUserByUsername(t *testing.T) { require.NotEmpty(t, ruser.Email, "email should not be blank") require.NotEmpty(t, ruser.FirstName, "first name should not be blank") require.NotEmpty(t, ruser.LastName, "last name should not be blank") + + t.Run("Get user with a / character in the email", func(t *testing.T) { + user := &model.User{ + Email: "email/with/slashes@example.com", + Username: GenerateTestUsername(), + Password: "Pa$$word11", + } + + newUser, resp := th.SystemAdminClient.CreateUser(user) + require.Nil(t, resp.Error) + + ruser, resp := th.SystemAdminClient.GetUserByEmail(user.Email, "") + require.Nil(t, resp.Error) + require.Equal(t, ruser.Id, newUser.Id) + }) } func TestGetUserByUsernameWithAcceptedTermsOfService(t *testing.T) {