mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Fix symlinks inside plugins path not being followed (#80205)
* Plugins: Loader: Fix symlinks not followed when loading external plugins * Add test case
This commit is contained in:
parent
314cdaf618
commit
c045a9f395
@ -51,7 +51,7 @@ func (s *Service) externalPluginSources() []plugins.PluginSource {
|
||||
|
||||
var pluginDirs []string
|
||||
for _, dir := range d {
|
||||
if dir.IsDir() {
|
||||
if dir.IsDir() || dir.Type()&os.ModeSymlink == os.ModeSymlink {
|
||||
pluginDirs = append(pluginDirs, filepath.Join(pluginsPath, dir.Name()))
|
||||
}
|
||||
}
|
||||
|
@ -78,4 +78,41 @@ func TestSources_List(t *testing.T) {
|
||||
require.False(t, exists)
|
||||
require.Equal(t, plugins.Signature{}, sig)
|
||||
})
|
||||
|
||||
t.Run("Plugin sources are populated with symbolic links", func(t *testing.T) {
|
||||
testdata, err := filepath.Abs("../testdata")
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := &setting.Cfg{
|
||||
StaticRootPath: testdata,
|
||||
PluginsPath: filepath.Join(testdata, "symbolic-plugin-dirs"),
|
||||
BundledPluginsPath: filepath.Join(testdata, "unsigned-panel"),
|
||||
}
|
||||
s := ProvideService(cfg)
|
||||
ctx := context.Background()
|
||||
srcs := s.List(ctx)
|
||||
uris := map[plugins.Class]map[string]struct{}{}
|
||||
for _, s := range srcs {
|
||||
class := s.PluginClass(ctx)
|
||||
if _, exists := uris[class]; !exists {
|
||||
uris[class] = map[string]struct{}{}
|
||||
}
|
||||
for _, uri := range s.PluginURIs(ctx) {
|
||||
uris[class][uri] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
require.Equal(t, uris[plugins.ClassCore], map[string]struct{}{
|
||||
filepath.Join(testdata, "app", "plugins", "datasource"): {},
|
||||
filepath.Join(testdata, "app", "plugins", "panel"): {},
|
||||
}, "should include core plugins")
|
||||
|
||||
require.Equal(t, uris[plugins.ClassBundled], map[string]struct{}{
|
||||
filepath.Join(testdata, "unsigned-panel"): {},
|
||||
}, "should include bundle plugin")
|
||||
|
||||
require.Equal(t, uris[plugins.ClassExternal], map[string]struct{}{
|
||||
filepath.Join(testdata, "symbolic-plugin-dirs", "plugin"): {},
|
||||
}, "should include external symlinked plugin")
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user