DataProxy: Ignore empty URL's in plugin routes (#27653)

This adds a check to see if plugin route URL is empty, and in such case
does not modify request schema and host of the request to be proxied.
This behavior is now the same as in the plugin proxy.

(cherry picked from commit 564d7ecea7)
This commit is contained in:
Domas
2020-09-18 14:22:07 +03:00
committed by Leonard Gram
parent bdeb380c56
commit 2870eab4d7
2 changed files with 31 additions and 14 deletions
+15
View File
@@ -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{})