Adds RemoteId to the fields to clean when coming from the API (#27047)

* Cleans the RemoteId when creating a user through the API

* Replace bad usage of the API with an App call in tests

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Miguel de la Cruz
2024-05-22 11:20:02 +02:00
коммит произвёл GitHub
родитель 441f5657c8
Коммит a4afae5b3b
2 изменённых файлов: 30 добавлений и 1 удалений

Просмотреть файл

@@ -115,6 +115,33 @@ func TestCreateUser(t *testing.T) {
_, 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")
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
email := th.GenerateTestEmail()
newUser := &model.User{
Id: model.NewId(),
RemoteId: model.NewString(model.NewId()),
Email: email,
Password: "Password1",
Username: GenerateTestUsername(),
EmailVerified: true,
}
_, resp, err = client.CreateUser(context.Background(), newUser)
require.Error(t, err)
require.ErrorContains(t, err, "Must call update for existing user")
CheckBadRequestStatus(t, resp)
_, appErr := th.App.GetUserByEmail(email)
require.NotNil(t, appErr)
newUser.Id = ""
_, resp, err = client.CreateUser(context.Background(), newUser)
require.NoError(t, err)
CheckCreatedStatus(t, resp)
createdUser, appErr := th.App.GetUserByEmail(email)
require.Nil(t, appErr)
require.Zero(t, *createdUser.RemoteId)
}, "Should not be able to define the RemoteID of a user through the API")
}
func TestCreateUserAudit(t *testing.T) {
@@ -3845,7 +3872,8 @@ func TestLogin(t *testing.T) {
t.Run("remote user login rejected", func(t *testing.T) {
email := th.GenerateTestEmail()
user := model.User{Email: email, Nickname: "Darth Vader", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId, RemoteId: model.NewString("remote-id")}
ruser, _, _ := th.Client.CreateUser(context.Background(), &user)
ruser, appErr := th.App.CreateUser(th.Context, &user)
require.Nil(t, appErr)
_, err := th.SystemAdminClient.UpdateUserPassword(context.Background(), ruser.Id, "", "password")
require.NoError(t, err)

Просмотреть файл

@@ -657,6 +657,7 @@ func (u *User) SanitizeInput(isAdmin bool) {
u.AuthService = ""
u.EmailVerified = false
}
u.RemoteId = NewString("")
u.DeleteAt = 0
u.LastPasswordUpdate = 0
u.LastPictureUpdate = 0