HttpService: duplicate some APIs from setup to start and clean mocks. (#69021)

* add apis to http start contract and clean mocks

* add apis to http start contract and clean mocks

* add `getStartContract` method

* fix new calls

* remove isTlsEnabled

* deprecates HttpServiceSetup.auth
This commit is contained in:
Pierre Gayvallet 2020-06-18 15:55:47 +02:00 committed by GitHub
parent f33192d35f
commit 9e8448fc06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
72 changed files with 376 additions and 264 deletions

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [CoreStart](./kibana-plugin-core-server.corestart.md) &gt; [http](./kibana-plugin-core-server.corestart.http.md)
## CoreStart.http property
[HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md)
<b>Signature:</b>
```typescript
http: HttpServiceStart;
```

View file

@ -18,6 +18,7 @@ export interface CoreStart
| --- | --- | --- |
| [capabilities](./kibana-plugin-core-server.corestart.capabilities.md) | <code>CapabilitiesStart</code> | [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) |
| [elasticsearch](./kibana-plugin-core-server.corestart.elasticsearch.md) | <code>ElasticsearchServiceStart</code> | [ElasticsearchServiceStart](./kibana-plugin-core-server.elasticsearchservicestart.md) |
| [http](./kibana-plugin-core-server.corestart.http.md) | <code>HttpServiceStart</code> | [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) |
| [savedObjects](./kibana-plugin-core-server.corestart.savedobjects.md) | <code>SavedObjectsServiceStart</code> | [SavedObjectsServiceStart](./kibana-plugin-core-server.savedobjectsservicestart.md) |
| [uiSettings](./kibana-plugin-core-server.corestart.uisettings.md) | <code>UiSettingsServiceStart</code> | [UiSettingsServiceStart](./kibana-plugin-core-server.uisettingsservicestart.md) |

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpAuth](./kibana-plugin-core-server.httpauth.md) &gt; [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)
<b>Signature:</b>
```typescript
get: GetAuthState;
```

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpAuth](./kibana-plugin-core-server.httpauth.md) &gt; [isAuthenticated](./kibana-plugin-core-server.httpauth.isauthenticated.md)
## HttpAuth.isAuthenticated property
Returns authentication status for a request. [IsAuthenticated](./kibana-plugin-core-server.isauthenticated.md)
<b>Signature:</b>
```typescript
isAuthenticated: IsAuthenticated;
```

View file

