коммит произвёл
GitHub
родитель
6fd49f56b5
Коммит
aba9339a24
@@ -65,18 +65,19 @@ func (a *App) EnsureBot(rctx request.CTX, pluginID string, bot *model.Bot) (stri
|
|||||||
if appErr := a.SetPluginKey(pluginID, botUserKey, []byte(user.Id)); appErr != nil {
|
if appErr := a.SetPluginKey(pluginID, botUserKey, []byte(user.Id)); appErr != nil {
|
||||||
return "", fmt.Errorf("failed to set plugin key: %w", appErr)
|
return "", fmt.Errorf("failed to set plugin key: %w", appErr)
|
||||||
}
|
}
|
||||||
} else {
|
return user.Id, nil
|
||||||
rctx.Logger().Error("Plugin attempted to use an account that already exists. Convert user to a bot "+
|
|
||||||
"account in the CLI by running 'mattermost user convert <username> --bot'. If the user is an "+
|
|
||||||
"existing user account you want to preserve, change its username and restart the Mattermost server, "+
|
|
||||||
"after which the plugin will create a bot account with that name. For more information about bot "+
|
|
||||||
"accounts, see https://mattermost.com/pl/default-bot-accounts", mlog.String("username",
|
|
||||||
bot.Username),
|
|
||||||
mlog.String("user_id",
|
|
||||||
user.Id),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return user.Id, nil
|
|
||||||
|
rctx.Logger().Error("Plugin attempted to use an account that already exists. Convert user to a bot "+
|
||||||
|
"account in the CLI by running 'mattermost user convert <username> --bot'. If the user is an "+
|
||||||
|
"existing user account you want to preserve, change its username and restart the Mattermost server, "+
|
||||||
|
"after which the plugin will create a bot account with that name. For more information about bot "+
|
||||||
|
"accounts, see https://mattermost.com/pl/default-bot-accounts", mlog.String("username",
|
||||||
|
bot.Username),
|
||||||
|
mlog.String("user_id",
|
||||||
|
user.Id),
|
||||||
|
)
|
||||||
|
return "", fmt.Errorf("username %q is already taken by a non-bot user", bot.Username)
|
||||||
}
|
}
|
||||||
|
|
||||||
createdBot, err := a.CreateBot(rctx, bot)
|
createdBot, err := a.CreateBot(rctx, bot)
|
||||||
|
|||||||
@@ -152,6 +152,23 @@ func TestEnsureBot(t *testing.T) {
|
|||||||
assert.Equal(t, "another bot", bot.Description)
|
assert.Equal(t, "another bot", bot.Description)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("ensure bot should fail if username belongs to a non-bot user", func(t *testing.T) {
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
pluginId := "pluginId"
|
||||||
|
|
||||||
|
// th.BasicUser is a regular (non-bot) user created by InitBasic.
|
||||||
|
// EnsureBot must return an error — not the human user's ID.
|
||||||
|
botID, err := th.App.EnsureBot(th.Context, pluginId, &model.Bot{
|
||||||
|
Username: th.BasicUser.Username,
|
||||||
|
Description: "a bot",
|
||||||
|
OwnerId: th.BasicUser.Id,
|
||||||
|
})
|
||||||
|
require.Error(t, err)
|
||||||
|
assert.Empty(t, botID)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("ensure bot should pass even after delete bot user", func(t *testing.T) {
|
t.Run("ensure bot should pass even after delete bot user", func(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user