MM-14723: Add config flag for creating bots (#10795)

* MM-14723 add config flag for creating bots

* MM-14723 - update i18n to handle new config flag

* MM-14723 - change API tests to allow bots by default

* Update i18n/en.json

Co-Authored-By: andresoro <ao15@my.fsu.edu>

* MM-14723: add config flag for enabling/disabling bot creation

* undo changes to apitestlib.go to explicitly change config in each test

* add unit tests for config changes

* MM-14723 update test cases

* MM-14723 update test cases to use UpdateConfig method
Этот коммит содержится в:
Andres Orozco
2019-05-13 10:48:32 -04:00
коммит произвёл Christopher Speller
родитель b3aa3d4567
Коммит 30061df036
5 изменённых файлов: 151 добавлений и 1 удалений

Просмотреть файл

@@ -527,6 +527,10 @@ func TestGetBotUser(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_BOT.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.SYSTEM_USER_ROLE_ID+" "+model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
bot := &model.Bot{
Username: GenerateTestUsername(),
DisplayName: "a bot",
@@ -2640,6 +2644,10 @@ func TestLogin(t *testing.T) {
defer th.TearDown()
th.Client.Logout()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
t.Run("missing password", func(t *testing.T) {
_, resp := th.Client.Login(th.BasicUser.Email, "")
CheckErrorMessage(t, resp, "api.user.login.blank_pwd.app_error")
@@ -2730,6 +2738,10 @@ func TestCBALogin(t *testing.T) {
defer th.TearDown()
th.App.SetLicense(model.NewTestLicense("saml"))
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ExperimentalSettings.ClientSideCertEnable = true
*cfg.ExperimentalSettings.ClientSideCertCheck = model.CLIENT_SIDE_CERT_CHECK_PRIMARY_AUTH
@@ -2784,6 +2796,10 @@ func TestCBALogin(t *testing.T) {
defer th.TearDown()
th.App.SetLicense(model.NewTestLicense("saml"))
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
th.Client.HttpHeader["X-SSL-Client-Cert"] = "valid_cert_fake"
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -3088,6 +3104,9 @@ func TestCreateUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_BOT.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.Client.CreateBot(&model.Bot{
Username: GenerateTestUsername(),
@@ -3125,6 +3144,9 @@ func TestCreateUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_MANAGE_BOTS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.SystemAdminClient.CreateBot(&model.Bot{
Username: GenerateTestUsername(),
@@ -3223,6 +3245,9 @@ func TestGetUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_READ_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.Client.CreateBot(&model.Bot{
Username: GenerateTestUsername(),
@@ -3266,6 +3291,9 @@ func TestGetUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_READ_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.SystemAdminClient.CreateBot(&model.Bot{
Username: GenerateTestUsername(),
@@ -3510,6 +3538,9 @@ func TestRevokeUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.Client.CreateBot(&model.Bot{
Username: GenerateTestUsername(),
@@ -3550,6 +3581,9 @@ func TestRevokeUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.SystemAdminClient.CreateBot(&model.Bot{
Username: GenerateTestUsername(),
@@ -3622,6 +3656,9 @@ func TestDisableUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.Client.CreateBot(&model.Bot{
Username: GenerateTestUsername(),
@@ -3662,6 +3699,9 @@ func TestDisableUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.SystemAdminClient.CreateBot(&model.Bot{
Username: GenerateTestUsername(),
@@ -3744,6 +3784,9 @@ func TestEnableUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.Client.CreateBot(&model.Bot{
Username: GenerateTestUsername(),
@@ -3788,6 +3831,9 @@ func TestEnableUserAccessToken(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_CREATE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN.Id, model.TEAM_USER_ROLE_ID)
th.App.UpdateUserRoles(th.BasicUser.Id, model.TEAM_USER_ROLE_ID, false)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.CreateBotAccounts = true
})
createdBot, resp := th.SystemAdminClient.CreateBot(&model.Bot{
Username: GenerateTestUsername(),