mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Adding tests for empty and [] values for elasticsearch.requestHeadersWhitelist
This commit is contained in:
parent
eeedc54ce8
commit
c5ce30f81c
2 changed files with 47 additions and 10 deletions
|
@ -5,18 +5,9 @@ import sinon from 'sinon';
|
|||
describe('plugins/elasticsearch', function () {
|
||||
describe('lib/map_uri', function () {
|
||||
|
||||
let server;
|
||||
let request;
|
||||
|
||||
beforeEach(function () {
|
||||
const get = sinon.stub()
|
||||
.withArgs('elasticsearch.url').returns('http://foobar:9200')
|
||||
.withArgs('elasticsearch.requestHeadersWhitelist').returns(['x-my-custom-HEADER', 'Authorization']);
|
||||
const config = function () { return { get: get }; };
|
||||
server = {
|
||||
config: config
|
||||
};
|
||||
|
||||
request = {
|
||||
path: '/elasticsearch/some/path',
|
||||
headers: {
|
||||
|
@ -31,7 +22,16 @@ describe('plugins/elasticsearch', function () {
|
|||
};
|
||||
});
|
||||
|
||||
it('only keeps the whitelisted request headers', function () {
|
||||
it('only sends the whitelisted request headers', function () {
|
||||
|
||||
const get = sinon.stub()
|
||||
.withArgs('elasticsearch.url').returns('http://foobar:9200')
|
||||
.withArgs('elasticsearch.requestHeadersWhitelist').returns(['x-my-custom-HEADER', 'Authorization']);
|
||||
const config = function () { return { get: get }; };
|
||||
const server = {
|
||||
config: config
|
||||
};
|
||||
|
||||
mapUri(server)(request, function (err, upstreamUri, upstreamHeaders) {
|
||||
expect(err).to.be(null);
|
||||
expect(upstreamHeaders).to.have.property('authorization');
|
||||
|
@ -39,5 +39,38 @@ describe('plugins/elasticsearch', function () {
|
|||
expect(Object.keys(upstreamHeaders).length).to.be(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('sends no headers if whitelist is set to []', function () {
|
||||
|
||||
const get = sinon.stub()
|
||||
.withArgs('elasticsearch.url').returns('http://foobar:9200')
|
||||
.withArgs('elasticsearch.requestHeadersWhitelist').returns([]);
|
||||
const config = function () { return { get: get }; };
|
||||
const server = {
|
||||
config: config
|
||||
};
|
||||
|
||||
mapUri(server)(request, function (err, upstreamUri, upstreamHeaders) {
|
||||
expect(err).to.be(null);
|
||||
expect(Object.keys(upstreamHeaders).length).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('sends no headers if whitelist is set to no value', function () {
|
||||
|
||||
const get = sinon.stub()
|
||||
.withArgs('elasticsearch.url').returns('http://foobar:9200')
|
||||
.withArgs('elasticsearch.requestHeadersWhitelist').returns([ null ]); // This is how Joi returns it
|
||||
const config = function () { return { get: get }; };
|
||||
const server = {
|
||||
config: config
|
||||
};
|
||||
|
||||
mapUri(server)(request, function (err, upstreamUri, upstreamHeaders) {
|
||||
expect(err).to.be(null);
|
||||
expect(Object.keys(upstreamHeaders).length).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,6 +3,10 @@ import _ from 'lodash';
|
|||
module.exports = function (originalHeaders, headersToKeep) {
|
||||
|
||||
const normalizeHeader = function (header) {
|
||||
if (!header) {
|
||||
return '';
|
||||
}
|
||||
header = header.toString();
|
||||
return header.trim().toLowerCase();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue