id forwarding: transfer Grafana id token to app plugins (#81967)

* id forwarding: allow for app plugins as well

* Add test
This commit is contained in:
Gabriel MABILLE
2024-02-06 16:26:17 +01:00
committed by GitHub
parent eab7990349
commit 4af5aef417
2 changed files with 22 additions and 2 deletions

View File

@ -51,4 +51,24 @@ func TestForwardIDMiddleware(t *testing.T) {
require.Len(t, cdt.CallResourceReq.Headers[forwardIDHeaderName], 0)
})
pluginContext = backend.PluginContext{
AppInstanceSettings: &backend.AppInstanceSettings{},
}
t.Run("Should set forwarded id header to app plugin if present", func(t *testing.T) {
cdt := clienttest.NewClientDecoratorTest(t, clienttest.WithMiddlewares(NewForwardIDMiddleware()))
ctx := context.WithValue(context.Background(), ctxkey.Key{}, &contextmodel.ReqContext{
Context: &web.Context{Req: &http.Request{}},
SignedInUser: &user.SignedInUser{IDToken: "some-token"},
})
err := cdt.Decorator.CallResource(ctx, &backend.CallResourceRequest{
PluginContext: pluginContext,
}, nopCallResourceSender)
require.NoError(t, err)
require.Equal(t, "some-token", cdt.CallResourceReq.Headers[forwardIDHeaderName][0])
})
}