diff --git a/src/plugins/elasticsearch/lib/__tests__/call_with_request.js b/src/plugins/elasticsearch/lib/__tests__/call_with_request.js new file mode 100644 index 0000000000000..ac487e91bce0c --- /dev/null +++ b/src/plugins/elasticsearch/lib/__tests__/call_with_request.js @@ -0,0 +1,28 @@ +import expect from 'expect.js'; +import callWithRequest from '../call_with_request'; + +describe('call_with_request', () => { + let mockClient; + + beforeEach(() => { + mockClient = { + search(params) { + this.params = params; + return Promise.resolve(this); + } + }; + }); + + it ('passes through all headers', () => { + const mockRequest = { + headers: { + authorization: 'Basic QWxhZGRpbjpPcGVuU2VzYW1l', + 'kbn-version': '4.6.0' + } + }; + return callWithRequest(mockClient)(mockRequest, 'search') + .then(() => { + expect(mockClient.params.headers).to.be(mockRequest.headers); + }); + }); +}); diff --git a/src/plugins/elasticsearch/lib/call_with_request.js b/src/plugins/elasticsearch/lib/call_with_request.js index cf440b260219a..a2026a86edf83 100644 --- a/src/plugins/elasticsearch/lib/call_with_request.js +++ b/src/plugins/elasticsearch/lib/call_with_request.js @@ -6,9 +6,7 @@ const toPath = require('lodash/internal/toPath'); module.exports = (client) => { return (req, endpoint, params = {}) => { - if (req.headers.authorization) { - _.set(params, 'headers.authorization', req.headers.authorization); - } + _.set(params, 'headers', req.headers); const path = toPath(endpoint); const api = _.get(client, path); let apiContext = _.get(client, path.slice(0, -1));