diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.http.md b/docs/development/core/server/kibana-plugin-core-server.corestart.http.md new file mode 100644 index 0000000000000..d81049dfbd340 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.corestart.http.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreStart](./kibana-plugin-core-server.corestart.md) > [http](./kibana-plugin-core-server.corestart.http.md) + +## CoreStart.http property + +[HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) + +Signature: + +```typescript +http: HttpServiceStart; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.md b/docs/development/core/server/kibana-plugin-core-server.corestart.md index c50e8924c9dd4..6a6bacf1eef40 100644 --- a/docs/development/core/server/kibana-plugin-core-server.corestart.md +++ b/docs/development/core/server/kibana-plugin-core-server.corestart.md @@ -18,6 +18,7 @@ export interface CoreStart | --- | --- | --- | | [capabilities](./kibana-plugin-core-server.corestart.capabilities.md) | CapabilitiesStart | [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) | | [elasticsearch](./kibana-plugin-core-server.corestart.elasticsearch.md) | ElasticsearchServiceStart | [ElasticsearchServiceStart](./kibana-plugin-core-server.elasticsearchservicestart.md) | +| [http](./kibana-plugin-core-server.corestart.http.md) | HttpServiceStart | [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) | | [savedObjects](./kibana-plugin-core-server.corestart.savedobjects.md) | SavedObjectsServiceStart | [SavedObjectsServiceStart](./kibana-plugin-core-server.savedobjectsservicestart.md) | | [uiSettings](./kibana-plugin-core-server.corestart.uisettings.md) | UiSettingsServiceStart | [UiSettingsServiceStart](./kibana-plugin-core-server.uisettingsservicestart.md) | diff --git a/docs/development/core/server/kibana-plugin-core-server.httpauth.get.md b/docs/development/core/server/kibana-plugin-core-server.httpauth.get.md new file mode 100644 index 0000000000000..4ea67cf895a27 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.httpauth.get.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [HttpAuth](./kibana-plugin-core-server.httpauth.md) > [get](./kibana-plugin-core-server.httpauth.get.md) + +## HttpAuth.get property + +Gets authentication state for a request. Returned by `auth` interceptor. [GetAuthState](./kibana-plugin-core-server.getauthstate.md) + +Signature: + +```typescript +get: GetAuthState; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.httpauth.isauthenticated.md b/docs/development/core/server/kibana-plugin-core-server.httpauth.isauthenticated.md new file mode 100644 index 0000000000000..54db6bce5f161 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.httpauth.isauthenticated.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [HttpAuth](./kibana-plugin-core-server.httpauth.md) > [isAuthenticated](./kibana-plugin-core-server.httpauth.isauthenticated.md) + +## HttpAuth.isAuthenticated property + +Returns authentication status for a request. [IsAuthenticated](./kibana-plugin-core-server.isauthenticated.md) + +Signature: + +```typescript +isAuthenticated: IsAuthenticated; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.httpauth.md b/docs/development/core/server/kibana-plugin-core-server.httpauth.md new file mode 100644 index 0000000000000..d9d77809570ab --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.httpauth.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [HttpAuth](./kibana-plugin-core-server.httpauth.md) + +## HttpAuth interface + + +Signature: + +```typescript +export interface HttpAuth +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [get](./kibana-plugin-core-server.httpauth.get.md) | GetAuthState | Gets authentication state for a request. Returned by auth interceptor. [GetAuthState](./kibana-plugin-core-server.getauthstate.md) | +| [isAuthenticated](./kibana-plugin-core-server.httpauth.isauthenticated.md) | IsAuthenticated | Returns authentication status for a request. [IsAuthenticated](./kibana-plugin-core-server.isauthenticated.md) | + diff --git a/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.auth.md b/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.auth.md index 6667779c1c7ae..da348a2282b1a 100644 --- a/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.auth.md +++ b/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.auth.md @@ -4,11 +4,15 @@ ## HttpServiceSetup.auth property +> Warning: This API is now obsolete. +> +> use [the start contract](./kibana-plugin-core-server.httpservicestart.auth.md) instead. +> + +Auth status. See [HttpAuth](./kibana-plugin-core-server.httpauth.md) + Signature: ```typescript -auth: { - get: GetAuthState; - isAuthenticated: IsAuthenticated; - }; +auth: HttpAuth; ``` diff --git a/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.istlsenabled.md b/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.istlsenabled.md deleted file mode 100644 index fa86da18393f5..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.istlsenabled.md +++ /dev/null @@ -1,13 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [HttpServiceSetup](./kibana-plugin-core-server.httpservicesetup.md) > [isTlsEnabled](./kibana-plugin-core-server.httpservicesetup.istlsenabled.md) - -## HttpServiceSetup.isTlsEnabled property - -Flag showing whether a server was configured to use TLS connection. - -Signature: - -```typescript -isTlsEnabled: boolean; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.md b/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.md index 2dd832813afb8..b12983836d9e5 100644 --- a/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.md +++ b/docs/development/core/server/kibana-plugin-core-server.httpservicesetup.md @@ -81,13 +81,12 @@ async (context, request, response) => { | Property | Type | Description | | --- | --- | --- | -| [auth](./kibana-plugin-core-server.httpservicesetup.auth.md) | {
get: GetAuthState;
isAuthenticated: IsAuthenticated;
} | | +| [auth](./kibana-plugin-core-server.httpservicesetup.auth.md) | HttpAuth | Auth status. See [HttpAuth](./kibana-plugin-core-server.httpauth.md) | | [basePath](./kibana-plugin-core-server.httpservicesetup.basepath.md) | IBasePath | Access or manipulate the Kibana base path See [IBasePath](./kibana-plugin-core-server.ibasepath.md). | | [createCookieSessionStorageFactory](./kibana-plugin-core-server.httpservicesetup.createcookiesessionstoragefactory.md) | <T>(cookieOptions: SessionStorageCookieOptions<T>) => Promise<SessionStorageFactory<T>> | Creates cookie based session storage factory [SessionStorageFactory](./kibana-plugin-core-server.sessionstoragefactory.md) | | [createRouter](./kibana-plugin-core-server.httpservicesetup.createrouter.md) | () => IRouter | Provides ability to declare a handler function for a particular path and HTTP request method. | | [csp](./kibana-plugin-core-server.httpservicesetup.csp.md) | ICspConfig | The CSP config used for Kibana. | | [getServerInfo](./kibana-plugin-core-server.httpservicesetup.getserverinfo.md) | () => HttpServerInfo | Provides common [information](./kibana-plugin-core-server.httpserverinfo.md) about the running http server. | -| [isTlsEnabled](./kibana-plugin-core-server.httpservicesetup.istlsenabled.md) | boolean | Flag showing whether a server was configured to use TLS connection. | | [registerAuth](./kibana-plugin-core-server.httpservicesetup.registerauth.md) | (handler: AuthenticationHandler) => void | To define custom authentication and/or authorization mechanism for incoming requests. | | [registerOnPostAuth](./kibana-plugin-core-server.httpservicesetup.registeronpostauth.md) | (handler: OnPostAuthHandler) => void | To define custom logic to perform for incoming requests. | | [registerOnPreAuth](./kibana-plugin-core-server.httpservicesetup.registeronpreauth.md) | (handler: OnPreAuthHandler) => void | To define custom logic to perform for incoming requests. | diff --git a/docs/development/core/server/kibana-plugin-core-server.httpservicestart.islistening.md b/docs/development/core/server/kibana-plugin-core-server.httpservicestart.auth.md similarity index 50% rename from docs/development/core/server/kibana-plugin-core-server.httpservicestart.islistening.md rename to docs/development/core/server/kibana-plugin-core-server.httpservicestart.auth.md index bf2922c62c15f..f7dffee2e125c 100644 --- a/docs/development/core/server/kibana-plugin-core-server.httpservicestart.islistening.md +++ b/docs/development/core/server/kibana-plugin-core-server.httpservicestart.auth.md @@ -1,13 +1,13 @@ -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) > [isListening](./kibana-plugin-core-server.httpservicestart.islistening.md) +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) > [auth](./kibana-plugin-core-server.httpservicestart.auth.md) -## HttpServiceStart.isListening property +## HttpServiceStart.auth property -Indicates if http server is listening on a given port +Auth status. See [HttpAuth](./kibana-plugin-core-server.httpauth.md) Signature: ```typescript -isListening: (port: number) => boolean; +auth: HttpAuth; ``` diff --git a/docs/development/core/server/kibana-plugin-core-server.httpservicestart.basepath.md b/docs/development/core/server/kibana-plugin-core-server.httpservicestart.basepath.md new file mode 100644 index 0000000000000..e8b2a0fc2cbaa --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.httpservicestart.basepath.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) > [basePath](./kibana-plugin-core-server.httpservicestart.basepath.md) + +## HttpServiceStart.basePath property + +Access or manipulate the Kibana base path See [IBasePath](./kibana-plugin-core-server.ibasepath.md). + +Signature: + +```typescript +basePath: IBasePath; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.httpservicestart.getserverinfo.md b/docs/development/core/server/kibana-plugin-core-server.httpservicestart.getserverinfo.md new file mode 100644 index 0000000000000..a95c8da64fdb0 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.httpservicestart.getserverinfo.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) > [getServerInfo](./kibana-plugin-core-server.httpservicestart.getserverinfo.md) + +## HttpServiceStart.getServerInfo property + +Provides common [information](./kibana-plugin-core-server.httpserverinfo.md) about the running http server. + +Signature: + +```typescript +getServerInfo: () => HttpServerInfo; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.httpservicestart.md b/docs/development/core/server/kibana-plugin-core-server.httpservicestart.md index 53239da516b25..bc99c1217f72b 100644 --- a/docs/development/core/server/kibana-plugin-core-server.httpservicestart.md +++ b/docs/development/core/server/kibana-plugin-core-server.httpservicestart.md @@ -15,5 +15,7 @@ export interface HttpServiceStart | Property | Type | Description | | --- | --- | --- | -| [isListening](./kibana-plugin-core-server.httpservicestart.islistening.md) | (port: number) => boolean | Indicates if http server is listening on a given port | +| [auth](./kibana-plugin-core-server.httpservicestart.auth.md) | HttpAuth | Auth status. See [HttpAuth](./kibana-plugin-core-server.httpauth.md) | +| [basePath](./kibana-plugin-core-server.httpservicestart.basepath.md) | IBasePath | Access or manipulate the Kibana base path See [IBasePath](./kibana-plugin-core-server.ibasepath.md). | +| [getServerInfo](./kibana-plugin-core-server.httpservicestart.getserverinfo.md) | () => HttpServerInfo | Provides common [information](./kibana-plugin-core-server.httpserverinfo.md) about the running http server. | diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md index a45bd3d44b28a..0f1bbbe7176e5 100644 --- a/docs/development/core/server/kibana-plugin-core-server.md +++ b/docs/development/core/server/kibana-plugin-core-server.md @@ -85,6 +85,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [EnvironmentMode](./kibana-plugin-core-server.environmentmode.md) | | | [ErrorHttpResponseOptions](./kibana-plugin-core-server.errorhttpresponseoptions.md) | HTTP response parameters | | [FakeRequest](./kibana-plugin-core-server.fakerequest.md) | Fake request object created manually by Kibana plugins. | +| [HttpAuth](./kibana-plugin-core-server.httpauth.md) | | | [HttpResources](./kibana-plugin-core-server.httpresources.md) | HttpResources service is responsible for serving static & dynamic assets for Kibana application via HTTP. Provides API allowing plug-ins to respond with: - a pre-configured HTML page bootstrapping Kibana client app - custom HTML page - custom JS script file. | | [HttpResourcesRenderOptions](./kibana-plugin-core-server.httpresourcesrenderoptions.md) | Allows to configure HTTP response parameters | | [HttpResourcesServiceToolkit](./kibana-plugin-core-server.httpresourcesservicetoolkit.md) | Extended set of [KibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) helpers used to respond with HTML or JS resource. | diff --git a/src/core/server/capabilities/capabilities_service.test.ts b/src/core/server/capabilities/capabilities_service.test.ts index 7d2e7391aa8d4..42dc1604281b8 100644 --- a/src/core/server/capabilities/capabilities_service.test.ts +++ b/src/core/server/capabilities/capabilities_service.test.ts @@ -17,19 +17,19 @@ * under the License. */ -import { httpServiceMock, HttpServiceSetupMock } from '../http/http_service.mock'; +import { httpServiceMock, InternalHttpServiceSetupMock } from '../http/http_service.mock'; import { mockRouter, RouterMock } from '../http/router/router.mock'; import { CapabilitiesService, CapabilitiesSetup } from './capabilities_service'; import { mockCoreContext } from '../core_context.mock'; describe('CapabilitiesService', () => { - let http: HttpServiceSetupMock; + let http: InternalHttpServiceSetupMock; let service: CapabilitiesService; let setup: CapabilitiesSetup; let router: RouterMock; beforeEach(() => { - http = httpServiceMock.createSetupContract(); + http = httpServiceMock.createInternalSetupContract(); router = mockRouter.create(); http.createRouter.mockReturnValue(router); service = new CapabilitiesService(mockCoreContext.create()); diff --git a/src/core/server/elasticsearch/elasticsearch_service.test.ts b/src/core/server/elasticsearch/elasticsearch_service.test.ts index e7dab3807733a..8bf0df74186a9 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.test.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.test.ts @@ -39,7 +39,7 @@ const delay = async (durationMs: number) => let elasticsearchService: ElasticsearchService; const configService = configServiceMock.create(); const deps = { - http: httpServiceMock.createSetupContract(), + http: httpServiceMock.createInternalSetupContract(), }; configService.atPath.mockReturnValue( new BehaviorSubject({ diff --git a/src/core/server/http/http_server.test.ts b/src/core/server/http/http_server.test.ts index 1798c3a921da4..9a5deb9b45562 100644 --- a/src/core/server/http/http_server.test.ts +++ b/src/core/server/http/http_server.test.ts @@ -1046,17 +1046,6 @@ describe('setup contract', () => { }); }); - describe('#isTlsEnabled', () => { - it('returns "true" if TLS enabled', async () => { - const { isTlsEnabled } = await server.setup(configWithSSL); - expect(isTlsEnabled).toBe(true); - }); - it('returns "false" if TLS not enabled', async () => { - const { isTlsEnabled } = await server.setup(config); - expect(isTlsEnabled).toBe(false); - }); - }); - describe('#getServerInfo', () => { it('returns correct information', async () => { let { getServerInfo } = await server.setup(config); diff --git a/src/core/server/http/http_server.ts b/src/core/server/http/http_server.ts index 8089ee901fa65..d4615dd4744e5 100644 --- a/src/core/server/http/http_server.ts +++ b/src/core/server/http/http_server.ts @@ -53,7 +53,6 @@ export interface HttpServerSetup { registerOnPreAuth: HttpServiceSetup['registerOnPreAuth']; registerOnPostAuth: HttpServiceSetup['registerOnPostAuth']; registerOnPreResponse: HttpServiceSetup['registerOnPreResponse']; - isTlsEnabled: HttpServiceSetup['isTlsEnabled']; getAuthHeaders: GetAuthHeaders; auth: { get: GetAuthState; @@ -133,7 +132,6 @@ export class HttpServer { port: config.port, protocol: this.server!.info.protocol, }), - isTlsEnabled: config.ssl.enabled, // Return server instance with the connection options so that we can properly // bridge core and the "legacy" Kibana internally. Once this bridge isn't // needed anymore we shouldn't return the instance from this method. diff --git a/src/core/server/http/http_service.mock.ts b/src/core/server/http/http_service.mock.ts index 0788a8f2af7a1..02ae6f5d95a87 100644 --- a/src/core/server/http/http_service.mock.ts +++ b/src/core/server/http/http_service.mock.ts @@ -19,9 +19,14 @@ import { Server } from 'hapi'; import { CspConfig } from '../csp'; -import { mockRouter } from './router/router.mock'; +import { mockRouter, RouterMock } from './router/router.mock'; import { configMock } from '../config/config.mock'; -import { InternalHttpServiceSetup } from './types'; +import { + InternalHttpServiceSetup, + HttpServiceSetup, + HttpServiceStart, + InternalHttpServiceStart, +} from './types'; import { HttpService } from './http_service'; import { AuthStatus } from './auth_state_storage'; import { OnPreAuthToolkit } from './lifecycle/on_pre_auth'; @@ -32,7 +37,23 @@ import { OnPreResponseToolkit } from './lifecycle/on_pre_response'; type BasePathMocked = jest.Mocked; type AuthMocked = jest.Mocked; -export type HttpServiceSetupMock = jest.Mocked & { + +export type HttpServiceSetupMock = jest.Mocked< + Omit +> & { + basePath: BasePathMocked; + createRouter: jest.MockedFunction<() => RouterMock>; +}; +export type InternalHttpServiceSetupMock = jest.Mocked< + Omit +> & { + basePath: BasePathMocked; + createRouter: jest.MockedFunction<(path: string) => RouterMock>; +}; +export type HttpServiceStartMock = jest.Mocked & { + basePath: BasePathMocked; +}; +export type InternalHttpServiceStartMock = jest.Mocked & { basePath: BasePathMocked; }; @@ -54,8 +75,8 @@ const createAuthMock = () => { return mock; }; -const createSetupContractMock = () => { - const setupContract: HttpServiceSetupMock = { +const createInternalSetupContractMock = () => { + const mock: InternalHttpServiceSetupMock = { // we can mock other hapi server methods when we need it server: ({ name: 'http-server-test', @@ -77,31 +98,78 @@ const createSetupContractMock = () => { csp: CspConfig.DEFAULT, auth: createAuthMock(), getAuthHeaders: jest.fn(), - isTlsEnabled: false, getServerInfo: jest.fn(), }; - setupContract.createCookieSessionStorageFactory.mockResolvedValue( - sessionStorageMock.createFactory() - ); - setupContract.createRouter.mockImplementation(() => mockRouter.create()); - setupContract.getAuthHeaders.mockReturnValue({ authorization: 'authorization-header' }); - setupContract.getServerInfo.mockReturnValue({ + mock.createCookieSessionStorageFactory.mockResolvedValue(sessionStorageMock.createFactory()); + mock.createRouter.mockImplementation(() => mockRouter.create()); + mock.getAuthHeaders.mockReturnValue({ authorization: 'authorization-header' }); + mock.getServerInfo.mockReturnValue({ host: 'localhost', name: 'kibana', port: 80, protocol: 'http', }); - return setupContract; + return mock; +}; + +const createSetupContractMock = () => { + const internalMock = createInternalSetupContractMock(); + + const mock: HttpServiceSetupMock = { + createCookieSessionStorageFactory: internalMock.createCookieSessionStorageFactory, + registerOnPreAuth: internalMock.registerOnPreAuth, + registerAuth: internalMock.registerAuth, + registerOnPostAuth: internalMock.registerOnPostAuth, + registerOnPreResponse: internalMock.registerOnPreResponse, + basePath: internalMock.basePath, + csp: CspConfig.DEFAULT, + createRouter: jest.fn(), + registerRouteHandlerContext: jest.fn(), + auth: { + get: internalMock.auth.get, + isAuthenticated: internalMock.auth.isAuthenticated, + }, + getServerInfo: internalMock.getServerInfo, + }; + + mock.createRouter.mockImplementation(() => internalMock.createRouter('')); + + return mock; +}; + +const createStartContractMock = () => { + const mock: HttpServiceStartMock = { + auth: createAuthMock(), + basePath: createBasePathMock(), + getServerInfo: jest.fn(), + }; + + return mock; +}; + +const createInternalStartContractMock = () => { + const mock: InternalHttpServiceStartMock = { + ...createStartContractMock(), + isListening: jest.fn(), + }; + + mock.isListening.mockReturnValue(true); + + return mock; }; type HttpServiceContract = PublicMethodsOf; + const createHttpServiceMock = () => { const mocked: jest.Mocked = { setup: jest.fn(), + getStartContract: jest.fn(), start: jest.fn(), stop: jest.fn(), }; - mocked.setup.mockResolvedValue(createSetupContractMock()); + mocked.setup.mockResolvedValue(createInternalSetupContractMock()); + mocked.getStartContract.mockReturnValue(createInternalStartContractMock()); + mocked.start.mockResolvedValue(createInternalStartContractMock()); return mocked; }; @@ -128,7 +196,10 @@ export const httpServiceMock = { create: createHttpServiceMock, createBasePath: createBasePathMock, createAuth: createAuthMock, + createInternalSetupContract: createInternalSetupContractMock, createSetupContract: createSetupContractMock, + createInternalStartContract: createInternalStartContractMock, + createStartContract: createStartContractMock, createOnPreAuthToolkit: createOnPreAuthToolkitMock, createOnPostAuthToolkit: createOnPostAuthToolkitMock, createOnPreResponseToolkit: createOnPreResponseToolkitMock, diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index ae9d53f9fd3db..c2fd653918171 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -22,6 +22,7 @@ import { first, map } from 'rxjs/operators'; import { Server } from 'hapi'; import { CoreService } from '../../types'; +import { pick } from '../../utils'; import { Logger, LoggerFactory } from '../logging'; import { ContextSetup } from '../context'; import { Env } from '../config'; @@ -38,7 +39,7 @@ import { RequestHandlerContextContainer, RequestHandlerContextProvider, InternalHttpServiceSetup, - HttpServiceStart, + InternalHttpServiceStart, } from './types'; import { RequestHandlerContext } from '../../server'; @@ -49,7 +50,8 @@ interface SetupDeps { } /** @internal */ -export class HttpService implements CoreService { +export class HttpService + implements CoreService { private readonly httpServer: HttpServer; private readonly httpsRedirectServer: HttpsRedirectServer; private readonly config$: Observable; @@ -59,6 +61,7 @@ export class HttpService implements CoreService { @@ -114,7 +117,16 @@ export class HttpService implements CoreService this.requestHandlerContext!.registerContext(pluginOpaqueId, contextName, provider), }; - return contract; + return this.internalSetup; + } + + // this method exists because we need the start contract to create the `CoreStart` used to start + // the `plugin` and `legacy` services. + public getStartContract(): InternalHttpServiceStart { + return { + ...pick(this.internalSetup!, ['auth', 'basePath', 'getServerInfo']), + isListening: () => this.httpServer.isListening(), + }; } public async start() { @@ -134,9 +146,7 @@ export class HttpService implements CoreService this.httpServer.isListening(), - }; + return this.getStartContract(); } /** diff --git a/src/core/server/http/router/router.mock.ts b/src/core/server/http/router/router.mock.ts index 651d1712100ee..f85f187164c92 100644 --- a/src/core/server/http/router/router.mock.ts +++ b/src/core/server/http/router/router.mock.ts @@ -19,7 +19,7 @@ import { IRouter } from './router'; -export type RouterMock = DeeplyMockedKeys; +export type RouterMock = jest.Mocked; function create({ routerPath = '' }: { routerPath?: string } = {}): RouterMock { return { diff --git a/src/core/server/http/types.ts b/src/core/server/http/types.ts index 77e0d6b61692d..7f2e70545d015 100644 --- a/src/core/server/http/types.ts +++ b/src/core/server/http/types.ts @@ -47,6 +47,22 @@ export type RequestHandlerContextProvider< TContextName extends keyof RequestHandlerContext > = IContextProvider, TContextName>; +/** + * @public + */ +export interface HttpAuth { + /** + * Gets authentication state for a request. Returned by `auth` interceptor. + * {@link GetAuthState} + */ + get: GetAuthState; + /** + * Returns authentication status for a request. + * {@link IsAuthenticated} + */ + isAuthenticated: IsAuthenticated; +} + /** * Kibana HTTP Service provides own abstraction for work with HTTP stack. * Plugins don't have direct access to `hapi` server and its primitives anymore. Moreover, @@ -185,28 +201,18 @@ export interface HttpServiceSetup { */ basePath: IBasePath; - auth: { - /** - * Gets authentication state for a request. Returned by `auth` interceptor. - * {@link GetAuthState} - */ - get: GetAuthState; - /** - * Returns authentication status for a request. - * {@link IsAuthenticated} - */ - isAuthenticated: IsAuthenticated; - }; - /** - * The CSP config used for Kibana. + * Auth status. + * See {@link HttpAuth} + * + * @deprecated use {@link HttpServiceStart.auth | the start contract} instead. */ - csp: ICspConfig; + auth: HttpAuth; /** - * Flag showing whether a server was configured to use TLS connection. + * The CSP config used for Kibana. */ - isTlsEnabled: boolean; + csp: ICspConfig; /** * Provides ability to declare a handler function for a particular path and HTTP request method. @@ -276,8 +282,28 @@ export interface InternalHttpServiceSetup /** @public */ export interface HttpServiceStart { - /** Indicates if http server is listening on a given port */ - isListening: (port: number) => boolean; + /** + * Access or manipulate the Kibana base path + * See {@link IBasePath}. + */ + basePath: IBasePath; + + /** + * Auth status. + * See {@link HttpAuth} + */ + auth: HttpAuth; + + /** + * Provides common {@link HttpServerInfo | information} about the running http server. + */ + getServerInfo: () => HttpServerInfo; +} + +/** @internal */ +export interface InternalHttpServiceStart extends HttpServiceStart { + /** Indicates if the http server is listening on the configured port */ + isListening: () => boolean; } /** @public */ diff --git a/src/core/server/http_resources/http_resources_service.test.ts b/src/core/server/http_resources/http_resources_service.test.ts index e6f129ba12d78..80afddc166570 100644 --- a/src/core/server/http_resources/http_resources_service.test.ts +++ b/src/core/server/http_resources/http_resources_service.test.ts @@ -37,7 +37,7 @@ describe('HttpResources service', () => { describe('#createRegistrar', () => { beforeEach(() => { setupDeps = { - http: httpServiceMock.createSetupContract(), + http: httpServiceMock.createInternalSetupContract(), rendering: renderingMock.createSetupContract(), }; service = new HttpResourcesService(coreContext); diff --git a/src/core/server/index.ts b/src/core/server/index.ts index dccd58c24a7d0..0da7e5d66cf2a 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -46,7 +46,7 @@ import { ElasticsearchServiceStart, } from './elasticsearch'; -import { HttpServiceSetup } from './http'; +import { HttpServiceSetup, HttpServiceStart } from './http'; import { HttpResources } from './http_resources'; import { PluginsServiceSetup, PluginsServiceStart, PluginOpaqueId } from './plugins'; @@ -121,6 +121,7 @@ export { CustomHttpResponseOptions, GetAuthHeaders, GetAuthState, + HttpAuth, HttpResponseOptions, HttpResponsePayload, HttpServerInfo, @@ -421,6 +422,8 @@ export interface CoreStart { capabilities: CapabilitiesStart; /** {@link ElasticsearchServiceStart} */ elasticsearch: ElasticsearchServiceStart; + /** {@link HttpServiceStart} */ + http: HttpServiceStart; /** {@link SavedObjectsServiceStart} */ savedObjects: SavedObjectsServiceStart; /** {@link UiSettingsServiceStart} */ diff --git a/src/core/server/internal_types.ts b/src/core/server/internal_types.ts index 09ec772a41756..f68ab633dcbe6 100644 --- a/src/core/server/internal_types.ts +++ b/src/core/server/internal_types.ts @@ -23,7 +23,7 @@ import { CapabilitiesSetup, CapabilitiesStart } from './capabilities'; import { ConfigDeprecationProvider } from './config'; import { ContextSetup } from './context'; import { InternalElasticsearchServiceSetup, ElasticsearchServiceStart } from './elasticsearch'; -import { InternalHttpServiceSetup } from './http'; +import { InternalHttpServiceSetup, InternalHttpServiceStart } from './http'; import { InternalSavedObjectsServiceSetup, InternalSavedObjectsServiceStart, @@ -56,6 +56,7 @@ export interface InternalCoreSetup { export interface InternalCoreStart { capabilities: CapabilitiesStart; elasticsearch: ElasticsearchServiceStart; + http: InternalHttpServiceStart; savedObjects: InternalSavedObjectsServiceStart; uiSettings: InternalUiSettingsServiceStart; } diff --git a/src/core/server/legacy/legacy_internals.test.ts b/src/core/server/legacy/legacy_internals.test.ts index 2ae5e3a3fd1e8..67f2f433d4570 100644 --- a/src/core/server/legacy/legacy_internals.test.ts +++ b/src/core/server/legacy/legacy_internals.test.ts @@ -45,7 +45,7 @@ describe('LegacyInternals', () => { beforeEach(async () => { uiExports = findLegacyPluginSpecsMock().uiExports; config = configMock.create() as any; - server = httpServiceMock.createSetupContract().server; + server = httpServiceMock.createInternalSetupContract().server; legacyInternals = new LegacyInternals(uiExports, config, server); }); @@ -107,7 +107,7 @@ describe('LegacyInternals', () => { beforeEach(async () => { uiExports = findLegacyPluginSpecsMock().uiExports; config = configMock.create() as any; - server = httpServiceMock.createSetupContract().server; + server = httpServiceMock.createInternalSetupContract().server; legacyInternals = new LegacyInternals(uiExports, config, server); }); diff --git a/src/core/server/legacy/legacy_service.test.ts b/src/core/server/legacy/legacy_service.test.ts index d9a0ac5e4ecff..fb9dc0776716a 100644 --- a/src/core/server/legacy/legacy_service.test.ts +++ b/src/core/server/legacy/legacy_service.test.ts @@ -85,7 +85,7 @@ beforeEach(() => { elasticsearch: { legacy: {} } as any, uiSettings: uiSettingsServiceMock.createSetupContract(), http: { - ...httpServiceMock.createSetupContract(), + ...httpServiceMock.createInternalSetupContract(), auth: { getAuthHeaders: () => undefined, } as any, @@ -119,7 +119,7 @@ beforeEach(() => { startDeps = { core: { - ...coreMock.createStart(), + ...coreMock.createInternalStart(), savedObjects: savedObjectsServiceMock.createInternalStartContract(), plugins: { contracts: new Map() }, }, diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts index 2ced8b4762406..cfc53b10d91f0 100644 --- a/src/core/server/legacy/legacy_service.ts +++ b/src/core/server/legacy/legacy_service.ts @@ -264,6 +264,11 @@ export class LegacyService implements CoreService { const coreStart: CoreStart = { capabilities: startDeps.core.capabilities, elasticsearch: startDeps.core.elasticsearch, + http: { + auth: startDeps.core.http.auth, + basePath: startDeps.core.http.basePath, + getServerInfo: startDeps.core.http.getServerInfo, + }, savedObjects: { getScopedClient: startDeps.core.savedObjects.getScopedClient, createScopedRepository: startDeps.core.savedObjects.createScopedRepository, @@ -302,7 +307,6 @@ export class LegacyService implements CoreService { isAuthenticated: setupDeps.core.http.auth.isAuthenticated, }, csp: setupDeps.core.http.csp, - isTlsEnabled: setupDeps.core.http.isTlsEnabled, getServerInfo: setupDeps.core.http.getServerInfo, }, metrics: { diff --git a/src/core/server/metrics/metrics_service.test.ts b/src/core/server/metrics/metrics_service.test.ts index 01a7429745cda..b3cc06ffca1d2 100644 --- a/src/core/server/metrics/metrics_service.test.ts +++ b/src/core/server/metrics/metrics_service.test.ts @@ -30,7 +30,7 @@ const testInterval = 100; const dummyMetrics = { metricA: 'value', metricB: 'otherValue' }; describe('MetricsService', () => { - const httpMock = httpServiceMock.createSetupContract(); + const httpMock = httpServiceMock.createInternalSetupContract(); let metricsService: MetricsService; beforeEach(() => { diff --git a/src/core/server/metrics/ops_metrics_collector.test.ts b/src/core/server/metrics/ops_metrics_collector.test.ts index 559588db60a42..9e76895b14578 100644 --- a/src/core/server/metrics/ops_metrics_collector.test.ts +++ b/src/core/server/metrics/ops_metrics_collector.test.ts @@ -29,7 +29,7 @@ describe('OpsMetricsCollector', () => { let collector: OpsMetricsCollector; beforeEach(() => { - const hapiServer = httpServiceMock.createSetupContract().server; + const hapiServer = httpServiceMock.createInternalSetupContract().server; collector = new OpsMetricsCollector(hapiServer); mockOsCollector.collect.mockResolvedValue('osMetrics'); diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index b6e9ffef6f3f1..f3ae5462f1631 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -19,7 +19,6 @@ import { of } from 'rxjs'; import { duration } from 'moment'; import { PluginInitializerContext, CoreSetup, CoreStart, StartServicesAccessor } from '.'; -import { CspConfig } from './csp'; import { loggingServiceMock } from './logging/logging_service.mock'; import { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock'; import { httpServiceMock } from './http/http_service.mock'; @@ -112,26 +111,10 @@ function createCoreSetupMock({ pluginStartDeps?: object; pluginStartContract?: any; } = {}) { - const httpService = httpServiceMock.createSetupContract(); const httpMock: jest.Mocked = { - createCookieSessionStorageFactory: httpService.createCookieSessionStorageFactory, - registerOnPreAuth: httpService.registerOnPreAuth, - registerAuth: httpService.registerAuth, - registerOnPostAuth: httpService.registerOnPostAuth, - registerOnPreResponse: httpService.registerOnPreResponse, - basePath: httpService.basePath, - csp: CspConfig.DEFAULT, - isTlsEnabled: httpService.isTlsEnabled, - createRouter: jest.fn(), - registerRouteHandlerContext: jest.fn(), - auth: { - get: httpService.auth.get, - isAuthenticated: httpService.auth.isAuthenticated, - }, + ...httpServiceMock.createSetupContract(), resources: httpResourcesMock.createRegistrar(), - getServerInfo: httpService.getServerInfo, }; - httpMock.createRouter.mockImplementation(() => httpService.createRouter('')); const uiSettingsMock = { register: uiSettingsServiceMock.createSetupContract().register, @@ -159,6 +142,7 @@ function createCoreStartMock() { const mock: MockedKeys = { capabilities: capabilitiesServiceMock.createStartContract(), elasticsearch: elasticsearchServiceMock.createStart(), + http: httpServiceMock.createStartContract(), savedObjects: savedObjectsServiceMock.createStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), }; @@ -171,7 +155,7 @@ function createInternalCoreSetupMock() { capabilities: capabilitiesServiceMock.createSetupContract(), context: contextServiceMock.createSetupContract(), elasticsearch: elasticsearchServiceMock.createInternalSetup(), - http: httpServiceMock.createSetupContract(), + http: httpServiceMock.createInternalSetupContract(), metrics: metricsServiceMock.createInternalSetupContract(), savedObjects: savedObjectsServiceMock.createInternalSetupContract(), status: statusServiceMock.createInternalSetupContract(), @@ -187,6 +171,7 @@ function createInternalCoreStartMock() { const startDeps: InternalCoreStart = { capabilities: capabilitiesServiceMock.createStartContract(), elasticsearch: elasticsearchServiceMock.createStart(), + http: httpServiceMock.createInternalStartContract(), savedObjects: savedObjectsServiceMock.createInternalStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), }; diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index f0db3a25e313d..31e36db49223a 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -164,7 +164,6 @@ export function createPluginSetupContext( basePath: deps.http.basePath, auth: { get: deps.http.auth.get, isAuthenticated: deps.http.auth.isAuthenticated }, csp: deps.http.csp, - isTlsEnabled: deps.http.isTlsEnabled, getServerInfo: deps.http.getServerInfo, }, metrics: { @@ -211,6 +210,11 @@ export function createPluginStartContext( resolveCapabilities: deps.capabilities.resolveCapabilities, }, elasticsearch: deps.elasticsearch, + http: { + auth: deps.http.auth, + basePath: deps.http.basePath, + getServerInfo: deps.http.getServerInfo, + }, savedObjects: { getScopedClient: deps.savedObjects.getScopedClient, createInternalRepository: deps.savedObjects.createInternalRepository, diff --git a/src/core/server/rendering/__mocks__/params.ts b/src/core/server/rendering/__mocks__/params.ts index 3e668b3f26ab5..ce2eea119d1bb 100644 --- a/src/core/server/rendering/__mocks__/params.ts +++ b/src/core/server/rendering/__mocks__/params.ts @@ -23,7 +23,7 @@ import { pluginServiceMock } from '../../plugins/plugins_service.mock'; import { legacyServiceMock } from '../../legacy/legacy_service.mock'; const context = mockCoreContext.create(); -const http = httpServiceMock.createSetupContract(); +const http = httpServiceMock.createInternalSetupContract(); const uiPlugins = pluginServiceMock.createUiPlugins(); const legacyPlugins = legacyServiceMock.createDiscoverPlugins(); diff --git a/src/core/server/saved_objects/saved_objects_service.test.ts b/src/core/server/saved_objects/saved_objects_service.test.ts index 9fba2728003d2..e8b2cf0b583b1 100644 --- a/src/core/server/saved_objects/saved_objects_service.test.ts +++ b/src/core/server/saved_objects/saved_objects_service.test.ts @@ -61,7 +61,7 @@ describe('SavedObjectsService', () => { const createSetupDeps = () => { const elasticsearchMock = elasticsearchServiceMock.createInternalSetup(); return { - http: httpServiceMock.createSetupContract(), + http: httpServiceMock.createInternalSetupContract(), elasticsearch: elasticsearchMock, legacyPlugins: legacyServiceMock.createDiscoverPlugins(), }; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 833c8918a0860..9dc3ac9b94d96 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -657,6 +657,8 @@ export interface CoreStart { // (undocumented) elasticsearch: ElasticsearchServiceStart; // (undocumented) + http: HttpServiceStart; + // (undocumented) savedObjects: SavedObjectsServiceStart; // (undocumented) uiSettings: UiSettingsServiceStart; @@ -905,6 +907,12 @@ export type Headers = { [header: string]: string | string[] | undefined; }; +// @public (undocumented) +export interface HttpAuth { + get: GetAuthState; + isAuthenticated: IsAuthenticated; +} + // @public export interface HttpResources { register: (route: RouteConfig, handler: HttpResourcesRequestHandler) => void; @@ -948,17 +956,13 @@ export interface HttpServerInfo { // @public export interface HttpServiceSetup { - // (undocumented) - auth: { - get: GetAuthState; - isAuthenticated: IsAuthenticated; - }; + // @deprecated + auth: HttpAuth; basePath: IBasePath; createCookieSessionStorageFactory: (cookieOptions: SessionStorageCookieOptions) => Promise>; createRouter: () => IRouter; csp: ICspConfig; getServerInfo: () => HttpServerInfo; - isTlsEnabled: boolean; registerAuth: (handler: AuthenticationHandler) => void; registerOnPostAuth: (handler: OnPostAuthHandler) => void; registerOnPreAuth: (handler: OnPreAuthHandler) => void; @@ -968,7 +972,9 @@ export interface HttpServiceSetup { // @public (undocumented) export interface HttpServiceStart { - isListening: (port: number) => boolean; + auth: HttpAuth; + basePath: IBasePath; + getServerInfo: () => HttpServerInfo; } // @public diff --git a/src/core/server/server.ts b/src/core/server/server.ts index 6ca580083648f..ae1a02cf71b88 100644 --- a/src/core/server/server.ts +++ b/src/core/server/server.ts @@ -202,10 +202,12 @@ export class Server { }); const capabilitiesStart = this.capabilities.start(); const uiSettingsStart = await this.uiSettings.start(); + const httpStart = this.http.getStartContract(); this.coreStart = { capabilities: capabilitiesStart, elasticsearch: elasticsearchStart, + http: httpStart, savedObjects: savedObjectsStart, uiSettings: uiSettingsStart, }; @@ -221,6 +223,7 @@ export class Server { }); await this.http.start(); + await this.rendering.start({ legacy: this.legacy, }); diff --git a/src/core/server/ui_settings/ui_settings_service.test.ts b/src/core/server/ui_settings/ui_settings_service.test.ts index ebcb0cf1d762f..096ca347e6f4b 100644 --- a/src/core/server/ui_settings/ui_settings_service.test.ts +++ b/src/core/server/ui_settings/ui_settings_service.test.ts @@ -49,7 +49,7 @@ describe('uiSettings', () => { beforeEach(() => { const coreContext = mockCoreContext.create(); coreContext.configService.atPath.mockReturnValue(new BehaviorSubject({ overrides })); - const httpSetup = httpServiceMock.createSetupContract(); + const httpSetup = httpServiceMock.createInternalSetupContract(); const savedObjectsSetup = savedObjectsServiceMock.createInternalSetupContract(); setupDeps = { http: httpSetup, savedObjects: savedObjectsSetup }; savedObjectsClient = savedObjectsClientMock.create(); diff --git a/x-pack/plugins/canvas/server/routes/custom_elements/create.test.ts b/x-pack/plugins/canvas/server/routes/custom_elements/create.test.ts index c260d6ca8ac16..db0417434227c 100644 --- a/x-pack/plugins/canvas/server/routes/custom_elements/create.test.ts +++ b/x-pack/plugins/canvas/server/routes/custom_elements/create.test.ts @@ -13,12 +13,7 @@ import { } from 'src/core/server/mocks'; import { CUSTOM_ELEMENT_TYPE } from '../../../common/lib/constants'; import { initializeCreateCustomElementRoute } from './create'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; const mockRouteContext = ({ core: { @@ -43,7 +38,7 @@ describe('POST custom element', () => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeCreateCustomElementRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/custom_elements/delete.test.ts b/x-pack/plugins/canvas/server/routes/custom_elements/delete.test.ts index e70fae5d18eaf..98b26ec368ab1 100644 --- a/x-pack/plugins/canvas/server/routes/custom_elements/delete.test.ts +++ b/x-pack/plugins/canvas/server/routes/custom_elements/delete.test.ts @@ -6,12 +6,7 @@ import { CUSTOM_ELEMENT_TYPE } from '../../../common/lib/constants'; import { initializeDeleteCustomElementRoute } from './delete'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { savedObjectsClientMock, httpServiceMock, @@ -32,7 +27,7 @@ describe('DELETE custom element', () => { beforeEach(() => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeDeleteCustomElementRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/custom_elements/find.test.ts b/x-pack/plugins/canvas/server/routes/custom_elements/find.test.ts index 6644d3b56c681..dead9ded8a14a 100644 --- a/x-pack/plugins/canvas/server/routes/custom_elements/find.test.ts +++ b/x-pack/plugins/canvas/server/routes/custom_elements/find.test.ts @@ -5,12 +5,7 @@ */ import { initializeFindCustomElementsRoute } from './find'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { savedObjectsClientMock, httpServiceMock, @@ -31,7 +26,7 @@ describe('Find custom element', () => { beforeEach(() => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeFindCustomElementsRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/custom_elements/get.test.ts b/x-pack/plugins/canvas/server/routes/custom_elements/get.test.ts index 03ae6048801bf..09b620aeff9bb 100644 --- a/x-pack/plugins/canvas/server/routes/custom_elements/get.test.ts +++ b/x-pack/plugins/canvas/server/routes/custom_elements/get.test.ts @@ -6,12 +6,7 @@ import { CUSTOM_ELEMENT_TYPE } from '../../../common/lib/constants'; import { initializeGetCustomElementRoute } from './get'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { savedObjectsClientMock, httpServiceMock, @@ -32,7 +27,7 @@ describe('GET custom element', () => { beforeEach(() => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeGetCustomElementRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/custom_elements/update.test.ts b/x-pack/plugins/canvas/server/routes/custom_elements/update.test.ts index e67e42c26cd2b..19477458bacb5 100644 --- a/x-pack/plugins/canvas/server/routes/custom_elements/update.test.ts +++ b/x-pack/plugins/canvas/server/routes/custom_elements/update.test.ts @@ -8,12 +8,7 @@ import sinon from 'sinon'; import { CustomElement } from '../../../types'; import { CUSTOM_ELEMENT_TYPE } from '../../../common/lib/constants'; import { initializeUpdateCustomElementRoute } from './update'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { savedObjectsClientMock, httpServiceMock, @@ -57,7 +52,7 @@ describe('PUT custom element', () => { clock = sinon.useFakeTimers(now); const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeUpdateCustomElementRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/es_fields/es_fields.test.ts b/x-pack/plugins/canvas/server/routes/es_fields/es_fields.test.ts index c3588957ff68e..93fdb4304acc6 100644 --- a/x-pack/plugins/canvas/server/routes/es_fields/es_fields.test.ts +++ b/x-pack/plugins/canvas/server/routes/es_fields/es_fields.test.ts @@ -5,12 +5,7 @@ */ import { initializeESFieldsRoute } from './es_fields'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { httpServiceMock, httpServerMock, @@ -31,7 +26,7 @@ describe('Retrieve ES Fields', () => { beforeEach(() => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeESFieldsRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/shareables/download.test.ts b/x-pack/plugins/canvas/server/routes/shareables/download.test.ts index be4765217d7aa..75eeb46c890d5 100644 --- a/x-pack/plugins/canvas/server/routes/shareables/download.test.ts +++ b/x-pack/plugins/canvas/server/routes/shareables/download.test.ts @@ -7,12 +7,7 @@ jest.mock('fs'); import fs from 'fs'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { httpServiceMock, httpServerMock, loggingServiceMock } from 'src/core/server/mocks'; import { initializeDownloadShareableWorkpadRoute } from './download'; @@ -25,7 +20,7 @@ describe('Download Canvas shareables runtime', () => { beforeEach(() => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeDownloadShareableWorkpadRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/shareables/zip.test.ts b/x-pack/plugins/canvas/server/routes/shareables/zip.test.ts index 63776f897a04c..5a2d122c2754b 100644 --- a/x-pack/plugins/canvas/server/routes/shareables/zip.test.ts +++ b/x-pack/plugins/canvas/server/routes/shareables/zip.test.ts @@ -7,12 +7,7 @@ jest.mock('archiver'); const archiver = require('archiver') as jest.Mock; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { httpServiceMock, httpServerMock, loggingServiceMock } from 'src/core/server/mocks'; import { initializeZipShareableWorkpadRoute } from './zip'; import { API_ROUTE_SHAREABLE_ZIP } from '../../../common/lib'; @@ -31,7 +26,7 @@ describe('Zips Canvas shareables runtime together with workpad', () => { beforeEach(() => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeZipShareableWorkpadRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/workpad/create.test.ts b/x-pack/plugins/canvas/server/routes/workpad/create.test.ts index 02b6376ece2ed..2ed63e7397108 100644 --- a/x-pack/plugins/canvas/server/routes/workpad/create.test.ts +++ b/x-pack/plugins/canvas/server/routes/workpad/create.test.ts @@ -13,12 +13,7 @@ import { } from 'src/core/server/mocks'; import { CANVAS_TYPE } from '../../../common/lib/constants'; import { initializeCreateWorkpadRoute } from './create'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; const mockRouteContext = ({ core: { @@ -43,7 +38,7 @@ describe('POST workpad', () => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeCreateWorkpadRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/workpad/delete.test.ts b/x-pack/plugins/canvas/server/routes/workpad/delete.test.ts index 57df4e7cffda6..712ff29400382 100644 --- a/x-pack/plugins/canvas/server/routes/workpad/delete.test.ts +++ b/x-pack/plugins/canvas/server/routes/workpad/delete.test.ts @@ -6,12 +6,7 @@ import { CANVAS_TYPE } from '../../../common/lib/constants'; import { initializeDeleteWorkpadRoute } from './delete'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { savedObjectsClientMock, httpServiceMock, @@ -32,7 +27,7 @@ describe('DELETE workpad', () => { beforeEach(() => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeDeleteWorkpadRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/workpad/find.test.ts b/x-pack/plugins/canvas/server/routes/workpad/find.test.ts index 08de9b20e9818..e2dd8552379b7 100644 --- a/x-pack/plugins/canvas/server/routes/workpad/find.test.ts +++ b/x-pack/plugins/canvas/server/routes/workpad/find.test.ts @@ -5,12 +5,7 @@ */ import { initializeFindWorkpadsRoute } from './find'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { savedObjectsClientMock, httpServiceMock, @@ -31,7 +26,7 @@ describe('Find workpad', () => { beforeEach(() => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeFindWorkpadsRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/workpad/get.test.ts b/x-pack/plugins/canvas/server/routes/workpad/get.test.ts index 6741f2b3fc9d6..9ecd9ceefed8d 100644 --- a/x-pack/plugins/canvas/server/routes/workpad/get.test.ts +++ b/x-pack/plugins/canvas/server/routes/workpad/get.test.ts @@ -6,12 +6,7 @@ import { CANVAS_TYPE } from '../../../common/lib/constants'; import { initializeGetWorkpadRoute } from './get'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { savedObjectsClientMock, httpServiceMock, @@ -34,7 +29,7 @@ describe('GET workpad', () => { beforeEach(() => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeGetWorkpadRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/canvas/server/routes/workpad/update.test.ts b/x-pack/plugins/canvas/server/routes/workpad/update.test.ts index a6b34e7165121..36ea984447d8a 100644 --- a/x-pack/plugins/canvas/server/routes/workpad/update.test.ts +++ b/x-pack/plugins/canvas/server/routes/workpad/update.test.ts @@ -7,12 +7,7 @@ import sinon from 'sinon'; import { CANVAS_TYPE } from '../../../common/lib/constants'; import { initializeUpdateWorkpadRoute, initializeUpdateWorkpadAssetsRoute } from './update'; -import { - IRouter, - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { savedObjectsClientMock, httpServiceMock, @@ -44,7 +39,7 @@ describe('PUT workpad', () => { clock = sinon.useFakeTimers(now); const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeUpdateWorkpadRoute({ router, logger: loggingServiceMock.create().get(), @@ -158,7 +153,7 @@ describe('update assets', () => { beforeEach(() => { clock = sinon.useFakeTimers(now); const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); initializeUpdateWorkpadAssetsRoute({ router, logger: loggingServiceMock.create().get(), diff --git a/x-pack/plugins/case/server/routes/api/__fixtures__/mock_router.ts b/x-pack/plugins/case/server/routes/api/__fixtures__/mock_router.ts index eff91fff32c02..e00c1c111b41b 100644 --- a/x-pack/plugins/case/server/routes/api/__fixtures__/mock_router.ts +++ b/x-pack/plugins/case/server/routes/api/__fixtures__/mock_router.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IRouter } from 'kibana/server'; import { loggingServiceMock, httpServiceMock } from '../../../../../../../src/core/server/mocks'; import { CaseService, CaseConfigureService } from '../../../services'; import { authenticationMock } from '../__fixtures__'; @@ -16,7 +15,7 @@ export const createRoute = async ( badAuth = false ) => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); const log = loggingServiceMock.create().get('case'); diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_create_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_create_route.test.ts index 0b5f04556596a..cf2349bc7023c 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_create_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_create_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Create auto-follow pattern', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerCreateRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_delete_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_delete_route.test.ts index 7468c643a3aa6..b2a3b631333b4 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_delete_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_delete_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Delete auto-follow pattern(s)', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerDeleteRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_fetch_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_fetch_route.test.ts index 1aa7112c75276..4f2417ec816f4 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_fetch_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_fetch_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Fetch all auto-follow patterns', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerFetchRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_get_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_get_route.test.ts index 980128027c2f9..802aebd6412fe 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_get_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_get_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Get one auto-follow pattern', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerGetRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_pause_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_pause_route.test.ts index 5b27c77ca86de..a92a9b5edb9b7 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_pause_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_pause_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Pause auto-follow pattern(s)', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerPauseRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_resume_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_resume_route.test.ts index afea0f631fe48..4ee77b1b3deaa 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_resume_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_resume_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Resume auto-follow pattern(s)', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerResumeRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_update_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_update_route.test.ts index bdce84f6404b1..711538e2a1ee0 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_update_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/auto_follow_pattern/register_update_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Update auto-follow pattern', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerUpdateRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_create_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_create_route.test.ts index ccf7c469fe780..de21458c0a25f 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_create_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_create_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Create follower index', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerCreateRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_fetch_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_fetch_route.test.ts index e1ec28a7c90b1..ec52f1e431e38 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_fetch_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_fetch_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Fetch all follower indices', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerFetchRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_get_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_get_route.test.ts index 99c871d5d4f2d..a0feeb2b1e5bc 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_get_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_get_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Get one follower index', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerGetRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_pause_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_pause_route.test.ts index 3d28d36ac6182..dcbec8703622e 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_pause_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_pause_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Pause follower index/indices', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerPauseRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_resume_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_resume_route.test.ts index 09975b262dca8..30d25c3bc4d03 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_resume_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_resume_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Resume follower index/indices', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerResumeRoute({ router, diff --git a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_unfollow_route.test.ts b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_unfollow_route.test.ts index 5f0d148bfcae9..a56eb8178b478 100644 --- a/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_unfollow_route.test.ts +++ b/x-pack/plugins/cross_cluster_replication/server/routes/api/follower_index/register_unfollow_route.test.ts @@ -5,7 +5,7 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server'; +import { kibanaResponseFactory, RequestHandler } from 'src/core/server'; import { isEsError } from '../../../shared_imports'; import { formatEsError } from '../../../lib/format_es_error'; @@ -19,7 +19,7 @@ describe('[CCR API] Unfollow follower index/indices', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerUnfollowRoute({ router, diff --git a/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.test.ts b/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.test.ts index b34ffe3e0baf5..060a423350ada 100644 --- a/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.test.ts +++ b/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.test.ts @@ -4,12 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { httpServerMock, httpServiceMock } from 'src/core/server/mocks'; -import { - kibanaResponseFactory, - RequestHandlerContext, - RequestHandler, - IRouter, -} from 'src/core/server'; +import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; import { License } from '../../../services/license'; import { IndexDataEnricher } from '../../../services/index_data_enricher'; @@ -46,7 +41,7 @@ describe('GET privileges', () => { let routeHandler: RequestHandler; beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerPrivilegesRoute({ router, @@ -115,7 +110,7 @@ describe('GET privileges', () => { describe('With security disabled', () => { beforeEach(() => { - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); registerPrivilegesRoute({ router, diff --git a/x-pack/plugins/security/server/plugin.test.ts b/x-pack/plugins/security/server/plugin.test.ts index e01c608e5f306..627d1408673be 100644 --- a/x-pack/plugins/security/server/plugin.test.ts +++ b/x-pack/plugins/security/server/plugin.test.ts @@ -36,7 +36,12 @@ describe('Security Plugin', () => { ); mockCoreSetup = coreMock.createSetup(); - mockCoreSetup.http.isTlsEnabled = true; + mockCoreSetup.http.getServerInfo.mockReturnValue({ + host: 'localhost', + name: 'kibana', + port: 80, + protocol: 'https', + }); mockClusterClient = elasticsearchServiceMock.createCustomClusterClient(); mockCoreSetup.elasticsearch.legacy.createClient.mockReturnValue(mockClusterClient); diff --git a/x-pack/plugins/security/server/plugin.ts b/x-pack/plugins/security/server/plugin.ts index c8f47aaae7b5d..a14617c8489cc 100644 --- a/x-pack/plugins/security/server/plugin.ts +++ b/x-pack/plugins/security/server/plugin.ts @@ -118,7 +118,7 @@ export class Plugin { this.initializerContext.config.create>().pipe( map((rawConfig) => createConfig(rawConfig, this.initializerContext.logger.get('config'), { - isTLSEnabled: core.http.isTlsEnabled, + isTLSEnabled: core.http.getServerInfo().protocol === 'https', }) ) ), diff --git a/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts b/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts index 09fc990e9935c..53f5a219dda5b 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts @@ -14,7 +14,7 @@ import { createResolveSavedObjectsImportErrorsMock, createMockSavedObjectsService, } from '../__fixtures__'; -import { CoreSetup, IRouter, kibanaResponseFactory, RouteValidatorConfig } from 'src/core/server'; +import { CoreSetup, kibanaResponseFactory, RouteValidatorConfig } from 'src/core/server'; import { loggingServiceMock, httpServiceMock, @@ -54,7 +54,7 @@ describe('copy to space', () => { const setup = async () => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); const savedObjectsRepositoryMock = createMockSavedObjectsRepository(spacesSavedObjects); diff --git a/x-pack/plugins/spaces/server/routes/api/external/delete.test.ts b/x-pack/plugins/spaces/server/routes/api/external/delete.test.ts index 774b794d77e29..f31ef657642e7 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/delete.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/delete.test.ts @@ -13,7 +13,6 @@ import { } from '../__fixtures__'; import { CoreSetup, - IRouter, kibanaResponseFactory, RouteValidatorConfig, SavedObjectsErrorHelpers, @@ -37,7 +36,7 @@ describe('Spaces Public API', () => { const setup = async () => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); const savedObjectsRepositoryMock = createMockSavedObjectsRepository(spacesSavedObjects); diff --git a/x-pack/plugins/spaces/server/routes/api/external/get.test.ts b/x-pack/plugins/spaces/server/routes/api/external/get.test.ts index 19f9b81baa0b0..55e153cf47f5b 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/get.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/get.test.ts @@ -11,7 +11,7 @@ import { mockRouteContext, } from '../__fixtures__'; import { initGetSpaceApi } from './get'; -import { CoreSetup, IRouter, kibanaResponseFactory } from 'src/core/server'; +import { CoreSetup, kibanaResponseFactory } from 'src/core/server'; import { loggingServiceMock, httpServiceMock, @@ -30,7 +30,7 @@ describe('GET space', () => { const setup = async () => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); const coreStart = coreMock.createStart(); diff --git a/x-pack/plugins/spaces/server/routes/api/external/get_all.test.ts b/x-pack/plugins/spaces/server/routes/api/external/get_all.test.ts index 380cc9dbe5abf..aabd4900c5469 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/get_all.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/get_all.test.ts @@ -10,7 +10,7 @@ import { mockRouteContext, mockRouteContextWithInvalidLicense, } from '../__fixtures__'; -import { CoreSetup, kibanaResponseFactory, IRouter } from 'src/core/server'; +import { CoreSetup, kibanaResponseFactory } from 'src/core/server'; import { loggingServiceMock, httpServiceMock, @@ -30,7 +30,7 @@ describe('GET /spaces/space', () => { const setup = async () => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); const coreStart = coreMock.createStart(); diff --git a/x-pack/plugins/spaces/server/routes/api/external/post.test.ts b/x-pack/plugins/spaces/server/routes/api/external/post.test.ts index ca3afc04b9798..5e09308f07d31 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/post.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/post.test.ts @@ -10,7 +10,7 @@ import { mockRouteContext, mockRouteContextWithInvalidLicense, } from '../__fixtures__'; -import { CoreSetup, kibanaResponseFactory, IRouter, RouteValidatorConfig } from 'src/core/server'; +import { CoreSetup, kibanaResponseFactory, RouteValidatorConfig } from 'src/core/server'; import { loggingServiceMock, httpServerMock, @@ -30,7 +30,7 @@ describe('Spaces Public API', () => { const setup = async () => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); const coreStart = coreMock.createStart(); diff --git a/x-pack/plugins/spaces/server/routes/api/external/put.test.ts b/x-pack/plugins/spaces/server/routes/api/external/put.test.ts index 62444fd3e4dfd..7b068d3784043 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/put.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/put.test.ts @@ -11,7 +11,7 @@ import { mockRouteContext, mockRouteContextWithInvalidLicense, } from '../__fixtures__'; -import { CoreSetup, IRouter, kibanaResponseFactory, RouteValidatorConfig } from 'src/core/server'; +import { CoreSetup, kibanaResponseFactory, RouteValidatorConfig } from 'src/core/server'; import { loggingServiceMock, httpServiceMock, @@ -31,7 +31,7 @@ describe('PUT /api/spaces/space', () => { const setup = async () => { const httpService = httpServiceMock.createSetupContract(); - const router = httpService.createRouter('') as jest.Mocked; + const router = httpService.createRouter(); const coreStart = coreMock.createStart();