Commit 8e19ba02 authored by Chris's avatar Chris Committed by GitHub

Reduce utils.Cfg references (#7650)

* app.UpdateConfig method

* test fix

* another test fix

* the config override option as-was is just error prone, remove it for now

* derp
parent 34a87fa8
......@@ -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
......
......@@ -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, "")
......
......@@ -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.")
}
......
......@@ -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 {
......
This diff is collapsed.
......@@ -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")
......
......@@ -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" {
......
......@@ -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",
......
......@@ -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
}
......
......@@ -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
}
......
......@@ -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