MM-14722 - Don't let bots create other bot accounts (#10808)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
1a4ea94805
Коммит
ae951f6449
@@ -725,6 +725,12 @@ func (api *PluginAPI) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
|
||||
if bot.OwnerId == "" {
|
||||
bot.OwnerId = api.id
|
||||
}
|
||||
// Bots cannot be owners of other bots
|
||||
if user, err := api.app.GetUser(bot.OwnerId); err == nil {
|
||||
if user.IsBot {
|
||||
return nil, model.NewAppError("CreateBot", "plugin_api.bot_cant_create_bot", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
return api.app.CreateBot(bot)
|
||||
}
|
||||
|
||||
@@ -755,3 +755,25 @@ func TestPluginAPIKVCompareAndSet(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginCreateBot(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
bot, err := api.CreateBot(&model.Bot{
|
||||
Username: model.NewRandomString(10),
|
||||
DisplayName: "bot",
|
||||
Description: "bot",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = api.CreateBot(&model.Bot{
|
||||
Username: model.NewRandomString(10),
|
||||
OwnerId: bot.UserId,
|
||||
DisplayName: "bot2",
|
||||
Description: "bot2",
|
||||
})
|
||||
require.NotNil(t, err)
|
||||
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user