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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2e7080e68d
Коммит
5dee75553d
@@ -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 {
|
if err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -111,6 +111,16 @@ func TestUpdateConfig(t *testing.T) {
|
|||||||
|
|
||||||
require.Equal(t, SiteName, cfg.TeamSettings.SiteName, "It should update the SiteName")
|
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) {
|
t.Run("Should not be able to modify PluginSettings.EnableUploads", func(t *testing.T) {
|
||||||
oldEnableUploads := *th.App.Config().PluginSettings.EnableUploads
|
oldEnableUploads := *th.App.Config().PluginSettings.EnableUploads
|
||||||
*cfg.PluginSettings.EnableUploads = !oldEnableUploads
|
*cfg.PluginSettings.EnableUploads = !oldEnableUploads
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user