Plugins: Allow disabling "skip host environment variables" per-plugin (#78266)
* Plugins: Allow disabling skipping host environment variables per-plugin * Renamed SkipEnvVarsDecorateFunc to SkipHostEnvVarsDecorateFunc * PR review feedback * fix tests
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
func TestSetDefaultNavURL(t *testing.T) {
|
||||
@@ -146,3 +148,64 @@ func Test_configureAppChildPlugin(t *testing.T) {
|
||||
require.Equal(t, "/grafana/plugins/parent-app", child.BaseURL)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSkipEnvVarsDecorateFunc(t *testing.T) {
|
||||
const pluginID = "plugin-id"
|
||||
|
||||
t.Run("feature flag is not present", func(t *testing.T) {
|
||||
f := SkipHostEnvVarsDecorateFunc(&config.Cfg{Features: featuremgmt.WithFeatures()})
|
||||
p, err := f(context.Background(), &plugins.Plugin{JSONData: plugins.JSONData{ID: pluginID}})
|
||||
require.NoError(t, err)
|
||||
require.False(t, p.SkipHostEnvVars)
|
||||
})
|
||||
|
||||
t.Run("feature flag is present", func(t *testing.T) {
|
||||
t.Run("no plugin settings should set SkipHostEnvVars to true", func(t *testing.T) {
|
||||
f := SkipHostEnvVarsDecorateFunc(&config.Cfg{
|
||||
Features: featuremgmt.WithFeatures(featuremgmt.FlagPluginsSkipHostEnvVars),
|
||||
})
|
||||
p, err := f(context.Background(), &plugins.Plugin{JSONData: plugins.JSONData{ID: pluginID}})
|
||||
require.NoError(t, err)
|
||||
require.True(t, p.SkipHostEnvVars)
|
||||
})
|
||||
|
||||
t.Run("plugin setting", func(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
pluginSettings setting.PluginSettings
|
||||
expSkipHostEnvVars bool
|
||||
}{
|
||||
{
|
||||
name: "forward_host_env_vars = false should set SkipHostEnvVars to true",
|
||||
pluginSettings: setting.PluginSettings{pluginID: map[string]string{"forward_host_env_vars": "false"}},
|
||||
expSkipHostEnvVars: true,
|
||||
},
|
||||
{
|
||||
name: "forward_host_env_vars = true should set SkipHostEnvVars to false",
|
||||
pluginSettings: setting.PluginSettings{pluginID: map[string]string{"forward_host_env_vars": "true"}},
|
||||
expSkipHostEnvVars: false,
|
||||
},
|
||||
{
|
||||
name: "invalid forward_host_env_vars should set SkipHostEnvVars to true",
|
||||
pluginSettings: setting.PluginSettings{pluginID: map[string]string{"forward_host_env_vars": "grilled cheese sandwich with bacon"}},
|
||||
expSkipHostEnvVars: true,
|
||||
},
|
||||
{
|
||||
name: "forward_host_env_vars absent should set SkipHostEnvVars to true",
|
||||
pluginSettings: setting.PluginSettings{pluginID: nil},
|
||||
expSkipHostEnvVars: true,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
f := SkipHostEnvVarsDecorateFunc(&config.Cfg{
|
||||
Features: featuremgmt.WithFeatures(featuremgmt.FlagPluginsSkipHostEnvVars),
|
||||
PluginSettings: tc.pluginSettings,
|
||||
})
|
||||
p, err := f(context.Background(), &plugins.Plugin{JSONData: plugins.JSONData{ID: pluginID}})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expSkipHostEnvVars, p.SkipHostEnvVars)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user