[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:
parent
475c618434
commit
bc171418d2
|
@ -525,25 +525,23 @@ export async function initRoutes(core, getLicenseId, emsSettings, kbnVersion, lo
|
|||
},
|
||||
},
|
||||
(context, request, response) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const santizedRange = path.normalize(request.params.range);
|
||||
const fontPath = path.join(__dirname, 'fonts', 'open_sans', `${santizedRange}.pbf`);
|
||||
fs.readFile(fontPath, (error, data) => {
|
||||
if (error) {
|
||||
reject(
|
||||
response.custom({
|
||||
statusCode: 404,
|
||||
})
|
||||
);
|
||||
} else {
|
||||
resolve(
|
||||
response.ok({
|
||||
body: data,
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
const range = path.normalize(request.params.range);
|
||||
return range.startsWith('..')
|
||||
? 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());
|
||||
} else {
|
||||
resolve(
|
||||
response.ok({
|
||||
body: data,
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -18,5 +18,19 @@ export default function ({ getService }) {
|
|||
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue