Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
435 lines
15 KiB
Go
435 lines
15 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/client"
|
|
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func (s *MmctlE2ETestSuite) TestListBotCmdF() {
|
|
s.SetupTestHelper().InitBasic(s.T()).DeleteBots(s.T())
|
|
|
|
s.RunForSystemAdminAndLocal("List Bot", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
bot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: s.th.BasicUser.Id})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, bot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
deletedBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: s.th.BasicUser.Id})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, deletedBot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
deletedBot, appErr = s.th.App.UpdateBotActive(s.th.Context, deletedBot.UserId, false)
|
|
s.Require().Nil(appErr)
|
|
|
|
err := botListCmdF(c, &cobra.Command{}, []string{})
|
|
s.Require().Nil(err)
|
|
s.Require().Equal(1, len(printer.GetLines()))
|
|
|
|
listedBot, ok := printer.GetLines()[0].(*model.Bot)
|
|
s.Require().True(ok)
|
|
s.Require().Equal(bot.Username, listedBot.Username)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("List Bot only orphaned", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
user, appErr := s.th.App.CreateUser(s.th.Context, &model.User{Email: s.th.GenerateTestEmail(), Username: model.NewUsername(), Password: model.NewId(), DeleteAt: 1})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteUser(s.th.Context, user)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
bot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: s.th.BasicUser.Id})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, bot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
deletedBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: user.Id})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, deletedBot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
deletedBot, appErr = s.th.App.UpdateBotActive(s.th.Context, deletedBot.UserId, false)
|
|
s.Require().Nil(appErr)
|
|
|
|
orphanBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: user.Id})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, orphanBot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("orphaned", true, "")
|
|
|
|
err := botListCmdF(c, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
s.Require().Equal(1, len(printer.GetLines()))
|
|
|
|
listedBot, ok := printer.GetLines()[0].(*model.Bot)
|
|
s.Require().True(ok)
|
|
s.Require().Equal(orphanBot.Username, listedBot.Username)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("List all Bots", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
user, appErr := s.th.App.CreateUser(s.th.Context, &model.User{Email: s.th.GenerateTestEmail(), Username: model.NewUsername(), Password: model.NewId(), DeleteAt: 1})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteUser(s.th.Context, user)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
bot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: s.th.BasicUser2.Id})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, bot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
orphanBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: user.Id})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, orphanBot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
deletedBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: s.th.BasicUser2.Id})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, deletedBot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
deletedBot, appErr = s.th.App.UpdateBotActive(s.th.Context, deletedBot.UserId, false)
|
|
s.Require().Nil(appErr)
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("all", true, "")
|
|
|
|
err := botListCmdF(c, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
s.Require().Equal(3, len(printer.GetLines()))
|
|
resultBot, ok := printer.GetLines()[0].(*model.Bot)
|
|
s.True(ok)
|
|
s.Require().Equal(bot, resultBot)
|
|
resultOrphanBot, ok := printer.GetLines()[1].(*model.Bot)
|
|
s.True(ok)
|
|
s.Require().Equal(orphanBot, resultOrphanBot)
|
|
resultDeletedBot, ok := printer.GetLines()[2].(*model.Bot)
|
|
s.True(ok)
|
|
s.Require().Equal(deletedBot, resultDeletedBot)
|
|
})
|
|
|
|
s.Run("List Bots without permission", func() {
|
|
printer.Clean()
|
|
|
|
cmd := &cobra.Command{}
|
|
|
|
err := botListCmdF(s.th.Client, cmd, []string{})
|
|
s.Require().Error(err)
|
|
s.Require().Equal("Failed to fetch bots: You do not have the appropriate permissions.", err.Error())
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestBotEnableCmd() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
s.th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true })
|
|
|
|
user, appErr := s.th.App.CreateUser(s.th.Context, &model.User{Email: s.th.GenerateTestEmail(), Username: model.NewUsername(), Password: model.NewId()})
|
|
s.Require().Nil(appErr)
|
|
|
|
s.RunForSystemAdminAndLocal("enable a bot", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
newBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: user.Id})
|
|
s.Require().Nil(appErr)
|
|
|
|
_, appErr = s.th.App.UpdateBotActive(s.th.Context, newBot.UserId, false)
|
|
s.Require().Nil(appErr)
|
|
|
|
err := botEnableCmdF(c, &cobra.Command{}, []string{newBot.UserId})
|
|
s.Require().Nil(err)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
|
|
printedBot := printer.GetLines()[0].(*model.Bot)
|
|
s.Require().Equal(newBot.UserId, printedBot.UserId)
|
|
s.Require().Equal(newBot.Username, printedBot.Username)
|
|
s.Require().Equal(newBot.OwnerId, printedBot.OwnerId)
|
|
|
|
bot, appErr := s.th.App.GetBot(s.th.Context, newBot.UserId, false)
|
|
s.Require().Nil(appErr)
|
|
s.Require().Equal(newBot.UserId, bot.UserId)
|
|
s.Require().Equal(newBot.Username, bot.Username)
|
|
s.Require().Equal(newBot.OwnerId, bot.OwnerId)
|
|
})
|
|
|
|
s.Run("enable a bot without permissions", func() {
|
|
printer.Clean()
|
|
|
|
newBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: user.Id})
|
|
s.Require().Nil(appErr)
|
|
|
|
_, appErr = s.th.App.UpdateBotActive(s.th.Context, newBot.UserId, false)
|
|
s.Require().Nil(appErr)
|
|
|
|
err := botEnableCmdF(s.th.Client, &cobra.Command{}, []string{newBot.UserId})
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 1)
|
|
|
|
s.Require().Contains(printer.GetErrorLines()[0], "could not enable bot")
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("enable a nonexistent bot", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
err := botEnableCmdF(c, &cobra.Command{}, []string{"nonexistent-bot-userid"})
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 1)
|
|
|
|
s.Require().Contains(printer.GetErrorLines()[0], "can't find user 'nonexistent-bot-userid'")
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("enable an already enabled bot", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
newBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: user.Id})
|
|
s.Require().Nil(appErr)
|
|
|
|
_, appErr = s.th.App.UpdateBotActive(s.th.Context, newBot.UserId, true)
|
|
s.Require().Nil(appErr)
|
|
|
|
err := botEnableCmdF(c, &cobra.Command{}, []string{newBot.UserId})
|
|
s.Require().Nil(err)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
|
|
printedBot := printer.GetLines()[0].(*model.Bot)
|
|
s.Require().Equal(newBot.UserId, printedBot.UserId)
|
|
s.Require().Equal(newBot.Username, printedBot.Username)
|
|
s.Require().Equal(newBot.OwnerId, printedBot.OwnerId)
|
|
|
|
bot, appErr := s.th.App.GetBot(s.th.Context, newBot.UserId, false)
|
|
s.Require().Nil(appErr)
|
|
s.Require().Equal(newBot.UserId, bot.UserId)
|
|
s.Require().Equal(newBot.Username, bot.Username)
|
|
s.Require().Equal(newBot.OwnerId, bot.OwnerId)
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestBotDisableCmd() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
s.th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true })
|
|
|
|
user, appErr := s.th.App.CreateUser(s.th.Context, &model.User{Email: s.th.GenerateTestEmail(), Username: model.NewUsername(), Password: model.NewId()})
|
|
s.Require().Nil(appErr)
|
|
|
|
s.RunForSystemAdminAndLocal("disable a bot", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
newBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: user.Id})
|
|
s.Require().Nil(appErr)
|
|
|
|
_, appErr = s.th.App.UpdateBotActive(s.th.Context, newBot.UserId, true)
|
|
s.Require().Nil(appErr)
|
|
|
|
err := botDisableCmdF(c, &cobra.Command{}, []string{newBot.UserId})
|
|
s.Require().Nil(err)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
|
|
printedBot := printer.GetLines()[0].(*model.Bot)
|
|
s.Require().Equal(newBot.UserId, printedBot.UserId)
|
|
s.Require().Equal(newBot.Username, printedBot.Username)
|
|
s.Require().Equal(newBot.OwnerId, printedBot.OwnerId)
|
|
|
|
_, appErr = s.th.App.GetBot(s.th.Context, newBot.UserId, false)
|
|
s.Require().NotNil(appErr)
|
|
s.Require().Equal("store.sql_bot.get.missing.app_error", appErr.Id)
|
|
})
|
|
|
|
s.Run("disable a bot without permissions", func() {
|
|
printer.Clean()
|
|
|
|
newBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: user.Id})
|
|
s.Require().Nil(appErr)
|
|
|
|
_, appErr = s.th.App.UpdateBotActive(s.th.Context, newBot.UserId, true)
|
|
s.Require().Nil(appErr)
|
|
|
|
err := botDisableCmdF(s.th.Client, &cobra.Command{}, []string{newBot.UserId})
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 1)
|
|
|
|
s.Require().Contains(printer.GetErrorLines()[0], "could not disable bot")
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("disable a nonexistent bot", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
err := botDisableCmdF(c, &cobra.Command{}, []string{"nonexistent-bot-userid"})
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 1)
|
|
|
|
s.Require().Contains(printer.GetErrorLines()[0], "can't find user 'nonexistent-bot-userid'")
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("disable an already disabled bot", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
newBot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: user.Id})
|
|
s.Require().Nil(appErr)
|
|
|
|
_, appErr = s.th.App.UpdateBotActive(s.th.Context, newBot.UserId, false)
|
|
s.Require().Nil(appErr)
|
|
|
|
err := botDisableCmdF(c, &cobra.Command{}, []string{newBot.UserId})
|
|
s.Require().Nil(err)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
|
|
printedBot := printer.GetLines()[0].(*model.Bot)
|
|
s.Require().Equal(newBot.UserId, printedBot.UserId)
|
|
s.Require().Equal(newBot.Username, printedBot.Username)
|
|
s.Require().Equal(newBot.OwnerId, printedBot.OwnerId)
|
|
|
|
_, appErr = s.th.App.GetBot(s.th.Context, newBot.UserId, false)
|
|
s.Require().NotNil(appErr)
|
|
s.Require().Equal("store.sql_bot.get.missing.app_error", appErr.Id)
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestBotAssignCmdF() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
s.RunForSystemAdminAndLocal("Assign Bot", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
botOwner, appErr := s.th.App.CreateUser(s.th.Context, &model.User{Email: s.th.GenerateTestEmail(), Username: model.NewUsername(), Password: model.NewId()})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteUser(s.th.Context, botOwner)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
newBotOwner, appErr := s.th.App.CreateUser(s.th.Context, &model.User{Email: s.th.GenerateTestEmail(), Username: model.NewUsername(), Password: model.NewId()})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteUser(s.th.Context, newBotOwner)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
bot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: botOwner.Id})
|
|
s.Require().Nil(appErr)
|
|
s.Require().Equal(bot.OwnerId, botOwner.Id)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, bot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
err := botAssignCmdF(c, &cobra.Command{}, []string{bot.UserId, newBotOwner.Id})
|
|
s.Require().Nil(err)
|
|
s.Require().Equal(1, len(printer.GetLines()))
|
|
newBot, ok := printer.GetLines()[0].(*model.Bot)
|
|
s.True(ok)
|
|
s.Require().Equal(newBotOwner.Id, newBot.OwnerId)
|
|
})
|
|
|
|
s.Run("Assign Bot without permission", func() {
|
|
printer.Clean()
|
|
|
|
botOwner, appErr := s.th.App.CreateUser(s.th.Context, &model.User{Email: s.th.GenerateTestEmail(), Username: model.NewUsername(), Password: model.NewId()})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteUser(s.th.Context, botOwner)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
newBotOwner, appErr := s.th.App.CreateUser(s.th.Context, &model.User{Email: s.th.GenerateTestEmail(), Username: model.NewUsername(), Password: model.NewId()})
|
|
s.Require().Nil(appErr)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteUser(s.th.Context, newBotOwner)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
bot, appErr := s.th.App.CreateBot(s.th.Context, &model.Bot{Username: model.NewUsername(), OwnerId: botOwner.Id})
|
|
s.Require().Nil(appErr)
|
|
s.Require().Equal(bot.OwnerId, botOwner.Id)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, bot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
|
|
err := botAssignCmdF(s.th.Client, &cobra.Command{}, []string{bot.UserId, newBotOwner.Id})
|
|
s.Require().NotNil(err)
|
|
s.Require().EqualError(err, fmt.Sprintf(`can not assign bot '%s' to user '%s'`, bot.UserId, newBotOwner.Id), err.Error())
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestBotCreateCmdF() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
createBots := *s.th.App.Config().ServiceSettings.EnableBotAccountCreation
|
|
s.th.App.UpdateConfig(func(c *model.Config) { *c.ServiceSettings.EnableBotAccountCreation = true })
|
|
defer s.th.App.UpdateConfig(func(c *model.Config) { *c.ServiceSettings.EnableBotAccountCreation = createBots })
|
|
|
|
s.Run("MM-T3941 Create Bot with an access token", func() {
|
|
printer.Clean()
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("with-token", true, "")
|
|
|
|
err := botCreateCmdF(s.th.Client, cmd, []string{"testbot"})
|
|
s.Require().Error(err)
|
|
s.Require().Empty(printer.GetLines())
|
|
s.Require().Empty(printer.GetErrorLines())
|
|
|
|
printer.Clean()
|
|
|
|
err = botCreateCmdF(s.th.SystemAdminClient, cmd, []string{"testbot"})
|
|
s.Require().NoError(err)
|
|
s.Require().Equal(2, len(printer.GetLines()))
|
|
bot, ok := printer.GetLines()[0].(*model.Bot)
|
|
s.Require().True(ok)
|
|
defer func() {
|
|
err := s.th.App.PermanentDeleteBot(s.th.Context, bot.UserId)
|
|
s.Require().Nil(err)
|
|
}()
|
|
token, ok := printer.GetLines()[1].(*model.UserAccessToken)
|
|
s.Require().True(ok)
|
|
defer func() {
|
|
err := s.th.App.RevokeUserAccessToken(s.th.Context, token)
|
|
s.Require().Nil(err)
|
|
}()
|
|
s.Require().Empty(printer.GetErrorLines())
|
|
})
|
|
}
|