MM-14722 - Don't let bots create other bot accounts (#10808)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
1a4ea94805
Коммит
ae951f6449
@@ -91,6 +91,42 @@ func TestCreateBot(t *testing.T) {
|
||||
|
||||
CheckErrorMessage(t, resp, "model.bot.is_valid.description.app_error")
|
||||
})
|
||||
|
||||
t.Run("bot attempt to create bot fails", func(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.CreateBotAccounts = true
|
||||
})
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
th.AddPermissionToRole(model.PERMISSION_CREATE_BOT.Id, model.TEAM_USER_ROLE_ID)
|
||||
th.AddPermissionToRole(model.PERMISSION_EDIT_OTHER_USERS.Id, model.TEAM_USER_ROLE_ID)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID+" "+model.SYSTEM_USER_ACCESS_TOKEN_ROLE_ID, false)
|
||||
|
||||
bot, resp := th.Client.CreateBot(&model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
})
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
th.App.UpdateUserRoles(bot.UserId, model.TEAM_USER_ROLE_ID+" "+model.SYSTEM_USER_ACCESS_TOKEN_ROLE_ID, false)
|
||||
|
||||
rtoken, resp := th.Client.CreateUserAccessToken(bot.UserId, "test token")
|
||||
CheckNoError(t, resp)
|
||||
th.Client.AuthToken = rtoken.Token
|
||||
|
||||
_, resp = th.Client.CreateBot(&model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
OwnerId: bot.UserId,
|
||||
DisplayName: "a bot2",
|
||||
Description: "bot2",
|
||||
})
|
||||
CheckErrorMessage(t, resp, "api.context.permissions.app_error")
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestPatchBot(t *testing.T) {
|
||||
@@ -1021,6 +1057,37 @@ func TestAssignBot(t *testing.T) {
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, th.BasicUser2.Id, after.OwnerId)
|
||||
})
|
||||
|
||||
t.Run("bot assigned to bot fails", func(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.AddPermissionToRole(model.PERMISSION_CREATE_BOT.Id, model.SYSTEM_USER_ROLE_ID)
|
||||
th.AddPermissionToRole(model.PERMISSION_READ_BOTS.Id, model.SYSTEM_USER_ROLE_ID)
|
||||
th.AddPermissionToRole(model.PERMISSION_READ_OTHERS_BOTS.Id, model.SYSTEM_USER_ROLE_ID)
|
||||
th.AddPermissionToRole(model.PERMISSION_MANAGE_BOTS.Id, model.SYSTEM_USER_ROLE_ID)
|
||||
th.AddPermissionToRole(model.PERMISSION_MANAGE_OTHERS_BOTS.Id, model.SYSTEM_USER_ROLE_ID)
|
||||
|
||||
bot := &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "bot",
|
||||
}
|
||||
bot, resp := th.Client.CreateBot(bot)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
|
||||
bot2, resp := th.Client.CreateBot(&model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
})
|
||||
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot2.UserId)
|
||||
|
||||
_, resp = th.Client.AssignBot(bot.UserId, bot2.UserId)
|
||||
CheckErrorMessage(t, resp, "api.context.permissions.app_error")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func sToP(s string) *string {
|
||||
|
||||
Ссылка в новой задаче
Block a user