[v9.3.x] QueryData: fix header parsing to support expressions (#58848)

QueryData: fix header parsing to support expressions (#58826)

fixes #58821

(cherry picked from commit 934fb2f0ee)

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2022-11-16 10:29:59 -05:00
committed by GitHub
co-authored by Ryan McKinley
parent 4890db3089
commit 7ec8550652
2 changed files with 16 additions and 0 deletions
+8
View File
@@ -259,6 +259,14 @@ func (pr parsedRequest) validateRequest() error {
return nil
}
if pr.hasExpression {
hasExpr := pr.httpRequest.URL.Query().Get("expression")
if hasExpr == "" || hasExpr == "true" {
return nil
}
return ErrQueryParamMismatch
}
vals := splitHeaders(pr.httpRequest.Header.Values(HeaderDatasourceUID))
count := len(vals)
if count > 0 { // header exists
+8
View File
@@ -288,8 +288,16 @@ func TestQueryDataMultipleSources(t *testing.T) {
HTTPRequest: nil,
}
// without query parameter
_, err = tc.queryService.QueryData(context.Background(), tc.signedInUser, true, reqDTO)
require.NoError(t, err)
httpreq, _ := http.NewRequest(http.MethodPost, "http://localhost/ds/query?expression=true", bytes.NewReader([]byte{}))
httpreq.Header.Add("X-Datasource-Uid", "gIEkMvIVz")
reqDTO.HTTPRequest = httpreq
// with query parameter
_, err = tc.queryService.QueryData(context.Background(), tc.signedInUser, true, reqDTO)
require.NoError(t, err)
})