mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
* refactor util encryption library so it doesn't have to import log * add util.SplitString to handle space and/or comma-separated config lines * go fmt
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
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.GetPluginSettingByIdQuery) error {
|
|
key, err := util.Encrypt([]byte("123"), "password")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
query.Result = &m.PluginSetting{
|
|
SecureJsonData: map[string][]byte{
|
|
"key": key,
|
|
},
|
|
}
|
|
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")
|
|
})
|
|
})
|
|
|
|
}
|