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:
@@ -68,7 +68,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load a Core plugin",
|
||||
class: plugins.ClassCore,
|
||||
cfg: &config.Cfg{},
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{filepath.Join(corePluginDir(t), "app/plugins/datasource/cloudwatch")},
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
@@ -118,7 +118,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load a Bundled plugin",
|
||||
class: plugins.ClassBundled,
|
||||
cfg: &config.Cfg{},
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "valid-v2-signature")},
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
@@ -158,7 +158,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
}, {
|
||||
name: "Load plugin with symbolic links",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{},
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "symbolic-plugin-dirs")},
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
@@ -235,7 +235,8 @@ func TestLoader_Load(t *testing.T) {
|
||||
name: "Load an unsigned plugin (development)",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
DevMode: true,
|
||||
DevMode: true,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "unsigned-datasource")},
|
||||
want: []*plugins.Plugin{
|
||||
@@ -272,7 +273,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
}, {
|
||||
name: "Load an unsigned plugin (production)",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{},
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "unsigned-datasource")},
|
||||
want: []*plugins.Plugin{},
|
||||
pluginErrors: map[string]*plugins.SignatureError{
|
||||
@@ -287,6 +288,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "unsigned-datasource")},
|
||||
want: []*plugins.Plugin{
|
||||
@@ -324,7 +326,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load a plugin with v1 manifest should return signatureInvalid",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{},
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "lacking-files")},
|
||||
want: []*plugins.Plugin{},
|
||||
pluginErrors: map[string]*plugins.SignatureError{
|
||||
@@ -339,6 +341,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "lacking-files")},
|
||||
want: []*plugins.Plugin{},
|
||||
@@ -354,6 +357,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "invalid-v2-missing-file")},
|
||||
want: []*plugins.Plugin{},
|
||||
@@ -369,6 +373,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "invalid-v2-extra-file")},
|
||||
want: []*plugins.Plugin{},
|
||||
@@ -384,6 +389,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
PluginsAllowUnsigned: []string{"test-app"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "test-app-with-includes")},
|
||||
want: []*plugins.Plugin{
|
||||
@@ -434,6 +440,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
cfg: &config.Cfg{
|
||||
DevMode: true,
|
||||
GrafanaAppSubURL: "grafana",
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "unsigned-datasource")},
|
||||
want: []*plugins.Plugin{
|
||||
@@ -697,6 +704,7 @@ func TestLoader_Load_CustomSource(t *testing.T) {
|
||||
PluginSettings: setting.PluginSettings{
|
||||
"grafana-worldmap-panel": {"cdn": "true"},
|
||||
},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}
|
||||
|
||||
pluginPaths := []string{filepath.Join(testDataDir(t), "cdn")}
|
||||
@@ -779,6 +787,7 @@ func TestLoader_Load_MultiplePlugins(t *testing.T) {
|
||||
name: "Load multiple plugins (broken, valid, unsigned)",
|
||||
cfg: &config.Cfg{
|
||||
GrafanaAppURL: "http://localhost:3000",
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
pluginPaths: []string{
|
||||
filepath.Join(testDataDir(t), "invalid-plugin-json"), // test-app
|
||||
@@ -875,6 +884,7 @@ func TestLoader_Load_RBACReady(t *testing.T) {
|
||||
name: "Load plugin defining one RBAC role",
|
||||
cfg: &config.Cfg{
|
||||
GrafanaAppURL: "http://localhost:3000",
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
pluginPaths: []string{filepath.Join(testDataDir(t), "test-app-with-roles")},
|
||||
want: []*plugins.Plugin{
|
||||
@@ -992,7 +1002,7 @@ func TestLoader_Load_Signature_RootURL(t *testing.T) {
|
||||
reg := fakes.NewFakePluginRegistry()
|
||||
procPrvdr := fakes.NewFakeBackendProcessProvider()
|
||||
procMgr := fakes.NewFakeProcessManager()
|
||||
cfg := &config.Cfg{GrafanaAppURL: defaultAppURL}
|
||||
cfg := &config.Cfg{GrafanaAppURL: defaultAppURL, Features: featuremgmt.WithFeatures()}
|
||||
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
||||
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
||||
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
||||
@@ -1068,7 +1078,7 @@ func TestLoader_Load_DuplicatePlugins(t *testing.T) {
|
||||
reg := fakes.NewFakePluginRegistry()
|
||||
procPrvdr := fakes.NewFakeBackendProcessProvider()
|
||||
procMgr := fakes.NewFakeProcessManager()
|
||||
cfg := &config.Cfg{}
|
||||
cfg := &config.Cfg{Features: featuremgmt.WithFeatures()}
|
||||
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
||||
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
||||
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
||||
@@ -1157,7 +1167,7 @@ func TestLoader_Load_SkipUninitializedPlugins(t *testing.T) {
|
||||
}
|
||||
}
|
||||
procMgr := fakes.NewFakeProcessManager()
|
||||
cfg := &config.Cfg{}
|
||||
cfg := &config.Cfg{Features: featuremgmt.WithFeatures()}
|
||||
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
||||
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
||||
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
||||
@@ -1214,7 +1224,7 @@ func TestLoader_AngularClass(t *testing.T) {
|
||||
},
|
||||
}
|
||||
// if angularDetected = true, it means that the detection has run
|
||||
l := newLoaderWithOpts(t, &config.Cfg{AngularSupportEnabled: true}, loaderDepOpts{
|
||||
l := newLoaderWithOpts(t, &config.Cfg{AngularSupportEnabled: true, Features: featuremgmt.WithFeatures()}, loaderDepOpts{
|
||||
angularInspector: angularinspector.AlwaysAngularFakeInspector,
|
||||
})
|
||||
p, err := l.Load(context.Background(), fakePluginSource)
|
||||
@@ -1242,8 +1252,8 @@ func TestLoader_Load_Angular(t *testing.T) {
|
||||
name string
|
||||
cfg *config.Cfg
|
||||
}{
|
||||
{name: "angular support enabled", cfg: &config.Cfg{AngularSupportEnabled: true}},
|
||||
{name: "angular support disabled", cfg: &config.Cfg{AngularSupportEnabled: false}},
|
||||
{name: "angular support enabled", cfg: &config.Cfg{AngularSupportEnabled: true, Features: featuremgmt.WithFeatures()}},
|
||||
{name: "angular support disabled", cfg: &config.Cfg{AngularSupportEnabled: false, Features: featuremgmt.WithFeatures()}},
|
||||
} {
|
||||
t.Run(cfgTc.name, func(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
@@ -1296,19 +1306,22 @@ func TestLoader_HideAngularDeprecation(t *testing.T) {
|
||||
{name: `without "hide_angular_deprecation" setting`, cfg: &config.Cfg{
|
||||
AngularSupportEnabled: true,
|
||||
PluginSettings: setting.PluginSettings{},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}},
|
||||
{name: `with "hide_angular_deprecation" = true`, cfg: &config.Cfg{
|
||||
AngularSupportEnabled: true,
|
||||
PluginSettings: setting.PluginSettings{
|
||||
"plugin-id": map[string]string{"hide_angular_deprecation": "true"},
|
||||
}},
|
||||
},
|
||||
},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}},
|
||||
{name: `with "hide_angular_deprecation" = false`, cfg: &config.Cfg{
|
||||
AngularSupportEnabled: true,
|
||||
PluginSettings: setting.PluginSettings{
|
||||
"plugin-id": map[string]string{"hide_angular_deprecation": "false"},
|
||||
}},
|
||||
},
|
||||
},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
l := newLoaderWithOpts(t, tc.cfg, loaderDepOpts{
|
||||
@@ -1395,7 +1408,7 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
|
||||
procPrvdr := fakes.NewFakeBackendProcessProvider()
|
||||
procMgr := fakes.NewFakeProcessManager()
|
||||
reg := fakes.NewFakePluginRegistry()
|
||||
cfg := &config.Cfg{}
|
||||
cfg := &config.Cfg{Features: featuremgmt.WithFeatures()}
|
||||
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
||||
|
||||
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
||||
@@ -1570,7 +1583,7 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
|
||||
reg := fakes.NewFakePluginRegistry()
|
||||
procPrvdr := fakes.NewFakeBackendProcessProvider()
|
||||
procMgr := fakes.NewFakeProcessManager()
|
||||
cfg := &config.Cfg{}
|
||||
cfg := &config.Cfg{Features: featuremgmt.WithFeatures()}
|
||||
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
||||
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
||||
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
||||
|
||||
Reference in New Issue
Block a user