[MM-57194] Don't return config values from plugins that are not installed (#28260)

Этот коммит содержится в:
Ben Schumacher
2024-09-23 10:17:07 +02:00
коммит произвёл GitHub
родитель 60b38bb91a
Коммит 87ad717434
2 изменённых файлов: 3 добавлений и 52 удалений

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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) {