diff --git a/pkg/api/pluginproxy/ds_auth_provider.go b/pkg/api/pluginproxy/ds_auth_provider.go index d1d8f822d70..1614e7ee455 100644 --- a/pkg/api/pluginproxy/ds_auth_provider.go +++ b/pkg/api/pluginproxy/ds_auth_provider.go @@ -22,22 +22,24 @@ func ApplyRoute(ctx context.Context, req *http.Request, proxyPath string, route SecureJsonData: ds.SecureJsonData.Decrypt(), } - interpolatedURL, err := InterpolateString(route.URL, data) - if err != nil { - logger.Error("Error interpolating proxy url", "error", err) - return - } + if len(route.URL) > 0 { + interpolatedURL, err := InterpolateString(route.URL, data) + if err != nil { + logger.Error("Error interpolating proxy url", "error", err) + return + } - routeURL, err := url.Parse(interpolatedURL) - if err != nil { - logger.Error("Error parsing plugin route url", "error", err) - return - } + routeURL, err := url.Parse(interpolatedURL) + if err != nil { + logger.Error("Error parsing plugin route url", "error", err) + return + } - req.URL.Scheme = routeURL.Scheme - req.URL.Host = routeURL.Host - req.Host = routeURL.Host - req.URL.Path = util.JoinURLFragments(routeURL.Path, proxyPath) + req.URL.Scheme = routeURL.Scheme + req.URL.Host = routeURL.Host + req.Host = routeURL.Host + req.URL.Path = util.JoinURLFragments(routeURL.Path, proxyPath) + } if err := addQueryString(req, route, data); err != nil { logger.Error("Failed to render plugin URL query string", "error", err) diff --git a/pkg/api/pluginproxy/ds_proxy_test.go b/pkg/api/pluginproxy/ds_proxy_test.go index 7f14665ae87..6e138e49270 100644 --- a/pkg/api/pluginproxy/ds_proxy_test.go +++ b/pkg/api/pluginproxy/ds_proxy_test.go @@ -67,6 +67,10 @@ func TestDSRouteRule(t *testing.T) { {Name: "x-header", Content: "my secret {{.SecureJsonData.key}}"}, }, }, + { + Path: "api/restricted", + ReqRole: models.ROLE_ADMIN, + }, }, } @@ -116,6 +120,17 @@ func TestDSRouteRule(t *testing.T) { }) }) + Convey("When matching route path with no url", func() { + proxy, err := NewDataSourceProxy(ds, plugin, ctx, "", &setting.Cfg{}) + So(err, ShouldBeNil) + proxy.route = plugin.Routes[4] + ApplyRoute(proxy.ctx.Req.Context(), req, proxy.proxyPath, proxy.route, proxy.ds) + + Convey("Should not replace request url", func() { + So(req.URL.String(), ShouldEqual, "http://localhost/asd") + }) + }) + Convey("Validating request", func() { Convey("plugin route with valid role", func() { proxy, err := NewDataSourceProxy(ds, plugin, ctx, "api/v4/some/method", &setting.Cfg{})