Plugins: Preserve trailing slash in plugin proxy (#86859)

* Plugins: Preserve trailing slash in plugin proxy

* enable toggle by default
This commit is contained in:
Marcus Efraimsson
2024-06-05 13:36:14 +02:00
committed by GitHub
parent 17f03882d4
commit fe3e5917f1
11 changed files with 72 additions and 1 deletions

View File

@ -316,10 +316,16 @@ func TestPluginProxyRoutes(t *testing.T) {
Method: "GET",
URL: "http://localhost/api/v2/instances",
},
{
Path: "/mypath/*",
Method: "GET",
URL: "https://example.com/api/v1/",
},
}
tcs := []struct {
proxyPath string
withFeatures []any
expectedURLPath string
expectedStatus int
}{
@ -362,6 +368,17 @@ func TestPluginProxyRoutes(t *testing.T) {
expectedURLPath: "/api/v2/instances/instance-one",
expectedStatus: http.StatusOK,
},
{
proxyPath: "/mypath/some-route/",
expectedURLPath: "/api/v1/some-route",
expectedStatus: http.StatusOK,
},
{
proxyPath: "/mypath/some-route/",
withFeatures: []any{featuremgmt.FlagPluginProxyPreserveTrailingSlash},
expectedURLPath: "/api/v1/some-route/",
expectedStatus: http.StatusOK,
},
}
for _, tc := range tcs {
@ -404,7 +421,7 @@ func TestPluginProxyRoutes(t *testing.T) {
SecureJSONData: map[string][]byte{},
}
cfg := &setting.Cfg{}
proxy, err := NewPluginProxy(ps, testRoutes, ctx, tc.proxyPath, cfg, secretsService, tracing.InitializeTracerForTest(), &http.Transport{}, acimpl.ProvideAccessControl(featuremgmt.WithFeatures()), featuremgmt.WithFeatures())
proxy, err := NewPluginProxy(ps, testRoutes, ctx, tc.proxyPath, cfg, secretsService, tracing.InitializeTracerForTest(), &http.Transport{}, acimpl.ProvideAccessControl(featuremgmt.WithFeatures()), featuremgmt.WithFeatures(tc.withFeatures...))
require.NoError(t, err)
proxy.HandleRequest()