[MM-27836] Fix possible panic when patching config (#15262)

* Fix possible panic when updating/patching config

* Remove un-needed check
This commit is contained in:
Claudio Costa
2020-08-17 14:53:48 +02:00
committed by GitHub
parent 095e5d788b
commit 58c6eabf95
2 changed files with 7 additions and 1 deletions

View File

@@ -180,7 +180,7 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
appCfg := c.App.Config()
if *appCfg.ServiceSettings.SiteURL != "" && *cfg.ServiceSettings.SiteURL == "" {
if *appCfg.ServiceSettings.SiteURL != "" && (cfg.ServiceSettings.SiteURL == nil || *cfg.ServiceSettings.SiteURL == "") {
c.Err = model.NewAppError("patchConfig", "api.config.update_config.clear_siteurl.app_error", nil, "", http.StatusBadRequest)
return
}

View File

@@ -550,6 +550,12 @@ func TestPatchConfig(t *testing.T) {
cfg, resp = th.SystemAdminClient.GetConfig()
CheckNoError(t, resp)
require.Equal(t, nonEmptyURL, *cfg.ServiceSettings.SiteURL)
// Check that sending an empty config returns an error.
_, resp = th.SystemAdminClient.PatchConfig(&model.Config{})
require.NotNil(t, resp.Error)
CheckBadRequestStatus(t, resp)
assert.Equal(t, "api.config.update_config.clear_siteurl.app_error", resp.Error.Id)
})
}