mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
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:
parent
2e7080e68d
commit
5dee75553d
2 changed files with 17 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue