[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,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,
})
);
}
});
});
}
);

View file

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