From ffb3897c8c33de00d498be582c6239c7e49bc93e Mon Sep 17 00:00:00 2001 From: Shota Gvinepadze Date: Wed, 29 Jan 2020 18:39:00 +0400 Subject: [PATCH] Disable signatures modification through API (#13682) Co-authored-by: mattermod --- api4/config.go | 3 +++ api4/config_test.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/api4/config.go b/api4/config.go index 0515f14b91..04ae19bea4 100644 --- a/api4/config.go +++ b/api4/config.go @@ -82,6 +82,9 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) { // Do not allow plugin uploads to be toggled through the API cfg.PluginSettings.EnableUploads = appCfg.PluginSettings.EnableUploads + // Do not allow certificates to be changed through the API + cfg.PluginSettings.SignaturePublicKeyFiles = appCfg.PluginSettings.SignaturePublicKeyFiles + c.App.HandleMessageExportConfig(cfg, appCfg) err := cfg.IsValid() diff --git a/api4/config_test.go b/api4/config_test.go index d89c4764b9..7826dcfc0b 100644 --- a/api4/config_test.go +++ b/api4/config_test.go @@ -128,6 +128,22 @@ func TestUpdateConfig(t *testing.T) { assert.Equal(t, oldEnableUploads, *cfg.PluginSettings.EnableUploads) assert.Equal(t, oldEnableUploads, *th.App.Config().PluginSettings.EnableUploads) }) + + t.Run("Should not be able to modify PluginSettings.SignaturePublicKeyFiles", func(t *testing.T) { + oldPublicKeys := th.App.Config().PluginSettings.SignaturePublicKeyFiles + cfg.PluginSettings.SignaturePublicKeyFiles = append(cfg.PluginSettings.SignaturePublicKeyFiles, "new_signature") + + cfg, resp = th.SystemAdminClient.UpdateConfig(cfg) + CheckNoError(t, resp) + assert.Equal(t, oldPublicKeys, cfg.PluginSettings.SignaturePublicKeyFiles) + assert.Equal(t, oldPublicKeys, th.App.Config().PluginSettings.SignaturePublicKeyFiles) + + cfg.PluginSettings.SignaturePublicKeyFiles = nil + cfg, resp = th.SystemAdminClient.UpdateConfig(cfg) + CheckNoError(t, resp) + assert.Equal(t, oldPublicKeys, cfg.PluginSettings.SignaturePublicKeyFiles) + assert.Equal(t, oldPublicKeys, th.App.Config().PluginSettings.SignaturePublicKeyFiles) + }) } func TestUpdateConfigMessageExportSpecialHandling(t *testing.T) {