Skip to content

Commit 83abbe1

Browse files
committed
add FTR test for endpoint
1 parent b085dee commit 83abbe1

File tree

5 files changed

+125
-57
lines changed

5 files changed

+125
-57
lines changed

src/core/server/i18n/routes/translations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const registerTranslationsRoute = (router: IRouter, locale: string) => {
4343
},
4444
},
4545
(ctx, req, res) => {
46-
if (req.params.locale !== locale) {
46+
if (req.params.locale.toLowerCase() !== locale.toLowerCase()) {
4747
return res.notFound({
4848
body: `Unknown locale: ${req.params.locale}`,
4949
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import expect from '@kbn/expect';
20+
import { FtrProviderContext } from '../../ftr_provider_context';
21+
22+
export default function ({ getService }: FtrProviderContext) {
23+
const supertest = getService('supertest');
24+
25+
describe('compression', () => {
26+
it(`uses compression when there isn't a referer`, async () => {
27+
await supertest
28+
.get('/app/kibana')
29+
.set('accept-encoding', 'gzip')
30+
.then((response) => {
31+
expect(response.header).to.have.property('content-encoding', 'gzip');
32+
});
33+
});
34+
35+
it(`uses compression when there is a whitelisted referer`, async () => {
36+
await supertest
37+
.get('/app/kibana')
38+
.set('accept-encoding', 'gzip')
39+
.set('referer', 'https://some-host.com')
40+
.then((response) => {
41+
expect(response.header).to.have.property('content-encoding', 'gzip');
42+
});
43+
});
44+
45+
it(`doesn't use compression when there is a non-whitelisted referer`, async () => {
46+
await supertest
47+
.get('/app/kibana')
48+
.set('accept-encoding', 'gzip')
49+
.set('referer', 'https://other.some-host.com')
50+
.then((response) => {
51+
expect(response.header).not.to.have.property('content-encoding');
52+
});
53+
});
54+
});
55+
}

test/api_integration/apis/core/index.js

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { FtrProviderContext } from '../../ftr_provider_context';
21+
22+
export default function ({ loadTestFile }: FtrProviderContext) {
23+
describe('core', () => {
24+
loadTestFile(require.resolve('./compression'));
25+
loadTestFile(require.resolve('./translations'));
26+
});
27+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import expect from '@kbn/expect';
20+
import { FtrProviderContext } from '../../ftr_provider_context';
21+
22+
export default function ({ getService }: FtrProviderContext) {
23+
const supertest = getService('supertest');
24+
25+
describe('translations', () => {
26+
it(`returns the translations with the correct headers`, async () => {
27+
await supertest.get('/translations/en.json').then((response) => {
28+
expect(response.body.locale).to.eql('en');
29+
30+
expect(response.header).to.have.property('content-type', 'application/json; charset=utf-8');
31+
expect(response.header).to.have.property('cache-control', 'must-revalidate');
32+
expect(response.header).to.have.property('etag');
33+
});
34+
});
35+
36+
it(`returns a 404 when not using the correct locale`, async () => {
37+
await supertest.get('/translations/foo.json').then((response) => {
38+
expect(response.status).to.eql(404);
39+
});
40+
});
41+
});
42+
}

0 commit comments

Comments
 (0)