Skip to content

Commit

Permalink
Merge branch 'master' into i18n/test_kibana_translation_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 27, 2020
2 parents b3f89eb + 2d0106d commit d0b9dac
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
24 changes: 17 additions & 7 deletions x-pack/plugins/maps/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,28 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
return badRequest('map.proxyElasticMapsServiceInMaps disabled');
}

const file = await emsClient.getDefaultFileManifest();
const layers = file.layers.map((layer) => {
const newLayer = { ...layer };
const id = encodeURIComponent(layer.layer_id);
const file = await emsClient.getDefaultFileManifest(); //need raw manifest
const fileLayers = await emsClient.getFileLayers();

const layers = file.layers.map((layerJson) => {
const newLayerJson = { ...layerJson };
const id = encodeURIComponent(layerJson.layer_id);

const fileLayer = fileLayers.find((fileLayer) => fileLayer.getId() === layerJson.layer_id);
const defaultFormat = layerJson.formats.find(
(format) => format.type === fileLayer.getDefaultFormatType()
);

const newUrl = `${EMS_FILES_DEFAULT_JSON_PATH}?id=${id}`;
newLayer.formats = [

//Only proxy default-format. Others are unused in Maps-app
newLayerJson.formats = [
{
...layer.formats[0],
...defaultFormat,
url: newUrl,
},
];
return newLayer;
return newLayerJson;
});
//rewrite
return ok({
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/api_integration/apis/maps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function ({ loadTestFile, getService }) {
loadTestFile(require.resolve('./migrations'));
loadTestFile(require.resolve('./get_tile'));
loadTestFile(require.resolve('./get_grid_tile'));
loadTestFile(require.resolve('./proxy_api'));
});
});
}
28 changes: 28 additions & 0 deletions x-pack/test/api_integration/apis/maps/proxy_api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';

export default function ({ getService }) {
const supertest = getService('supertest');

describe('EMS proxy', () => {
it('should correctly rewrite url and format', async () => {
const resp = await supertest
.get(`/api/maps/ems/files/v7.10/manifest`)
.set('kbn-xsrf', 'kibana')
.expect(200);

expect(resp.body.layers.length).to.be.greaterThan(0);

//Check world-layer
const worldLayer = resp.body.layers.find((layer) => layer.layer_id === 'world_countries');
expect(worldLayer.formats.length).to.be.greaterThan(0);
expect(worldLayer.formats[0].type).to.be('geojson');
expect(worldLayer.formats[0].url).to.be('file?id=world_countries');
});
});
}
1 change: 1 addition & 0 deletions x-pack/test/api_integration/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function getApiIntegrationConfig({ readConfigFile }: FtrConfigProvi
...xPackFunctionalTestsConfig.get('kbnTestServer'),
serverArgs: [
...xPackFunctionalTestsConfig.get('kbnTestServer.serverArgs'),
'--map.proxyElasticMapsServiceInMaps=true',
'--xpack.security.session.idleTimeout=3600000', // 1 hour
'--telemetry.optIn=true',
'--xpack.fleet.enabled=true',
Expand Down

0 comments on commit d0b9dac

Please sign in to comment.