MM-53098 Fix for checking bot and user permissions on shared endpoints (#23751)
* temp commit * update test to allow bot creation * add bot check to updateUser and deleteUser * add more unit tests * lint fixes * lint fix * update based on doc * add more unit tests * lint fixes * fix unit tests * fix unit tests --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2abcdfe76a
Коммит
30140c0a27
@@ -1932,6 +1932,27 @@ func TestUpdateAdminUser(t *testing.T) {
|
||||
require.Equal(t, user.Email, u2.Email)
|
||||
}
|
||||
|
||||
func TestUpdateBotUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(c *model.Config) {
|
||||
*c.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
bot := th.CreateBotWithSystemAdminClient()
|
||||
botUser, _, err := th.SystemAdminClient.GetUser(context.Background(), bot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
updateUser, _, err := th.SystemAdminClient.UpdateUser(context.Background(), botUser)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, botUser.Id, updateUser.Id)
|
||||
|
||||
_, resp, err := th.Client.UpdateUser(context.Background(), botUser)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestPatchUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
@@ -2043,6 +2064,27 @@ func TestPatchUser(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestPatchBotUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(c *model.Config) {
|
||||
*c.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
bot := th.CreateBotWithSystemAdminClient()
|
||||
patch := &model.UserPatch{}
|
||||
patch.Email = model.NewString("newemail@test.com")
|
||||
|
||||
user, _, err := th.SystemAdminClient.PatchUser(context.Background(), bot.UserId, patch)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bot.UserId, user.Id)
|
||||
|
||||
_, resp, err := th.Client.PatchUser(context.Background(), bot.UserId, patch)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestPatchAdminUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
@@ -2063,6 +2105,7 @@ func TestPatchAdminUser(t *testing.T) {
|
||||
_, _, err = th.SystemAdminClient.PatchUser(context.Background(), user.Id, patch)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestUserUnicodeNames(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
@@ -2229,6 +2272,21 @@ func TestDeleteUser(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestDeleteBotUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(c *model.Config) {
|
||||
*c.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
bot := th.CreateBotWithSystemAdminClient()
|
||||
|
||||
_, err := th.Client.DeleteUser(context.Background(), bot.UserId)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err.Error(), ": You do not have the appropriate permissions.")
|
||||
}
|
||||
|
||||
func TestPermanentDeleteUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user