MM-15006: Returning informative errors on config validation (#10585)

* MM-15006: Returning informative errors on config validation

* Adding new unit test verifying the validation and correct response
This commit is contained in:
Jesús Espino 2019-04-11 08:57:25 +02:00 committed by GitHub
parent 2e7080e68d
commit 5dee75553d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -95,7 +95,13 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
err := c.App.SaveConfig(cfg, true)
err := cfg.IsValid()
if err != nil {
c.Err = err
return
}
err = c.App.SaveConfig(cfg, true)
if err != nil {
c.Err = err
return

View file

@ -111,6 +111,16 @@ func TestUpdateConfig(t *testing.T) {
require.Equal(t, SiteName, cfg.TeamSettings.SiteName, "It should update the SiteName")
t.Run("Should fail with validation error if invalid config setting is passed", func(t *testing.T) {
//Revert the change
badcfg := cfg.Clone()
badcfg.PasswordSettings.MinimumLength = model.NewInt(4)
badcfg.PasswordSettings.MinimumLength = model.NewInt(4)
_, resp = th.SystemAdminClient.UpdateConfig(badcfg)
CheckBadRequestStatus(t, resp)
CheckErrorMessage(t, resp, "model.config.is_valid.password_length.app_error")
})
t.Run("Should not be able to modify PluginSettings.EnableUploads", func(t *testing.T) {
oldEnableUploads := *th.App.Config().PluginSettings.EnableUploads
*cfg.PluginSettings.EnableUploads = !oldEnableUploads