Skip to content

Commit

Permalink
add x-elastic-internal-origin header to vector tile, glyphs, and font…
Browse files Browse the repository at this point in the history
…s APIs (#163331)

Closes #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="https://github.com/elastic/kibana/assets/373691/0a057039-b8b5-4fba-8db2-aec91a2d519f">

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
nreese and kibanamachine authored Aug 9, 2023
1 parent 0cfea61 commit a038fb0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,23 +25,32 @@ 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',
},
};
}

if (resourceType === 'Tile' && url.startsWith(GETTILE)) {
return {
url,
method: 'GET' as 'GET',
headers: { [ELASTIC_HTTP_VERSION_HEADER]: '1' },
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
[X_ELASTIC_INTERNAL_ORIGIN_REQUEST]: 'kibana',
},
};
}

if (resourceType === 'Tile' && url.startsWith(GETGRIDTILE)) {
return {
url,
method: 'GET' as 'GET',
headers: { [ELASTIC_HTTP_VERSION_HEADER]: '1' },
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
[X_ELASTIC_INTERNAL_ORIGIN_REQUEST]: 'kibana',
},
};
}

Expand Down
9 changes: 8 additions & 1 deletion x-pack/test/api_integration/apis/maps/fonts_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -49,20 +53,23 @@ 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);
});

it('should return 404 when file is not in font folder (..)', async () => {
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);
});

it('should return 404 when file is not in font folder (./..)', async () => {
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);
});
});
Expand Down
13 changes: 12 additions & 1 deletion x-pack/test/api_integration/apis/maps/get_grid_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
});
Expand Down
8 changes: 7 additions & 1 deletion x-pack/test/api_integration/apis/maps/get_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit a038fb0

Please sign in to comment.