mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
* extract http_tools to package
* fix readme
* start moving stuff
* cleaning up `isDevCliParent`
* choose bootstrap script
* fix bootstrap script logic
* fix watch paths logic
* import REPO_ROOT from correct package
* create the @kbn/crypto package
* update core's `dev` config
* only export bootstrap function
* extract sslConfig to http-tools package
* fix core types
* fix optimizer tests
* fix cli_dev_mode tests
* fix basePath proxy tests
* update generated doc
* fix unit tests
* create @kbn/dev-cli-mode package
* remove useless comment
* self-review NITS
* update CODEOWNERS file
* add devOnly flag
* use variable for DEV_MODE_PATH
* review comments
* fix logger/log adapter
* fix log calls in base path proxy server
* address some review comments
* rename @kbn/http-tools to @kbn/server-http-tools
* more review comments
* move test to correct file
* add comment on getBootstrapScript
* fix lint
* lint
* add cli-dev-mode to eslint dev packages
* review comments
* update yarn.lock
* Revert "[ci] skip building ts refs when not necessary (#95739)"
This reverts commit e46a74f7
122 lines
3.2 KiB
TypeScript
122 lines
3.2 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
* Side Public License, v 1.
|
|
*/
|
|
|
|
import { ByteSizeValue } from '@kbn/config-schema';
|
|
import { getServerOptions } from './get_server_options';
|
|
import { IHttpConfig } from './types';
|
|
|
|
jest.mock('fs', () => {
|
|
const original = jest.requireActual('fs');
|
|
return {
|
|
// Hapi Inert patches native methods
|
|
...original,
|
|
readFileSync: jest.fn(),
|
|
};
|
|
});
|
|
|
|
const createConfig = (parts: Partial<IHttpConfig>): IHttpConfig => ({
|
|
host: 'localhost',
|
|
port: 5601,
|
|
socketTimeout: 120000,
|
|
keepaliveTimeout: 120000,
|
|
maxPayload: ByteSizeValue.parse('1048576b'),
|
|
...parts,
|
|
cors: {
|
|
enabled: false,
|
|
allowCredentials: false,
|
|
allowOrigin: ['*'],
|
|
...parts.cors,
|
|
},
|
|
ssl: {
|
|
enabled: false,
|
|
...parts.ssl,
|
|
},
|
|
});
|
|
|
|
describe('getServerOptions', () => {
|
|
beforeEach(() =>
|
|
jest.requireMock('fs').readFileSync.mockImplementation((path: string) => `content-${path}`)
|
|
);
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('properly configures TLS with default options', () => {
|
|
const httpConfig = createConfig({
|
|
ssl: {
|
|
enabled: true,
|
|
key: 'some-key-path',
|
|
certificate: 'some-certificate-path',
|
|
},
|
|
});
|
|
|
|
expect(getServerOptions(httpConfig).tls).toMatchInlineSnapshot(`
|
|
Object {
|
|
"ca": undefined,
|
|
"cert": "some-certificate-path",
|
|
"ciphers": undefined,
|
|
"honorCipherOrder": true,
|
|
"key": "some-key-path",
|
|
"passphrase": undefined,
|
|
"rejectUnauthorized": undefined,
|
|
"requestCert": undefined,
|
|
"secureOptions": undefined,
|
|
}
|
|
`);
|
|
});
|
|
|
|
it('properly configures TLS with client authentication', () => {
|
|
const httpConfig = createConfig({
|
|
ssl: {
|
|
enabled: true,
|
|
key: 'some-key-path',
|
|
certificate: 'some-certificate-path',
|
|
certificateAuthorities: ['ca-1', 'ca-2'],
|
|
cipherSuites: ['suite-a', 'suite-b'],
|
|
keyPassphrase: 'passPhrase',
|
|
rejectUnauthorized: true,
|
|
requestCert: true,
|
|
getSecureOptions: () => 42,
|
|
},
|
|
});
|
|
|
|
expect(getServerOptions(httpConfig).tls).toMatchInlineSnapshot(`
|
|
Object {
|
|
"ca": Array [
|
|
"ca-1",
|
|
"ca-2",
|
|
],
|
|
"cert": "some-certificate-path",
|
|
"ciphers": "suite-a:suite-b",
|
|
"honorCipherOrder": true,
|
|
"key": "some-key-path",
|
|
"passphrase": "passPhrase",
|
|
"rejectUnauthorized": true,
|
|
"requestCert": true,
|
|
"secureOptions": 42,
|
|
}
|
|
`);
|
|
});
|
|
|
|
it('properly configures CORS when cors enabled', () => {
|
|
const httpConfig = createConfig({
|
|
cors: {
|
|
enabled: true,
|
|
allowCredentials: false,
|
|
allowOrigin: ['*'],
|
|
},
|
|
});
|
|
|
|
expect(getServerOptions(httpConfig).routes?.cors).toEqual({
|
|
credentials: false,
|
|
origin: ['*'],
|
|
headers: ['Accept', 'Authorization', 'Content-Type', 'If-None-Match', 'kbn-xsrf'],
|
|
});
|
|
});
|
|
});
|