Fix: only recurse a symbolic link if it is a directory (#35455)
* only recurse a symbolic link if it is a directory * added test for detecting valid plugins using lib dirs with symbolic links in them (like oracle) * fix linting errors * added extra checks as per code-review
This commit is contained in:
@@ -21,6 +21,8 @@ import (
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
const defaultAppURL = "http://localhost:3000/"
|
||||
|
||||
func TestPluginManager_Init(t *testing.T) {
|
||||
t.Run("Base case (core + bundled plugins)", func(t *testing.T) {
|
||||
staticRootPath, err := filepath.Abs("../../../public")
|
||||
@@ -289,7 +291,7 @@ func TestPluginManager_Init(t *testing.T) {
|
||||
setting.AppUrl = origAppURL
|
||||
setting.AppSubUrl = origAppSubURL
|
||||
})
|
||||
setting.AppUrl = "http://localhost:3000/"
|
||||
setting.AppUrl = defaultAppURL
|
||||
setting.AppSubUrl = "/grafana"
|
||||
|
||||
pm := createManager(t, func(pm *PluginManager) {
|
||||
@@ -316,7 +318,7 @@ func TestPluginManager_Init(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
setting.AppUrl = origAppURL
|
||||
})
|
||||
setting.AppUrl = "http://localhost:3000/"
|
||||
setting.AppUrl = defaultAppURL
|
||||
|
||||
pm := createManager(t, func(pm *PluginManager) {
|
||||
pm.Cfg.PluginsPath = "testdata/valid-v2-pvt-signature"
|
||||
@@ -342,7 +344,7 @@ func TestPluginManager_Init(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
setting.AppUrl = origAppURL
|
||||
})
|
||||
setting.AppUrl = "http://localhost:3000/"
|
||||
setting.AppUrl = defaultAppURL
|
||||
|
||||
pm := createManager(t, func(pm *PluginManager) {
|
||||
pm.Cfg.PluginsPath = "testdata/invalid-v2-signature"
|
||||
@@ -358,7 +360,7 @@ func TestPluginManager_Init(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
setting.AppUrl = origAppURL
|
||||
})
|
||||
setting.AppUrl = "http://localhost:3000/"
|
||||
setting.AppUrl = defaultAppURL
|
||||
|
||||
pm := createManager(t, func(pm *PluginManager) {
|
||||
pm.Cfg.PluginsPath = "testdata/invalid-v2-signature-2"
|
||||
@@ -368,6 +370,33 @@ func TestPluginManager_Init(t *testing.T) {
|
||||
assert.Equal(t, []error{fmt.Errorf(`plugin 'test' has a modified signature`)}, pm.scanningErrors)
|
||||
assert.Nil(t, pm.plugins[("test")])
|
||||
})
|
||||
|
||||
t.Run("With back-end plugin with a lib dir that has symbolic links", func(t *testing.T) {
|
||||
origAppURL := setting.AppUrl
|
||||
t.Cleanup(func() {
|
||||
setting.AppUrl = origAppURL
|
||||
})
|
||||
setting.AppUrl = defaultAppURL
|
||||
|
||||
pm := createManager(t, func(pm *PluginManager) {
|
||||
pm.Cfg.PluginsPath = "testdata/symbolic-file-links"
|
||||
})
|
||||
err := pm.Init()
|
||||
require.NoError(t, err)
|
||||
// This plugin should be properly registered, even though it has a symbolicly linked file in it.
|
||||
require.Empty(t, pm.scanningErrors)
|
||||
const pluginID = "test"
|
||||
assert.NotNil(t, pm.plugins[pluginID])
|
||||
assert.Equal(t, "datasource", pm.plugins[pluginID].Type)
|
||||
assert.Equal(t, "Test", pm.plugins[pluginID].Name)
|
||||
assert.Equal(t, pluginID, pm.plugins[pluginID].Id)
|
||||
assert.Equal(t, "1.0.0", pm.plugins[pluginID].Info.Version)
|
||||
assert.Equal(t, plugins.PluginSignatureValid, pm.plugins[pluginID].Signature)
|
||||
assert.Equal(t, plugins.GrafanaType, pm.plugins[pluginID].SignatureType)
|
||||
assert.Equal(t, "Grafana Labs", pm.plugins[pluginID].SignatureOrg)
|
||||
assert.False(t, pm.plugins[pluginID].IsCorePlugin)
|
||||
assert.NotNil(t, pm.plugins[("test")])
|
||||
})
|
||||
}
|
||||
|
||||
func TestPluginManager_IsBackendOnlyPlugin(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user