[MM-28841] Filter settings sent to the client based on tag (#15578)
* Filter settings sent to the client based on tag Right now we're filtering in client the sections based on the RestrictSystemAdmin setting but we're still sending those settings through the API call. In this PR we include a new tag cloud_restrictable and some method to remove those settings/fields from the final JSON sent to the client
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
886c4898d8
Коммит
ab816b18ce
@@ -4,6 +4,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
@@ -1293,6 +1294,50 @@ func TestConfigSanitize(t *testing.T) {
|
||||
assert.Equal(t, FAKE_SETTING, c.SqlSettings.DataSourceSearchReplicas[0])
|
||||
}
|
||||
|
||||
func TestConfigFilteredByTag(t *testing.T) {
|
||||
c := Config{}
|
||||
c.SetDefaults()
|
||||
|
||||
cfgMap := structToMapFilteredByTag(c, ConfigAccessTagType, ConfigAccessTagCloudRestrictable)
|
||||
|
||||
// Remove entire sections but the map is still there
|
||||
clusterSettings, ok := cfgMap["SqlSettings"].(map[string]interface{})
|
||||
require.True(t, ok)
|
||||
require.Equal(t, 0, len(clusterSettings))
|
||||
|
||||
// Some fields are removed if they have the filtering tag
|
||||
serviceSettings, ok := cfgMap["ServiceSettings"].(map[string]interface{})
|
||||
require.True(t, ok)
|
||||
_, ok = serviceSettings["ListenAddress"]
|
||||
require.False(t, ok)
|
||||
}
|
||||
|
||||
func TestConfigToJSONFiltered(t *testing.T) {
|
||||
c := Config{}
|
||||
c.SetDefaults()
|
||||
|
||||
jsonCfgFiltered := c.ToJsonFiltered(ConfigAccessTagType, ConfigAccessTagCloudRestrictable)
|
||||
|
||||
unmarshaledCfg := make(map[string]json.RawMessage)
|
||||
err := json.Unmarshal([]byte(jsonCfgFiltered), &unmarshaledCfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, ok := unmarshaledCfg["SqlSettings"]
|
||||
require.False(t, ok)
|
||||
|
||||
serviceSettingsRaw, ok := unmarshaledCfg["ServiceSettings"]
|
||||
require.True(t, ok)
|
||||
|
||||
unmarshaledServiceSettings := make(map[string]json.RawMessage)
|
||||
err = json.Unmarshal([]byte(serviceSettingsRaw), &unmarshaledServiceSettings)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, ok = unmarshaledServiceSettings["ListenAddress"]
|
||||
require.False(t, ok)
|
||||
_, ok = unmarshaledServiceSettings["SiteURL"]
|
||||
require.True(t, ok)
|
||||
}
|
||||
|
||||
func TestConfigMarketplaceDefaults(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user