Fix maps font path (#115453)

* fixed font path

* fix functional tests

* fix directory issue

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Thom Heymann 2021-10-20 10:22:04 +01:00 committed by GitHub
parent 8fcfa79e73
commit 6e7dfcd99a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View file

@ -488,10 +488,11 @@ export async function initRoutes(core, getLicenseId, emsSettings, kbnVersion, lo
},
(context, request, response) => {
const range = path.normalize(request.params.range);
return range.startsWith('..')
const rootPath = path.resolve(__dirname, 'fonts', 'open_sans');
const fontPath = path.resolve(rootPath, `${range}.pbf`);
return !fontPath.startsWith(rootPath)
? response.notFound()
: new Promise((resolve) => {
const fontPath = path.join(__dirname, 'fonts', 'open_sans', `${range}.pbf`);
fs.readFile(fontPath, (error, data) => {
if (error) {
resolve(response.notFound());

View file

@ -6,11 +6,33 @@
*/
import expect from '@kbn/expect';
import path from 'path';
import { copyFile, rm } from 'fs/promises';
export default function ({ getService }) {
const supertest = getService('supertest');
const log = getService('log');
describe('fonts', () => {
// [HACK]: On CI tests are run from the different directories than the built and running Kibana
// instance. To workaround that we use Kibana `process.cwd()` to construct font path manually.
// x-pack tests can be run from root directory or from within x-pack so need to cater for both possibilities.
const fontPath = path.join(
process.cwd().replace(/x-pack.*$/, ''),
'x-pack/plugins/maps/server/fonts/open_sans/0-255.pbf'
);
const destinationPath = path.join(path.dirname(fontPath), '..', path.basename(fontPath));
before(async () => {
log.debug(`Copying test file from '${fontPath}' to '${destinationPath}'`);
await copyFile(fontPath, destinationPath);
});
after(async () => {
log.debug(`Removing test file '${destinationPath}'`);
await rm(destinationPath);
});
it('should return fonts', async () => {
const resp = await supertest
.get(`/api/maps/fonts/Open%20Sans%20Regular,Arial%20Unicode%20MS%20Regular/0-255`)
@ -25,12 +47,12 @@ export default function ({ getService }) {
.expect(404);
});
it('should return 404 when file is not in font folder (../)', async () => {
await supertest.get(`/api/maps/fonts/open_sans/..%2fopen_sans%2f0-255`).expect(404);
it('should return 404 when file is not in font folder (..)', async () => {
await supertest.get(`/api/maps/fonts/open_sans/..%2f0-255`).expect(404);
});
it('should return 404 when file is not in font folder (./../)', async () => {
await supertest.get(`/api/maps/fonts/open_sans/.%2f..%2fopen_sans%2f0-255`).expect(404);
it('should return 404 when file is not in font folder (./..)', async () => {
await supertest.get(`/api/maps/fonts/open_sans/.%2f..%2f0-255`).expect(404);
});
});
}