feat(app routes): worked on app routes, added unit test, changed Grafana-Context header to start with X to be standard compliant, got cloud saas queries to work via app route feature and header template
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package pluginproxy
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestPluginProxy(t *testing.T) {
|
||||
|
||||
Convey("When getting proxy headers", t, func() {
|
||||
route := &plugins.AppPluginRoute{
|
||||
Headers: []plugins.AppPluginRouteHeader{
|
||||
{Name: "x-header", Content: "my secret {{.SecureJsonData.key}}"},
|
||||
},
|
||||
}
|
||||
|
||||
setting.SecretKey = "password"
|
||||
|
||||
bus.AddHandler("test", func(query *m.GetAppSettingByAppIdQuery) error {
|
||||
query.Result = &m.AppSettings{
|
||||
SecureJsonData: map[string][]byte{
|
||||
"key": util.Encrypt([]byte("123"), "password"),
|
||||
},
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
header, err := getHeaders(route, 1, "my-app")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("Should render header template", func() {
|
||||
So(header.Get("x-header"), ShouldEqual, "my secret 123")
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user