add x-elastic-internal-origin header to vector tile, glyphs, and fonts APIs (#163331)

Closes https://github.com/elastic/kibana/issues/163311

To test
* create map with documents layer (that uses vector tile scaling,
default).
* verify header is provided in request

<img width="500" alt="Screen Shot 2023-08-07 at 10 25 11 AM"
src="0a057039-b8b5-4fba-8db2-aec91a2d519f">

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2023-08-09 15:26:18 -06:00 committed by GitHub
parent 0cfea61424
commit a038fb09ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 7 deletions

View file

@ -5,7 +5,10 @@
* 2.0.
*/
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import {
ELASTIC_HTTP_VERSION_HEADER,
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
} from '@kbn/core-http-common';
import {
FONTS_API_PATH,
MVT_GETTILE_API_PATH,
@ -22,7 +25,10 @@ export function transformRequest(url: string, resourceType: string | undefined)
return {
url,
method: 'GET' as 'GET',
headers: { [ELASTIC_HTTP_VERSION_HEADER]: '1' },
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
[X_ELASTIC_INTERNAL_ORIGIN_REQUEST]: 'kibana',
},
};
}
@ -30,7 +36,10 @@ export function transformRequest(url: string, resourceType: string | undefined)
return {
url,
method: 'GET' as 'GET',
headers: { [ELASTIC_HTTP_VERSION_HEADER]: '1' },
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
[X_ELASTIC_INTERNAL_ORIGIN_REQUEST]: 'kibana',
},
};
}
@ -38,7 +47,10 @@ export function transformRequest(url: string, resourceType: string | undefined)
return {
url,
method: 'GET' as 'GET',
headers: { [ELASTIC_HTTP_VERSION_HEADER]: '1' },
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
[X_ELASTIC_INTERNAL_ORIGIN_REQUEST]: 'kibana',
},
};
}

View file

@ -6,7 +6,10 @@
*/
import expect from '@kbn/expect';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import {
ELASTIC_HTTP_VERSION_HEADER,
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
} from '@kbn/core-http-common';
import path from 'path';
import { copyFile, rm } from 'fs/promises';
@ -38,6 +41,7 @@ export default function ({ getService }) {
const resp = await supertest
.get(`/internal/maps/fonts/Open%20Sans%20Regular,Arial%20Unicode%20MS%20Regular/0-255`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.expect(200);
expect(resp.body.length).to.be(74696);
@ -49,6 +53,7 @@ export default function ({ getService }) {
`/internal/maps/fonts/Open%20Sans%20Regular,Arial%20Unicode%20MS%20Regular/noGonaFindMe`
)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.expect(404);
});
@ -56,6 +61,7 @@ export default function ({ getService }) {
await supertest
.get(`/internal/maps/fonts/open_sans/..%2f0-255`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.expect(404);
});
@ -63,6 +69,7 @@ export default function ({ getService }) {
await supertest
.get(`/internal/maps/fonts/open_sans/.%2f..%2f0-255`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.expect(404);
});
});

View file

@ -9,7 +9,10 @@ import { VectorTile } from '@mapbox/vector-tile';
import Protobuf from 'pbf';
import expect from '@kbn/expect';
import { getTileUrlParams } from '@kbn/maps-vector-tile-utils';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import {
ELASTIC_HTTP_VERSION_HEADER,
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
} from '@kbn/core-http-common';
function findFeature(layer, callbackFn) {
for (let i = 0; i < layer.length; i++) {
@ -75,6 +78,7 @@ export default function ({ getService }) {
.get('/internal/maps/mvt/getGridTile/3/2/3.pbf?' + getTileUrlParams(defaultParams))
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(200);
@ -89,6 +93,7 @@ export default function ({ getService }) {
.get('/internal/maps/mvt/getGridTile/3/2/3.pbf?' + getTileUrlParams(defaultParams))
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(200);
@ -120,6 +125,7 @@ export default function ({ getService }) {
.get('/internal/maps/mvt/getGridTile/3/2/3.pbf?' + tileUrlParams)
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(200);
@ -151,6 +157,7 @@ export default function ({ getService }) {
.get('/internal/maps/mvt/getGridTile/3/2/3.pbf?' + tileUrlParams)
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(200);
@ -189,6 +196,7 @@ export default function ({ getService }) {
.get('/internal/maps/mvt/getGridTile/3/2/3.pbf?' + tileUrlParams)
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(200);
@ -230,6 +238,7 @@ export default function ({ getService }) {
.get('/internal/maps/mvt/getGridTile/3/2/3.pbf?' + tileUrlParams)
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(200);
@ -258,6 +267,7 @@ export default function ({ getService }) {
.get('/internal/maps/mvt/getGridTile/3/2/3.pbf?' + getTileUrlParams(defaultParams))
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(200);
@ -304,6 +314,7 @@ export default function ({ getService }) {
.get('/internal/maps/mvt/getGridTile/3/2/3.pbf?' + tileUrlParams)
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(404);
});

View file

@ -8,7 +8,10 @@
import { VectorTile } from '@mapbox/vector-tile';
import Protobuf from 'pbf';
import expect from '@kbn/expect';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import {
ELASTIC_HTTP_VERSION_HEADER,
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
} from '@kbn/core-http-common';
import { getTileUrlParams } from '@kbn/maps-vector-tile-utils';
function findFeature(layer, callbackFn) {
@ -75,6 +78,7 @@ export default function ({ getService }) {
.get(`/internal/maps/mvt/getTile/2/1/1.pbf?${getTileUrlParams(defaultParams)}`)
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(200);
@ -138,6 +142,7 @@ export default function ({ getService }) {
.get(`/internal/maps/mvt/getTile/2/1/1.pbf?${tileUrlParams}`)
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(200);
@ -182,6 +187,7 @@ export default function ({ getService }) {
.get(`/internal/maps/mvt/getTile/2/1/1.pbf?${tileUrlParams}`)
.set('kbn-xsrf', 'kibana')
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.responseType('blob')
.expect(404);
});