Skip to content

Commit 30441a5

Browse files
committed
align cors settings names with elasticsearch
1 parent 96bb72f commit 30441a5

8 files changed

Lines changed: 35 additions & 33 deletions

File tree

docs/setup/settings.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,11 @@ deprecation warning at startup. This setting cannot end in a slash (`/`).
453453
| `server.cors.enabled:`
454454
| experimental[] Set to `true` to allow cross-origin API calls. *Default:* `false`
455455

456-
| `server.cors.credentials:`
456+
| `server.cors.allowCredentials:`
457457
| experimental[] Set to `true` to allow browser code to access response body whenever request performed with user credentials. *Default:* `false`
458458

459-
| `server.cors.origin:`
460-
| experimental[] List of origins permitted to access resources. You must specify explicit hostnames and not use `*` for `server.cors.origin` when `server.cors.credentials: true`. *Default:* "*"
459+
| `server.cors.allowOrigin:`
460+
| experimental[] List of origins permitted to access resources. You must specify explicit hostnames and not use `*` for `server.cors.allowOrigin` when `server.cors.allowCredentials: true`. *Default:* "*"
461461

462462
| `server.compression.referrerWhitelist:`
463463
| Specifies an array of trusted hostnames, such as the {kib} host, or a reverse

src/core/server/http/__snapshots__/http_config.test.ts.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/server/http/http_config.test.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -331,51 +331,53 @@ describe('with compression', () => {
331331
});
332332