@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpAuth](./kibana-plugin-core-server.httpauth.md)
## HttpAuth interface
<b>Signature:</b>
```typescript
export interface HttpAuth
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [get](./kibana-plugin-core-server.httpauth.get.md) | <code>GetAuthState</code> | Gets authentication state for a request. Returned by <code>auth</code> interceptor. [GetAuthState](./kibana-plugin-core-server.getauthstate.md) |
| [isAuthenticated](./kibana-plugin-core-server.httpauth.isauthenticated.md) | <code>IsAuthenticated</code> | Returns authentication status for a request. [IsAuthenticated](./kibana-plugin-core-server.isauthenticated.md) |

View file

@ -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)
<b>Signature:</b>
```typescript
auth: {
get: GetAuthState;
isAuthenticated: IsAuthenticated;
};
auth: HttpAuth;
```

View file

@ -1,13 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpServiceSetup](./kibana-plugin-core-server.httpservicesetup.md) &gt; [isTlsEnabled](./kibana-plugin-core-server.httpservicesetup.istlsenabled.md)
## HttpServiceSetup.isTlsEnabled property
Flag showing whether a server was configured to use TLS connection.
<b>Signature:</b>
```typescript
isTlsEnabled: boolean;
```

View file

@ -81,13 +81,12 @@ async (context, request, response) => {
| Property | Type | Description |
| --- | --- | --- |
| [auth](./kibana-plugin-core-server.httpservicesetup.auth.md) | <code>{</code><br/><code> get: GetAuthState;</code><br/><code> isAuthenticated: IsAuthenticated;</code><br/><code> }</code> | |
| [auth](./kibana-plugin-core-server.httpservicesetup.auth.md) | <code>HttpAuth</code> | Auth status. See [HttpAuth](./kibana-plugin-core-server.httpauth.md) |
| [basePath](./kibana-plugin-core-server.httpservicesetup.basepath.md) | <code>IBasePath</code> | Access or manipulate the Kibana base path See [IBasePath](./kibana-plugin-core-server.ibasepath.md)<!-- -->. |
| [createCookieSessionStorageFactory](./kibana-plugin-core-server.httpservicesetup.createcookiesessionstoragefactory.md) | <code>&lt;T&gt;(cookieOptions: SessionStorageCookieOptions&lt;T&gt;) =&gt; Promise&lt;SessionStorageFactory&lt;T&gt;&gt;</code> | Creates cookie based session storage factory [SessionStorageFactory](./kibana-plugin-core-server.sessionstoragefactory.md) |
| [createRouter](./kibana-plugin-core-server.httpservicesetup.createrouter.md) | <code>() =&gt; IRouter</code> | Provides ability to declare a handler function for a particular path and HTTP request method. |
| [csp](./kibana-plugin-core-server.httpservicesetup.csp.md) | <code>ICspConfig</code> | The CSP config used for Kibana. |
| [getServerInfo](./kibana-plugin-core-server.httpservicesetup.getserverinfo.md) | <code>() =&gt; HttpServerInfo</code> | Provides common [information](./kibana-plugin-core-server.httpserverinfo.md) about the running http server. |
| [isTlsEnabled](./kibana-plugin-core-server.httpservicesetup.istlsenabled.md) | <code>boolean</code> | Flag showing whether a server was configured to use TLS connection. |
| [registerAuth](./kibana-plugin-core-server.httpservicesetup.registerauth.md) | <code>(handler: AuthenticationHandler) =&gt; void</code> | To define custom authentication and/or authorization mechanism for incoming requests. |
| [registerOnPostAuth](./kibana-plugin-core-server.httpservicesetup.registeronpostauth.md) | <code>(handler: OnPostAuthHandler) =&gt; void</code> | To define custom logic to perform for incoming requests. |
| [registerOnPreAuth](./kibana-plugin-core-server.httpservicesetup.registeronpreauth.md) | <code>(handler: OnPreAuthHandler) =&gt; void</code> | To define custom logic to perform for incoming requests. |

View file

@ -1,13 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) &gt; [isListening](./kibana-plugin-core-server.httpservicestart.islistening.md)
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) &gt; [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)
<b>Signature:</b>
```typescript
isListening: (port: number) => boolean;
auth: HttpAuth;
```

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) &gt; [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)<!-- -->.
<b>Signature:</b>
```typescript
basePath: IBasePath;
```

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) &gt; [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.
<b>Signature:</b>
```typescript
getServerInfo: () => HttpServerInfo;
```

View file

@ -15,5 +15,7 @@ export interface HttpServiceStart
| Property | Type | Description |
| --- | --- | --- |
| [isListening](./kibana-plugin-core-server.httpservicestart.islistening.md) | <code>(port: number) =&gt; boolean</code> | Indicates if http server is listening on a given port |
| [auth](./kibana-plugin-core-server.httpservicestart.auth.md) | <code>HttpAuth</code> | Auth status. See [HttpAuth](./kibana-plugin-core-server.httpauth.md) |
| [basePath](./kibana-plugin-core-server.httpservicestart.basepath.md) | <code>IBasePath</code> | Access or manipulate the Kibana base path See [IBasePath](./kibana-plugin-core-server.ibasepath.md)<!-- -->. |
| [getServerInfo](./kibana-plugin-core-server.httpservicestart.getserverinfo.md) | <code>() =&gt; HttpServerInfo</code> | Provides common [information](./kibana-plugin-core-server.httpserverinfo.md) about the running http server. |

View file

@ -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 &amp; 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. |

View file

@ -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());

View file

@ -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({

View file

@ -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);

View file

@ -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.

View file

@ -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<InternalHttpServiceSetup['basePath']>;
type AuthMocked = jest.Mocked<InternalHttpServiceSetup['auth']>;
export type HttpServiceSetupMock = jest.Mocked<InternalHttpServiceSetup> & {
export type HttpServiceSetupMock = jest.Mocked<
Omit<HttpServiceSetup, 'basePath' | 'createRouter'>
> & {
basePath: BasePathMocked;
createRouter: jest.MockedFunction<() => RouterMock>;
};
export type InternalHttpServiceSetupMock = jest.Mocked<
Omit<InternalHttpServiceSetup, 'basePath' | 'createRouter'>
> & {
basePath: BasePathMocked;
createRouter: jest.MockedFunction<(path: string) => RouterMock>;
};
export type HttpServiceStartMock = jest.Mocked<HttpServiceStart> & {
basePath: BasePathMocked;
};
export type InternalHttpServiceStartMock = jest.Mocked<InternalHttpServiceStart> & {
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<HttpService>;
const createHttpServiceMock = () => {
const mocked: jest.Mocked<HttpServiceContract> = {
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,

View file

@ -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<InternalHttpServiceSetup, HttpServiceStart> {
export class HttpService
implements CoreService<InternalHttpServiceSetup, InternalHttpServiceStart> {
private readonly httpServer: HttpServer;
private readonly httpsRedirectServer: HttpsRedirectServer;
private readonly config$: Observable<HttpConfig>;
@ -59,6 +61,7 @@ export class HttpService implements CoreService<InternalHttpServiceSetup, HttpSe
private readonly log: Logger;
private readonly env: Env;
private notReadyServer?: Server;
private internalSetup?: InternalHttpServiceSetup;
private requestHandlerContext?: RequestHandlerContextContainer;
constructor(private readonly coreContext: CoreContext) {
@ -97,7 +100,7 @@ export class HttpService implements CoreService<InternalHttpServiceSetup, HttpSe
registerCoreHandlers(serverContract, config, this.env);
const contract: InternalHttpServiceSetup = {
this.internalSetup = {
...serverContract,
createRouter: (path: string, pluginId: PluginOpaqueId = this.coreContext.coreId) => {
@ -114,7 +117,16 @@ export class HttpService implements CoreService<InternalHttpServiceSetup, HttpSe
) => 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<InternalHttpServiceSetup, HttpSe
await this.httpServer.start();
}
return {
isListening: () => this.httpServer.isListening(),
};
return this.getStartContract();
}
/**

View file

@ -19,7 +19,7 @@
import { IRouter } from './router';
export type RouterMock = DeeplyMockedKeys<IRouter>;
export type RouterMock = jest.Mocked<IRouter>;
function create({ routerPath = '' }: { routerPath?: string } = {}): RouterMock {
return {

View file

@ -47,6 +47,22 @@ export type RequestHandlerContextProvider<
TContextName extends keyof RequestHandlerContext
> = IContextProvider<RequestHandler<any, any, any>, 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,29 +201,19 @@ 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;
};
/**
* Auth status.
* See {@link HttpAuth}
*
* @deprecated use {@link HttpServiceStart.auth | the start contract} instead.
*/
auth: HttpAuth;
/**
* The CSP config used for Kibana.
*/
csp: ICspConfig;
/**
* Flag showing whether a server was configured to use TLS connection.
*/
isTlsEnabled: boolean;
/**
* 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 */

View file

@ -37,7 +37,7 @@ describe('HttpResources service', () => {
describe('#createRegistrar', () => {
beforeEach(() => {
setupDeps = {
http: httpServiceMock.createSetupContract(),
http: httpServiceMock.createInternalSetupContract(),
rendering: renderingMock.createSetupContract(),
};
service = new HttpResourcesService(coreContext);

View file

@ -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} */

View file

@ -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;
}

View file

@ -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);
});

View file

@ -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() },
},

View file

@ -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: {

View file

@ -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(() => {

View file

@ -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');

View file

@ -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<CoreSetup['http']> = {
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<CoreStart> = {
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(),
};

View file

@ -164,7 +164,6 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
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<TPlugin, TPluginDependencies>(
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,

View file

@ -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();

View file

@ -61,7 +61,7 @@ describe('SavedObjectsService', () => {
const createSetupDeps = () => {
const elasticsearchMock = elasticsearchServiceMock.createInternalSetup();
return {
http: httpServiceMock.createSetupContract(),
http: httpServiceMock.createInternalSetupContract(),
elasticsearch: elasticsearchMock,
legacyPlugins: legacyServiceMock.createDiscoverPlugins(),
};

View file

@ -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: <P, Q, B>(route: RouteConfig<P, Q, B, 'get'>, handler: HttpResourcesRequestHandler<P, Q, B>) => void;
@ -948,17 +956,13 @@ export interface HttpServerInfo {
// @public
export interface HttpServiceSetup {
// (undocumented)
auth: {
get: GetAuthState;
isAuthenticated: IsAuthenticated;
};
// @deprecated
auth: HttpAuth;
basePath: IBasePath;
createCookieSessionStorageFactory: <T>(cookieOptions: SessionStorageCookieOptions<T>) => Promise<SessionStorageFactory<T>>;
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

View file

@ -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,
});

View file

@ -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();

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeCreateCustomElementRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeDeleteCustomElementRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeFindCustomElementsRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeGetCustomElementRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeUpdateCustomElementRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeESFieldsRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeDownloadShareableWorkpadRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeZipShareableWorkpadRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeCreateWorkpadRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeDeleteWorkpadRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeFindWorkpadsRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
initializeGetWorkpadRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
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<IRouter>;
const router = httpService.createRouter();
initializeUpdateWorkpadAssetsRoute({
router,
logger: loggingServiceMock.create().get(),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
const log = loggingServiceMock.create().get('case');

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerCreateRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerDeleteRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerFetchRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerGetRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerPauseRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerResumeRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerUpdateRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerCreateRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerFetchRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerGetRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerPauseRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerResumeRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
const router = httpService.createRouter();
registerUnfollowRoute({
router,

View file

@ -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<any, any, any>;
beforeEach(() => {
const router = httpService.createRouter('') as jest.Mocked<IRouter>;
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<IRouter>;
const router = httpService.createRouter();
registerPrivilegesRoute({
router,

View file

@ -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);

View file

@ -118,7 +118,7 @@ export class Plugin {
this.initializerContext.config.create<TypeOf<typeof ConfigSchema>>().pipe(
map((rawConfig) =>
createConfig(rawConfig, this.initializerContext.logger.get('config'), {
isTLSEnabled: core.http.isTlsEnabled,
isTLSEnabled: core.http.getServerInfo().protocol === 'https',
})
)
),

View file

@ -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<IRouter>;
const router = httpService.createRouter();
const savedObjectsRepositoryMock = createMockSavedObjectsRepository(spacesSavedObjects);

View file

@ -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<IRouter>;
const router = httpService.createRouter();
const savedObjectsRepositoryMock = createMockSavedObjectsRepository(spacesSavedObjects);

View file

@ -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<IRouter>;
const router = httpService.createRouter();
const coreStart = coreMock.createStart();

View file

@ -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<IRouter>;
const router = httpService.createRouter();
const coreStart = coreMock.createStart();

View file

@ -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<IRouter>;
const router = httpService.createRouter();
const coreStart = coreMock.createStart();

View file

@ -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<IRouter>;
const router = httpService.createRouter();
const coreStart = coreMock.createStart();