From 5dee75553d5d0d4becaf330c1ff5d54bd42f6b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Thu, 11 Apr 2019 08:57:25 +0200 Subject: [PATCH] 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 --- api4/config.go | 8 +++++++- api4/config_test.go | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api4/config.go b/api4/config.go index 815a3da3340..0be330cb948 100644 --- a/api4/config.go +++ b/api4/config.go @@ -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 diff --git a/api4/config_test.go b/api4/config_test.go index 89040c3c3a1..f2d2373ad50 100644 --- a/api4/config_test.go +++ b/api4/config_test.go @@ -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