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

fixes #58821
This commit is contained in:
Ryan McKinley 2022-11-16 15:17:24 +00:00 committed by GitHub
parent 9a5a344304
commit 934fb2f0ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

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

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)
})