[Maps] fix fonts api (#107768)

* [Maps] fix fonts api

* update expect statement name

* eslint

* add test case for './../'

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2021-08-09 13:17:58 -06:00 committed by GitHub
parent 475c618434
commit bc171418d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 19 deletions

View file

@ -525,16 +525,14 @@ export async function initRoutes(core, getLicenseId, emsSettings, kbnVersion, lo
}, },
}, },
(context, request, response) => { (context, request, response) => {
return new Promise((resolve, reject) => { const range = path.normalize(request.params.range);
const santizedRange = path.normalize(request.params.range); return range.startsWith('..')
const fontPath = path.join(__dirname, 'fonts', 'open_sans', `${santizedRange}.pbf`); ? response.notFound()
: new Promise((resolve) => {
const fontPath = path.join(__dirname, 'fonts', 'open_sans', `${range}.pbf`);
fs.readFile(fontPath, (error, data) => { fs.readFile(fontPath, (error, data) => {
if (error) { if (error) {
reject( resolve(response.notFound());
response.custom({
statusCode: 404,
})
);
} else { } else {
resolve( resolve(
response.ok({ response.ok({

View file

@ -18,5 +18,19 @@ export default function ({ getService }) {
expect(resp.body.length).to.be(74696); expect(resp.body.length).to.be(74696);
}); });
it('should return 404 when file not found', async () => {
await supertest
.get(`/api/maps/fonts/Open%20Sans%20Regular,Arial%20Unicode%20MS%20Regular/noGonaFindMe`)
.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/.%2f..%2fopen_sans%2f0-255`).expect(404);
});
}); });
} }