[MM-57194] Allow plugins to mark setting fields as secret (#27986)
Co-authored-by: Claudio Costa <cstcld91@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
84a0c09d56
Коммит
70fe2abea6
@@ -1387,7 +1387,7 @@ func TestConfigSanitize(t *testing.T) {
|
||||
QueryTimeLag: NewPointer("QueryTimeLag"),
|
||||
}}
|
||||
|
||||
c.Sanitize()
|
||||
c.Sanitize(nil)
|
||||
|
||||
assert.Equal(t, FakeSetting, *c.LdapSettings.BindPassword)
|
||||
assert.Equal(t, FakeSetting, *c.FileSettings.PublicLinkSalt)
|
||||
@@ -1409,12 +1409,201 @@ func TestConfigSanitize(t *testing.T) {
|
||||
t.Run("with default config", func(t *testing.T) {
|
||||
c := Config{}
|
||||
c.SetDefaults()
|
||||
c.Sanitize()
|
||||
c.Sanitize(nil)
|
||||
|
||||
assert.Len(t, c.SqlSettings.ReplicaLagSettings, 0)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPluginSettingsSanitize(t *testing.T) {
|
||||
plugins := map[string]map[string]any{
|
||||
"plugin.id": {
|
||||
"somesetting": "some value",
|
||||
"secrettext": "a secret",
|
||||
"secretnumber": 123,
|
||||
},
|
||||
"another.plugin": {
|
||||
"somesetting": 456,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range map[string]struct {
|
||||
manifests []*Manifest
|
||||
expected map[string]map[string]any
|
||||
}{
|
||||
"nil list of manifests": {
|
||||
manifests: nil,
|
||||
expected: map[string]map[string]any{
|
||||
"plugin.id": {
|
||||
"somesetting": FakeSetting,
|
||||
"secrettext": FakeSetting,
|
||||
"secretnumber": FakeSetting,
|
||||
},
|
||||
"another.plugin": {
|
||||
"somesetting": FakeSetting,
|
||||
},
|
||||
},
|
||||
},
|
||||
"empty list of manifests": {
|
||||
manifests: []*Manifest{},
|
||||
expected: map[string]map[string]any{
|
||||
"plugin.id": {
|
||||
"somesetting": FakeSetting,
|
||||
"secrettext": FakeSetting,
|
||||
"secretnumber": FakeSetting,
|
||||
},
|
||||
"another.plugin": {
|
||||
"somesetting": FakeSetting,
|
||||
},
|
||||
},
|
||||
},
|
||||
"one plugin installed": {
|
||||
manifests: []*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,
|
||||
},
|
||||
},
|
||||
},
|
||||
"two plugins installed": {
|
||||
manifests: []*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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: "another.plugin",
|
||||
SettingsSchema: &PluginSettingsSchema{
|
||||
Settings: []*PluginSetting{
|
||||
{
|
||||
Key: "somesetting",
|
||||
Type: "number",
|
||||
Secret: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]map[string]any{
|
||||
"plugin.id": {
|
||||
"somesetting": "some value",
|
||||
"secrettext": FakeSetting,
|
||||
"secretnumber": FakeSetting,
|
||||
},
|
||||
"another.plugin": {
|
||||
"somesetting": 456,
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
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
|
||||
}
|
||||
|
||||
c := PluginSettings{}
|
||||
c.SetDefaults(*NewLogSettings())
|
||||
c.Plugins = plugins
|
||||
|
||||
c.Sanitize(tc.manifests)
|
||||
|
||||
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) {
|
||||
c := Config{}
|
||||
c.SetDefaults()
|
||||
|
||||
Ссылка в новой задаче
Block a user