Plugins: Automatically forward plugin request HTTP headers in outgoing HTTP requests (#60417)
Automatically forward core plugin request HTTP headers in outgoing HTTP requests. Core datasource plugin authors don't have to specifically handle forwarding of HTTP headers, e.g. do not have to "hardcode" the header-names in the datasource plugin, if not having custom needs. Fixes #57065
This commit is contained in:
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/tsdb/prometheus/client"
|
||||
apiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
|
||||
p "github.com/prometheus/common/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/httpclient"
|
||||
@@ -343,27 +342,6 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrometheusCanonicalHeaders(t *testing.T) {
|
||||
// Ensure headers are always canonicalized for all outgoing requests
|
||||
b, err := json.Marshal(models.QueryModel{})
|
||||
require.NoError(t, err)
|
||||
query := backend.DataQuery{JSON: b}
|
||||
tctx, err := setup(true)
|
||||
require.NoError(t, err)
|
||||
const idToken = "abc"
|
||||
_, err = executeWithHeaders(tctx, query, queryResult{}, map[string]string{
|
||||
"X-Id-Token": idToken,
|
||||
"X-ID-Token": idToken,
|
||||
"X-Other": "thing",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, tctx.httpProvider.req.Header)
|
||||
// Check the request that hit the fake prometheus server to ensure headers are valid
|
||||
assert.Equal(t, []string{idToken}, tctx.httpProvider.req.Header["X-Id-Token"])
|
||||
assert.Empty(t, tctx.httpProvider.req.Header["X-ID-Token"]) //nolint:staticcheck
|
||||
assert.Equal(t, []string{"thing"}, tctx.httpProvider.req.Header["X-Other"])
|
||||
}
|
||||
|
||||
type queryResult struct {
|
||||
Type p.ValueType `json:"resultType"`
|
||||
Result interface{} `json:"result"`
|
||||
|
||||
Reference in New Issue
Block a user