Plugins: Don't auto prepend app sub url to plugin asset paths (#81658)

* don't prepend app sub url to paths

* simplify logo path

* fix(plugins): dynamically prepend appSubUrl for System module resolving to work

* fix(sandbox): support dynamic appSuburl prepend when loading plugin module.js

* fix tests

* update test name

* fix tests

* update fe + add some tests

* refactor(plugins): move wrangleurl to utils, rename to resolveModulePath, update usage

* chore: fix a typo

* test(plugins): add missing name to utils test

* reset test flag

---------

Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
This commit is contained in:
Will Browne
2024-02-08 12:19:28 +01:00
committed by GitHub
co-authored by Jack Westbrook
parent 18963dc3ae
commit 99feb928cf
11 changed files with 289 additions and 252 deletions
@@ -83,8 +83,8 @@ func TestLoader_Load(t *testing.T) {
},
Description: "Data source for Amazon AWS monitoring service",
Logos: plugins.Logos{
Small: "/public/app/plugins/datasource/cloudwatch/img/amazon-web-services.png",
Large: "/public/app/plugins/datasource/cloudwatch/img/amazon-web-services.png",
Small: "public/app/plugins/datasource/cloudwatch/img/amazon-web-services.png",
Large: "public/app/plugins/datasource/cloudwatch/img/amazon-web-services.png",
},
},
Includes: []*plugins.Includes{
@@ -106,9 +106,8 @@ func TestLoader_Load(t *testing.T) {
Backend: true,
QueryOptions: map[string]bool{"minInterval": true},
},
Module: "core:plugin/cloudwatch",
BaseURL: "/public/app/plugins/datasource/cloudwatch",
Module: "core:plugin/cloudwatch",
BaseURL: "public/app/plugins/datasource/cloudwatch",
FS: mustNewStaticFSForTests(t, filepath.Join(corePluginDir(t), "app/plugins/datasource/cloudwatch")),
Signature: plugins.SignatureStatusInternal,
Class: plugins.ClassCore,
@@ -133,8 +132,8 @@ func TestLoader_Load(t *testing.T) {
},
Version: "1.0.0",
Logos: plugins.Logos{
Small: "/public/img/icn-datasource.svg",
Large: "/public/img/icn-datasource.svg",
Small: "public/img/icn-datasource.svg",
Large: "public/img/icn-datasource.svg",
},
Description: "Test",
},
@@ -146,8 +145,8 @@ func TestLoader_Load(t *testing.T) {
Backend: true,
State: "alpha",
},
Module: "/public/plugins/test-datasource/module.js",
BaseURL: "/public/plugins/test-datasource",
Module: "public/plugins/test-datasource/module.js",
BaseURL: "public/plugins/test-datasource",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "valid-v2-signature/plugin/")),
Signature: "valid",
SignatureType: plugins.SignatureTypeGrafana,
@@ -172,8 +171,8 @@ func TestLoader_Load(t *testing.T) {
URL: "http://test.com",
},
Logos: plugins.Logos{
Small: "/public/plugins/test-app/img/logo_small.png",
Large: "/public/plugins/test-app/img/logo_large.png",
Small: "public/plugins/test-app/img/logo_small.png",
Large: "public/plugins/test-app/img/logo_large.png",
},
Links: []plugins.InfoLink{
{Name: "Project site", URL: "http://project.com"},
@@ -181,8 +180,8 @@ func TestLoader_Load(t *testing.T) {
},
Description: "Official Grafana Test App & Dashboard bundle",
Screenshots: []plugins.Screenshots{
{Path: "/public/plugins/test-app/img/screenshot1.png", Name: "img1"},
{Path: "/public/plugins/test-app/img/screenshot2.png", Name: "img2"},
{Path: "public/plugins/test-app/img/screenshot1.png", Name: "img1"},
{Path: "public/plugins/test-app/img/screenshot2.png", Name: "img2"},
},
Version: "1.0.0",
Updated: "2015-02-10",
@@ -223,8 +222,8 @@ func TestLoader_Load(t *testing.T) {
},
},
Class: plugins.ClassExternal,
Module: "/public/plugins/test-app/module.js",
BaseURL: "/public/plugins/test-app",
Module: "public/plugins/test-app/module.js",
BaseURL: "public/plugins/test-app",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "includes-symlinks")),
Signature: "valid",
SignatureType: plugins.SignatureTypeGrafana,
@@ -251,8 +250,8 @@ func TestLoader_Load(t *testing.T) {
URL: "https://grafana.com",
},
Logos: plugins.Logos{
Small: "/public/img/icn-datasource.svg",
Large: "/public/img/icn-datasource.svg",
Small: "public/img/icn-datasource.svg",
Large: "public/img/icn-datasource.svg",
},
Description: "Test",
},
@@ -264,8 +263,8 @@ func TestLoader_Load(t *testing.T) {
State: plugins.ReleaseStateAlpha,
},
Class: plugins.ClassExternal,
Module: "/public/plugins/test-datasource/module.js",
BaseURL: "/public/plugins/test-datasource",
Module: "public/plugins/test-datasource/module.js",
BaseURL: "public/plugins/test-datasource",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "unsigned-datasource/plugin")),
Signature: "unsigned",
},
@@ -303,8 +302,8 @@ func TestLoader_Load(t *testing.T) {
URL: "https://grafana.com",
},
Logos: plugins.Logos{
Small: "/public/img/icn-datasource.svg",
Large: "/public/img/icn-datasource.svg",
Small: "public/img/icn-datasource.svg",
Large: "public/img/icn-datasource.svg",
},
Description: "Test",
},
@@ -316,8 +315,8 @@ func TestLoader_Load(t *testing.T) {
State: plugins.ReleaseStateAlpha,
},
Class: plugins.ClassExternal,
Module: "/public/plugins/test-datasource/module.js",
BaseURL: "/public/plugins/test-datasource",
Module: "public/plugins/test-datasource/module.js",
BaseURL: "public/plugins/test-datasource",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "unsigned-datasource/plugin")),
Signature: plugins.SignatureStatusUnsigned,
},
@@ -409,8 +408,8 @@ func TestLoader_Load(t *testing.T) {
{Name: "License & Terms", URL: "http://license.com"},
},
Logos: plugins.Logos{
Small: "/public/img/icn-app.svg",
Large: "/public/img/icn-app.svg",
Small: "public/img/icn-app.svg",
Large: "public/img/icn-app.svg",
},
Updated: "2015-02-10",
},
@@ -429,8 +428,8 @@ func TestLoader_Load(t *testing.T) {
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "test-app-with-includes")),
Class: plugins.ClassExternal,
Signature: plugins.SignatureStatusUnsigned,
Module: "/public/plugins/test-app/module.js",
BaseURL: "/public/plugins/test-app",
Module: "public/plugins/test-app/module.js",
BaseURL: "public/plugins/test-app",
},
},
},
@@ -455,8 +454,8 @@ func TestLoader_Load(t *testing.T) {
URL: "https://grafana.com",
},
Logos: plugins.Logos{
Small: "/grafana/public/img/icn-datasource.svg",
Large: "/grafana/public/img/icn-datasource.svg",
Small: "public/img/icn-datasource.svg",
Large: "public/img/icn-datasource.svg",
},
Description: "Test",
},
@@ -468,8 +467,8 @@ func TestLoader_Load(t *testing.T) {
State: plugins.ReleaseStateAlpha,
},
Class: plugins.ClassExternal,
Module: "/grafana/public/plugins/test-datasource/module.js",
BaseURL: "/grafana/public/plugins/test-datasource",
Module: "public/plugins/test-datasource/module.js",
BaseURL: "public/plugins/test-datasource",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "unsigned-datasource/plugin")),
Signature: plugins.SignatureStatusUnsigned,
},
@@ -526,8 +525,8 @@ func TestLoader_Load_ExternalRegistration(t *testing.T) {
},
Version: "1.0.0",
Logos: plugins.Logos{
Small: "/public/plugins/grafana-test-datasource/img/ds.svg",
Large: "/public/plugins/grafana-test-datasource/img/ds.svg",
Small: "public/plugins/grafana-test-datasource/img/ds.svg",
Large: "public/plugins/grafana-test-datasource/img/ds.svg",
},
Updated: "2023-08-03",
Screenshots: []plugins.Screenshots{},
@@ -557,8 +556,8 @@ func TestLoader_Load_ExternalRegistration(t *testing.T) {
FS: mustNewStaticFSForTests(t, pluginPaths[0]),
Class: plugins.ClassExternal,
Signature: plugins.SignatureStatusUnsigned,
Module: "/public/plugins/grafana-test-datasource/module.js",
BaseURL: "/public/plugins/grafana-test-datasource",
Module: "public/plugins/grafana-test-datasource/module.js",
BaseURL: "public/plugins/grafana-test-datasource",
ExternalService: &auth.ExternalService{
ClientID: "client-id",
ClientSecret: "secretz",
@@ -628,8 +627,8 @@ func TestLoader_Load_ExternalRegistration(t *testing.T) {
},
Version: "1.0.0",
Logos: plugins.Logos{
Small: "/public/plugins/grafana-test-datasource/img/ds.svg",
Large: "/public/plugins/grafana-test-datasource/img/ds.svg",
Small: "public/plugins/grafana-test-datasource/img/ds.svg",
Large: "public/plugins/grafana-test-datasource/img/ds.svg",
},
Updated: "2023-08-03",
Screenshots: []plugins.Screenshots{},
@@ -650,8 +649,8 @@ func TestLoader_Load_ExternalRegistration(t *testing.T) {
FS: mustNewStaticFSForTests(t, pluginPaths[0]),
Class: plugins.ClassExternal,
Signature: plugins.SignatureStatusUnsigned,
Module: "/public/plugins/grafana-test-datasource/module.js",
BaseURL: "/public/plugins/grafana-test-datasource",
Module: "public/plugins/grafana-test-datasource/module.js",
BaseURL: "public/plugins/grafana-test-datasource",
ExternalService: &auth.ExternalService{
ClientID: "client-id",
ClientSecret: "secretz",
@@ -808,8 +807,8 @@ func TestLoader_Load_MultiplePlugins(t *testing.T) {
URL: "https://willbrowne.com",
},
Logos: plugins.Logos{
Small: "/public/img/icn-datasource.svg",
Large: "/public/img/icn-datasource.svg",
Small: "public/img/icn-datasource.svg",
Large: "public/img/icn-datasource.svg",
},
Description: "Test",
Version: "1.0.0",
@@ -823,8 +822,8 @@ func TestLoader_Load_MultiplePlugins(t *testing.T) {
State: plugins.ReleaseStateAlpha,
},
Class: plugins.ClassExternal,
Module: "/public/plugins/test-datasource/module.js",
BaseURL: "/public/plugins/test-datasource",
Module: "public/plugins/test-datasource/module.js",
BaseURL: "public/plugins/test-datasource",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "valid-v2-pvt-signature/plugin")),
Signature: "valid",
SignatureType: plugins.SignatureTypePrivate,
@@ -904,8 +903,8 @@ func TestLoader_Load_RBACReady(t *testing.T) {
Version: "1.0.0",
Links: []plugins.InfoLink{},
Logos: plugins.Logos{
Small: "/public/img/icn-app.svg",
Large: "/public/img/icn-app.svg",
Small: "public/img/icn-app.svg",
Large: "public/img/icn-app.svg",
},
Updated: "2015-02-10",
},
@@ -936,8 +935,8 @@ func TestLoader_Load_RBACReady(t *testing.T) {
Signature: plugins.SignatureStatusValid,
SignatureType: plugins.SignatureTypePrivate,
SignatureOrg: "gabrielmabille",
Module: "/public/plugins/test-app/module.js",
BaseURL: "/public/plugins/test-app",
Module: "public/plugins/test-app/module.js",
BaseURL: "public/plugins/test-app",
},
},
},
@@ -981,8 +980,8 @@ func TestLoader_Load_Signature_RootURL(t *testing.T) {
Author: plugins.InfoLink{Name: "Will Browne", URL: "https://willbrowne.com"},
Description: "Test",
Logos: plugins.Logos{
Small: "/public/img/icn-datasource.svg",
Large: "/public/img/icn-datasource.svg",
Small: "public/img/icn-datasource.svg",
Large: "public/img/icn-datasource.svg",
},
Version: "1.0.0",
},
@@ -996,8 +995,8 @@ func TestLoader_Load_Signature_RootURL(t *testing.T) {
Signature: plugins.SignatureStatusValid,
SignatureType: plugins.SignatureTypePrivate,
SignatureOrg: "Will Browne",
Module: "/public/plugins/test-datasource/module.js",
BaseURL: "/public/plugins/test-datasource",
Module: "public/plugins/test-datasource/module.js",
BaseURL: "public/plugins/test-datasource",
},
}
@@ -1043,12 +1042,12 @@ func TestLoader_Load_DuplicatePlugins(t *testing.T) {
{Name: "License & Terms", URL: "http://license.com"},
},
Logos: plugins.Logos{
Small: "/public/plugins/test-app/img/logo_small.png",
Large: "/public/plugins/test-app/img/logo_large.png",
Small: "public/plugins/test-app/img/logo_small.png",
Large: "public/plugins/test-app/img/logo_large.png",
},
Screenshots: []plugins.Screenshots{
{Path: "/public/plugins/test-app/img/screenshot1.png", Name: "img1"},
{Path: "/public/plugins/test-app/img/screenshot2.png", Name: "img2"},
{Path: "public/plugins/test-app/img/screenshot1.png", Name: "img1"},
{Path: "public/plugins/test-app/img/screenshot2.png", Name: "img2"},
},
Updated: "2015-02-10",
},
@@ -1072,8 +1071,8 @@ func TestLoader_Load_DuplicatePlugins(t *testing.T) {
Signature: plugins.SignatureStatusValid,
SignatureType: plugins.SignatureTypeGrafana,
SignatureOrg: "Grafana Labs",
Module: "/public/plugins/test-app/module.js",
BaseURL: "/public/plugins/test-app",
Module: "public/plugins/test-app/module.js",
BaseURL: "public/plugins/test-app",
},
}
@@ -1123,12 +1122,12 @@ func TestLoader_Load_SkipUninitializedPlugins(t *testing.T) {
{Name: "License & Terms", URL: "http://license.com"},
},
Logos: plugins.Logos{
Small: "/public/plugins/test-app/img/logo_small.png",
Large: "/public/plugins/test-app/img/logo_large.png",
Small: "public/plugins/test-app/img/logo_small.png",
Large: "public/plugins/test-app/img/logo_large.png",
},
Screenshots: []plugins.Screenshots{
{Path: "/public/plugins/test-app/img/screenshot1.png", Name: "img1"},
{Path: "/public/plugins/test-app/img/screenshot2.png", Name: "img2"},
{Path: "public/plugins/test-app/img/screenshot1.png", Name: "img1"},
{Path: "public/plugins/test-app/img/screenshot2.png", Name: "img2"},
},
Updated: "2015-02-10",
},
@@ -1152,8 +1151,8 @@ func TestLoader_Load_SkipUninitializedPlugins(t *testing.T) {
Signature: plugins.SignatureStatusValid,
SignatureType: plugins.SignatureTypeGrafana,
SignatureOrg: "Grafana Labs",
Module: "/public/plugins/test-app/module.js",
BaseURL: "/public/plugins/test-app",
Module: "public/plugins/test-app/module.js",
BaseURL: "public/plugins/test-app",
},
}
@@ -1345,8 +1344,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
URL: "http://grafana.com",
},
Logos: plugins.Logos{
Small: "/public/img/icn-datasource.svg",
Large: "/public/img/icn-datasource.svg",
Small: "public/img/icn-datasource.svg",
Large: "public/img/icn-datasource.svg",
},
Description: "Parent plugin",
Version: "1.0.0",
@@ -1358,8 +1357,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
},
Backend: true,
},
Module: "/public/plugins/test-datasource/module.js",
BaseURL: "/public/plugins/test-datasource",
Module: "public/plugins/test-datasource/module.js",
BaseURL: "public/plugins/test-datasource",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "nested-plugins/parent")),
Signature: plugins.SignatureStatusValid,
SignatureType: plugins.SignatureTypeGrafana,
@@ -1378,8 +1377,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
URL: "http://grafana.com",
},
Logos: plugins.Logos{
Small: "/public/img/icn-panel.svg",
Large: "/public/img/icn-panel.svg",
Small: "public/img/icn-panel.svg",
Large: "public/img/icn-panel.svg",
},
Description: "Child plugin",
Version: "1.0.1",
@@ -1390,8 +1389,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
Plugins: []plugins.Dependency{},
},
},
Module: "/public/plugins/test-panel/module.js",
BaseURL: "/public/plugins/test-panel",
Module: "public/plugins/test-panel/module.js",
BaseURL: "public/plugins/test-panel",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "nested-plugins/parent/nested")),
Signature: plugins.SignatureStatusValid,
SignatureType: plugins.SignatureTypeGrafana,
@@ -1470,8 +1469,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
{Name: "License", URL: "https://github.com/grafana/grafana-starter-app/blob/master/LICENSE"},
},
Logos: plugins.Logos{
Small: "/public/plugins/myorgid-simple-app/img/logo.svg",
Large: "/public/plugins/myorgid-simple-app/img/logo.svg",
Small: "public/plugins/myorgid-simple-app/img/logo.svg",
Large: "public/plugins/myorgid-simple-app/img/logo.svg",
},
Screenshots: []plugins.Screenshots{},
Description: "Grafana App Plugin Template",
@@ -1526,8 +1525,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
},
Backend: false,
},
Module: "/public/plugins/myorgid-simple-app/module.js",
BaseURL: "/public/plugins/myorgid-simple-app",
Module: "public/plugins/myorgid-simple-app/module.js",
BaseURL: "public/plugins/myorgid-simple-app",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "app-with-child/dist")),
DefaultNavURL: "/plugins/myorgid-simple-app/page/root-page-react",
Signature: plugins.SignatureStatusValid,
@@ -1550,8 +1549,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
{Name: "License", URL: "https://github.com/grafana/grafana-starter-panel/blob/master/LICENSE"},
},
Logos: plugins.Logos{
Small: "/public/plugins/myorgid-simple-panel/img/logo.svg",
Large: "/public/plugins/myorgid-simple-panel/img/logo.svg",
Small: "public/plugins/myorgid-simple-panel/img/logo.svg",
Large: "public/plugins/myorgid-simple-panel/img/logo.svg",
},
Screenshots: []plugins.Screenshots{},
Description: "Grafana Panel Plugin Template",
@@ -1564,8 +1563,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) {
Plugins: []plugins.Dependency{},
},
},
Module: "/public/plugins/myorgid-simple-app/child/module.js",
BaseURL: "/public/plugins/myorgid-simple-app",
Module: "public/plugins/myorgid-simple-app/child/module.js",
BaseURL: "public/plugins/myorgid-simple-app",
FS: mustNewStaticFSForTests(t, filepath.Join(testDataDir(t), "app-with-child/dist/child")),
IncludedInAppID: parent.ID,
Signature: plugins.SignatureStatusValid,