333333
describe('cors', () => {
334-
describe('origin', () => {
334+
describe('allowOrigin', () => {
335335
it('list cannot be empty', () => {
336336
expect(() =>
337337
config.schema.validate({
338338
cors: {
339-
origin: [],
339+
allowOrigin: [],
340340
},
341341
})
342342
).toThrowErrorMatchingInlineSnapshot(`
343-
"[cors.origin]: types that failed validation:
344-
- [cors.origin.0]: expected value to equal [*]
345-
- [cors.origin.1]: array size is [0], but cannot be smaller than [1]"
346-
`);
343+
"[cors.allowOrigin]: types that failed validation:
344+
- [cors.allowOrigin.0]: expected value to equal [*]
345+
- [cors.allowOrigin.1]: array size is [0], but cannot be smaller than [1]"
346+
`);
347347
});
348348

349349
it('list of valid URLs', () => {
350-
const origin = ['http://127.0.0.1:3000', 'https://elastic.co'];
350+
const allowOrigin = ['http://127.0.0.1:3000', 'https://elastic.co'];
351351
expect(
352352
config.schema.validate({
353-
cors: { origin },
354-
}).cors.origin
355-
).toStrictEqual(origin);
353+
cors: { allowOrigin },
354+
}).cors.allowOrigin
355+
).toStrictEqual(allowOrigin);
356356

357357
expect(() =>
358358
config.schema.validate({
359359
cors: {
360-
origin: ['*://elastic.co/*'],
360+
allowOrigin: ['*://elastic.co/*'],
361361
},
362362
})
363363
).toThrow();
364364
});
365365

366366
it('can be configured as "*" wildcard', () => {
367-
expect(config.schema.validate({ cors: { origin: '*' } }).cors.origin).toBe('*');
367+
expect(config.schema.validate({ cors: { allowOrigin: '*' } }).cors.allowOrigin).toBe('*');
368368
});
369369
});
370370
describe('credentials', () => {
371-
it('cannot use wildcard origin if "credentials: true"', () => {
371+
it('cannot use wildcard allowOrigin if "credentials: true"', () => {
372372
expect(
373-
() => config.schema.validate({ cors: { credentials: true, origin: '*' } }).cors.origin
373+
() =>
374+
config.schema.validate({ cors: { allowCredentials: true, allowOrigin: '*' } }).cors
375+
.allowOrigin
374376
).toThrowErrorMatchingInlineSnapshot(
375377
`"[cors]: Cannot specify wildcard origin \\"*\\" with \\"credentials: true\\". Please provide a list of allowed origins."`
376378
);
377379
expect(
378-
() => config.schema.validate({ cors: { credentials: true } }).cors.origin
380+
() => config.schema.validate({ cors: { allowCredentials: true } }).cors.allowOrigin
379381
).toThrowErrorMatchingInlineSnapshot(
380382
`"[cors]: Cannot specify wildcard origin \\"*\\" with \\"credentials: true\\". Please provide a list of allowed origins."`
381383
);

src/core/server/http/http_config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export const config = {
4848
cors: schema.object(
4949
{
5050
enabled: schema.boolean({ defaultValue: false }),
51-
credentials: schema.boolean({ defaultValue: false }),
52-
origin: schema.oneOf(
51+
allowCredentials: schema.boolean({ defaultValue: false }),
52+
allowOrigin: schema.oneOf(
5353
[schema.literal('*'), schema.arrayOf(hostURISchema, { minSize: 1 })],
5454
{
5555
defaultValue: '*',
@@ -58,7 +58,7 @@ export const config = {
5858
},
5959
{
6060
validate(value) {
61-
if (value.credentials === true && value.origin === '*') {
61+
if (value.allowCredentials === true && value.allowOrigin === '*') {
6262
return 'Cannot specify wildcard origin "*" with "credentials: true". Please provide a list of allowed origins.';
6363
}
6464
},
@@ -168,8 +168,8 @@ export class HttpConfig {
168168
public port: number;
169169
public cors: {
170170
enabled: boolean;
171-
credentials: boolean;
172-
origin: '*' | string[];
171+
allowCredentials: boolean;
172+
allowOrigin: '*' | string[];
173173
};
174174
public customResponseHeaders: Record<string, string | string[]>;
175175
public maxPayload: ByteSizeValue;

src/core/server/http/http_tools.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ describe('getServerOptions', () => {
196196
config.schema.validate({
197197
cors: {
198198
enabled: true,
199-
credentials: false,
200-
origin: '*',
199+
allowCredentials: false,
200+
allowOrigin: '*',
201201
},
202202
}),
203203
{} as any,

src/core/server/http/http_tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const corsAllowedHeaders = ['Accept', 'Authorization', 'Content-Type', 'If-None-
3939
export function getServerOptions(config: HttpConfig, { configureTLS = true } = {}) {
4040
const cors: RouteOptionsCors | false = config.cors.enabled
4141
? {
42-
credentials: config.cors.credentials,
43-
origin: config.cors.origin,
42+
credentials: config.cors.allowCredentials,
43+
origin: config.cors.allowOrigin,
4444
headers: corsAllowedHeaders,
4545
}
4646
: false;

x-pack/test/functional_cors/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
5555
`--plugin-path=${corsTestPlugin}`,
5656
`--test.cors.port=${pluginPort}`,
5757
'--server.cors.enabled=true',
58-
'--server.cors.credentials=true',
59-
`--server.cors.origin=["${originUrl}"]`,
58+
'--server.cors.allowCredentials=true',
59+
`--server.cors.allowOrigin=["${originUrl}"]`,
6060
],
6161
},
6262
};

x-pack/test/functional_cors/tests/cors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
1515
describe('CORS', () => {
1616
it('Communicates to Kibana with configured CORS', async () => {
1717
const args: string[] = config.get('kbnTestServer.serverArgs');
18-
const originSetting = args.find((str) => str.includes('server.cors.origin'));
18+
const originSetting = args.find((str) => str.includes('server.cors.allowOrigin'));
1919
if (!originSetting) {
20-
throw new Error('Cannot find "server.cors.origin" argument');
20+
throw new Error('Cannot find "server.cors.allowOrigin" argument');
2121
}
2222
const [, value] = originSetting.split('=');
2323
const url = JSON.parse(value);

0 commit comments

Comments
 (0)