summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/admin.go6
-rw-r--r--api/admin_test.go62
-rw-r--r--api/api.go2
-rw-r--r--api/apitestlib.go17
-rw-r--r--api/channel_test.go228
-rw-r--r--api/command_help_test.go11
-rw-r--r--api/command_loadtest_test.go31
-rw-r--r--api/command_test.go51
-rw-r--r--api/context.go8
-rw-r--r--api/emoji.go14
-rw-r--r--api/emoji_test.go42
-rw-r--r--api/file.go20
-rw-r--r--api/file_test.go74
-rw-r--r--api/general.go2
-rw-r--r--api/general_test.go11
-rw-r--r--api/license.go2
-rw-r--r--api/oauth.go2
-rw-r--r--api/oauth_test.go106
-rw-r--r--api/post.go2
-rw-r--r--api/post_test.go70
-rw-r--r--api/status_test.go7
-rw-r--r--api/team.go4
-rw-r--r--api/team_test.go18
-rw-r--r--api/user.go40
-rw-r--r--api/user_test.go184
-rw-r--r--api/webhook_test.go166
-rw-r--r--api/websocket_test.go11
27 files changed, 641 insertions, 550 deletions
diff --git a/api/admin.go b/api/admin.go
index 5b532c81a..ff5971734 100644
--- a/api/admin.go
+++ b/api/admin.go
@@ -235,12 +235,12 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
}
func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
- if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
+ if r.ContentLength > *c.App.Config().FileSettings.MaxFileSize {
c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
return
}
- if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil {
+ if err := r.ParseMultipartForm(*c.App.Config().FileSettings.MaxFileSize); err != nil {
c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.parse.app_error", nil, "", http.StatusBadRequest)
return
}
@@ -358,7 +358,7 @@ func samlMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
}
func addCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
- err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize)
+ err := r.ParseMultipartForm(*c.App.Config().FileSettings.MaxFileSize)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
diff --git a/api/admin_test.go b/api/admin_test.go
index e4ff1c202..5c11d5a5c 100644
--- a/api/admin_test.go
+++ b/api/admin_test.go
@@ -118,8 +118,8 @@ func TestReloadConfig(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
- *utils.Cfg.TeamSettings.EnableOpenServer = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = true })
}
func TestInvalidateAllCache(t *testing.T) {
@@ -143,13 +143,13 @@ func TestSaveConfig(t *testing.T) {
t.Fatal("Shouldn't have permissions")
}
- *utils.Cfg.TeamSettings.EnableOpenServer = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = false })
if _, err := th.SystemAdminClient.SaveConfig(utils.Cfg); err != nil {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.EnableOpenServer = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = true })
}
func TestRecycleDatabaseConnection(t *testing.T) {
@@ -169,27 +169,27 @@ func TestEmailTest(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
- SendEmailNotifications := utils.Cfg.EmailSettings.SendEmailNotifications
- SMTPServer := utils.Cfg.EmailSettings.SMTPServer
- SMTPPort := utils.Cfg.EmailSettings.SMTPPort
- FeedbackEmail := utils.Cfg.EmailSettings.FeedbackEmail
+ SendEmailNotifications := th.App.Config().EmailSettings.SendEmailNotifications
+ SMTPServer := th.App.Config().EmailSettings.SMTPServer
+ SMTPPort := th.App.Config().EmailSettings.SMTPPort
+ FeedbackEmail := th.App.Config().EmailSettings.FeedbackEmail
defer func() {
- utils.Cfg.EmailSettings.SendEmailNotifications = SendEmailNotifications
- utils.Cfg.EmailSettings.SMTPServer = SMTPServer
- utils.Cfg.EmailSettings.SMTPPort = SMTPPort
- utils.Cfg.EmailSettings.FeedbackEmail = FeedbackEmail
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.SendEmailNotifications = SendEmailNotifications })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.SMTPServer = SMTPServer })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.SMTPPort = SMTPPort })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.FeedbackEmail = FeedbackEmail })
}()
- utils.Cfg.EmailSettings.SendEmailNotifications = false
- utils.Cfg.EmailSettings.SMTPServer = ""
- utils.Cfg.EmailSettings.SMTPPort = ""
- utils.Cfg.EmailSettings.FeedbackEmail = ""
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.SendEmailNotifications = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.SMTPServer = "" })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.SMTPPort = "" })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.FeedbackEmail = "" })
- if _, err := th.BasicClient.TestEmail(utils.Cfg); err == nil {
+ if _, err := th.BasicClient.TestEmail(th.App.Config()); err == nil {
t.Fatal("Shouldn't have permissions")
}
- if _, err := th.SystemAdminClient.TestEmail(utils.Cfg); err == nil {
+ if _, err := th.SystemAdminClient.TestEmail(th.App.Config()); err == nil {
t.Fatal("should have errored")
} else {
if err.Id != "api.admin.test_email.missing_server" {
@@ -202,11 +202,11 @@ func TestLdapTest(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
- if _, err := th.BasicClient.TestLdap(utils.Cfg); err == nil {
+ if _, err := th.BasicClient.TestLdap(th.App.Config()); err == nil {
t.Fatal("Shouldn't have permissions")
}
- if _, err := th.SystemAdminClient.TestLdap(utils.Cfg); err == nil {
+ if _, err := th.SystemAdminClient.TestLdap(th.App.Config()); err == nil {
t.Fatal("should have errored")
}
}
@@ -221,11 +221,11 @@ func TestGetTeamAnalyticsStandard(t *testing.T) {
t.Fatal("Shouldn't have permissions")
}
- maxUsersForStats := *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics
+ maxUsersForStats := *th.App.Config().AnalyticsSettings.MaxUsersForStatistics
defer func() {
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = maxUsersForStats
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.AnalyticsSettings.MaxUsersForStatistics = maxUsersForStats })
}()
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = 1000000
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.AnalyticsSettings.MaxUsersForStatistics = 1000000 })
if result, err := th.SystemAdminClient.GetTeamAnalytics(th.BasicTeam.Id, "standard"); err != nil {
t.Fatal(err)
@@ -339,7 +339,7 @@ func TestGetTeamAnalyticsStandard(t *testing.T) {
}
}
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = 1
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.AnalyticsSettings.MaxUsersForStatistics = 1 })
if result, err := th.SystemAdminClient.GetSystemAnalytics("standard"); err != nil {
t.Fatal(err)
@@ -452,11 +452,11 @@ func TestGetTeamAnalyticsExtra(t *testing.T) {
t.Fatal("Shouldn't have permissions")
}
- maxUsersForStats := *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics
+ maxUsersForStats := *th.App.Config().AnalyticsSettings.MaxUsersForStatistics
defer func() {
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = maxUsersForStats
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.AnalyticsSettings.MaxUsersForStatistics = maxUsersForStats })
}()
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = 1000000
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.AnalyticsSettings.MaxUsersForStatistics = 1000000 })
if result, err := th.SystemAdminClient.GetTeamAnalytics(th.BasicTeam.Id, "extra_counts"); err != nil {
t.Fatal(err)
@@ -560,7 +560,7 @@ func TestGetTeamAnalyticsExtra(t *testing.T) {
}
}
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = 1
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.AnalyticsSettings.MaxUsersForStatistics = 1 })
if result, err := th.SystemAdminClient.GetSystemAnalytics("extra_counts"); err != nil {
t.Fatal(err)
@@ -678,11 +678,11 @@ func TestDisableAPIv3(t *testing.T) {
Client := th.BasicClient
- enableAPIv3 := *utils.Cfg.ServiceSettings.EnableAPIv3
+ enableAPIv3 := *th.App.Config().ServiceSettings.EnableAPIv3
defer func() {
- *utils.Cfg.ServiceSettings.EnableAPIv3 = enableAPIv3
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableAPIv3 = enableAPIv3 })
}()
- *utils.Cfg.ServiceSettings.EnableAPIv3 = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableAPIv3 = false })
_, err := Client.GetUser(th.BasicUser.Id, "")
diff --git a/api/api.go b/api/api.go
index 59fc87c71..4f593cfa5 100644
--- a/api/api.go
+++ b/api/api.go
@@ -117,7 +117,7 @@ func Init(a *app.App, root *mux.Router) *API {
a.InitEmailBatching()
- if *utils.Cfg.ServiceSettings.EnableAPIv3 {
+ if *a.Config().ServiceSettings.EnableAPIv3 {
l4g.Info("API version 3 is scheduled for deprecation. Please see https://api.mattermost.com for details.")
}
diff --git a/api/apitestlib.go b/api/apitestlib.go
index 4c4773318..5fc94cfec 100644
--- a/api/apitestlib.go
+++ b/api/apitestlib.go
@@ -71,28 +71,29 @@ func setupTestHelper(enterprise bool) *TestHelper {
var options []app.Option
if testStore != nil {
options = append(options, app.StoreOverride(testStore))
- options = append(options, app.ConfigOverride(func(cfg *model.Config) {
- cfg.ServiceSettings.ListenAddress = new(string)
- *cfg.ServiceSettings.ListenAddress = ":0"
- }))
}
th := &TestHelper{
App: app.New(options...),
}
- *utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
- *utils.Cfg.RateLimitSettings.Enable = false
- utils.Cfg.EmailSettings.SendEmailNotifications = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.SendEmailNotifications = true })
utils.DisableDebugLogForTest()
+ prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
+ if testStore != nil {
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
+ }
th.App.StartServer()
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = prevListenAddress })
api4.Init(th.App, th.App.Srv.Router, false)
Init(th.App, th.App.Srv.Router)
wsapi.Init(th.App, th.App.Srv.WebSocketRouter)
utils.EnableDebugLogForTest()
th.App.Srv.Store.MarkSystemRanUnitTests()
- *utils.Cfg.TeamSettings.EnableOpenServer = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = true })
utils.SetIsLicensed(enterprise)
if enterprise {
diff --git a/api/channel_test.go b/api/channel_test.go
index 64a09f78d..ade7993b5 100644
--- a/api/channel_test.go
+++ b/api/channel_test.go
@@ -99,17 +99,17 @@ func TestCreateChannel(t *testing.T) {
isLicensed := utils.IsLicensed()
license := utils.License()
- restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
- restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
+ restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
+ restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
defer func() {
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
utils.SetDefaultRolesBasedOnConfig()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
@@ -124,8 +124,12 @@ func TestCreateChannel(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_TEAM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_TEAM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_TEAM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic2()
@@ -150,8 +154,12 @@ func TestCreateChannel(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
channel2.Name = "zz" + model.NewId() + "a"
@@ -186,8 +194,8 @@ func TestCreateChannel(t *testing.T) {
t.Fatal("should have succeeded")
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL
- *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL })
utils.SetDefaultRolesBasedOnConfig()
}
@@ -361,17 +369,17 @@ func TestUpdateChannel(t *testing.T) {
isLicensed := utils.IsLicensed()
license := utils.License()
- restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
- restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
+ restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
+ restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
defer func() {
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -394,8 +402,12 @@ func TestUpdateChannel(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
+ })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -433,8 +445,12 @@ func TestUpdateChannel(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
+ })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -459,8 +475,12 @@ func TestUpdateChannel(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
+ })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -600,17 +620,17 @@ func TestUpdateChannelHeader(t *testing.T) {
isLicensed := utils.IsLicensed()
license := utils.License()
- restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
- restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
+ restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
+ restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
defer func() {
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -637,8 +657,12 @@ func TestUpdateChannelHeader(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
th.MakeUserChannelUser(th.BasicUser, channel2)
th.MakeUserChannelUser(th.BasicUser, channel3)
@@ -662,8 +686,12 @@ func TestUpdateChannelHeader(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannelHeader(data2); err == nil {
@@ -685,8 +713,12 @@ func TestUpdateChannelHeader(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannelHeader(data2); err == nil {
@@ -784,17 +816,17 @@ func TestUpdateChannelPurpose(t *testing.T) {
isLicensed := utils.IsLicensed()
license := utils.License()
- restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
- restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
+ restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
+ restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
defer func() {
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -821,8 +853,12 @@ func TestUpdateChannelPurpose(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
th.MakeUserChannelUser(th.BasicUser, channel2)
th.MakeUserChannelUser(th.BasicUser, channel3)
@@ -846,8 +882,12 @@ func TestUpdateChannelPurpose(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannelPurpose(data2); err == nil {
@@ -869,8 +909,12 @@ func TestUpdateChannelPurpose(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannelPurpose(data2); err == nil {
@@ -1358,17 +1402,17 @@ func TestDeleteChannel(t *testing.T) {
isLicensed := utils.IsLicensed()
license := utils.License()
- restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
- restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
+ restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
+ restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
defer func() {
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1397,8 +1441,12 @@ func TestDeleteChannel(t *testing.T) {
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
- *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
th.LoginSystemAdmin()
@@ -1453,8 +1501,12 @@ func TestDeleteChannel(t *testing.T) {
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
- *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
th.LoginSystemAdmin()
@@ -1488,8 +1540,12 @@ func TestDeleteChannel(t *testing.T) {
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
- *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
- *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
+ })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
th.LoginSystemAdmin()
@@ -1540,8 +1596,8 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_ALL
- *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_ALL })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_ALL })
utils.SetDefaultRolesBasedOnConfig()
}
@@ -1619,11 +1675,15 @@ func TestAddChannelMember(t *testing.T) {
}
// Test policy does not apply to TE.
- restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers
+ restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManageMembers
defer func() {
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = restrictPrivateChannel
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = restrictPrivateChannel
+ })
}()
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
channel3 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
@@ -1641,7 +1701,7 @@ func TestAddChannelMember(t *testing.T) {
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1656,7 +1716,9 @@ func TestAddChannelMember(t *testing.T) {
}
// Test with CHANNEL_ADMIN level permission.
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
+ })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1681,7 +1743,9 @@ func TestAddChannelMember(t *testing.T) {
}
// Test with TEAM_ADMIN level permission.
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
+ })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1706,7 +1770,9 @@ func TestAddChannelMember(t *testing.T) {
}
// Test with SYSTEM_ADMIN level permission.
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
+ })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1794,11 +1860,15 @@ func TestRemoveChannelMember(t *testing.T) {
th.LoginBasic()
// Test policy does not apply to TE.
- restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers
+ restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManageMembers
defer func() {
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = restrictPrivateChannel
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = restrictPrivateChannel
+ })
}()
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
channel3 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
@@ -1817,7 +1887,7 @@ func TestRemoveChannelMember(t *testing.T) {
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1833,7 +1903,9 @@ func TestRemoveChannelMember(t *testing.T) {
}
// Test with CHANNEL_ADMIN level permission.
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
+ })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1858,7 +1930,9 @@ func TestRemoveChannelMember(t *testing.T) {
}
// Test with TEAM_ADMIN level permission.
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
+ })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1884,7 +1958,9 @@ func TestRemoveChannelMember(t *testing.T) {
}
// Test with SYSTEM_ADMIN level permission.
- *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
+ })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
diff --git a/api/command_help_test.go b/api/command_help_test.go
index 4ca9ef152..181298d7e 100644
--- a/api/command_help_test.go
+++ b/api/command_help_test.go
@@ -7,7 +7,6 @@ import (
"testing"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
)
func TestHelpCommand(t *testing.T) {
@@ -17,18 +16,20 @@ func TestHelpCommand(t *testing.T) {
Client := th.BasicClient
channel := th.BasicChannel
- HelpLink := *utils.Cfg.SupportSettings.HelpLink
+ HelpLink := *th.App.Config().SupportSettings.HelpLink
defer func() {
- *utils.Cfg.SupportSettings.HelpLink = HelpLink
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.SupportSettings.HelpLink = HelpLink })
}()
- *utils.Cfg.SupportSettings.HelpLink = ""
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.SupportSettings.HelpLink = "" })
rs1 := Client.Must(Client.Command(channel.Id, "/help ")).Data.(*model.CommandResponse)
if rs1.GotoLocation != model.SUPPORT_SETTINGS_DEFAULT_HELP_LINK {
t.Fatal("failed to default help link")
}
- *utils.Cfg.SupportSettings.HelpLink = "https://docs.mattermost.com/guides/user.html"
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.SupportSettings.HelpLink = "https://docs.mattermost.com/guides/user.html"
+ })
rs2 := Client.Must(Client.Command(channel.Id, "/help ")).Data.(*model.CommandResponse)
if rs2.GotoLocation != "https://docs.mattermost.com/guides/user.html" {
t.Fatal("failed to help link")
diff --git a/api/command_loadtest_test.go b/api/command_loadtest_test.go
index 346b3379e..62545ae64 100644
--- a/api/command_loadtest_test.go
+++ b/api/command_loadtest_test.go
@@ -9,7 +9,6 @@ import (
"time"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
)
func TestLoadTestHelpCommands(t *testing.T) {
@@ -20,12 +19,12 @@ func TestLoadTestHelpCommands(t *testing.T) {
channel := th.BasicChannel
// enable testing to use /test but don't save it since we don't want to overwrite config.json
- enableTesting := utils.Cfg.ServiceSettings.EnableTesting
+ enableTesting := th.App.Config().ServiceSettings.EnableTesting
defer func() {
- utils.Cfg.ServiceSettings.EnableTesting = enableTesting
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting })
}()
- utils.Cfg.ServiceSettings.EnableTesting = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.Command(channel.Id, "/test help")).Data.(*model.CommandResponse)
if !strings.Contains(rs.Text, "Mattermost testing commands to help") {
@@ -43,12 +42,12 @@ func TestLoadTestSetupCommands(t *testing.T) {
channel := th.BasicChannel
// enable testing to use /test but don't save it since we don't want to overwrite config.json
- enableTesting := utils.Cfg.ServiceSettings.EnableTesting
+ enableTesting := th.App.Config().ServiceSettings.EnableTesting
defer func() {
- utils.Cfg.ServiceSettings.EnableTesting = enableTesting
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting })
}()
- utils.Cfg.ServiceSettings.EnableTesting = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.Command(channel.Id, "/test setup fuzz 1 1 1")).Data.(*model.CommandResponse)
if rs.Text != "Created enviroment" {
@@ -66,12 +65,12 @@ func TestLoadTestUsersCommands(t *testing.T) {
channel := th.BasicChannel
// enable testing to use /test but don't save it since we don't want to overwrite config.json
- enableTesting := utils.Cfg.ServiceSettings.EnableTesting
+ enableTesting := th.App.Config().ServiceSettings.EnableTesting
defer func() {
- utils.Cfg.ServiceSettings.EnableTesting = enableTesting
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting })
}()
- utils.Cfg.ServiceSettings.EnableTesting = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.Command(channel.Id, "/test users fuzz 1 2")).Data.(*model.CommandResponse)
if rs.Text != "Added users" {
@@ -89,12 +88,12 @@ func TestLoadTestChannelsCommands(t *testing.T) {
channel := th.BasicChannel
// enable testing to use /test but don't save it since we don't want to overwrite config.json
- enableTesting := utils.Cfg.ServiceSettings.EnableTesting
+ enableTesting := th.App.Config().ServiceSettings.EnableTesting
defer func() {
- utils.Cfg.ServiceSettings.EnableTesting = enableTesting
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting })
}()
- utils.Cfg.ServiceSettings.EnableTesting = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.Command(channel.Id, "/test channels fuzz 1 2")).Data.(*model.CommandResponse)
if rs.Text != "Added channels" {
@@ -112,12 +111,12 @@ func TestLoadTestPostsCommands(t *testing.T) {
channel := th.BasicChannel
// enable testing to use /test but don't save it since we don't want to overwrite config.json
- enableTesting := utils.Cfg.ServiceSettings.EnableTesting
+ enableTesting := th.App.Config().ServiceSettings.EnableTesting
defer func() {
- utils.Cfg.ServiceSettings.EnableTesting = enableTesting
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting })
}()
- utils.Cfg.ServiceSettings.EnableTesting = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.Command(channel.Id, "/test posts fuzz 2 3 2")).Data.(*model.CommandResponse)
if rs.Text != "Added posts" {
diff --git a/api/command_test.go b/api/command_test.go
index 948193852..7eadca124 100644
--- a/api/command_test.go
+++ b/api/command_test.go
@@ -10,7 +10,6 @@ import (
"time"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
)
func TestListCommands(t *testing.T) {
@@ -45,11 +44,11 @@ func TestCreateCommand(t *testing.T) {
user := th.SystemAdminUser
team := th.SystemAdminTeam
- enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
+ enableCommands := *th.App.Config().ServiceSettings.EnableCommands
defer func() {
- utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
}()
- *utils.Cfg.ServiceSettings.EnableCommands = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
cmd1 := &model.Command{
CreatorId: user.Id,
@@ -108,11 +107,11 @@ func TestListTeamCommands(t *testing.T) {
Client := th.SystemAdminClient
- enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
+ enableCommands := *th.App.Config().ServiceSettings.EnableCommands
defer func() {
- utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
}()
- *utils.Cfg.ServiceSettings.EnableCommands = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
cmd1 := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger"}
cmd1 = Client.Must(Client.CreateCommand(cmd1)).Data.(*model.Command)
@@ -136,11 +135,11 @@ func TestUpdateCommand(t *testing.T) {
user := th.SystemAdminUser
team := th.SystemAdminTeam
- enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
+ enableCommands := *th.App.Config().ServiceSettings.EnableCommands
defer func() {
- utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
}()
- *utils.Cfg.ServiceSettings.EnableCommands = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
cmd1 := &model.Command{
CreatorId: user.Id,
@@ -175,11 +174,11 @@ func TestRegenToken(t *testing.T) {
Client := th.SystemAdminClient
- enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
+ enableCommands := *th.App.Config().ServiceSettings.EnableCommands
defer func() {
- utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
}()
- *utils.Cfg.ServiceSettings.EnableCommands = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger"}
cmd = Client.Must(Client.CreateCommand(cmd)).Data.(*model.Command)
@@ -202,14 +201,14 @@ func TestDeleteCommand(t *testing.T) {
Client := th.SystemAdminClient
- enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
- onlyAdminIntegration := *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableCommands := *th.App.Config().ServiceSettings.EnableCommands
+ onlyAdminIntegration := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- *utils.Cfg.ServiceSettings.EnableCommands = enableCommands
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = onlyAdminIntegration
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = enableCommands })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = onlyAdminIntegration })
}()
- *utils.Cfg.ServiceSettings.EnableCommands = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger"}
cmd = Client.Must(Client.CreateCommand(cmd)).Data.(*model.Command)
@@ -248,14 +247,16 @@ func TestTestCommand(t *testing.T) {
Client := th.SystemAdminClient
channel1 := th.SystemAdminChannel
- enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
- allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
+ enableCommands := *th.App.Config().ServiceSettings.EnableCommands
+ allowedInternalConnections := *th.App.Config().ServiceSettings.AllowedUntrustedInternalConnections
defer func() {
- utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
- utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
+ })
}()
- *utils.Cfg.ServiceSettings.EnableCommands = true
- *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost"
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost" })
cmd1 := &model.Command{
URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V3 + "/teams/command_test",
diff --git a/api/context.go b/api/context.go
index 0322b6c43..aa5f2a163 100644
--- a/api/context.go
+++ b/api/context.go
@@ -191,7 +191,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.Path = "/" + strings.Join(splitURL[2:], "/")
}
- if h.isApi && !*utils.Cfg.ServiceSettings.EnableAPIv3 {
+ if h.isApi && !*c.App.Config().ServiceSettings.EnableAPIv3 {
c.Err = model.NewAppError("ServeHTTP", "api.context.v3_disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -229,7 +229,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.Err.Where = r.URL.Path
// Block out detailed error when not in developer mode
- if !*utils.Cfg.ServiceSettings.EnableDeveloper {
+ if !*c.App.Config().ServiceSettings.EnableDeveloper {
c.Err.DetailedError = ""
}
@@ -294,7 +294,7 @@ func (c *Context) LogDebug(err *model.AppError) {
}
func (c *Context) UserRequired() {
- if !*utils.Cfg.ServiceSettings.EnableUserAccessTokens && c.Session.Props[model.SESSION_PROP_TYPE] == model.SESSION_TYPE_USER_ACCESS_TOKEN {
+ if !*c.App.Config().ServiceSettings.EnableUserAccessTokens && c.Session.Props[model.SESSION_PROP_TYPE] == model.SESSION_TYPE_USER_ACCESS_TOKEN {
c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "UserAccessToken", http.StatusUnauthorized)
return
}
@@ -307,7 +307,7 @@ func (c *Context) UserRequired() {
func (c *Context) MfaRequired() {
// Must be licensed for MFA and have it configured for enforcement
- if !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication || !*utils.Cfg.ServiceSettings.EnforceMultifactorAuthentication {
+ if !utils.IsLicensed() || !*utils.License().Features.MFA || !*c.App.Config().ServiceSettings.EnableMultifactorAuthentication || !*c.App.Config().ServiceSettings.EnforceMultifactorAuthentication {
return
}
diff --git a/api/emoji.go b/api/emoji.go
index b4ad9fa2c..4a9995d64 100644
--- a/api/emoji.go
+++ b/api/emoji.go
@@ -31,7 +31,7 @@ func (api *API) InitEmoji() {
}
func getEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
- if !*utils.Cfg.ServiceSettings.EnableCustomEmoji {
+ if !*c.App.Config().ServiceSettings.EnableCustomEmoji {
c.Err = model.NewAppError("getEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -46,7 +46,7 @@ func getEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
}
func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
- if !*utils.Cfg.ServiceSettings.EnableCustomEmoji {
+ if !*c.App.Config().ServiceSettings.EnableCustomEmoji {
c.Err = model.NewAppError("createEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -57,7 +57,7 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*c.App.Config().FileSettings.DriverName) == 0 {
c.Err = model.NewAppError("createEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -124,12 +124,12 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
}
func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
- if !*utils.Cfg.ServiceSettings.EnableCustomEmoji {
+ if !*c.App.Config().ServiceSettings.EnableCustomEmoji {
c.Err = model.NewAppError("deleteEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*c.App.Config().FileSettings.DriverName) == 0 {
c.Err = model.NewAppError("deleteImage", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -163,12 +163,12 @@ func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) {
- if !*utils.Cfg.ServiceSettings.EnableCustomEmoji {
+ if !*c.App.Config().ServiceSettings.EnableCustomEmoji {
c.Err = model.NewAppError("getEmojiImage", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*c.App.Config().FileSettings.DriverName) == 0 {
c.Err = model.NewAppError("getEmojiImage", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
return
}
diff --git a/api/emoji_test.go b/api/emoji_test.go
index 5ee034e9c..8aae047d4 100644
--- a/api/emoji_test.go
+++ b/api/emoji_test.go
@@ -22,11 +22,11 @@ func TestGetEmoji(t *testing.T) {
Client := th.BasicClient
- EnableCustomEmoji := *utils.Cfg.ServiceSettings.EnableCustomEmoji
+ EnableCustomEmoji := *th.App.Config().ServiceSettings.EnableCustomEmoji
defer func() {
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = EnableCustomEmoji
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = EnableCustomEmoji })
}()
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true })
emojis := []*model.Emoji{
{
@@ -102,11 +102,11 @@ func TestCreateEmoji(t *testing.T) {
Client := th.BasicClient
- EnableCustomEmoji := *utils.Cfg.ServiceSettings.EnableCustomEmoji
+ EnableCustomEmoji := *th.App.Config().ServiceSettings.EnableCustomEmoji
defer func() {
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = EnableCustomEmoji
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = EnableCustomEmoji })
}()
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = false })
emoji := &model.Emoji{
CreatorId: th.BasicUser.Id,
@@ -118,7 +118,7 @@ func TestCreateEmoji(t *testing.T) {
t.Fatal("shouldn't be able to create an emoji when they're disabled")
}
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true })
// try to create a valid gif emoji when they're enabled
if emojiResult, err := Client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif"); err != nil {
@@ -226,11 +226,11 @@ func TestDeleteEmoji(t *testing.T) {
Client := th.BasicClient
- EnableCustomEmoji := *utils.Cfg.ServiceSettings.EnableCustomEmoji
+ EnableCustomEmoji := *th.App.Config().ServiceSettings.EnableCustomEmoji
defer func() {
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = EnableCustomEmoji
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = EnableCustomEmoji })
}()
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = false })
emoji1 := createTestEmoji(t, th.App, &model.Emoji{
CreatorId: th.BasicUser.Id,
@@ -241,7 +241,7 @@ func TestDeleteEmoji(t *testing.T) {
t.Fatal("shouldn't have been able to delete an emoji when they're disabled")
}
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true })
if deleted, err := Client.DeleteEmoji(emoji1.Id); err != nil {
t.Fatal(err)
@@ -286,14 +286,18 @@ func TestGetEmojiImage(t *testing.T) {
Client := th.BasicClient
- EnableCustomEmoji := *utils.Cfg.ServiceSettings.EnableCustomEmoji
- RestrictCustomEmojiCreation := *utils.Cfg.ServiceSettings.RestrictCustomEmojiCreation
+ EnableCustomEmoji := *th.App.Config().ServiceSettings.EnableCustomEmoji
+ RestrictCustomEmojiCreation := *th.App.Config().ServiceSettings.RestrictCustomEmojiCreation
defer func() {
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = EnableCustomEmoji
- *utils.Cfg.ServiceSettings.RestrictCustomEmojiCreation = RestrictCustomEmojiCreation
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = EnableCustomEmoji })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.RestrictCustomEmojiCreation = RestrictCustomEmojiCreation
+ })
}()
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = true
- *utils.Cfg.ServiceSettings.RestrictCustomEmojiCreation = model.RESTRICT_EMOJI_CREATION_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.RestrictCustomEmojiCreation = model.RESTRICT_EMOJI_CREATION_ALL
+ })
emoji1 := &model.Emoji{
CreatorId: th.BasicUser.Id,
@@ -302,13 +306,13 @@ func TestGetEmojiImage(t *testing.T) {
emoji1 = Client.MustGeneric(Client.CreateEmoji(emoji1, utils.CreateTestGif(t, 10, 10), "image.gif")).(*model.Emoji)
defer func() { Client.MustGeneric(Client.DeleteEmoji(emoji1.Id)) }()
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = false })
if _, err := Client.DoApiGet(Client.GetCustomEmojiImageUrl(emoji1.Id), "", ""); err == nil {
t.Fatal("should've failed to get emoji image when disabled")
}
- *utils.Cfg.ServiceSettings.EnableCustomEmoji = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true })
if resp, err := Client.DoApiGet(Client.GetCustomEmojiImageUrl(emoji1.Id), "", ""); err != nil {
t.Fatal(err)
diff --git a/api/file.go b/api/file.go
index 28007f222..bcb79bd5c 100644
--- a/api/file.go
+++ b/api/file.go
@@ -46,17 +46,17 @@ func (api *API) InitFile() {
}
func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
- if !*utils.Cfg.FileSettings.EnableFileAttachments {
+ if !*c.App.Config().FileSettings.EnableFileAttachments {
c.Err = model.NewAppError("uploadFile", "api.file.attachments.disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
- if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
+ if r.ContentLength > *c.App.Config().FileSettings.MaxFileSize {
c.Err = model.NewAppError("uploadFile", "api.file.upload_file.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
return
}
- if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil {
+ if err := r.ParseMultipartForm(*c.App.Config().FileSettings.MaxFileSize); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -159,7 +159,7 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
- if !utils.Cfg.FileSettings.EnablePublicLink {
+ if !c.App.Config().FileSettings.EnablePublicLink {
c.Err = model.NewAppError("getPublicFile", "api.file.get_file.public_disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -173,7 +173,7 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
hash := r.URL.Query().Get("h")
if len(hash) > 0 {
- correctHash := app.GeneratePublicLinkHash(info.Id, *utils.Cfg.FileSettings.PublicLinkSalt)
+ correctHash := app.GeneratePublicLinkHash(info.Id, *c.App.Config().FileSettings.PublicLinkSalt)
if hash != correctHash {
c.Err = model.NewAppError("getPublicFile", "api.file.get_file.public_invalid.app_error", nil, "", http.StatusBadRequest)
@@ -196,7 +196,7 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool) (*model.FileInfo, *model.AppError) {
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*c.App.Config().FileSettings.DriverName) == 0 {
return nil, model.NewAppError("getFileInfoForRequest", "api.file.get_info_for_request.storage.app_error", nil, "", http.StatusNotImplemented)
}
@@ -231,10 +231,10 @@ func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool)
}
func getPublicFileOld(c *Context, w http.ResponseWriter, r *http.Request) {
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*c.App.Config().FileSettings.DriverName) == 0 {
c.Err = model.NewAppError("getPublicFile", "api.file.get_public_file_old.storage.app_error", nil, "", http.StatusNotImplemented)
return
- } else if !utils.Cfg.FileSettings.EnablePublicLink {
+ } else if !c.App.Config().FileSettings.EnablePublicLink {
c.Err = model.NewAppError("getPublicFile", "api.file.get_file.public_disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -249,7 +249,7 @@ func getPublicFileOld(c *Context, w http.ResponseWriter, r *http.Request) {
hash := r.URL.Query().Get("h")
if len(hash) > 0 {
- correctHash := app.GeneratePublicLinkHash(filename, *utils.Cfg.FileSettings.PublicLinkSalt)
+ correctHash := app.GeneratePublicLinkHash(filename, *c.App.Config().FileSettings.PublicLinkSalt)
if hash != correctHash {
c.Err = model.NewAppError("getPublicFile", "api.file.get_file.public_invalid.app_error", nil, "", http.StatusBadRequest)
@@ -316,7 +316,7 @@ func writeFileResponse(filename string, contentType string, bytes []byte, w http
}
func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) {
- if !utils.Cfg.FileSettings.EnablePublicLink {
+ if !c.App.Config().FileSettings.EnablePublicLink {
c.Err = model.NewAppError("getPublicLink", "api.file.get_public_link.disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
diff --git a/api/file_test.go b/api/file_test.go
index 2935f0804..31eb3daef 100644
--- a/api/file_test.go
+++ b/api/file_test.go
@@ -27,7 +27,7 @@ func TestUploadFile(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Logf("skipping because no file driver is enabled")
return
}
@@ -121,11 +121,11 @@ func TestUploadFile(t *testing.T) {
t.Fatal("should have failed - bad channel id")
}
- enableFileAttachments := *utils.Cfg.FileSettings.EnableFileAttachments
+ enableFileAttachments := *th.App.Config().FileSettings.EnableFileAttachments
defer func() {
- *utils.Cfg.FileSettings.EnableFileAttachments = enableFileAttachments
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnableFileAttachments = enableFileAttachments })
}()
- *utils.Cfg.FileSettings.EnableFileAttachments = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnableFileAttachments = false })
if data, err := readTestFile("test.png"); err != nil {
t.Fatal(err)
@@ -145,7 +145,7 @@ func TestGetFileInfo(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
@@ -215,7 +215,7 @@ func TestGetFile(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
@@ -298,7 +298,7 @@ func TestGetFileThumbnail(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
@@ -355,7 +355,7 @@ func TestGetFilePreview(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
@@ -412,18 +412,18 @@ func TestGetPublicFile(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
- enablePublicLink := utils.Cfg.FileSettings.EnablePublicLink
- publicLinkSalt := *utils.Cfg.FileSettings.PublicLinkSalt
+ enablePublicLink := th.App.Config().FileSettings.EnablePublicLink
+ publicLinkSalt := *th.App.Config().FileSettings.PublicLinkSalt
defer func() {
- utils.Cfg.FileSettings.EnablePublicLink = enablePublicLink
- *utils.Cfg.FileSettings.PublicLinkSalt = publicLinkSalt
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = enablePublicLink })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = publicLinkSalt })
}()
- utils.Cfg.FileSettings.EnablePublicLink = true
- *utils.Cfg.FileSettings.PublicLinkSalt = model.NewId()
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = model.NewId() })
Client := th.BasicClient
channel := th.BasicChannel
@@ -453,15 +453,15 @@ func TestGetPublicFile(t *testing.T) {
t.Fatal("should've failed to get image with public link without hash", resp.Status)
}
- utils.Cfg.FileSettings.EnablePublicLink = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = false })
if resp, err := http.Get(link); err == nil && resp.StatusCode != http.StatusNotImplemented {
t.Fatal("should've failed to get image with disabled public link")
}
- utils.Cfg.FileSettings.EnablePublicLink = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true })
// test after the salt has changed
- *utils.Cfg.FileSettings.PublicLinkSalt = model.NewId()
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = model.NewId() })
if resp, err := http.Get(link); err == nil && resp.StatusCode != http.StatusBadRequest {
t.Fatal("should've failed to get image with public link after salt changed")
@@ -480,18 +480,18 @@ func TestGetPublicFileOld(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
- enablePublicLink := utils.Cfg.FileSettings.EnablePublicLink
- publicLinkSalt := *utils.Cfg.FileSettings.PublicLinkSalt
+ enablePublicLink := th.App.Config().FileSettings.EnablePublicLink
+ publicLinkSalt := *th.App.Config().FileSettings.PublicLinkSalt
defer func() {
- utils.Cfg.FileSettings.EnablePublicLink = enablePublicLink
- *utils.Cfg.FileSettings.PublicLinkSalt = publicLinkSalt
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = enablePublicLink })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = publicLinkSalt })
}()
- utils.Cfg.FileSettings.EnablePublicLink = true
- *utils.Cfg.FileSettings.PublicLinkSalt = model.NewId()
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = model.NewId() })
channel := th.BasicChannel
@@ -530,15 +530,15 @@ func TestGetPublicFileOld(t *testing.T) {
t.Fatal("should've failed to get image with public link without hash", resp.Status)
}
- utils.Cfg.FileSettings.EnablePublicLink = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = false })
if resp, err := http.Get(link); err == nil && resp.StatusCode != http.StatusNotImplemented {
t.Fatal("should've failed to get image with disabled public link")
}
- utils.Cfg.FileSettings.EnablePublicLink = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true })
// test after the salt has changed
- *utils.Cfg.FileSettings.PublicLinkSalt = model.NewId()
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = model.NewId() })
if resp, err := http.Get(link); err == nil && resp.StatusCode != http.StatusBadRequest {
t.Fatal("should've failed to get image with public link after salt changed")
@@ -562,15 +562,15 @@ func TestGetPublicLink(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
- enablePublicLink := utils.Cfg.FileSettings.EnablePublicLink
+ enablePublicLink := th.App.Config().FileSettings.EnablePublicLink
defer func() {
- utils.Cfg.FileSettings.EnablePublicLink = enablePublicLink
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = enablePublicLink })
}()
- utils.Cfg.FileSettings.EnablePublicLink = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true })
Client := th.BasicClient
channel := th.BasicChannel
@@ -590,13 +590,13 @@ func TestGetPublicLink(t *testing.T) {
// Hacky way to assign file to a post (usually would be done by CreatePost call)
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
- utils.Cfg.FileSettings.EnablePublicLink = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = false })
if _, err := Client.GetPublicLink(fileId); err == nil {
t.Fatal("should've failed to get public link when disabled")
}
- utils.Cfg.FileSettings.EnablePublicLink = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true })
if link, err := Client.GetPublicLink(fileId); err != nil {
t.Fatal(err)
@@ -632,7 +632,7 @@ func TestMigrateFilenamesToFileInfos(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
@@ -745,7 +745,7 @@ func TestFindTeamIdForFilename(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
@@ -812,7 +812,7 @@ func TestGetInfoForFilename(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- if *utils.Cfg.FileSettings.DriverName == "" {
+ if *th.App.Config().FileSettings.DriverName == "" {
t.Skip("skipping because no file driver is enabled")
}
diff --git a/api/general.go b/api/general.go
index 015baec4e..5e7780fdb 100644
--- a/api/general.go
+++ b/api/general.go
@@ -30,7 +30,7 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
func logClient(c *Context, w http.ResponseWriter, r *http.Request) {
forceToDebug := false
- if !*utils.Cfg.ServiceSettings.EnableDeveloper {
+ if !*c.App.Config().ServiceSettings.EnableDeveloper {
if c.Session.UserId == "" {
c.Err = model.NewAppError("Permissions", "api.context.permissions.app_error", nil, "", http.StatusForbidden)
return
diff --git a/api/general_test.go b/api/general_test.go
index 3de39ca83..3f61d9d32 100644
--- a/api/general_test.go
+++ b/api/general_test.go
@@ -4,9 +4,8 @@
package api
import (
+ "github.com/mattermost/mattermost-server/model"
"testing"
-
- "github.com/mattermost/mattermost-server/utils"
)
func TestGetClientProperties(t *testing.T) {
@@ -30,11 +29,11 @@ func TestLogClient(t *testing.T) {
t.Fatal("failed to log")
}
- enableDeveloper := *utils.Cfg.ServiceSettings.EnableDeveloper
+ enableDeveloper := *th.App.Config().ServiceSettings.EnableDeveloper
defer func() {
- *utils.Cfg.ServiceSettings.EnableDeveloper = enableDeveloper
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableDeveloper = enableDeveloper })
}()
- *utils.Cfg.ServiceSettings.EnableDeveloper = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableDeveloper = false })
th.BasicClient.Logout()
@@ -42,7 +41,7 @@ func TestLogClient(t *testing.T) {
t.Fatal("should have failed")
}
- *utils.Cfg.ServiceSettings.EnableDeveloper = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableDeveloper = true })
if ret, _ := th.BasicClient.LogClient("this is a test"); !ret {
t.Fatal("failed to log")
diff --git a/api/license.go b/api/license.go
index 18d6a20a3..371f4be02 100644
--- a/api/license.go
+++ b/api/license.go
@@ -24,7 +24,7 @@ func (api *API) InitLicense() {
func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt")
- err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize)
+ err := r.ParseMultipartForm(*c.App.Config().FileSettings.MaxFileSize)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
diff --git a/api/oauth.go b/api/oauth.go
index 0a26a6f98..51a1828d1 100644
--- a/api/oauth.go
+++ b/api/oauth.go
@@ -173,7 +173,7 @@ func signupWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
service := params["service"]
- if !utils.Cfg.TeamSettings.EnableUserCreation {
+ if !c.App.Config().TeamSettings.EnableUserCreation {
c.Err = model.NewAppError("signupWithOAuth", "api.oauth.singup_with_oauth.disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
diff --git a/api/oauth_test.go b/api/oauth_test.go
index 0f809dfe6..1510e3520 100644
--- a/api/oauth_test.go
+++ b/api/oauth_test.go
@@ -25,14 +25,14 @@ func TestOAuthRegisterApp(t *testing.T) {
oauthApp := &model.OAuthApp{Name: "TestApp" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}, IsTrusted: true}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
+ if !th.App.Config().ServiceSettings.EnableOAuthServiceProvider {
if _, err := Client.RegisterApp(oauthApp); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
// calling the endpoint without an app
if _, err := Client.DoApiPost("/oauth/register", ""); err == nil {
@@ -88,12 +88,12 @@ func TestOAuthRegisterApp(t *testing.T) {
t.Fatal("should have failed. not enough permissions")
}
- adminOnly := *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -115,18 +115,18 @@ func TestOAuthAllow(t *testing.T) {
Client := th.BasicClient
AdminClient := th.SystemAdminClient
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oauthApp := &model.OAuthApp{Name: "TestApp" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
oauthApp = AdminClient.Must(AdminClient.RegisterApp(oauthApp)).Data.(*model.OAuthApp)
state := "123"
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
if _, err := Client.AllowOAuth(model.AUTHCODE_RESPONSE_TYPE, oauthApp.Id, oauthApp.CallbackUrls[0], "all", state); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
if result, err := Client.AllowOAuth(model.AUTHCODE_RESPONSE_TYPE, oauthApp.Id, oauthApp.CallbackUrls[0], "all", state); err != nil {
t.Fatal(err)
@@ -202,21 +202,21 @@ func TestOAuthGetAppsByUser(t *testing.T) {
Client := th.BasicClient
AdminClient := th.SystemAdminClient
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
+ if !th.App.Config().ServiceSettings.EnableOAuthServiceProvider {
if _, err := Client.GetOAuthAppsByUser(); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
if _, err := Client.GetOAuthAppsByUser(); err == nil {
t.Fatal("Should have failed.")
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
if result, err := Client.GetOAuthAppsByUser(); err != nil {
@@ -274,15 +274,15 @@ func TestOAuthGetAppInfo(t *testing.T) {
Client := th.BasicClient
AdminClient := th.SystemAdminClient
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
+ if !th.App.Config().ServiceSettings.EnableOAuthServiceProvider {
if _, err := Client.GetOAuthAppInfo("fakeId"); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oauthApp := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -304,15 +304,15 @@ func TestOAuthGetAuthorizedApps(t *testing.T) {
Client := th.BasicClient
AdminClient := th.SystemAdminClient
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
+ if !th.App.Config().ServiceSettings.EnableOAuthServiceProvider {
if _, err := Client.GetOAuthAuthorizedApps(); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oauthApp := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
oauthApp = AdminClient.Must(AdminClient.RegisterApp(oauthApp)).Data.(*model.OAuthApp)
@@ -339,15 +339,15 @@ func TestOAuthDeauthorizeApp(t *testing.T) {
Client := th.BasicClient
AdminClient := th.SystemAdminClient
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
+ if !th.App.Config().ServiceSettings.EnableOAuthServiceProvider {
if err := Client.OAuthDeauthorizeApp(model.NewId()); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oauthApp := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -392,15 +392,15 @@ func TestOAuthRegenerateAppSecret(t *testing.T) {
Client := th.BasicClient
AdminClient := th.SystemAdminClient
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
+ if !th.App.Config().ServiceSettings.EnableOAuthServiceProvider {
if _, err := AdminClient.RegenerateOAuthAppSecret(model.NewId()); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oauthApp := &model.OAuthApp{Name: "TestApp6" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -435,16 +435,16 @@ func TestOAuthDeleteApp(t *testing.T) {
Client := th.BasicClient
AdminClient := th.SystemAdminClient
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
+ if !th.App.Config().ServiceSettings.EnableOAuthServiceProvider {
if _, err := Client.DeleteOAuthApp("fakeId"); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
oauthApp := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -567,27 +567,27 @@ func TestOAuthAccessToken(t *testing.T) {
Client := th.BasicClient
- enableOAuth := utils.Cfg.ServiceSettings.EnableOAuthServiceProvider
- adminOnly := *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider
+ adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
oauthApp := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
oauthApp = Client.Must(Client.RegisterApp(oauthApp)).Data.(*model.OAuthApp)
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
data := url.Values{"grant_type": []string{"junk"}, "client_id": []string{"12345678901234567890123456"}, "client_secret": []string{"12345678901234567890123456"}, "code": []string{"junk"}, "redirect_uri": []string{oauthApp.CallbackUrls[0]}}
if _, err := Client.GetAccessToken(data); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
redirect := Client.Must(Client.AllowOAuth(model.AUTHCODE_RESPONSE_TYPE, oauthApp.Id, oauthApp.CallbackUrls[0], "all", "123")).Data.(map[string]string)["redirect"]
rurl, _ := url.Parse(redirect)
@@ -788,19 +788,19 @@ func TestOAuthComplete(t *testing.T) {
closeBody(r)
}
- utils.Cfg.GitLabSettings.Enable = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.Enable = true })
if r, err := HttpGet(Client.Url+"/login/gitlab/complete?code=123&state=!#$#F@#Yˆ&~ñ", Client.HttpClient, "", true); err == nil {
t.Fatal("should have failed - gitlab disabled")
closeBody(r)
}
- utils.Cfg.GitLabSettings.AuthEndpoint = Client.Url + "/oauth/authorize"
- utils.Cfg.GitLabSettings.Id = model.NewId()
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.AuthEndpoint = Client.Url + "/oauth/authorize" })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.Id = model.NewId() })
stateProps := map[string]string{}
stateProps["action"] = model.OAUTH_ACTION_LOGIN
stateProps["team_id"] = th.BasicTeam.Id
- stateProps["redirect_to"] = utils.Cfg.GitLabSettings.AuthEndpoint
+ stateProps["redirect_to"] = th.App.Config().GitLabSettings.AuthEndpoint
state := base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps)))
if r, err := HttpGet(Client.Url+"/login/gitlab/complete?code=123&state="+url.QueryEscape(state), Client.HttpClient, "", true); err == nil {
@@ -808,7 +808,7 @@ func TestOAuthComplete(t *testing.T) {
closeBody(r)
}
- stateProps["hash"] = utils.HashSha256(utils.Cfg.GitLabSettings.Id)
+ stateProps["hash"] = utils.HashSha256(th.App.Config().GitLabSettings.Id)
state = base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps)))
if r, err := HttpGet(Client.Url+"/login/gitlab/complete?code=123&state="+url.QueryEscape(state), Client.HttpClient, "", true); err == nil {
t.Fatal("should have failed - no connection")
@@ -816,14 +816,14 @@ func TestOAuthComplete(t *testing.T) {
}
// We are going to use mattermost as the provider emulating gitlab
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
- adminOnly := *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
oauthApp := &model.OAuthApp{
@@ -838,11 +838,11 @@ func TestOAuthComplete(t *testing.T) {
}
oauthApp = Client.Must(Client.RegisterApp(oauthApp)).Data.(*model.OAuthApp)
- utils.Cfg.GitLabSettings.Id = oauthApp.Id
- utils.Cfg.GitLabSettings.Secret = oauthApp.ClientSecret
- utils.Cfg.GitLabSettings.AuthEndpoint = Client.Url + "/oauth/authorize"
- utils.Cfg.GitLabSettings.TokenEndpoint = Client.Url + "/oauth/access_token"
- utils.Cfg.GitLabSettings.UserApiEndpoint = Client.ApiUrl + "/users/me"
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.Id = oauthApp.Id })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.Secret = oauthApp.ClientSecret })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.AuthEndpoint = Client.Url + "/oauth/authorize" })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.TokenEndpoint = Client.Url + "/oauth/access_token" })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.UserApiEndpoint = Client.ApiUrl + "/users/me" })
provider := &MattermostTestProvider{}
@@ -851,8 +851,8 @@ func TestOAuthComplete(t *testing.T) {
code := rurl.Query().Get("code")
stateProps["action"] = model.OAUTH_ACTION_EMAIL_TO_SSO
delete(stateProps, "team_id")
- stateProps["redirect_to"] = utils.Cfg.GitLabSettings.AuthEndpoint
- stateProps["hash"] = utils.HashSha256(utils.Cfg.GitLabSettings.Id)
+ stateProps["redirect_to"] = th.App.Config().GitLabSettings.AuthEndpoint
+ stateProps["hash"] = utils.HashSha256(th.App.Config().GitLabSettings.Id)
stateProps["redirect_to"] = "/oauth/authorize"
state = base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps)))
if r, err := HttpGet(Client.Url+"/login/"+model.SERVICE_GITLAB+"/complete?code="+url.QueryEscape(code)+"&state="+url.QueryEscape(state), Client.HttpClient, "", false); err == nil {
diff --git a/api/post.go b/api/post.go
index b2b8e3d0e..e85b9870d 100644
--- a/api/post.go
+++ b/api/post.go
@@ -534,7 +534,7 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
- if !*utils.Cfg.ServiceSettings.EnableLinkPreviews {
+ if !*c.App.Config().ServiceSettings.EnableLinkPreviews {
c.Err = model.NewAppError("getOpenGraphMetadata", "api.post.link_preview_disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
diff --git a/api/post_test.go b/api/post_test.go
index 58a9fae73..8b5cbd454 100644
--- a/api/post_test.go
+++ b/api/post_test.go
@@ -158,14 +158,14 @@ func TestCreatePost(t *testing.T) {
isLicensed := utils.IsLicensed()
license := utils.License()
- disableTownSquareReadOnly := utils.Cfg.TeamSettings.ExperimentalTownSquareIsReadOnly
+ disableTownSquareReadOnly := th.App.Config().TeamSettings.ExperimentalTownSquareIsReadOnly
defer func() {
- utils.Cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = disableTownSquareReadOnly
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = disableTownSquareReadOnly })
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
utils.SetDefaultRolesBasedOnConfig()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
@@ -237,14 +237,18 @@ func testCreatePostWithOutgoingHook(
user := th.SystemAdminUser
channel := th.CreateChannel(Client, team)
- enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
- allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
+ enableOutgoingHooks := th.App.Config().ServiceSettings.EnableOutgoingWebhooks
+ allowedInternalConnections := *th.App.Config().ServiceSettings.AllowedUntrustedInternalConnections
defer func() {
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
- utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
+ })
}()
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
- *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
+ })
var hook *model.OutgoingWebhook
var post *model.Post
@@ -398,14 +402,14 @@ func TestUpdatePost(t *testing.T) {
Client := th.BasicClient
channel1 := th.BasicChannel
- allowEditPost := *utils.Cfg.ServiceSettings.AllowEditPost
- postEditTimeLimit := *utils.Cfg.ServiceSettings.PostEditTimeLimit
+ allowEditPost := *th.App.Config().ServiceSettings.AllowEditPost
+ postEditTimeLimit := *th.App.Config().ServiceSettings.PostEditTimeLimit
defer func() {
- *utils.Cfg.ServiceSettings.AllowEditPost = allowEditPost
- *utils.Cfg.ServiceSettings.PostEditTimeLimit = postEditTimeLimit
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = allowEditPost })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.PostEditTimeLimit = postEditTimeLimit })
}()
- *utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS })
post1 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a"}
rpost1, err := Client.CreatePost(post1)
@@ -480,7 +484,7 @@ func TestUpdatePost(t *testing.T) {
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
- *utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_NEVER
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_NEVER })
post4 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
rpost4, err := Client.CreatePost(post4)
@@ -493,8 +497,8 @@ func TestUpdatePost(t *testing.T) {
t.Fatal("shouldn't have been able to update a message when not allowed")
}
- *utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_TIME_LIMIT
- *utils.Cfg.ServiceSettings.PostEditTimeLimit = 1 //seconds
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_TIME_LIMIT })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.PostEditTimeLimit = 1 }) //seconds
post5 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
rpost5, err := Client.CreatePost(post5)
@@ -969,12 +973,12 @@ func TestDeletePosts(t *testing.T) {
channel1 := th.BasicChannel
team1 := th.BasicTeam
- restrictPostDelete := *utils.Cfg.ServiceSettings.RestrictPostDelete
+ restrictPostDelete := *th.App.Config().ServiceSettings.RestrictPostDelete
defer func() {
- *utils.Cfg.ServiceSettings.RestrictPostDelete = restrictPostDelete
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.RestrictPostDelete = restrictPostDelete })
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_ALL
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_ALL })
utils.SetDefaultRolesBasedOnConfig()
time.Sleep(10 * time.Millisecond)
@@ -1050,7 +1054,9 @@ func TestDeletePosts(t *testing.T) {
SystemAdminClient.Must(SystemAdminClient.DeletePost(channel1.Id, post4b.Id))
- *utils.Cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_TEAM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -1073,7 +1079,9 @@ func TestDeletePosts(t *testing.T) {
SystemAdminClient.Must(SystemAdminClient.DeletePost(channel1.Id, post5b.Id))
- *utils.Cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_SYSTEM_ADMIN
+ })
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -1466,14 +1474,18 @@ func TestGetOpenGraphMetadata(t *testing.T) {
Client := th.BasicClient
- enableLinkPreviews := *utils.Cfg.ServiceSettings.EnableLinkPreviews
- allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
+ enableLinkPreviews := *th.App.Config().ServiceSettings.EnableLinkPreviews
+ allowedInternalConnections := *th.App.Config().ServiceSettings.AllowedUntrustedInternalConnections
defer func() {
- *utils.Cfg.ServiceSettings.EnableLinkPreviews = enableLinkPreviews
- utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableLinkPreviews = enableLinkPreviews })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
+ })
}()
- *utils.Cfg.ServiceSettings.EnableLinkPreviews = true
- *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableLinkPreviews = true })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
+ })
ogDataCacheMissCount := 0
@@ -1524,7 +1536,7 @@ func TestGetOpenGraphMetadata(t *testing.T) {
}
}
- *utils.Cfg.ServiceSettings.EnableLinkPreviews = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableLinkPreviews = false })
if _, err := Client.DoApiPost("/get_opengraph_metadata", "{\"url\":\"/og-data/\"}"); err == nil || err.StatusCode != http.StatusNotImplemented {
t.Fatal("should have failed with 501 - disabled link previews")
}
diff --git a/api/status_test.go b/api/status_test.go
index 2d7e27326..19d422b16 100644
--- a/api/status_test.go
+++ b/api/status_test.go
@@ -10,7 +10,6 @@ import (
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
- "github.com/mattermost/mattermost-server/utils"
)
func TestStatuses(t *testing.T) {
@@ -141,11 +140,11 @@ func TestStatuses(t *testing.T) {
th.App.SetStatusAwayIfNeeded(th.BasicUser.Id, false)
- awayTimeout := *utils.Cfg.TeamSettings.UserStatusAwayTimeout
+ awayTimeout := *th.App.Config().TeamSettings.UserStatusAwayTimeout
defer func() {
- *utils.Cfg.TeamSettings.UserStatusAwayTimeout = awayTimeout
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.UserStatusAwayTimeout = awayTimeout })
}()
- *utils.Cfg.TeamSettings.UserStatusAwayTimeout = 1
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.UserStatusAwayTimeout = 1 })
time.Sleep(1500 * time.Millisecond)
diff --git a/api/team.go b/api/team.go
index 49b20686d..9bb76af2a 100644
--- a/api/team.go
+++ b/api/team.go
@@ -123,9 +123,9 @@ func inviteMembers(c *Context, w http.ResponseWriter, r *http.Request) {
if utils.IsLicensed() && !app.SessionHasPermissionToTeam(c.Session, c.TeamId, model.PERMISSION_INVITE_USER) {
errorId := ""
- if *utils.Cfg.TeamSettings.RestrictTeamInvite == model.PERMISSIONS_SYSTEM_ADMIN {
+ if *c.App.Config().TeamSettings.RestrictTeamInvite == model.PERMISSIONS_SYSTEM_ADMIN {
errorId = "api.team.invite_members.restricted_system_admin.app_error"
- } else if *utils.Cfg.TeamSettings.RestrictTeamInvite == model.PERMISSIONS_TEAM_ADMIN {
+ } else if *c.App.Config().TeamSettings.RestrictTeamInvite == model.PERMISSIONS_TEAM_ADMIN {
errorId = "api.team.invite_members.restricted_team_admin.app_error"
}
diff --git a/api/team_test.go b/api/team_test.go
index 1e4b36433..680bd7ea7 100644
--- a/api/team_test.go
+++ b/api/team_test.go
@@ -140,18 +140,18 @@ func TestAddUserToTeam(t *testing.T) {
}
// Restore config/license at end of test case.
- restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite
+ restrictTeamInvite := *th.App.Config().TeamSettings.RestrictTeamInvite
isLicensed := utils.IsLicensed()
license := utils.License()
defer func() {
- *utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite })
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
// Set the config so that only team admins can add a user to a team.
- *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
utils.SetDefaultRolesBasedOnConfig()
// Test without the EE license to see that the permission restriction is ignored.
@@ -175,7 +175,7 @@ func TestAddUserToTeam(t *testing.T) {
// Should work as team admin.
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
th.App.InvalidateAllCaches()
- *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -187,7 +187,7 @@ func TestAddUserToTeam(t *testing.T) {
}
// Change permission level to System Admin
- *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
utils.SetDefaultRolesBasedOnConfig()
// Should not work as team admin.
@@ -565,12 +565,12 @@ func TestInviteMembers(t *testing.T) {
t.Fatal("Should have errored out on no invites to send")
}
- restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite
+ restrictTeamInvite := *th.App.Config().TeamSettings.RestrictTeamInvite
defer func() {
- *utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite })
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic2()
@@ -605,7 +605,7 @@ func TestInviteMembers(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.InviteMembers(invites); err == nil {
diff --git a/api/user.go b/api/user.go
index 1e77b8e2e..365e082ae 100644
--- a/api/user.go
+++ b/api/user.go
@@ -169,9 +169,9 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
}
c.App.ClearSessionCacheForUser(c.Session.UserId)
- c.Session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthMobileInDays)
+ c.Session.SetExpireInDays(*c.App.Config().ServiceSettings.SessionLengthMobileInDays)
- maxAge := *utils.Cfg.ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
+ maxAge := *c.App.Config().ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
secure := false
if app.GetProtocol(r) == "https" {
@@ -249,11 +249,11 @@ func getMe(c *Context, w http.ResponseWriter, r *http.Request) {
c.RemoveSessionCookie(w, r)
l4g.Error(utils.T("api.user.get_me.getting.error"), c.Session.UserId)
return
- } else if c.HandleEtag(user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress), "Get Me", w, r) {
+ } else if c.HandleEtag(user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress), "Get Me", w, r) {
return
} else {
user.Sanitize(map[string]bool{})
- w.Header().Set(model.HEADER_ETAG_SERVER, user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress))
+ w.Header().Set(model.HEADER_ETAG_SERVER, user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress))
w.Write([]byte(user.ToJson()))
return
}
@@ -321,7 +321,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- etag := user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress)
+ etag := user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress)
if c.HandleEtag(etag, "Get User", w, r) {
return
@@ -343,12 +343,12 @@ func getByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
if user, err = c.App.GetUserByUsername(username); err != nil {
c.Err = err
return
- } else if c.HandleEtag(user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress), "Get By Username", w, r) {
+ } else if c.HandleEtag(user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress), "Get By Username", w, r) {
return
} else {
sanitizeProfile(c, user)
- w.Header().Set(model.HEADER_ETAG_SERVER, user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress))
+ w.Header().Set(model.HEADER_ETAG_SERVER, user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress))
w.Write([]byte(user.ToJson()))
return
}
@@ -361,12 +361,12 @@ func getByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
if user, err := c.App.GetUserByEmail(email); err != nil {
c.Err = err
return
- } else if c.HandleEtag(user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress), "Get By Email", w, r) {
+ } else if c.HandleEtag(user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress), "Get By Email", w, r) {
return
} else {
sanitizeProfile(c, user)
- w.Header().Set(model.HEADER_ETAG_SERVER, user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress))
+ w.Header().Set(model.HEADER_ETAG_SERVER, user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress))
w.Write([]byte(user.ToJson()))
return
}
@@ -579,17 +579,17 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
}
func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*c.App.Config().FileSettings.DriverName) == 0 {
c.Err = model.NewAppError("uploadProfileImage", "api.user.upload_profile_user.storage.app_error", nil, "", http.StatusNotImplemented)
return
}
- if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
+ if r.ContentLength > *c.App.Config().FileSettings.MaxFileSize {
c.Err = model.NewAppError("uploadProfileImage", "api.user.upload_profile_user.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
return
}
- if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil {
+ if err := r.ParseMultipartForm(*c.App.Config().FileSettings.MaxFileSize); err != nil {
c.Err = model.NewAppError("uploadProfileImage", "api.user.upload_profile_user.parse.app_error", nil, "", http.StatusBadRequest)
return
}
@@ -830,7 +830,7 @@ func updateUserNotify(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAuditWithUserId(ruser.Id, "")
- options := utils.Cfg.GetSanitizeOptions()
+ options := c.App.Config().GetSanitizeOptions()
options["passwordupdate"] = false
ruser.Sanitize(options)
w.Write([]byte(ruser.ToJson()))
@@ -1100,7 +1100,7 @@ func updateMfa(c *Context, w http.ResponseWriter, r *http.Request) {
}
func checkMfa(c *Context, w http.ResponseWriter, r *http.Request) {
- if !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication {
+ if !utils.IsLicensed() || !*utils.License().Features.MFA || !*c.App.Config().ServiceSettings.EnableMultifactorAuthentication {
rdata := map[string]string{}
rdata["mfa_required"] = "false"
w.Write([]byte(model.MapToJson(rdata)))
@@ -1249,7 +1249,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
}
func sanitizeProfile(c *Context, user *model.User) *model.User {
- options := utils.Cfg.GetSanitizeOptions()
+ options := c.App.Config().GetSanitizeOptions()
if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
options["email"] = true
@@ -1288,8 +1288,8 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
searchOptions[store.USER_SEARCH_OPTION_ALLOW_INACTIVE] = props.AllowInactive
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
- hideFullName := !utils.Cfg.PrivacySettings.ShowFullName
- hideEmail := !utils.Cfg.PrivacySettings.ShowEmailAddress
+ hideFullName := !c.App.Config().PrivacySettings.ShowFullName
+ hideEmail := !c.App.Config().PrivacySettings.ShowEmailAddress
if hideFullName && hideEmail {
searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME] = true
@@ -1348,7 +1348,7 @@ func autocompleteUsersInChannel(c *Context, w http.ResponseWriter, r *http.Reque
searchOptions := map[string]bool{}
- hideFullName := !utils.Cfg.PrivacySettings.ShowFullName
+ hideFullName := !c.App.Config().PrivacySettings.ShowFullName
if hideFullName && !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME] = true
} else {
@@ -1378,7 +1378,7 @@ func autocompleteUsersInTeam(c *Context, w http.ResponseWriter, r *http.Request)
searchOptions := map[string]bool{}
- hideFullName := !utils.Cfg.PrivacySettings.ShowFullName
+ hideFullName := !c.App.Config().PrivacySettings.ShowFullName
if hideFullName && !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME] = true
} else {
@@ -1399,7 +1399,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
searchOptions := map[string]bool{}
- hideFullName := !utils.Cfg.PrivacySettings.ShowFullName
+ hideFullName := !c.App.Config().PrivacySettings.ShowFullName
if hideFullName && !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME] = true
} else {
diff --git a/api/user_test.go b/api/user_test.go
index 52120d5f2..c339d3346 100644
--- a/api/user_test.go
+++ b/api/user_test.go
@@ -89,18 +89,18 @@ func TestLogin(t *testing.T) {
Client := th.BasicClient
- enableSignInWithEmail := *utils.Cfg.EmailSettings.EnableSignInWithEmail
- enableSignInWithUsername := *utils.Cfg.EmailSettings.EnableSignInWithUsername
- enableLdap := *utils.Cfg.LdapSettings.Enable
+ enableSignInWithEmail := *th.App.Config().EmailSettings.EnableSignInWithEmail
+ enableSignInWithUsername := *th.App.Config().EmailSettings.EnableSignInWithUsername
+ enableLdap := *th.App.Config().LdapSettings.Enable
defer func() {
- *utils.Cfg.EmailSettings.EnableSignInWithEmail = enableSignInWithEmail
- *utils.Cfg.EmailSettings.EnableSignInWithUsername = enableSignInWithUsername
- *utils.Cfg.LdapSettings.Enable = enableLdap
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignInWithEmail = enableSignInWithEmail })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignInWithUsername = enableSignInWithUsername })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.LdapSettings.Enable = enableLdap })
}()
- *utils.Cfg.EmailSettings.EnableSignInWithEmail = false
- *utils.Cfg.EmailSettings.EnableSignInWithUsername = false
- *utils.Cfg.LdapSettings.Enable = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignInWithEmail = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignInWithUsername = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.LdapSettings.Enable = false })
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
rteam, _ := Client.CreateTeam(&team)
@@ -127,7 +127,7 @@ func TestLogin(t *testing.T) {
t.Fatal("shouldn't be able to log in by email when disabled")
}
- *utils.Cfg.EmailSettings.EnableSignInWithEmail = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignInWithEmail = true })
if result, err := Client.Login(user.Email, user.Password); err != nil {
t.Fatal(err)
} else {
@@ -140,7 +140,7 @@ func TestLogin(t *testing.T) {
t.Fatal("shouldn't be able to log in by username when disabled")
}
- *utils.Cfg.EmailSettings.EnableSignInWithUsername = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignInWithUsername = true })
if result, err := Client.Login(user.Username, user.Password); err != nil {
t.Fatal(err)
} else {
@@ -186,7 +186,7 @@ func TestLogin(t *testing.T) {
props["display_name"] = rteam2.Data.(*model.Team).DisplayName
props["time"] = fmt.Sprintf("%v", model.GetMillis())
data := model.MapToJson(props)
- hash := utils.HashSha256(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
+ hash := utils.HashSha256(fmt.Sprintf("%v:%v", data, th.App.Config().EmailSettings.InviteSalt))
ruser2, err := Client.CreateUserFromSignup(&user2, data, hash)
if err != nil {
@@ -272,14 +272,14 @@ func TestPasswordGuessLockout(t *testing.T) {
user := th.BasicUser
Client.Must(Client.Logout())
- enableSignInWithEmail := *utils.Cfg.EmailSettings.EnableSignInWithEmail
- passwordAttempts := *utils.Cfg.ServiceSettings.MaximumLoginAttempts
+ enableSignInWithEmail := *th.App.Config().EmailSettings.EnableSignInWithEmail
+ passwordAttempts := *th.App.Config().ServiceSettings.MaximumLoginAttempts
defer func() {
- *utils.Cfg.EmailSettings.EnableSignInWithEmail = enableSignInWithEmail
- *utils.Cfg.ServiceSettings.MaximumLoginAttempts = passwordAttempts
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignInWithEmail = enableSignInWithEmail })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.MaximumLoginAttempts = passwordAttempts })
}()
- *utils.Cfg.EmailSettings.EnableSignInWithEmail = true
- *utils.Cfg.ServiceSettings.MaximumLoginAttempts = 2
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignInWithEmail = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.MaximumLoginAttempts = 2 })
// OK to log in
if _, err := Client.Login(user.Username, user.Password); err != nil {
@@ -410,14 +410,14 @@ func TestGetUser(t *testing.T) {
t.Fatal("shouldn't exist")
}
- emailPrivacy := utils.Cfg.PrivacySettings.ShowEmailAddress
- namePrivacy := utils.Cfg.PrivacySettings.ShowFullName
+ emailPrivacy := th.App.Config().PrivacySettings.ShowEmailAddress
+ namePrivacy := th.App.Config().PrivacySettings.ShowFullName
defer func() {
- utils.Cfg.PrivacySettings.ShowEmailAddress = emailPrivacy
- utils.Cfg.PrivacySettings.ShowFullName = namePrivacy
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = emailPrivacy })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = namePrivacy })
}()
- utils.Cfg.PrivacySettings.ShowEmailAddress = false
- utils.Cfg.PrivacySettings.ShowFullName = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = false })
if result, err := Client.GetUser(ruser2.Data.(*model.User).Id, ""); err != nil {
t.Fatal(err)
@@ -440,8 +440,8 @@ func TestGetUser(t *testing.T) {
}
}
- utils.Cfg.PrivacySettings.ShowEmailAddress = true
- utils.Cfg.PrivacySettings.ShowFullName = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = true })
if result, err := Client.GetUser(ruser2.Data.(*model.User).Id, ""); err != nil {
t.Fatal(err)
@@ -517,12 +517,12 @@ func TestGetProfiles(t *testing.T) {
th.BasicClient.Must(th.BasicClient.CreateDirectChannel(th.BasicUser2.Id))
- prevShowEmail := utils.Cfg.PrivacySettings.ShowEmailAddress
+ prevShowEmail := th.App.Config().PrivacySettings.ShowEmailAddress
defer func() {
- utils.Cfg.PrivacySettings.ShowEmailAddress = prevShowEmail
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = prevShowEmail })
}()
- utils.Cfg.PrivacySettings.ShowEmailAddress = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = true })
if result, err := th.BasicClient.GetProfiles(0, 100, ""); err != nil {
t.Fatal(err)
@@ -549,7 +549,7 @@ func TestGetProfiles(t *testing.T) {
}
}
- utils.Cfg.PrivacySettings.ShowEmailAddress = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false })
if result, err := th.BasicClient.GetProfiles(0, 100, ""); err != nil {
t.Fatal(err)
@@ -572,12 +572,12 @@ func TestGetProfilesByIds(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- prevShowEmail := utils.Cfg.PrivacySettings.ShowEmailAddress
+ prevShowEmail := th.App.Config().PrivacySettings.ShowEmailAddress
defer func() {
- utils.Cfg.PrivacySettings.ShowEmailAddress = prevShowEmail
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = prevShowEmail })
}()
- utils.Cfg.PrivacySettings.ShowEmailAddress = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = true })
if result, err := th.BasicClient.GetProfilesByIds([]string{th.BasicUser.Id}); err != nil {
t.Fatal(err)
@@ -595,7 +595,7 @@ func TestGetProfilesByIds(t *testing.T) {
}
}
- utils.Cfg.PrivacySettings.ShowEmailAddress = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false })
if result, err := th.BasicClient.GetProfilesByIds([]string{th.BasicUser.Id}); err != nil {
t.Fatal(err)
@@ -709,23 +709,23 @@ func TestUserCreateImage(t *testing.T) {
}
}
- if *utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
- endpoint := utils.Cfg.FileSettings.AmazonS3Endpoint
- accessKey := utils.Cfg.FileSettings.AmazonS3AccessKeyId
- secretKey := utils.Cfg.FileSettings.AmazonS3SecretAccessKey
- secure := *utils.Cfg.FileSettings.AmazonS3SSL
- signV2 := *utils.Cfg.FileSettings.AmazonS3SignV2
- region := utils.Cfg.FileSettings.AmazonS3Region
+ if *th.App.Config().FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
+ endpoint := th.App.Config().FileSettings.AmazonS3Endpoint
+ accessKey := th.App.Config().FileSettings.AmazonS3AccessKeyId
+ secretKey := th.App.Config().FileSettings.AmazonS3SecretAccessKey
+ secure := *th.App.Config().FileSettings.AmazonS3SSL
+ signV2 := *th.App.Config().FileSettings.AmazonS3SignV2
+ region := th.App.Config().FileSettings.AmazonS3Region
s3Clnt, err := s3New(endpoint, accessKey, secretKey, secure, signV2, region)
if err != nil {
t.Fatal(err)
}
- bucket := utils.Cfg.FileSettings.AmazonS3Bucket
+ bucket := th.App.Config().FileSettings.AmazonS3Bucket
if err = s3Clnt.RemoveObject(bucket, "/users/"+user.Id+"/profile.png"); err != nil {
t.Fatal(err)
}
} else {
- path := utils.Cfg.FileSettings.Directory + "/users/" + user.Id + "/profile.png"
+ path := th.App.Config().FileSettings.Directory + "/users/" + user.Id + "/profile.png"
if err := os.Remove(path); err != nil {
t.Fatal("Couldn't remove file at " + path)
}
@@ -748,7 +748,7 @@ func TestUserUploadProfileImage(t *testing.T) {
th.LinkUserToTeam(user, team)
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
- if *utils.Cfg.FileSettings.DriverName != "" {
+ if *th.App.Config().FileSettings.DriverName != "" {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
@@ -817,23 +817,23 @@ func TestUserUploadProfileImage(t *testing.T) {
Client.DoApiGet("/users/"+user.Id+"/image", "", "")
- if *utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
- endpoint := utils.Cfg.FileSettings.AmazonS3Endpoint
- accessKey := utils.Cfg.FileSettings.AmazonS3AccessKeyId
- secretKey := utils.Cfg.FileSettings.AmazonS3SecretAccessKey
- secure := *utils.Cfg.FileSettings.AmazonS3SSL
- signV2 := *utils.Cfg.FileSettings.AmazonS3SignV2
- region := utils.Cfg.FileSettings.AmazonS3Region
+ if *th.App.Config().FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
+ endpoint := th.App.Config().FileSettings.AmazonS3Endpoint
+ accessKey := th.App.Config().FileSettings.AmazonS3AccessKeyId
+ secretKey := th.App.Config().FileSettings.AmazonS3SecretAccessKey
+ secure := *th.App.Config().FileSettings.AmazonS3SSL
+ signV2 := *th.App.Config().FileSettings.AmazonS3SignV2
+ region := th.App.Config().FileSettings.AmazonS3Region
s3Clnt, err := s3New(endpoint, accessKey, secretKey, secure, signV2, region)
if err != nil {
t.Fatal(err)
}
- bucket := utils.Cfg.FileSettings.AmazonS3Bucket
+ bucket := th.App.Config().FileSettings.AmazonS3Bucket
if err = s3Clnt.RemoveObject(bucket, "/users/"+user.Id+"/profile.png"); err != nil {
t.Fatal(err)
}
} else {
- path := utils.Cfg.FileSettings.Directory + "users/" + user.Id + "/profile.png"
+ path := th.App.Config().FileSettings.Directory + "users/" + user.Id + "/profile.png"
if err := os.Remove(path); err != nil {
t.Fatal("Couldn't remove file at " + path)
}
@@ -960,11 +960,11 @@ func TestUserUpdatePassword(t *testing.T) {
}
// Test lockout
- passwordAttempts := *utils.Cfg.ServiceSettings.MaximumLoginAttempts
+ passwordAttempts := *th.App.Config().ServiceSettings.MaximumLoginAttempts
defer func() {
- *utils.Cfg.ServiceSettings.MaximumLoginAttempts = passwordAttempts
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.MaximumLoginAttempts = passwordAttempts })
}()
- *utils.Cfg.ServiceSettings.MaximumLoginAttempts = 2
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.MaximumLoginAttempts = 2 })
// Fail twice
if _, err := Client.UpdateUserPassword(user.Id, "badpwd", "newpwd"); err == nil {
@@ -1887,11 +1887,11 @@ func TestUpdateMfa(t *testing.T) {
isLicensed := utils.IsLicensed()
license := utils.License()
- enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication
+ enableMfa := *th.App.Config().ServiceSettings.EnableMultifactorAuthentication
defer func() {
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
- *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa })
}()
utils.SetIsLicensed(false)
utils.SetLicense(&model.License{Features: &model.Features{}})
@@ -1925,7 +1925,7 @@ func TestUpdateMfa(t *testing.T) {
utils.SetIsLicensed(true)
*utils.License().Features.MFA = true
- *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = true })
if _, err := Client.UpdateMfa(true, "123456"); err == nil {
t.Fatal("should have failed - bad token")
@@ -2059,12 +2059,12 @@ func TestGetProfilesInChannel(t *testing.T) {
Client := th.BasicClient
- prevShowEmail := utils.Cfg.PrivacySettings.ShowEmailAddress
+ prevShowEmail := th.App.Config().PrivacySettings.ShowEmailAddress
defer func() {
- utils.Cfg.PrivacySettings.ShowEmailAddress = prevShowEmail
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = prevShowEmail })
}()
- utils.Cfg.PrivacySettings.ShowEmailAddress = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = true })
if result, err := Client.GetProfilesInChannel(th.BasicChannel.Id, 0, 100, ""); err != nil {
t.Fatal(err)
@@ -2090,7 +2090,7 @@ func TestGetProfilesInChannel(t *testing.T) {
Client.Must(Client.JoinChannel(th.BasicChannel.Id))
- utils.Cfg.PrivacySettings.ShowEmailAddress = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false })
if result, err := Client.GetProfilesInChannel(th.BasicChannel.Id, 0, 100, ""); err != nil {
t.Fatal(err)
@@ -2133,12 +2133,12 @@ func TestGetProfilesNotInChannel(t *testing.T) {
Client := th.BasicClient
- prevShowEmail := utils.Cfg.PrivacySettings.ShowEmailAddress
+ prevShowEmail := th.App.Config().PrivacySettings.ShowEmailAddress
defer func() {
- utils.Cfg.PrivacySettings.ShowEmailAddress = prevShowEmail
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = prevShowEmail })
}()
- utils.Cfg.PrivacySettings.ShowEmailAddress = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = true })
if result, err := Client.GetProfilesNotInChannel(th.BasicChannel.Id, 0, 100, ""); err != nil {
t.Fatal(err)
@@ -2176,7 +2176,7 @@ func TestGetProfilesNotInChannel(t *testing.T) {
Client.Must(Client.JoinChannel(th.BasicChannel.Id))
- utils.Cfg.PrivacySettings.ShowEmailAddress = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false })
if result, err := Client.GetProfilesNotInChannel(th.BasicChannel.Id, 0, 100, ""); err != nil {
t.Fatal(err)
@@ -2359,14 +2359,14 @@ func TestSearchUsers(t *testing.T) {
}
}
- emailPrivacy := utils.Cfg.PrivacySettings.ShowEmailAddress
- namePrivacy := utils.Cfg.PrivacySettings.ShowFullName
+ emailPrivacy := th.App.Config().PrivacySettings.ShowEmailAddress
+ namePrivacy := th.App.Config().PrivacySettings.ShowFullName
defer func() {
- utils.Cfg.PrivacySettings.ShowEmailAddress = emailPrivacy
- utils.Cfg.PrivacySettings.ShowFullName = namePrivacy
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = emailPrivacy })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = namePrivacy })
}()
- utils.Cfg.PrivacySettings.ShowEmailAddress = false
- utils.Cfg.PrivacySettings.ShowFullName = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = false })
privacyEmailPrefix := strings.ToLower(model.NewId())
privacyUser := &model.User{Email: privacyEmailPrefix + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", FirstName: model.NewId(), LastName: "Jimmers"}
@@ -2390,7 +2390,7 @@ func TestSearchUsers(t *testing.T) {
}
}
- utils.Cfg.PrivacySettings.ShowEmailAddress = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = true })
if result, err := Client.SearchUsers(model.UserSearch{Term: privacyUser.FirstName}); err != nil {
t.Fatal(err)
@@ -2409,8 +2409,8 @@ func TestSearchUsers(t *testing.T) {
}
}
- utils.Cfg.PrivacySettings.ShowEmailAddress = false
- utils.Cfg.PrivacySettings.ShowFullName = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = true })
if result, err := Client.SearchUsers(model.UserSearch{Term: privacyUser.FirstName}); err != nil {
t.Fatal(err)
@@ -2446,7 +2446,7 @@ func TestSearchUsers(t *testing.T) {
}
}
- utils.Cfg.PrivacySettings.ShowEmailAddress = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = true })
if result, err := Client.SearchUsers(model.UserSearch{Term: privacyEmailPrefix}); err != nil {
t.Fatal(err)
@@ -2653,11 +2653,11 @@ func TestAutocompleteUsers(t *testing.T) {
}
}
- namePrivacy := utils.Cfg.PrivacySettings.ShowFullName
+ namePrivacy := th.App.Config().PrivacySettings.ShowFullName
defer func() {
- utils.Cfg.PrivacySettings.ShowFullName = namePrivacy
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = namePrivacy })
}()
- utils.Cfg.PrivacySettings.ShowFullName = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = false })
privacyUser := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", FirstName: model.NewId(), LastName: "Jimmers"}
privacyUser = Client.Must(Client.CreateUser(privacyUser, "")).Data.(*model.User)
@@ -2712,15 +2712,15 @@ func TestGetByUsername(t *testing.T) {
}
}
- emailPrivacy := utils.Cfg.PrivacySettings.ShowEmailAddress
- namePrivacy := utils.Cfg.PrivacySettings.ShowFullName
+ emailPrivacy := th.App.Config().PrivacySettings.ShowEmailAddress
+ namePrivacy := th.App.Config().PrivacySettings.ShowFullName
defer func() {
- utils.Cfg.PrivacySettings.ShowEmailAddress = emailPrivacy
- utils.Cfg.PrivacySettings.ShowFullName = namePrivacy
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = emailPrivacy })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = namePrivacy })
}()
- utils.Cfg.PrivacySettings.ShowEmailAddress = false
- utils.Cfg.PrivacySettings.ShowFullName = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = false })
if result, err := Client.GetByUsername(th.BasicUser2.Username, ""); err != nil {
t.Fatal(err)
@@ -2749,15 +2749,15 @@ func TestGetByEmail(t *testing.T) {
t.Fatal("Failed to get user by email")
}
- emailPrivacy := utils.Cfg.PrivacySettings.ShowEmailAddress
- namePrivacy := utils.Cfg.PrivacySettings.ShowFullName
+ emailPrivacy := th.App.Config().PrivacySettings.ShowEmailAddress
+ namePrivacy := th.App.Config().PrivacySettings.ShowFullName
defer func() {
- utils.Cfg.PrivacySettings.ShowEmailAddress = emailPrivacy
- utils.Cfg.PrivacySettings.ShowFullName = namePrivacy
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = emailPrivacy })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = namePrivacy })
}()
- utils.Cfg.PrivacySettings.ShowEmailAddress = false
- utils.Cfg.PrivacySettings.ShowFullName = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = false })
if user, respMetdata := Client.GetByEmail(th.BasicUser2.Email, ""); respMetdata.Error != nil {
t.Fatal(respMetdata.Error)
diff --git a/api/webhook_test.go b/api/webhook_test.go
index cb58fde76..6aa857af8 100644
--- a/api/webhook_test.go
+++ b/api/webhook_test.go
@@ -25,15 +25,15 @@ func TestCreateIncomingHook(t *testing.T) {
user2 := th.CreateUser(Client)
th.LinkUserToTeam(user2, team)
- enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
- enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
+ enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
- utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
hook := &model.IncomingWebhook{ChannelId: channel1.Id}
@@ -100,7 +100,7 @@ func TestCreateIncomingHook(t *testing.T) {
t.Fatal(err)
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.CreateIncomingWebhook(hook); err != nil {
@@ -113,7 +113,7 @@ func TestCreateIncomingHook(t *testing.T) {
t.Fatal("should have failed - channel is private and not a member")
}
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false })
if _, err := Client.CreateIncomingWebhook(hook); err == nil {
t.Fatal("should have errored - webhooks turned off")
@@ -139,16 +139,16 @@ func TestUpdateIncomingHook(t *testing.T) {
th.LinkUserToTeam(user3, team2)
th.UpdateUserToTeamAdmin(user3, team2)
- enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
- enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
+ enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
- utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
hook := createIncomingWebhook(channel1.Id, Client, t)
@@ -229,10 +229,10 @@ func TestUpdateIncomingHook(t *testing.T) {
}
})
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
t.Run("OnlyAdminIntegrationsDisabled", func(t *testing.T) {
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
t.Run("UpdateHookOfSameUser", func(t *testing.T) {
@@ -255,7 +255,7 @@ func TestUpdateIncomingHook(t *testing.T) {
})
})
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
Client.Logout()
@@ -275,7 +275,7 @@ func TestUpdateIncomingHook(t *testing.T) {
})
t.Run("IncomingHooksDisabled", func(t *testing.T) {
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false })
if _, err := Client.UpdateIncomingWebhook(hook); err == nil {
t.Fatal("should have failed - incoming hooks are disabled")
}
@@ -338,15 +338,15 @@ func TestListIncomingHooks(t *testing.T) {
user2 := th.CreateUser(Client)
th.LinkUserToTeam(user2, team)
- enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
- enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
+ enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
- utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
hook1 := &model.IncomingWebhook{ChannelId: channel1.Id}
@@ -373,14 +373,14 @@ func TestListIncomingHooks(t *testing.T) {
t.Fatal("should have errored - not system/team admin")
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.ListIncomingWebhooks(); err != nil {
t.Fatal(err)
}
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false })
if _, err := Client.ListIncomingWebhooks(); err == nil {
t.Fatal("should have errored - webhooks turned off")
@@ -397,15 +397,15 @@ func TestDeleteIncomingHook(t *testing.T) {
user2 := th.CreateUser(Client)
th.LinkUserToTeam(user2, team)
- enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
- enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
+ enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
- utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
hook := &model.IncomingWebhook{ChannelId: channel1.Id}
@@ -439,7 +439,7 @@ func TestDeleteIncomingHook(t *testing.T) {
t.Fatal("should have failed - not system/team admin")
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.DeleteIncomingWebhook(hook.Id); err == nil {
@@ -453,7 +453,7 @@ func TestDeleteIncomingHook(t *testing.T) {
t.Fatal(err)
}
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false })
if _, err := Client.DeleteIncomingWebhook(hook.Id); err == nil {
t.Fatal("should have errored - webhooks turned off")
@@ -475,15 +475,15 @@ func TestCreateOutgoingHook(t *testing.T) {
user3 := th.CreateUser(Client)
th.LinkUserToTeam(user3, team2)
- enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
- enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableOutgoingHooks := th.App.Config().ServiceSettings.EnableOutgoingWebhooks
+ enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
- utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
@@ -554,7 +554,7 @@ func TestCreateOutgoingHook(t *testing.T) {
t.Fatal("should have failed - not system/team admin")
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.CreateOutgoingWebhook(hook); err != nil {
@@ -569,7 +569,7 @@ func TestCreateOutgoingHook(t *testing.T) {
t.Fatal("should have failed - wrong team")
}
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = false })
if _, err := Client.CreateOutgoingWebhook(hook); err == nil {
t.Fatal("should have errored - webhooks turned off")
@@ -586,15 +586,15 @@ func TestListOutgoingHooks(t *testing.T) {
user2 := th.CreateUser(Client)
th.LinkUserToTeam(user2, team)
- enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
- enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableOutgoingHooks := th.App.Config().ServiceSettings.EnableOutgoingWebhooks
+ enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
- utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
hook1 := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
@@ -621,14 +621,14 @@ func TestListOutgoingHooks(t *testing.T) {
t.Fatal("should have failed - not system/team admin")
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.ListOutgoingWebhooks(); err != nil {
t.Fatal(err)
}
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = false })
if _, err := Client.ListOutgoingWebhooks(); err == nil {
t.Fatal("should have errored - webhooks turned off")
@@ -651,16 +651,16 @@ func TestUpdateOutgoingHook(t *testing.T) {
user3 := th.CreateUser(Client)
th.LinkUserToTeam(user3, team2)
- enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
- enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableOutgoingHooks := th.App.Config().ServiceSettings.EnableOutgoingWebhooks
+ enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
- utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
hook := createOutgoingWebhook(channel1.Id, []string{"http://nowhere.com"}, []string{"cats"}, Client, t)
@@ -669,13 +669,13 @@ func TestUpdateOutgoingHook(t *testing.T) {
hook.DisplayName = "Cats"
hook.Description = "Get me some cats"
t.Run("OutgoingHooksDisabled", func(t *testing.T) {
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = false })
if _, err := Client.UpdateOutgoingWebhook(hook); err == nil {
t.Fatal("should have failed - outgoing webhooks disabled")
}
})
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
t.Run("UpdateOutgoingWebhook", func(t *testing.T) {
if result, err := Client.UpdateOutgoingWebhook(hook); err != nil {
t.Fatal("failed to update outgoing web hook")
@@ -734,7 +734,7 @@ func TestUpdateOutgoingHook(t *testing.T) {
t.Fatal("should have failed - user does not have permissions to manage webhooks")
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
hook2 := createOutgoingWebhook(channel1.Id, []string{"http://nowhereelse.com"}, []string{"dogs"}, Client, t)
@@ -742,7 +742,7 @@ func TestUpdateOutgoingHook(t *testing.T) {
t.Fatal("update webhook failed when admin only integrations is turned off")
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
Client.Logout()
@@ -829,15 +829,15 @@ func TestDeleteOutgoingHook(t *testing.T) {
user2 := th.CreateUser(Client)
th.LinkUserToTeam(user2, team)
- enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
- enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableOutgoingHooks := th.App.Config().ServiceSettings.EnableOutgoingWebhooks
+ enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
- utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
@@ -871,7 +871,7 @@ func TestDeleteOutgoingHook(t *testing.T) {
t.Fatal("should have failed - not system/team admin")
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.DeleteOutgoingWebhook(hook.Id); err == nil {
@@ -885,7 +885,7 @@ func TestDeleteOutgoingHook(t *testing.T) {
t.Fatal(err)
}
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = false })
if _, err := Client.DeleteOutgoingWebhook(hook.Id); err == nil {
t.Fatal("should have errored - webhooks turned off")
@@ -905,15 +905,15 @@ func TestRegenOutgoingHookToken(t *testing.T) {
user3 := th.CreateUser(Client)
th.LinkUserToTeam(user3, team2)
- enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
- enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ enableOutgoingHooks := th.App.Config().ServiceSettings.EnableOutgoingWebhooks
+ enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
- utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
utils.SetDefaultRolesBasedOnConfig()
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
@@ -948,7 +948,7 @@ func TestRegenOutgoingHookToken(t *testing.T) {
t.Fatal("should have failed - not system/team admin")
}
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
utils.SetDefaultRolesBasedOnConfig()
hook = &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
@@ -966,7 +966,7 @@ func TestRegenOutgoingHookToken(t *testing.T) {
t.Fatal("should have failed - wrong team")
}
- utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = false })
if _, err := Client.RegenOutgoingWebhookToken(hook.Id); err == nil {
t.Fatal("should have errored - webhooks turned off")
@@ -983,11 +983,11 @@ func TestIncomingWebhooks(t *testing.T) {
user2 := th.CreateUser(Client)
th.LinkUserToTeam(user2, team)
- enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
+ enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
defer func() {
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
}()
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
hook := &model.IncomingWebhook{ChannelId: channel1.Id}
hook = Client.Must(Client.CreateIncomingWebhook(hook)).Data.(*model.IncomingWebhook)
@@ -1030,14 +1030,14 @@ func TestIncomingWebhooks(t *testing.T) {
isLicensed := utils.IsLicensed()
license := utils.License()
- disableTownSquareReadOnly := utils.Cfg.TeamSettings.ExperimentalTownSquareIsReadOnly
+ disableTownSquareReadOnly := th.App.Config().TeamSettings.ExperimentalTownSquareIsReadOnly
defer func() {
- utils.Cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = disableTownSquareReadOnly
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = disableTownSquareReadOnly })
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- *utils.Cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
utils.SetDefaultRolesBasedOnConfig()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
@@ -1134,7 +1134,7 @@ func TestIncomingWebhooks(t *testing.T) {
t.Fatal("should have failed with bad request - attachment too long")
}
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = false
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false })
if _, err := Client.DoPost(url, "{\"text\":\"this is a test\"}", "application/json"); err == nil {
t.Fatal("should have failed - webhooks turned off")
diff --git a/api/websocket_test.go b/api/websocket_test.go
index 42604124b..0a39a012f 100644
--- a/api/websocket_test.go
+++ b/api/websocket_test.go
@@ -13,7 +13,6 @@ import (
"github.com/gorilla/websocket"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
)
/*func TestWebSocketAuthentication(t *testing.T) {
@@ -343,7 +342,7 @@ func TestWebsocketOriginSecurity(t *testing.T) {
}
// Should succeed now because open CORS
- *utils.Cfg.ServiceSettings.AllowCorsFrom = "*"
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowCorsFrom = "*" })
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX_V3+"/users/websocket", http.Header{
"Origin": []string{"http://www.evil.com"},
})
@@ -352,7 +351,7 @@ func TestWebsocketOriginSecurity(t *testing.T) {
}
// Should succeed now because matching CORS
- *utils.Cfg.ServiceSettings.AllowCorsFrom = "http://www.evil.com"
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowCorsFrom = "http://www.evil.com" })
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX_V3+"/users/websocket", http.Header{
"Origin": []string{"http://www.evil.com"},
})
@@ -361,7 +360,7 @@ func TestWebsocketOriginSecurity(t *testing.T) {
}
// Should fail because non-matching CORS
- *utils.Cfg.ServiceSettings.AllowCorsFrom = "http://www.good.com"
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowCorsFrom = "http://www.good.com" })
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX_V3+"/users/websocket", http.Header{
"Origin": []string{"http://www.evil.com"},
})
@@ -370,7 +369,7 @@ func TestWebsocketOriginSecurity(t *testing.T) {
}
// Should fail because non-matching CORS
- *utils.Cfg.ServiceSettings.AllowCorsFrom = "http://www.good.com"
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowCorsFrom = "http://www.good.com" })
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX_V3+"/users/websocket", http.Header{
"Origin": []string{"http://www.good.co"},
})
@@ -378,5 +377,5 @@ func TestWebsocketOriginSecurity(t *testing.T) {
t.Fatal("Should have errored because Origin does not match host! SECURITY ISSUE!")
}
- *utils.Cfg.ServiceSettings.AllowCorsFrom = ""
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowCorsFrom = "" })
}