|
|
|
|
@@ -26,7 +26,6 @@ import (
|
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/sources"
|
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/pfs"
|
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pipeline"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginerrs"
|
|
|
|
|
@@ -68,7 +67,7 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
{
|
|
|
|
|
name: "Load a Core plugin",
|
|
|
|
|
class: plugins.ClassCore,
|
|
|
|
|
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
|
|
|
|
cfg: &config.PluginManagementCfg{},
|
|
|
|
|
pluginPaths: []string{filepath.Join(corePluginDir(t), "app/plugins/datasource/cloudwatch")},
|
|
|
|
|
want: []*plugins.Plugin{
|
|
|
|
|
{
|
|
|
|
|
@@ -117,7 +116,7 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
{
|
|
|
|
|
name: "Load a Bundled plugin",
|
|
|
|
|
class: plugins.ClassBundled,
|
|
|
|
|
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
|
|
|
|
cfg: &config.PluginManagementCfg{},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "valid-v2-signature")},
|
|
|
|
|
want: []*plugins.Plugin{
|
|
|
|
|
{
|
|
|
|
|
@@ -158,7 +157,7 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
{
|
|
|
|
|
name: "Load plugin with symbolic links",
|
|
|
|
|
class: plugins.ClassExternal,
|
|
|
|
|
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
|
|
|
|
cfg: &config.PluginManagementCfg{},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "symbolic-plugin-dirs")},
|
|
|
|
|
want: []*plugins.Plugin{
|
|
|
|
|
{
|
|
|
|
|
@@ -238,8 +237,7 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
name: "Load an unsigned plugin (development)",
|
|
|
|
|
class: plugins.ClassExternal,
|
|
|
|
|
cfg: &config.PluginManagementCfg{
|
|
|
|
|
DevMode: true,
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
DevMode: true,
|
|
|
|
|
},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "unsigned-datasource")},
|
|
|
|
|
want: []*plugins.Plugin{
|
|
|
|
|
@@ -277,7 +275,7 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
{
|
|
|
|
|
name: "Load an unsigned plugin (production)",
|
|
|
|
|
class: plugins.ClassExternal,
|
|
|
|
|
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
|
|
|
|
cfg: &config.PluginManagementCfg{},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "unsigned-datasource")},
|
|
|
|
|
want: []*plugins.Plugin{},
|
|
|
|
|
pluginErrors: map[string]*plugins.SignatureError{
|
|
|
|
|
@@ -292,7 +290,6 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
class: plugins.ClassExternal,
|
|
|
|
|
cfg: &config.PluginManagementCfg{
|
|
|
|
|
PluginsAllowUnsigned: []string{"test-datasource"},
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "unsigned-datasource")},
|
|
|
|
|
want: []*plugins.Plugin{
|
|
|
|
|
@@ -330,7 +327,7 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
{
|
|
|
|
|
name: "Load a plugin with v1 manifest should return signatureInvalid",
|
|
|
|
|
class: plugins.ClassExternal,
|
|
|
|
|
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
|
|
|
|
cfg: &config.PluginManagementCfg{},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "lacking-files")},
|
|
|
|
|
want: []*plugins.Plugin{},
|
|
|
|
|
pluginErrors: map[string]*plugins.SignatureError{
|
|
|
|
|
@@ -345,7 +342,6 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
class: plugins.ClassExternal,
|
|
|
|
|
cfg: &config.PluginManagementCfg{
|
|
|
|
|
PluginsAllowUnsigned: []string{"test-datasource"},
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "lacking-files")},
|
|
|
|
|
want: []*plugins.Plugin{},
|
|
|
|
|
@@ -361,7 +357,6 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
class: plugins.ClassExternal,
|
|
|
|
|
cfg: &config.PluginManagementCfg{
|
|
|
|
|
PluginsAllowUnsigned: []string{"test-datasource"},
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "invalid-v2-missing-file")},
|
|
|
|
|
want: []*plugins.Plugin{},
|
|
|
|
|
@@ -377,7 +372,6 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
class: plugins.ClassExternal,
|
|
|
|
|
cfg: &config.PluginManagementCfg{
|
|
|
|
|
PluginsAllowUnsigned: []string{"test-datasource"},
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "invalid-v2-extra-file")},
|
|
|
|
|
want: []*plugins.Plugin{},
|
|
|
|
|
@@ -393,7 +387,6 @@ func TestLoader_Load(t *testing.T) {
|
|
|
|
|
class: plugins.ClassExternal,
|
|
|
|
|
cfg: &config.PluginManagementCfg{
|
|
|
|
|
PluginsAllowUnsigned: []string{"test-app"},
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "test-app-with-includes")},
|
|
|
|
|
want: []*plugins.Plugin{
|
|
|
|
|
@@ -471,7 +464,6 @@ func TestLoader_Load_ExternalRegistration(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
t.Run("Load a plugin with service account registration", func(t *testing.T) {
|
|
|
|
|
cfg := &config.PluginManagementCfg{
|
|
|
|
|
Features: featuremgmt.WithFeatures(featuremgmt.FlagExternalServiceAccounts),
|
|
|
|
|
PluginsAllowUnsigned: []string{"grafana-test-datasource"},
|
|
|
|
|
}
|
|
|
|
|
pluginPaths := []string{filepath.Join(testDataDir(t), "external-registration")}
|
|
|
|
|
@@ -564,7 +556,6 @@ 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")}
|
|
|
|
|
@@ -647,7 +638,6 @@ func TestLoader_Load_MultiplePlugins(t *testing.T) {
|
|
|
|
|
name: "Load multiple plugins (broken, valid, unsigned)",
|
|
|
|
|
cfg: &config.PluginManagementCfg{
|
|
|
|
|
GrafanaAppURL: "http://localhost:3000",
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
},
|
|
|
|
|
pluginPaths: []string{
|
|
|
|
|
filepath.Join(testDataDir(t), "invalid-plugin-json"), // test-app
|
|
|
|
|
@@ -744,7 +734,6 @@ func TestLoader_Load_RBACReady(t *testing.T) {
|
|
|
|
|
name: "Load plugin defining one RBAC role",
|
|
|
|
|
cfg: &config.PluginManagementCfg{
|
|
|
|
|
GrafanaAppURL: "http://localhost:3000",
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
},
|
|
|
|
|
pluginPaths: []string{filepath.Join(testDataDir(t), "test-app-with-roles")},
|
|
|
|
|
want: []*plugins.Plugin{
|
|
|
|
|
@@ -863,7 +852,7 @@ func TestLoader_Load_Signature_RootURL(t *testing.T) {
|
|
|
|
|
reg := fakes.NewFakePluginRegistry()
|
|
|
|
|
procPrvdr := fakes.NewFakeBackendProcessProvider()
|
|
|
|
|
procMgr := fakes.NewFakeProcessManager()
|
|
|
|
|
cfg := &config.PluginManagementCfg{GrafanaAppURL: defaultAppURL, Features: featuremgmt.WithFeatures()}
|
|
|
|
|
cfg := &config.PluginManagementCfg{GrafanaAppURL: defaultAppURL}
|
|
|
|
|
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
|
|
|
|
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
|
|
|
|
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
|
|
|
|
@@ -940,7 +929,7 @@ func TestLoader_Load_DuplicatePlugins(t *testing.T) {
|
|
|
|
|
reg := fakes.NewFakePluginRegistry()
|
|
|
|
|
procPrvdr := fakes.NewFakeBackendProcessProvider()
|
|
|
|
|
procMgr := fakes.NewFakeProcessManager()
|
|
|
|
|
cfg := &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()}
|
|
|
|
|
cfg := &config.PluginManagementCfg{}
|
|
|
|
|
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
|
|
|
|
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
|
|
|
|
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
|
|
|
|
@@ -1030,7 +1019,7 @@ func TestLoader_Load_SkipUninitializedPlugins(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
procMgr := fakes.NewFakeProcessManager()
|
|
|
|
|
cfg := &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()}
|
|
|
|
|
cfg := &config.PluginManagementCfg{}
|
|
|
|
|
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
|
|
|
|
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
|
|
|
|
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
|
|
|
|
@@ -1087,7 +1076,7 @@ func TestLoader_AngularClass(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
// if angularDetected = true, it means that the detection has run
|
|
|
|
|
l := newLoaderWithOpts(t, &config.PluginManagementCfg{AngularSupportEnabled: true, Features: featuremgmt.WithFeatures()}, loaderDepOpts{
|
|
|
|
|
l := newLoaderWithOpts(t, &config.PluginManagementCfg{AngularSupportEnabled: true}, loaderDepOpts{
|
|
|
|
|
angularInspector: angularinspector.AlwaysAngularFakeInspector,
|
|
|
|
|
})
|
|
|
|
|
p, err := l.Load(context.Background(), fakePluginSource)
|
|
|
|
|
@@ -1115,8 +1104,8 @@ func TestLoader_Load_Angular(t *testing.T) {
|
|
|
|
|
name string
|
|
|
|
|
cfg *config.PluginManagementCfg
|
|
|
|
|
}{
|
|
|
|
|
{name: "angular support enabled", cfg: &config.PluginManagementCfg{AngularSupportEnabled: true, Features: featuremgmt.WithFeatures()}},
|
|
|
|
|
{name: "angular support disabled", cfg: &config.PluginManagementCfg{AngularSupportEnabled: false, Features: featuremgmt.WithFeatures()}},
|
|
|
|
|
{name: "angular support enabled", cfg: &config.PluginManagementCfg{AngularSupportEnabled: true}},
|
|
|
|
|
{name: "angular support disabled", cfg: &config.PluginManagementCfg{AngularSupportEnabled: false}},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(cfgTc.name, func(t *testing.T) {
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
|
@@ -1169,17 +1158,14 @@ func TestLoader_HideAngularDeprecation(t *testing.T) {
|
|
|
|
|
{name: "with plugin id in HideAngularDeprecation list", cfg: &config.PluginManagementCfg{
|
|
|
|
|
AngularSupportEnabled: true,
|
|
|
|
|
HideAngularDeprecation: []string{"one-app", "two-panel", "test-datasource", "three-datasource"},
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
}, expHideAngularDeprecation: true},
|
|
|
|
|
{name: "without plugin id in HideAngularDeprecation list", cfg: &config.PluginManagementCfg{
|
|
|
|
|
AngularSupportEnabled: true,
|
|
|
|
|
HideAngularDeprecation: []string{"one-app", "two-panel", "three-datasource"},
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
}, expHideAngularDeprecation: false},
|
|
|
|
|
{name: "with empty HideAngularDeprecation", cfg: &config.PluginManagementCfg{
|
|
|
|
|
AngularSupportEnabled: true,
|
|
|
|
|
HideAngularDeprecation: nil,
|
|
|
|
|
Features: featuremgmt.WithFeatures(),
|
|
|
|
|
}, expHideAngularDeprecation: false},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
|
@@ -1267,7 +1253,7 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
|
|
|
|
|
procPrvdr := fakes.NewFakeBackendProcessProvider()
|
|
|
|
|
procMgr := fakes.NewFakeProcessManager()
|
|
|
|
|
reg := fakes.NewFakePluginRegistry()
|
|
|
|
|
cfg := &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()}
|
|
|
|
|
cfg := &config.PluginManagementCfg{}
|
|
|
|
|
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
|
|
|
|
|
|
|
|
|
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
|
|
|
|
@@ -1444,7 +1430,7 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
|
|
|
|
|
reg := fakes.NewFakePluginRegistry()
|
|
|
|
|
procPrvdr := fakes.NewFakeBackendProcessProvider()
|
|
|
|
|
procMgr := fakes.NewFakeProcessManager()
|
|
|
|
|
cfg := &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()}
|
|
|
|
|
cfg := &config.PluginManagementCfg{}
|
|
|
|
|
l := newLoader(t, cfg, reg, procMgr, procPrvdr, newFakeSignatureErrorTracker())
|
|
|
|
|
got, err := l.Load(context.Background(), &fakes.FakePluginSource{
|
|
|
|
|
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
|
|
|
|
@@ -1485,7 +1471,7 @@ func newLoader(t *testing.T, cfg *config.PluginManagementCfg, reg registry.Servi
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
return ProvideService(pipeline.ProvideDiscoveryStage(cfg,
|
|
|
|
|
finder.NewLocalFinder(false, featuremgmt.WithFeatures()), reg),
|
|
|
|
|
finder.NewLocalFinder(false), reg),
|
|
|
|
|
pipeline.ProvideBootstrapStage(cfg, signature.DefaultCalculator(cfg), assets),
|
|
|
|
|
pipeline.ProvideValidationStage(cfg, signature.NewValidator(signature.NewUnsignedAuthorizer(cfg)), angularInspector, sigErrTracker),
|
|
|
|
|
pipeline.ProvideInitializationStage(cfg, reg, backendFactory, proc, &fakes.FakeAuthService{}, fakes.NewFakeRoleRegistry(), fakes.NewFakePluginEnvProvider()),
|
|
|
|
|
@@ -1517,7 +1503,7 @@ func newLoaderWithOpts(t *testing.T, cfg *config.PluginManagementCfg, opts loade
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ProvideService(pipeline.ProvideDiscoveryStage(cfg,
|
|
|
|
|
finder.NewLocalFinder(false, featuremgmt.WithFeatures()), reg),
|
|
|
|
|
finder.NewLocalFinder(false), reg),
|
|
|
|
|
pipeline.ProvideBootstrapStage(cfg, signature.DefaultCalculator(cfg), assets),
|
|
|
|
|
pipeline.ProvideValidationStage(cfg, signature.NewValidator(signature.NewUnsignedAuthorizer(cfg)), angularInspector, sigErrTracker),
|
|
|
|
|
pipeline.ProvideInitializationStage(cfg, reg, backendFactoryProvider, proc, authServiceRegistry, fakes.NewFakeRoleRegistry(), fakes.NewFakePluginEnvProvider()),
|
|
|
|
|
|