From 4325439bf28d596bc384e7c1beaa39843d4891b5 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Mon, 20 May 2019 12:58:57 -0700 Subject: [PATCH 01/20] [feat] create additional http servers allow for additional http servers to be created, tracked and returned --- src/core/server/http/http_service.test.ts | 39 ++++++++++++++++++++++- src/core/server/http/http_service.ts | 25 +++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index 7b3fd024b477c..e6223fd23cd9e 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -21,8 +21,9 @@ import { mockHttpServer } from './http_service.test.mocks'; import { noop } from 'lodash'; import { BehaviorSubject } from 'rxjs'; +import { first } from 'rxjs/operators'; import { HttpService, Router } from '.'; -import { HttpConfigType, config } from './http_config'; +import { HttpConfigType, config, HttpConfig } from './http_config'; import { Config, ConfigService, Env, ObjectToConfigAdapter } from '../config'; import { loggingServiceMock } from '../logging/logging_service.mock'; import { getEnvOptions } from '../config/__mocks__/env'; @@ -76,6 +77,42 @@ test('creates and sets up http server', async () => { expect(httpServer.start).toHaveBeenCalledTimes(1); }); +test('creates and sets up second http server', async () => { + const configService = createConfigService({ + host: 'example.org', + port: 1234, + }); + + const httpServer = { + isListening: () => false, + setup: jest.fn(), + start: jest.fn(), + stop: noop, + }; + mockHttpServer.mockImplementation(() => httpServer); + + const service = new HttpService({ configService, env, logger }); + await service.setup(); + await service.start(); + + const configService2 = createConfigService({ + host: 'example.org', + port: 2345, + }); + + const config2 = configService2.atPath('server', HttpConfig); + const cfg = await config2.pipe(first()).toPromise(); + await service.createServer(cfg); + + expect(mockHttpServer.mock.instances.length).toBe(2); + + try { + await service.createServer(cfg); + } catch (err) { + expect(err.message).toBe('port 2345 is already in use'); + } +}); + test('logs error if already set up', async () => { const configService = createConfigService(); diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 3a9fcb7be54e7..c83a2794bd672 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -20,6 +20,7 @@ import { Observable, Subscription } from 'rxjs'; import { first, map } from 'rxjs/operators'; +import { LoggerFactory } from '../logging'; import { CoreService } from '../../types'; import { Logger } from '../logging'; import { CoreContext } from '../core_context'; @@ -38,13 +39,16 @@ export interface HttpServiceStart { /** @internal */ export class HttpService implements CoreService { private readonly httpServer: HttpServer; + private readonly secondaryServers: Map = new Map(); private readonly httpsRedirectServer: HttpsRedirectServer; private readonly config$: Observable; private configSubscription?: Subscription; + private readonly logger: LoggerFactory; private readonly log: Logger; constructor(private readonly coreContext: CoreContext) { + this.logger = coreContext.logger; this.log = coreContext.logger.get('http'); this.config$ = coreContext.configService .atPath('server') @@ -94,6 +98,23 @@ export class HttpService implements CoreService Date: Tue, 21 May 2019 13:11:38 -0700 Subject: [PATCH 02/20] respond to pr feedback --- src/core/server/http/http_server.ts | 1 + src/core/server/http/http_service.test.ts | 17 +++++++++++------ src/core/server/http/http_service.ts | 13 ++++++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/core/server/http/http_server.ts b/src/core/server/http/http_server.ts index db2233b59a2e8..7a6a48c718b49 100644 --- a/src/core/server/http/http_server.ts +++ b/src/core/server/http/http_server.ts @@ -69,6 +69,7 @@ export interface HttpServerSetup { get: AuthStateStorage['get']; isAuthenticated: AuthStateStorage['isAuthenticated']; }; + createNewServer?: (config: HttpConfig) => Promise; } export class HttpServer { diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index e6223fd23cd9e..21486bf26f67d 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -27,6 +27,9 @@ import { HttpConfigType, config, HttpConfig } from './http_config'; import { Config, ConfigService, Env, ObjectToConfigAdapter } from '../config'; import { loggingServiceMock } from '../logging/logging_service.mock'; import { getEnvOptions } from '../config/__mocks__/env'; +import { exec } from 'child_process'; +import { expectationFailed } from 'hapi/node_modules/@types/boom'; +import { executionAsyncId } from 'async_hooks'; const logger = loggingServiceMock.create(); const env = Env.createDefault(getEnvOptions()); @@ -92,7 +95,7 @@ test('creates and sets up second http server', async () => { mockHttpServer.mockImplementation(() => httpServer); const service = new HttpService({ configService, env, logger }); - await service.setup(); + const serverSetup = await service.setup(); await service.start(); const configService2 = createConfigService({ @@ -100,14 +103,14 @@ test('creates and sets up second http server', async () => { port: 2345, }); - const config2 = configService2.atPath('server', HttpConfig); + const config2 = configService2.atPath('server'); const cfg = await config2.pipe(first()).toPromise(); - await service.createServer(cfg); + await serverSetup.createNewServer(cfg); expect(mockHttpServer.mock.instances.length).toBe(2); try { - await service.createServer(cfg); + await serverSetup.createNewServer(cfg); } catch (err) { expect(err.message).toBe('port 2345 is already in use'); } @@ -190,8 +193,10 @@ test('returns http server contract on setup', async () => { })); const service = new HttpService({ configService, env, logger }); - - expect(await service.setup()).toBe(httpServer); + const setup = await service.setup(); + expect(setup.createNewServer).toBeDefined(); + delete setup.createNewServer; + expect(setup).toEqual(httpServer); }); test('does not start http server if process is dev cluster master', async () => { diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index c83a2794bd672..173fc8df3bcb9 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -73,7 +73,8 @@ export class HttpService implements CoreService this.createServer(cfg) } }; } public async start() { @@ -98,7 +99,7 @@ export class HttpService implements CoreService s.stop())); + this.secondaryServers.clear(); } } From d925d31d942140cb262ba05232c016da8b2f5267 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Tue, 21 May 2019 13:12:40 -0700 Subject: [PATCH 03/20] tweak test --- src/core/server/http/http_service.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index 21486bf26f67d..1102aa0f76cdb 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -30,6 +30,7 @@ import { getEnvOptions } from '../config/__mocks__/env'; import { exec } from 'child_process'; import { expectationFailed } from 'hapi/node_modules/@types/boom'; import { executionAsyncId } from 'async_hooks'; +import { create } from 'domain'; const logger = loggingServiceMock.create(); const env = Env.createDefault(getEnvOptions()); @@ -193,10 +194,9 @@ test('returns http server contract on setup', async () => { })); const service = new HttpService({ configService, env, logger }); - const setup = await service.setup(); - expect(setup.createNewServer).toBeDefined(); - delete setup.createNewServer; - expect(setup).toEqual(httpServer); + const { createNewServer, ...setupHttpServer } = await service.setup(); + expect(createNewServer).toBeDefined(); + expect(setupHttpServer).toEqual(httpServer); }); test('does not start http server if process is dev cluster master', async () => { From a5af007457baf1053d21e03f46229485c975560b Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Tue, 21 May 2019 13:24:36 -0700 Subject: [PATCH 04/20] update documentation --- src/core/server/server.api.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 745fbdb7d9d99..b69b5778b2196 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -4,6 +4,7 @@ ```ts +import { ByteSizeValue } from '@kbn/config-schema'; import { ConfigOptions } from 'elasticsearch'; import { Duration } from 'moment'; import { ObjectType } from '@kbn/config-schema'; From aa6c9d5f17d360309eb2164035801faca473328d Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Tue, 21 May 2019 15:04:49 -0700 Subject: [PATCH 05/20] destructure port, remove unnecessary imports --- src/core/server/http/http_service.test.ts | 4 ---- src/core/server/http/http_service.ts | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index 1102aa0f76cdb..a35c763a1b482 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -27,10 +27,6 @@ import { HttpConfigType, config, HttpConfig } from './http_config'; import { Config, ConfigService, Env, ObjectToConfigAdapter } from '../config'; import { loggingServiceMock } from '../logging/logging_service.mock'; import { getEnvOptions } from '../config/__mocks__/env'; -import { exec } from 'child_process'; -import { expectationFailed } from 'hapi/node_modules/@types/boom'; -import { executionAsyncId } from 'async_hooks'; -import { create } from 'domain'; const logger = loggingServiceMock.create(); const env = Env.createDefault(getEnvOptions()); diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 173fc8df3bcb9..8bf85898e67e3 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -100,7 +100,7 @@ export class HttpService implements CoreService Date: Wed, 22 May 2019 08:05:24 -0700 Subject: [PATCH 06/20] [fix] export correct type --- src/core/server/http/http_service.mock.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/server/http/http_service.mock.ts b/src/core/server/http/http_service.mock.ts index 6d49ac3010ef0..f86ec94ccac5f 100644 --- a/src/core/server/http/http_service.mock.ts +++ b/src/core/server/http/http_service.mock.ts @@ -19,6 +19,8 @@ import { Server, ServerOptions } from 'hapi'; import { HttpService } from './http_service'; +import { HttpConfig } from './http_config'; +import { HttpServerSetup } from './http_server'; const createSetupContractMock = () => { const setupContract = { @@ -35,6 +37,7 @@ const createSetupContractMock = () => { get: jest.fn(), isAuthenticated: jest.fn(), }, + createNewServer: async (cfg: HttpConfig): Promise => ({} as HttpServerSetup), }; return setupContract; }; From 6abbb112d14f696a66f2ecb5d49de8cd97cfcaf7 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Thu, 23 May 2019 10:57:39 -0700 Subject: [PATCH 07/20] [feat] expose createNewServer to plugins --- src/core/server/index.ts | 1 + src/core/server/plugins/plugin_context.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/core/server/index.ts b/src/core/server/index.ts index e144c0f2568f8..e8e3563b7ca3a 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -86,6 +86,7 @@ export interface CoreSetup { registerOnPostAuth: HttpServiceSetup['registerOnPostAuth']; getBasePathFor: HttpServiceSetup['getBasePathFor']; setBasePathFor: HttpServiceSetup['setBasePathFor']; + createNewServer: HttpServiceSetup['createNewServer']; }; } diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index b2a88bbd32760..9dfc2df1c2d20 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -122,6 +122,7 @@ export function createPluginSetupContext( registerOnPostAuth: deps.http.registerOnPostAuth, getBasePathFor: deps.http.getBasePathFor, setBasePathFor: deps.http.setBasePathFor, + createNewServer: deps.http.createNewServer, }, }; } From a09339c636cef9b7e0cc5f99b83d6e09c7372866 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Thu, 23 May 2019 11:19:38 -0700 Subject: [PATCH 08/20] [fix] respond to pr feedback --- src/core/server/http/http_service.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 8bf85898e67e3..865acc6013767 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -29,7 +29,9 @@ import { HttpServer, HttpServerSetup } from './http_server'; import { HttpsRedirectServer } from './https_redirect_server'; /** @public */ -export type HttpServiceSetup = HttpServerSetup; +export type HttpServiceSetup = HttpServerSetup & { + createNewServer?: (cfg: HttpConfig) => Promise; +}; /** @public */ export interface HttpServiceStart { /** Indicates if http server is listening on a port */ @@ -73,8 +75,9 @@ export class HttpService implements CoreService this.createServer(cfg) } }; + const setup = this.httpServer.setup(config) as HttpServiceSetup; + setup.createNewServer = (cfg: HttpConfig) => this.createServer(cfg); + return setup; } public async start() { @@ -99,10 +102,14 @@ export class HttpService implements CoreService) { const { port } = config; - if (!port || this.secondaryServers.has(port)) { + if (!port) { + throw new Error('port must be defined'); + } + + if (this.secondaryServers.has(port)) { throw new Error(`port ${port} is already in use`); } From c8fd431fadedeb01c68b71afbf7642405a587e05 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Fri, 24 May 2019 10:21:24 -0700 Subject: [PATCH 09/20] todo: add schema validation & integration test --- src/core/server/http/http_service.test.ts | 6 ++++++ src/core/server/http/http_service.ts | 17 ++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index a35c763a1b482..a792c0ee053d5 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -111,6 +111,12 @@ test('creates and sets up second http server', async () => { } catch (err) { expect(err.message).toBe('port 2345 is already in use'); } + + try { + await serverSetup.createNewServer({ host: 'example.org' }); + } catch (err) { + expect(err.message).toBe('port must be defined'); + } }); test('logs error if already set up', async () => { diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 865acc6013767..2703116ee44f2 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -30,7 +30,7 @@ import { HttpsRedirectServer } from './https_redirect_server'; /** @public */ export type HttpServiceSetup = HttpServerSetup & { - createNewServer?: (cfg: HttpConfig) => Promise; + createNewServer: (cfg: Partial) => Promise; }; /** @public */ export interface HttpServiceStart { @@ -75,8 +75,11 @@ export class HttpService implements CoreService this.createServer(cfg); + const httpSetup = (this.httpServer.setup(config) || {}) as HttpServiceSetup; + const setup = { + ...httpSetup, + ...{ createNewServer: (cfg: Partial) => this.createServer(cfg) }, + }; return setup; } @@ -102,8 +105,8 @@ export class HttpService implements CoreService) { - const { port } = config; + private async createServer(cfg: Partial) { + const { port } = cfg; if (!port) { throw new Error('port must be defined'); @@ -114,11 +117,11 @@ export class HttpService implements CoreService Date: Fri, 24 May 2019 11:19:28 -0700 Subject: [PATCH 10/20] use reach --- src/core/server/http/http_server.ts | 2 +- src/core/server/http/http_service.mock.ts | 3 ++- src/core/server/http/http_service.ts | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/server/http/http_server.ts b/src/core/server/http/http_server.ts index 7a6a48c718b49..416acef5fc4d9 100644 --- a/src/core/server/http/http_server.ts +++ b/src/core/server/http/http_server.ts @@ -69,7 +69,7 @@ export interface HttpServerSetup { get: AuthStateStorage['get']; isAuthenticated: AuthStateStorage['isAuthenticated']; }; - createNewServer?: (config: HttpConfig) => Promise; + createNewServer?: (config: Partial) => Promise; } export class HttpServer { diff --git a/src/core/server/http/http_service.mock.ts b/src/core/server/http/http_service.mock.ts index f86ec94ccac5f..7dccacee8509a 100644 --- a/src/core/server/http/http_service.mock.ts +++ b/src/core/server/http/http_service.mock.ts @@ -37,7 +37,8 @@ const createSetupContractMock = () => { get: jest.fn(), isAuthenticated: jest.fn(), }, - createNewServer: async (cfg: HttpConfig): Promise => ({} as HttpServerSetup), + createNewServer: async (cfg: Partial): Promise => + ({} as HttpServerSetup), }; return setupContract; }; diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 2703116ee44f2..c3d9ff8ba902a 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -24,7 +24,7 @@ import { LoggerFactory } from '../logging'; import { CoreService } from '../../types'; import { Logger } from '../logging'; import { CoreContext } from '../core_context'; -import { HttpConfig, HttpConfigType } from './http_config'; +import { HttpConfig, HttpConfigType, config } from './http_config'; import { HttpServer, HttpServerSetup } from './http_server'; import { HttpsRedirectServer } from './https_redirect_server'; @@ -116,6 +116,11 @@ export class HttpService implements CoreService Date: Fri, 24 May 2019 16:17:51 -0700 Subject: [PATCH 11/20] [fix] use validateKey to validate partial --- src/core/server/http/http_service.test.ts | 9 +-------- src/core/server/http/http_service.ts | 3 +-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index a792c0ee053d5..d259d54c10948 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -95,15 +95,8 @@ test('creates and sets up second http server', async () => { const serverSetup = await service.setup(); await service.start(); - const configService2 = createConfigService({ - host: 'example.org', - port: 2345, - }); - - const config2 = configService2.atPath('server'); - const cfg = await config2.pipe(first()).toPromise(); + const cfg = { port: 2345 }; await serverSetup.createNewServer(cfg); - expect(mockHttpServer.mock.instances.length).toBe(2); try { diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index c3d9ff8ba902a..feafd404ed65e 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -117,8 +117,7 @@ export class HttpService implements CoreService Date: Fri, 24 May 2019 16:20:01 -0700 Subject: [PATCH 12/20] [fix] change config shadowing --- src/core/server/http/http_service.test.ts | 3 +-- src/core/server/http/http_service.ts | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index d259d54c10948..88e108ea4c880 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -21,9 +21,8 @@ import { mockHttpServer } from './http_service.test.mocks'; import { noop } from 'lodash'; import { BehaviorSubject } from 'rxjs'; -import { first } from 'rxjs/operators'; import { HttpService, Router } from '.'; -import { HttpConfigType, config, HttpConfig } from './http_config'; +import { HttpConfigType, config } from './http_config'; import { Config, ConfigService, Env, ObjectToConfigAdapter } from '../config'; import { loggingServiceMock } from '../logging/logging_service.mock'; import { getEnvOptions } from '../config/__mocks__/env'; diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index feafd404ed65e..4c1cab25b39c6 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -24,7 +24,7 @@ import { LoggerFactory } from '../logging'; import { CoreService } from '../../types'; import { Logger } from '../logging'; import { CoreContext } from '../core_context'; -import { HttpConfig, HttpConfigType, config } from './http_config'; +import { HttpConfig, HttpConfigType, config as httpConfig } from './http_config'; import { HttpServer, HttpServerSetup } from './http_server'; import { HttpsRedirectServer } from './https_redirect_server'; @@ -116,8 +116,8 @@ export class HttpService implements CoreService Date: Tue, 28 May 2019 10:36:19 -0700 Subject: [PATCH 13/20] check kibana port & prevent shadowing --- src/core/server/http/http_service.test.ts | 6 ++++++ src/core/server/http/http_service.ts | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index 88e108ea4c880..b520dfd2f30c2 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -104,6 +104,12 @@ test('creates and sets up second http server', async () => { expect(err.message).toBe('port 2345 is already in use'); } + try { + await serverSetup.createNewServer({ port: 1234 }); + } catch (err) { + expect(err.message).toBe('port 1234 is already in use'); + } + try { await serverSetup.createNewServer({ host: 'example.org' }); } catch (err) { diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 4c1cab25b39c6..c7dd0b9a5ab58 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -78,7 +78,7 @@ export class HttpService implements CoreService) => this.createServer(cfg) }, + ...{ createNewServer: this.createServer.bind(this) }, }; return setup; } @@ -107,12 +107,14 @@ export class HttpService implements CoreService) { const { port } = cfg; + const config = await this.config$.pipe(first()).toPromise(); if (!port) { throw new Error('port must be defined'); } - if (this.secondaryServers.has(port)) { + // verify that main server and none of the secondary servers are already using this port + if (this.secondaryServers.has(port) || config.port === port) { throw new Error(`port ${port} is already in use`); } From 9252c797567c8f8ce9d4fe9a45698a9093cd8179 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Tue, 28 May 2019 13:22:48 -0700 Subject: [PATCH 14/20] centralize start/stop for servers, add integration test --- src/core/server/http/http_server.ts | 20 ++++++++++-------- .../server/http/http_service.test.mocks.ts | 11 +++++++--- src/core/server/http/http_service.test.ts | 21 +++++++++---------- src/core/server/http/http_service.ts | 9 ++++++-- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/core/server/http/http_server.ts b/src/core/server/http/http_server.ts index 416acef5fc4d9..88edd4b989801 100644 --- a/src/core/server/http/http_server.ts +++ b/src/core/server/http/http_server.ts @@ -74,6 +74,7 @@ export interface HttpServerSetup { export class HttpServer { private server?: Server; + private serverOptions?: ServerOptions; private registeredRouters = new Set(); private authRegistered = false; private basePathCache = new WeakMap< @@ -123,13 +124,13 @@ export class HttpServer { } public setup(config: HttpConfig): HttpServerSetup { - const serverOptions = getServerOptions(config); - this.server = createServer(serverOptions); + this.serverOptions = getServerOptions(config); + this.server = createServer(this.serverOptions); this.setupBasePathRewrite(config); return { - options: serverOptions, + options: this.serverOptions, registerRouter: this.registerRouter.bind(this), registerOnPreAuth: this.registerOnPreAuth.bind(this), registerOnPostAuth: this.registerOnPostAuth.bind(this), @@ -150,12 +151,16 @@ export class HttpServer { }; } - public async start(config: HttpConfig) { + public async start(config?: HttpConfig) { if (this.server === undefined) { throw new Error('Http server is not setup up yet'); } this.log.debug('starting http server'); + if (config && config.basePath && !config.rewriteBasePath) { + this.setupBasePathRewrite(config); + } + for (const router of this.registeredRouters) { for (const route of router.getRoutes()) { const isAuthRequired = Boolean(this.authRegistered && route.authRequired); @@ -171,12 +176,9 @@ export class HttpServer { } await this.server.start(); + const serverPath = config ? config.rewriteBasePath || config.basePath : ''; - this.log.debug( - `http server running at ${this.server.info.uri}${ - config.rewriteBasePath ? config.basePath : '' - }` - ); + this.log.debug(`http server running at ${this.server.info.uri}${serverPath}`); } public async stop() { diff --git a/src/core/server/http/http_service.test.mocks.ts b/src/core/server/http/http_service.test.mocks.ts index a0d7ff5069eb0..c147944f2b7d8 100644 --- a/src/core/server/http/http_service.test.mocks.ts +++ b/src/core/server/http/http_service.test.mocks.ts @@ -19,6 +19,11 @@ export const mockHttpServer = jest.fn(); -jest.mock('./http_server', () => ({ - HttpServer: mockHttpServer, -})); +jest.mock('./http_server', () => { + const realHttpServer = jest.requireActual('./http_server'); + + return { + ...realHttpServer, + HttpServer: mockHttpServer, + }; +}); diff --git a/src/core/server/http/http_service.test.ts b/src/core/server/http/http_service.test.ts index b520dfd2f30c2..16f946ffcc7ae 100644 --- a/src/core/server/http/http_service.test.ts +++ b/src/core/server/http/http_service.test.ts @@ -76,27 +76,23 @@ test('creates and sets up http server', async () => { expect(httpServer.start).toHaveBeenCalledTimes(1); }); +// this is an integration test! test('creates and sets up second http server', async () => { const configService = createConfigService({ - host: 'example.org', + host: 'localhost', port: 1234, }); + const { HttpServer } = jest.requireActual('./http_server'); - const httpServer = { - isListening: () => false, - setup: jest.fn(), - start: jest.fn(), - stop: noop, - }; - mockHttpServer.mockImplementation(() => httpServer); + mockHttpServer.mockImplementation((...args) => new HttpServer(...args)); const service = new HttpService({ configService, env, logger }); const serverSetup = await service.setup(); - await service.start(); - const cfg = { port: 2345 }; await serverSetup.createNewServer(cfg); - expect(mockHttpServer.mock.instances.length).toBe(2); + const server = await service.start(); + expect(server.isListening()).toBeTruthy(); + expect(server.isListening(cfg.port)).toBeTruthy(); try { await serverSetup.createNewServer(cfg); @@ -115,6 +111,9 @@ test('creates and sets up second http server', async () => { } catch (err) { expect(err.message).toBe('port must be defined'); } + await service.stop(); + expect(server.isListening()).toBeFalsy(); + expect(server.isListening(cfg.port)).toBeFalsy(); }); test('logs error if already set up', async () => { diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index c7dd0b9a5ab58..9ecdb9a892942 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -97,11 +97,16 @@ export class HttpService implements CoreService server.start())); } return { - isListening: () => this.httpServer.isListening(), + isListening: (port = 0) => { + const server = this.secondaryServers.get(port); + if (server) return server.isListening(); + return this.httpServer.isListening(); + }, }; } From 6bb33b441aad23888b0ac014b04cda51b1c776d6 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Tue, 28 May 2019 15:29:14 -0700 Subject: [PATCH 15/20] remove unnecessary property --- src/core/server/http/http_server.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/server/http/http_server.ts b/src/core/server/http/http_server.ts index 88edd4b989801..5252dbfb82e85 100644 --- a/src/core/server/http/http_server.ts +++ b/src/core/server/http/http_server.ts @@ -74,7 +74,6 @@ export interface HttpServerSetup { export class HttpServer { private server?: Server; - private serverOptions?: ServerOptions; private registeredRouters = new Set(); private authRegistered = false; private basePathCache = new WeakMap< @@ -124,13 +123,13 @@ export class HttpServer { } public setup(config: HttpConfig): HttpServerSetup { - this.serverOptions = getServerOptions(config); - this.server = createServer(this.serverOptions); + const serverOptions = getServerOptions(config); + this.server = createServer(serverOptions); this.setupBasePathRewrite(config); return { - options: this.serverOptions, + options: serverOptions, registerRouter: this.registerRouter.bind(this), registerOnPreAuth: this.registerOnPreAuth.bind(this), registerOnPostAuth: this.registerOnPostAuth.bind(this), From d7e4044356cd80915c5fa91dd40b7145dc72d030 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 29 May 2019 09:50:51 -0700 Subject: [PATCH 16/20] never forget your await --- src/core/server/http/http_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 9ecdb9a892942..201fcf16b2270 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -97,7 +97,7 @@ export class HttpService implements CoreService server.start())); } From 920da222e91e3992b050f910c770aba6321a01be Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 29 May 2019 10:07:25 -0700 Subject: [PATCH 17/20] remove option to pass config into start --- src/core/server/http/http_server.ts | 10 ++++------ src/core/server/http/http_service.ts | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/server/http/http_server.ts b/src/core/server/http/http_server.ts index 5252dbfb82e85..36e7c2d267b90 100644 --- a/src/core/server/http/http_server.ts +++ b/src/core/server/http/http_server.ts @@ -74,6 +74,7 @@ export interface HttpServerSetup { export class HttpServer { private server?: Server; + private config?: HttpConfig; private registeredRouters = new Set(); private authRegistered = false; private basePathCache = new WeakMap< @@ -125,6 +126,7 @@ export class HttpServer { public setup(config: HttpConfig): HttpServerSetup { const serverOptions = getServerOptions(config); this.server = createServer(serverOptions); + this.config = config; this.setupBasePathRewrite(config); @@ -150,16 +152,12 @@ export class HttpServer { }; } - public async start(config?: HttpConfig) { + public async start() { if (this.server === undefined) { throw new Error('Http server is not setup up yet'); } this.log.debug('starting http server'); - if (config && config.basePath && !config.rewriteBasePath) { - this.setupBasePathRewrite(config); - } - for (const router of this.registeredRouters) { for (const route of router.getRoutes()) { const isAuthRequired = Boolean(this.authRegistered && route.authRequired); @@ -175,7 +173,7 @@ export class HttpServer { } await this.server.start(); - const serverPath = config ? config.rewriteBasePath || config.basePath : ''; + const serverPath = this.config ? this.config.rewriteBasePath || this.config.basePath : ''; this.log.debug(`http server running at ${this.server.info.uri}${serverPath}`); } diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 201fcf16b2270..103eb79c5c6be 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -97,7 +97,7 @@ export class HttpService implements CoreService server.start())); } From b361884c1e070ccea1dbdc940589c076b64481d1 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 29 May 2019 10:40:10 -0700 Subject: [PATCH 18/20] fix pr feedback --- src/core/server/http/http_server.ts | 4 +--- src/core/server/http/http_service.ts | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/server/http/http_server.ts b/src/core/server/http/http_server.ts index 36e7c2d267b90..bdf02889841bb 100644 --- a/src/core/server/http/http_server.ts +++ b/src/core/server/http/http_server.ts @@ -69,7 +69,6 @@ export interface HttpServerSetup { get: AuthStateStorage['get']; isAuthenticated: AuthStateStorage['isAuthenticated']; }; - createNewServer?: (config: Partial) => Promise; } export class HttpServer { @@ -173,8 +172,7 @@ export class HttpServer { } await this.server.start(); - const serverPath = this.config ? this.config.rewriteBasePath || this.config.basePath : ''; - + const serverPath = this.config!.rewriteBasePath || this.config!.basePath || ''; this.log.debug(`http server running at ${this.server.info.uri}${serverPath}`); } diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 103eb79c5c6be..fec3774e2f366 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -29,9 +29,9 @@ import { HttpServer, HttpServerSetup } from './http_server'; import { HttpsRedirectServer } from './https_redirect_server'; /** @public */ -export type HttpServiceSetup = HttpServerSetup & { +export interface HttpServiceSetup extends HttpServerSetup { createNewServer: (cfg: Partial) => Promise; -}; +} /** @public */ export interface HttpServiceStart { /** Indicates if http server is listening on a port */ From 6f0e5c9a66f5d924264e73b3279b5d8b0b8ac367 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 29 May 2019 11:17:30 -0700 Subject: [PATCH 19/20] fix documentation --- .../server/kibana-plugin-server.coresetup.http.md | 1 + .../core/server/kibana-plugin-server.coresetup.md | 2 +- ...-plugin-server.httpservicesetup.createnewserver.md | 11 +++++++++++ .../server/kibana-plugin-server.httpservicesetup.md | 11 +++++++++-- docs/development/core/server/kibana-plugin-server.md | 2 +- src/core/server/server.api.md | 8 +++++++- 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 docs/development/core/server/kibana-plugin-server.httpservicesetup.createnewserver.md diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.http.md b/docs/development/core/server/kibana-plugin-server.coresetup.http.md index 8cb25af29e4ba..81e099b7828fe 100644 --- a/docs/development/core/server/kibana-plugin-server.coresetup.http.md +++ b/docs/development/core/server/kibana-plugin-server.coresetup.http.md @@ -13,5 +13,6 @@ http: { registerOnPostAuth: HttpServiceSetup['registerOnPostAuth']; getBasePathFor: HttpServiceSetup['getBasePathFor']; setBasePathFor: HttpServiceSetup['setBasePathFor']; + createNewServer: HttpServiceSetup['createNewServer']; }; ``` diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.md b/docs/development/core/server/kibana-plugin-server.coresetup.md index 7b46817842def..7be8599d563a7 100644 --- a/docs/development/core/server/kibana-plugin-server.coresetup.md +++ b/docs/development/core/server/kibana-plugin-server.coresetup.md @@ -17,5 +17,5 @@ export interface CoreSetup | Property | Type | Description | | --- | --- | --- | | [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | {`

` adminClient$: Observable<ClusterClient>;`

` dataClient$: Observable<ClusterClient>;`

` } | | -| [http](./kibana-plugin-server.coresetup.http.md) | {`

` registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];`

` registerAuth: HttpServiceSetup['registerAuth'];`

` registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];`

` getBasePathFor: HttpServiceSetup['getBasePathFor'];`

` setBasePathFor: HttpServiceSetup['setBasePathFor'];`

` } | | +| [http](./kibana-plugin-server.coresetup.http.md) | {`

` registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];`

` registerAuth: HttpServiceSetup['registerAuth'];`

` registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];`

` getBasePathFor: HttpServiceSetup['getBasePathFor'];`

` setBasePathFor: HttpServiceSetup['setBasePathFor'];`

` createNewServer: HttpServiceSetup['createNewServer'];`

` } | | diff --git a/docs/development/core/server/kibana-plugin-server.httpservicesetup.createnewserver.md b/docs/development/core/server/kibana-plugin-server.httpservicesetup.createnewserver.md new file mode 100644 index 0000000000000..e33f1c51abee9 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.httpservicesetup.createnewserver.md @@ -0,0 +1,11 @@ + + +[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) > [createNewServer](./kibana-plugin-server.httpservicesetup.createnewserver.md) + +## HttpServiceSetup.createNewServer property + +Signature: + +```typescript +createNewServer: (cfg: Partial) => Promise; +``` diff --git a/docs/development/core/server/kibana-plugin-server.httpservicesetup.md b/docs/development/core/server/kibana-plugin-server.httpservicesetup.md index 36335c0d5f4cd..a1b77ba466399 100644 --- a/docs/development/core/server/kibana-plugin-server.httpservicesetup.md +++ b/docs/development/core/server/kibana-plugin-server.httpservicesetup.md @@ -2,11 +2,18 @@ [Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) -## HttpServiceSetup type +## HttpServiceSetup interface Signature: ```typescript -export declare type HttpServiceSetup = HttpServerSetup; +export interface HttpServiceSetup extends HttpServerSetup ``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [createNewServer](./kibana-plugin-server.httpservicesetup.createnewserver.md) | (cfg: Partial<HttpConfig>) => Promise<HttpServerSetup> | | + diff --git a/docs/development/core/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md index 843f2a65e9562..0c03795c1b571 100644 --- a/docs/development/core/server/kibana-plugin-server.md +++ b/docs/development/core/server/kibana-plugin-server.md @@ -29,6 +29,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [CoreStart](./kibana-plugin-server.corestart.md) | Context passed to the plugins start method. | | [DiscoveredPlugin](./kibana-plugin-server.discoveredplugin.md) | Small container object used to expose information about discovered plugins that may or may not have been started. | | [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) | | +| [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | | | [HttpServiceStart](./kibana-plugin-server.httpservicestart.md) | | | [InternalCoreStart](./kibana-plugin-server.internalcorestart.md) | | | [Logger](./kibana-plugin-server.logger.md) | Logger exposes all the necessary methods to log any type of information and this is the interface used by the logging consumers including plugins. | @@ -49,7 +50,6 @@ The plugin integrates with the core system via lifecycle events: `setup` | [AuthenticationHandler](./kibana-plugin-server.authenticationhandler.md) | | | [ElasticsearchClientConfig](./kibana-plugin-server.elasticsearchclientconfig.md) | | | [Headers](./kibana-plugin-server.headers.md) | | -| [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | | | [OnPostAuthHandler](./kibana-plugin-server.onpostauthhandler.md) | | | [OnPreAuthHandler](./kibana-plugin-server.onpreauthhandler.md) | | | [PluginInitializer](./kibana-plugin-server.plugininitializer.md) | The plugin export at the root of a plugin's server directory should conform to this interface. | diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index b69b5778b2196..2d2472103e5ab 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -89,6 +89,7 @@ export interface CoreSetup { registerOnPostAuth: HttpServiceSetup['registerOnPostAuth']; getBasePathFor: HttpServiceSetup['getBasePathFor']; setBasePathFor: HttpServiceSetup['setBasePathFor']; + createNewServer: HttpServiceSetup['createNewServer']; }; } @@ -134,7 +135,12 @@ export type Headers = Record; // Warning: (ae-forgotten-export) The symbol "HttpServerSetup" needs to be exported by the entry point index.d.ts // // @public (undocumented) -export type HttpServiceSetup = HttpServerSetup; +export interface HttpServiceSetup extends HttpServerSetup { + // Warning: (ae-forgotten-export) The symbol "HttpConfig" needs to be exported by the entry point index.d.ts + // + // (undocumented) + createNewServer: (cfg: Partial) => Promise; +} // @public (undocumented) export interface HttpServiceStart { From c38727fc8d37f456043adb51b44b4803d2269497 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 29 May 2019 11:56:20 -0700 Subject: [PATCH 20/20] fix test failures --- src/core/server/http/http_server.test.ts | 60 ++++++++++++------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/core/server/http/http_server.test.ts b/src/core/server/http/http_server.test.ts index 0f1a85a336b04..618fbfe7a2067 100644 --- a/src/core/server/http/http_server.test.ts +++ b/src/core/server/http/http_server.test.ts @@ -58,7 +58,7 @@ test('listening after started', async () => { expect(server.isListening()).toBe(false); await server.setup(config); - await server.start(config); + await server.start(); expect(server.isListening()).toBe(true); }); @@ -72,7 +72,7 @@ test('200 OK with body', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/foo/') @@ -92,7 +92,7 @@ test('202 Accepted with body', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/foo/') @@ -112,7 +112,7 @@ test('204 No content', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/foo/') @@ -134,7 +134,7 @@ test('400 Bad request with error', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/foo/') @@ -164,7 +164,7 @@ test('valid params', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/foo/some-string') @@ -194,7 +194,7 @@ test('invalid params', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/foo/some-string') @@ -227,7 +227,7 @@ test('valid query', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/foo/?bar=test&quux=123') @@ -257,7 +257,7 @@ test('invalid query', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/foo/?bar=test') @@ -290,7 +290,7 @@ test('valid body', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .post('/foo/') @@ -324,7 +324,7 @@ test('invalid body', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .post('/foo/') @@ -357,7 +357,7 @@ test('handles putting', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .put('/foo/') @@ -388,7 +388,7 @@ test('handles deleting', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .delete('/foo/3') @@ -414,7 +414,7 @@ test('filtered headers', async () => { const { registerRouter, server: innerServer } = await server.setup(config); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/foo/?bar=quux') @@ -444,10 +444,10 @@ describe('with `basepath: /bar` and `rewriteBasePath: false`', () => { res.ok({ key: 'value:/foo' }) ); - const { registerRouter, server: innerServer } = await server.setup(config); + const { registerRouter, server: innerServer } = await server.setup(configWithBasePath); registerRouter(router); - await server.start(configWithBasePath); + await server.start(); innerServerListener = innerServer.listener; }); @@ -508,7 +508,7 @@ describe('with `basepath: /bar` and `rewriteBasePath: true`', () => { const { registerRouter, server: innerServer } = await server.setup(configWithBasePath); registerRouter(router); - await server.start(configWithBasePath); + await server.start(); innerServerListener = innerServer.listener; }); @@ -571,10 +571,10 @@ describe('with defined `redirectHttpFromPort`', () => { const router = new Router('/'); router.get({ path: '/', validate: false }, async (req, res) => res.ok({ key: 'value:/' })); - const { registerRouter } = await server.setup(config); + const { registerRouter } = await server.setup(configWithSSL); registerRouter(router); - await server.start(configWithSSL); + await server.start(); }); }); @@ -610,7 +610,7 @@ test('registers registerOnPostAuth interceptor several times', async () => { }); test('throws an error if starts without set up', async () => { - await expect(server.start(config)).rejects.toThrowErrorMatchingInlineSnapshot( + await expect(server.start()).rejects.toThrowErrorMatchingInlineSnapshot( `"Http server is not setup up yet"` ); }); @@ -634,7 +634,7 @@ test('#getBasePathFor() returns base path associated with an incoming request', router.get({ path: '/', validate: false }, (req, res) => res.ok({ key: getBasePathFor(req) })); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/') .expect(200) @@ -668,7 +668,7 @@ test('#getBasePathFor() is based on server base path', async () => { ); registerRouter(router); - await server.start(configWithBasePath); + await server.start(); await supertest(innerServer.listener) .get('/') .expect(200) @@ -727,7 +727,7 @@ test('Should enable auth for a route by default if registerAuth has been called' .mockImplementation((req, sessionStorage, t) => t.authenticated({})); await registerAuth(authenticate, cookieOptions); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/') .expect(200); @@ -744,7 +744,7 @@ test('Should support disabling auth for a route', async () => { const authenticate = jest.fn(); await registerAuth(authenticate, cookieOptions); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/') .expect(200); @@ -764,7 +764,7 @@ describe('#auth.isAuthenticated()', () => { await registerAuth((req, sessionStorage, t) => t.authenticated({}), cookieOptions); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/') .expect(200, { isAuthenticated: true }); @@ -781,7 +781,7 @@ describe('#auth.isAuthenticated()', () => { await registerAuth((req, sessionStorage, t) => t.authenticated({}), cookieOptions); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/') .expect(200, { isAuthenticated: false }); @@ -796,7 +796,7 @@ describe('#auth.isAuthenticated()', () => { ); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/') .expect(200, { isAuthenticated: false }); @@ -815,7 +815,7 @@ describe('#auth.get()', () => { const router = new Router(''); router.get({ path: '/', validate: false }, async (req, res) => res.ok(auth.get(req))); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/') @@ -828,7 +828,7 @@ describe('#auth.get()', () => { router.get({ path: '/', validate: false }, async (req, res) => res.ok(auth.get(req))); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/') .expect(200, { status: 'unknown' }); @@ -845,7 +845,7 @@ describe('#auth.get()', () => { ); registerRouter(router); - await server.start(config); + await server.start(); await supertest(innerServer.listener) .get('/')