From dd1c8c22dc9f131d8e02f6f3be1daf975b76520d Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 13 Feb 2020 14:26:57 -0500 Subject: [PATCH] Fix panic when receiving a config to update to if some settings are not set (#13889) --- api4/config.go | 2 ++ api4/config_test.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/api4/config.go b/api4/config.go index 301870abbc..1914ea4b19 100644 --- a/api4/config.go +++ b/api4/config.go @@ -57,6 +57,8 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) { return } + cfg.SetDefaults() + if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) { c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) return diff --git a/api4/config_test.go b/api4/config_test.go index 6478ef1e75..ac41d52e29 100644 --- a/api4/config_test.go +++ b/api4/config_test.go @@ -103,6 +103,11 @@ func TestUpdateConfig(t *testing.T) { require.Equal(t, SiteName, cfg.TeamSettings.SiteName, "It should update the SiteName") + t.Run("Should set defaults for missing fields", func(t *testing.T) { + _, appErr := th.SystemAdminClient.DoApiPut(th.SystemAdminClient.GetConfigRoute(), `{"ServiceSettings":{}}`) + require.Nil(t, appErr) + }) + t.Run("Should fail with validation error if invalid config setting is passed", func(t *testing.T) { //Revert the change badcfg := cfg.Clone()