pluginproxy_test.go 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package pluginproxy
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/bus"
  5. m "github.com/grafana/grafana/pkg/models"
  6. "github.com/grafana/grafana/pkg/plugins"
  7. "github.com/grafana/grafana/pkg/setting"
  8. "github.com/grafana/grafana/pkg/util"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestPluginProxy(t *testing.T) {
  12. Convey("When getting proxy headers", t, func() {
  13. route := &plugins.AppPluginRoute{
  14. Headers: []plugins.AppPluginRouteHeader{
  15. {Name: "x-header", Content: "my secret {{.SecureJsonData.key}}"},
  16. },
  17. }
  18. setting.SecretKey = "password"
  19. bus.AddHandler("test", func(query *m.GetPluginSettingByIdQuery) error {
  20. query.Result = &m.PluginSetting{
  21. SecureJsonData: map[string][]byte{
  22. "key": util.Encrypt([]byte("123"), "password"),
  23. },
  24. }
  25. return nil
  26. })
  27. header, err := getHeaders(route, 1, "my-app")
  28. So(err, ShouldBeNil)
  29. Convey("Should render header template", func() {
  30. So(header.Get("x-header"), ShouldEqual, "my secret 123")
  31. })
  32. })
  33. }