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

fixes #58821
pull/58841/head^2
Ryan McKinley 3 years ago committed by GitHub
parent 9a5a344304
commit 934fb2f0ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      pkg/services/query/query.go
  2. 8
      pkg/services/query/query_test.go

@ -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

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

Loading…
Cancel
Save