From 87ad7174344a3b131f9100af579ae6b0f8a60a00 Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Mon, 23 Sep 2024 10:17:07 +0200 Subject: [PATCH] [MM-57194] Don't return config values from plugins that are not installed (#28260) --- server/public/model/config.go | 6 ++-- server/public/model/config_test.go | 49 ------------------------------ 2 files changed, 3 insertions(+), 52 deletions(-) diff --git a/server/public/model/config.go b/server/public/model/config.go index 7a7cd1d763..0cdd7e46a3 100644 --- a/server/public/model/config.go +++ b/server/public/model/config.go @@ -3226,9 +3226,9 @@ func (s *PluginSettings) Sanitize(pluginManifests []*Manifest) { for key := range settings { if manifest == nil { - // Sanitize plugin settings for plugins that are not installed - settings[key] = FakeSetting - continue + // Don't return plugin settings for plugins that are not installed + delete(s.Plugins, id) + break } for _, definedSetting := range manifest.SettingsSchema.Settings { diff --git a/server/public/model/config_test.go b/server/public/model/config_test.go index a1cdef2247..82fd7ba64a 100644 --- a/server/public/model/config_test.go +++ b/server/public/model/config_test.go @@ -1488,9 +1488,6 @@ func TestPluginSettingsSanitize(t *testing.T) { "secrettext": FakeSetting, "secretnumber": FakeSetting, }, - "another.plugin": { - "somesetting": FakeSetting, - }, }, }, "two plugins installed": { @@ -1543,9 +1540,6 @@ func TestPluginSettingsSanitize(t *testing.T) { }, } { t.Run(name, func(t *testing.T) { - name := name // TODO: Remove once go1.22 is used - tc := tc // TODO: Remove once go1.22 is used - if name != "one plugin installed" { return } @@ -1559,49 +1553,6 @@ func TestPluginSettingsSanitize(t *testing.T) { assert.Equal(t, tc.expected, c.Plugins, name) }) } - - t.Run("one plugin installed, two in the config", func(t *testing.T) { - c := PluginSettings{} - c.SetDefaults(*NewLogSettings()) - c.Plugins = plugins - - c.Sanitize([]*Manifest{ - { - Id: "plugin.id", - SettingsSchema: &PluginSettingsSchema{ - Settings: []*PluginSetting{ - { - Key: "somesetting", - Type: "text", - Secret: false, - }, - { - Key: "secrettext", - Type: "text", - Secret: true, - }, - { - Key: "secretnumber", - Type: "number", - Secret: true, - }, - }, - }, - }, - }) - - expected := map[string]map[string]any{ - "plugin.id": { - "somesetting": "some value", - "secrettext": FakeSetting, - "secretnumber": FakeSetting, - }, - "another.plugin": { - "somesetting": FakeSetting, - }, - } - assert.Equal(t, expected, c.Plugins) - }) } func TestConfigFilteredByTag(t *testing.T) {