mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
Move server-side http
implementation to packages (#136105)
* create context packages
* move context files into packages
* adapt imports
* create empty router packages
* fix more context imports
* move router code to packages
* fix import
* woups
* start adapting router imports
* fix more imports
* fix more core imports
* start adapting external usages
* export kibanaResponseFactory from server index...
* Revert "start adapting external usages"
This reverts commit 47ee463fbb
.
* adapt external usages
* fix console test
* create empty packages
* start moving all the things
* fix tests
* start adapting imports
* that's a lot of usages
* that's a lot of usages bis
* fix bad paths
* use export type
* lint
* fix external unit tests
* self review
* switch to `import type`
* stop re-exporting the router mock from the other mock package
* update codeowners for CSP folder
This commit is contained in:
parent
43b16a9ef7
commit
84db06c15d
186 changed files with 1447 additions and 337 deletions
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
|
@ -331,7 +331,7 @@
|
||||||
# Kibana Platform Security
|
# Kibana Platform Security
|
||||||
/packages/kbn-crypto/ @elastic/kibana-security
|
/packages/kbn-crypto/ @elastic/kibana-security
|
||||||
/packages/kbn-handlebars/ @elastic/kibana-security
|
/packages/kbn-handlebars/ @elastic/kibana-security
|
||||||
/src/core/server/http/csp/ @elastic/kibana-security @elastic/kibana-core
|
/packages/core/http/core-http-server-internal/src/csp/ @elastic/kibana-security @elastic/kibana-core
|
||||||
/src/plugins/interactive_setup/ @elastic/kibana-security
|
/src/plugins/interactive_setup/ @elastic/kibana-security
|
||||||
/test/interactive_setup_api_integration/ @elastic/kibana-security
|
/test/interactive_setup_api_integration/ @elastic/kibana-security
|
||||||
/test/interactive_setup_functional/ @elastic/kibana-security
|
/test/interactive_setup_functional/ @elastic/kibana-security
|
||||||
|
|
12
package.json
12
package.json
|
@ -180,7 +180,13 @@
|
||||||
"@kbn/core-http-browser-internal": "link:bazel-bin/packages/core/http/core-http-browser-internal",
|
"@kbn/core-http-browser-internal": "link:bazel-bin/packages/core/http/core-http-browser-internal",
|
||||||
"@kbn/core-http-browser-mocks": "link:bazel-bin/packages/core/http/core-http-browser-mocks",
|
"@kbn/core-http-browser-mocks": "link:bazel-bin/packages/core/http/core-http-browser-mocks",
|
||||||
"@kbn/core-http-common": "link:bazel-bin/packages/core/http/core-http-common",
|
"@kbn/core-http-common": "link:bazel-bin/packages/core/http/core-http-common",
|
||||||
|
"@kbn/core-http-context-server-internal": "link:bazel-bin/packages/core/http/core-http-context-server-internal",
|
||||||
|
"@kbn/core-http-context-server-mocks": "link:bazel-bin/packages/core/http/core-http-context-server-mocks",
|
||||||
|
"@kbn/core-http-router-server-internal": "link:bazel-bin/packages/core/http/core-http-router-server-internal",
|
||||||
|
"@kbn/core-http-router-server-mocks": "link:bazel-bin/packages/core/http/core-http-router-server-mocks",
|
||||||
"@kbn/core-http-server": "link:bazel-bin/packages/core/http/core-http-server",
|
"@kbn/core-http-server": "link:bazel-bin/packages/core/http/core-http-server",
|
||||||
|
"@kbn/core-http-server-internal": "link:bazel-bin/packages/core/http/core-http-server-internal",
|
||||||
|
"@kbn/core-http-server-mocks": "link:bazel-bin/packages/core/http/core-http-server-mocks",
|
||||||
"@kbn/core-i18n-browser": "link:bazel-bin/packages/core/i18n/core-i18n-browser",
|
"@kbn/core-i18n-browser": "link:bazel-bin/packages/core/i18n/core-i18n-browser",
|
||||||
"@kbn/core-i18n-browser-internal": "link:bazel-bin/packages/core/i18n/core-i18n-browser-internal",
|
"@kbn/core-i18n-browser-internal": "link:bazel-bin/packages/core/i18n/core-i18n-browser-internal",
|
||||||
"@kbn/core-i18n-browser-mocks": "link:bazel-bin/packages/core/i18n/core-i18n-browser-mocks",
|
"@kbn/core-i18n-browser-mocks": "link:bazel-bin/packages/core/i18n/core-i18n-browser-mocks",
|
||||||
|
@ -746,7 +752,13 @@
|
||||||
"@types/kbn__core-http-browser-internal": "link:bazel-bin/packages/core/http/core-http-browser-internal/npm_module_types",
|
"@types/kbn__core-http-browser-internal": "link:bazel-bin/packages/core/http/core-http-browser-internal/npm_module_types",
|
||||||
"@types/kbn__core-http-browser-mocks": "link:bazel-bin/packages/core/http/core-http-browser-mocks/npm_module_types",
|
"@types/kbn__core-http-browser-mocks": "link:bazel-bin/packages/core/http/core-http-browser-mocks/npm_module_types",
|
||||||
"@types/kbn__core-http-common": "link:bazel-bin/packages/core/http/core-http-common/npm_module_types",
|
"@types/kbn__core-http-common": "link:bazel-bin/packages/core/http/core-http-common/npm_module_types",
|
||||||
|
"@types/kbn__core-http-context-server-internal": "link:bazel-bin/packages/core/http/core-http-context-server-internal/npm_module_types",
|
||||||
|
"@types/kbn__core-http-context-server-mocks": "link:bazel-bin/packages/core/http/core-http-context-server-mocks/npm_module_types",
|
||||||
|
"@types/kbn__core-http-router-server-internal": "link:bazel-bin/packages/core/http/core-http-router-server-internal/npm_module_types",
|
||||||
|
"@types/kbn__core-http-router-server-mocks": "link:bazel-bin/packages/core/http/core-http-router-server-mocks/npm_module_types",
|
||||||
"@types/kbn__core-http-server": "link:bazel-bin/packages/core/http/core-http-server/npm_module_types",
|
"@types/kbn__core-http-server": "link:bazel-bin/packages/core/http/core-http-server/npm_module_types",
|
||||||
|
"@types/kbn__core-http-server-internal": "link:bazel-bin/packages/core/http/core-http-server-internal/npm_module_types",
|
||||||
|
"@types/kbn__core-http-server-mocks": "link:bazel-bin/packages/core/http/core-http-server-mocks/npm_module_types",
|
||||||
"@types/kbn__core-i18n-browser": "link:bazel-bin/packages/core/i18n/core-i18n-browser/npm_module_types",
|
"@types/kbn__core-i18n-browser": "link:bazel-bin/packages/core/i18n/core-i18n-browser/npm_module_types",
|
||||||
"@types/kbn__core-i18n-browser-internal": "link:bazel-bin/packages/core/i18n/core-i18n-browser-internal/npm_module_types",
|
"@types/kbn__core-i18n-browser-internal": "link:bazel-bin/packages/core/i18n/core-i18n-browser-internal/npm_module_types",
|
||||||
"@types/kbn__core-i18n-browser-mocks": "link:bazel-bin/packages/core/i18n/core-i18n-browser-mocks/npm_module_types",
|
"@types/kbn__core-i18n-browser-mocks": "link:bazel-bin/packages/core/i18n/core-i18n-browser-mocks/npm_module_types",
|
||||||
|
|
|
@ -49,6 +49,12 @@ filegroup(
|
||||||
"//packages/core/http/core-http-browser-mocks:build",
|
"//packages/core/http/core-http-browser-mocks:build",
|
||||||
"//packages/core/http/core-http-browser:build",
|
"//packages/core/http/core-http-browser:build",
|
||||||
"//packages/core/http/core-http-common:build",
|
"//packages/core/http/core-http-common:build",
|
||||||
|
"//packages/core/http/core-http-context-server-internal:build",
|
||||||
|
"//packages/core/http/core-http-context-server-mocks:build",
|
||||||
|
"//packages/core/http/core-http-router-server-internal:build",
|
||||||
|
"//packages/core/http/core-http-router-server-mocks:build",
|
||||||
|
"//packages/core/http/core-http-server-internal:build",
|
||||||
|
"//packages/core/http/core-http-server-mocks:build",
|
||||||
"//packages/core/http/core-http-server:build",
|
"//packages/core/http/core-http-server:build",
|
||||||
"//packages/core/i18n/core-i18n-browser-internal:build",
|
"//packages/core/i18n/core-i18n-browser-internal:build",
|
||||||
"//packages/core/i18n/core-i18n-browser-mocks:build",
|
"//packages/core/i18n/core-i18n-browser-mocks:build",
|
||||||
|
@ -240,6 +246,12 @@ filegroup(
|
||||||
"//packages/core/http/core-http-browser-mocks:build_types",
|
"//packages/core/http/core-http-browser-mocks:build_types",
|
||||||
"//packages/core/http/core-http-browser:build_types",
|
"//packages/core/http/core-http-browser:build_types",
|
||||||
"//packages/core/http/core-http-common:build_types",
|
"//packages/core/http/core-http-common:build_types",
|
||||||
|
"//packages/core/http/core-http-context-server-internal:build_types",
|
||||||
|
"//packages/core/http/core-http-context-server-mocks:build_types",
|
||||||
|
"//packages/core/http/core-http-router-server-internal:build_types",
|
||||||
|
"//packages/core/http/core-http-router-server-mocks:build_types",
|
||||||
|
"//packages/core/http/core-http-server-internal:build_types",
|
||||||
|
"//packages/core/http/core-http-server-mocks:build_types",
|
||||||
"//packages/core/http/core-http-server:build_types",
|
"//packages/core/http/core-http-server:build_types",
|
||||||
"//packages/core/i18n/core-i18n-browser-internal:build_types",
|
"//packages/core/i18n/core-i18n-browser-internal:build_types",
|
||||||
"//packages/core/i18n/core-i18n-browser-mocks:build_types",
|
"//packages/core/i18n/core-i18n-browser-mocks:build_types",
|
||||||
|
|
104
packages/core/http/core-http-context-server-internal/BUILD.bazel
Normal file
104
packages/core/http/core-http-context-server-internal/BUILD.bazel
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-http-context-server-internal"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-http-context-server-internal"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
"@npm//lodash",
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"@npm//lodash",
|
||||||
|
"//packages/kbn-utility-types:npm_module_types",
|
||||||
|
"//packages/core/base/core-base-common:npm_module_types",
|
||||||
|
"//packages/core/base/core-base-common-internal:npm_module_types",
|
||||||
|
"//packages/core/base/core-base-server-internal:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-server:npm_module_types",
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
# @kbn/core-http-context-server-internal
|
||||||
|
|
||||||
|
This package contains the internal types and implementation for Core's internal `http` context service.
|
|
@ -6,9 +6,8 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { contextMock } from './context_container.mock';
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
export const MockContextConstructor = jest.fn(contextMock.create);
|
rootDir: '../../../..',
|
||||||
jest.doMock('./context_container', () => ({
|
roots: ['<rootDir>/packages/core/http/core-http-context-server-internal'],
|
||||||
ContextContainer: MockContextConstructor,
|
};
|
||||||
}));
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-http-context-server-internal",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
|
@ -7,9 +7,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { PluginOpaqueId } from '@kbn/core-base-common';
|
import type { PluginOpaqueId } from '@kbn/core-base-common';
|
||||||
import type { RequestHandlerContextBase } from '@kbn/core-http-server';
|
import type {
|
||||||
|
RequestHandlerContextBase,
|
||||||
|
KibanaRequest,
|
||||||
|
KibanaResponseFactory,
|
||||||
|
} from '@kbn/core-http-server';
|
||||||
import { ContextContainer } from './context_container';
|
import { ContextContainer } from './context_container';
|
||||||
import { httpServerMock } from '../http/http_server.mocks';
|
|
||||||
|
|
||||||
const pluginA = Symbol('pluginA');
|
const pluginA = Symbol('pluginA');
|
||||||
const pluginB = Symbol('pluginB');
|
const pluginB = Symbol('pluginB');
|
||||||
|
@ -35,6 +38,13 @@ interface MyContext extends RequestHandlerContextBase {
|
||||||
|
|
||||||
type TestContext<T> = T & RequestHandlerContextBase;
|
type TestContext<T> = T & RequestHandlerContextBase;
|
||||||
|
|
||||||
|
const createKibanaRequest = (): KibanaRequest => {
|
||||||
|
return {} as unknown as KibanaRequest;
|
||||||
|
};
|
||||||
|
const createKibanaResponseFactory = (): KibanaResponseFactory => {
|
||||||
|
return {} as unknown as KibanaResponseFactory;
|
||||||
|
};
|
||||||
|
|
||||||
describe('ContextContainer', () => {
|
describe('ContextContainer', () => {
|
||||||
describe('registerContext', () => {
|
describe('registerContext', () => {
|
||||||
it('throws an error if the same context is registered twice', () => {
|
it('throws an error if the same context is registered twice', () => {
|
||||||
|
@ -145,8 +155,8 @@ describe('ContextContainer', () => {
|
||||||
});
|
});
|
||||||
const handler1 = contextContainer.createHandler(pluginC, rawHandler1);
|
const handler1 = contextContainer.createHandler(pluginC, rawHandler1);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
await handler1(request, response);
|
await handler1(request, response);
|
||||||
|
|
||||||
expect(core1provider).not.toHaveBeenCalled();
|
expect(core1provider).not.toHaveBeenCalled();
|
||||||
|
@ -188,8 +198,8 @@ describe('ContextContainer', () => {
|
||||||
});
|
});
|
||||||
const handler1 = contextContainer.createHandler(pluginC, rawHandler1);
|
const handler1 = contextContainer.createHandler(pluginC, rawHandler1);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
await handler1(request, response);
|
await handler1(request, response);
|
||||||
|
|
||||||
expect(core1provider).not.toHaveBeenCalled();
|
expect(core1provider).not.toHaveBeenCalled();
|
||||||
|
@ -229,8 +239,8 @@ describe('ContextContainer', () => {
|
||||||
});
|
});
|
||||||
const handler1 = contextContainer.createHandler(pluginC, rawHandler1);
|
const handler1 = contextContainer.createHandler(pluginC, rawHandler1);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
await handler1(request, response);
|
await handler1(request, response);
|
||||||
|
|
||||||
expect(core1provider).not.toHaveBeenCalled();
|
expect(core1provider).not.toHaveBeenCalled();
|
||||||
|
@ -271,8 +281,8 @@ describe('ContextContainer', () => {
|
||||||
});
|
});
|
||||||
const handler1 = contextContainer.createHandler(pluginC, rawHandler1);
|
const handler1 = contextContainer.createHandler(pluginC, rawHandler1);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
await handler1(request, response);
|
await handler1(request, response);
|
||||||
|
|
||||||
expect(core1provider).not.toHaveBeenCalled();
|
expect(core1provider).not.toHaveBeenCalled();
|
||||||
|
@ -356,8 +366,8 @@ describe('ContextContainer', () => {
|
||||||
|
|
||||||
const handler2 = contextContainer.createHandler(pluginD, rawHandler2);
|
const handler2 = contextContainer.createHandler(pluginD, rawHandler2);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
|
|
||||||
await handler1(request, response);
|
await handler1(request, response);
|
||||||
await handler2(request, response);
|
await handler2(request, response);
|
||||||
|
@ -400,8 +410,8 @@ describe('ContextContainer', () => {
|
||||||
});
|
});
|
||||||
const handler1 = contextContainer.createHandler(pluginB, rawHandler1);
|
const handler1 = contextContainer.createHandler(pluginB, rawHandler1);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
expect(await handler1(request, response)).toEqual('handler1');
|
expect(await handler1(request, response)).toEqual('handler1');
|
||||||
|
|
||||||
expect(rawHandler1).toHaveBeenCalledWith(expect.any(Object), request, response);
|
expect(rawHandler1).toHaveBeenCalledWith(expect.any(Object), request, response);
|
||||||
|
@ -430,8 +440,8 @@ describe('ContextContainer', () => {
|
||||||
});
|
});
|
||||||
const handler1 = contextContainer.createHandler(pluginA, rawHandler1);
|
const handler1 = contextContainer.createHandler(pluginA, rawHandler1);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
expect(await handler1(request, response)).toEqual('handler1');
|
expect(await handler1(request, response)).toEqual('handler1');
|
||||||
|
|
||||||
// If no context is registered for pluginA, only core contexts should be exposed
|
// If no context is registered for pluginA, only core contexts should be exposed
|
||||||
|
@ -454,8 +464,8 @@ describe('ContextContainer', () => {
|
||||||
});
|
});
|
||||||
const handler1 = contextContainer.createHandler(coreId, rawHandler1);
|
const handler1 = contextContainer.createHandler(coreId, rawHandler1);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
expect(await handler1(request, response)).toEqual('handler1');
|
expect(await handler1(request, response)).toEqual('handler1');
|
||||||
|
|
||||||
expect(rawHandler1).toHaveBeenCalledWith(expect.any(Object), request, response);
|
expect(rawHandler1).toHaveBeenCalledWith(expect.any(Object), request, response);
|
||||||
|
@ -465,8 +475,8 @@ describe('ContextContainer', () => {
|
||||||
expect.assertions(7);
|
expect.assertions(7);
|
||||||
const contextContainer = new ContextContainer(plugins, coreId);
|
const contextContainer = new ContextContainer(plugins, coreId);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
contextContainer.registerContext<MyContext, 'core1'>(coreId, 'core1', (context, req, res) => {
|
contextContainer.registerContext<MyContext, 'core1'>(coreId, 'core1', (context, req, res) => {
|
||||||
expect(req).toBe(request);
|
expect(req).toBe(request);
|
||||||
expect(res).toBe(response);
|
expect(res).toBe(response);
|
||||||
|
@ -567,8 +577,8 @@ describe('ContextContainer', () => {
|
||||||
|
|
||||||
const handler2 = contextContainer.createHandler(pluginD, rawHandler2);
|
const handler2 = contextContainer.createHandler(pluginD, rawHandler2);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
|
|
||||||
await handler1(request, response);
|
await handler1(request, response);
|
||||||
await handler2(request, response);
|
await handler2(request, response);
|
||||||
|
@ -597,8 +607,8 @@ describe('ContextContainer', () => {
|
||||||
const rawHandler1 = jest.fn(() => 'handler1' as any);
|
const rawHandler1 = jest.fn(() => 'handler1' as any);
|
||||||
const handler1 = contextContainer.createHandler(pluginA, rawHandler1);
|
const handler1 = contextContainer.createHandler(pluginA, rawHandler1);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
expect(await handler1(request, response)).toEqual('handler1');
|
expect(await handler1(request, response)).toEqual('handler1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -608,8 +618,8 @@ describe('ContextContainer', () => {
|
||||||
const rawHandler1 = jest.fn(() => 'handler1' as any);
|
const rawHandler1 = jest.fn(() => 'handler1' as any);
|
||||||
const handler1 = contextContainer.createHandler(pluginA, rawHandler1);
|
const handler1 = contextContainer.createHandler(pluginA, rawHandler1);
|
||||||
|
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = createKibanaRequest();
|
||||||
const response = httpServerMock.createResponseFactory();
|
const response = createKibanaResponseFactory();
|
||||||
await handler1(request, response);
|
await handler1(request, response);
|
||||||
expect(rawHandler1).toHaveBeenCalledWith(
|
expect(rawHandler1).toHaveBeenCalledWith(
|
||||||
{ resolve: expect.any(Function) },
|
{ resolve: expect.any(Function) },
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { IContextContainer } from '@kbn/core-http-server';
|
||||||
|
|
||||||
|
const createContextMock = (mockContext: any = {}) => {
|
||||||
|
const contextMock: jest.Mocked<IContextContainer> = {
|
||||||
|
registerContext: jest.fn(),
|
||||||
|
createHandler: jest.fn(),
|
||||||
|
};
|
||||||
|
contextMock.createHandler.mockImplementation(
|
||||||
|
(pluginId, handler) =>
|
||||||
|
(...args) =>
|
||||||
|
Promise.resolve(handler(mockContext, ...args))
|
||||||
|
);
|
||||||
|
return contextMock;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const MockContextConstructor = jest.fn(createContextMock);
|
||||||
|
jest.doMock('./context_container', () => ({
|
||||||
|
ContextContainer: MockContextConstructor,
|
||||||
|
}));
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.bazel.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"emitDeclarationOnly": true,
|
||||||
|
"outDir": "target_types",
|
||||||
|
"rootDir": "src",
|
||||||
|
"stripInternal": false,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
100
packages/core/http/core-http-context-server-mocks/BUILD.bazel
Normal file
100
packages/core/http/core-http-context-server-mocks/BUILD.bazel
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-http-context-server-mocks"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-http-context-server-mocks"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"//packages/kbn-utility-types:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-server:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-context-server-internal:npm_module_types",
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
# @kbn/core-http-context-server-mocks
|
||||||
|
|
||||||
|
This package contains the mocks for Core's internal `http` context service.
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
|
rootDir: '../../../..',
|
||||||
|
roots: ['<rootDir>/packages/core/http/core-http-context-server-mocks'],
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-http-context-server-mocks",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
|
@ -7,8 +7,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||||
|
import type {
|
||||||
import { ContextService, InternalContextSetup, InternalContextPreboot } from './context_service';
|
ContextService,
|
||||||
|
InternalContextSetup,
|
||||||
|
InternalContextPreboot,
|
||||||
|
} from '@kbn/core-http-context-server-internal';
|
||||||
import { contextMock } from './context_container.mock';
|
import { contextMock } from './context_container.mock';
|
||||||
|
|
||||||
const createPrebootContractMock = (mockContext = {}) => {
|
const createPrebootContractMock = (mockContext = {}) => {
|
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type { ContextContainerMock } from './context_container.mock';
|
||||||
|
export { contextMock } from './context_container.mock';
|
||||||
|
export { contextServiceMock } from './context_service.mock';
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.bazel.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"emitDeclarationOnly": true,
|
||||||
|
"outDir": "target_types",
|
||||||
|
"rootDir": "src",
|
||||||
|
"stripInternal": false,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
114
packages/core/http/core-http-router-server-internal/BUILD.bazel
Normal file
114
packages/core/http/core-http-router-server-internal/BUILD.bazel
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-http-router-server-internal"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-http-router-server-internal"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
"@npm//@hapi/boom",
|
||||||
|
"@npm//uuid",
|
||||||
|
"@npm//rxjs",
|
||||||
|
"@npm//type-detect",
|
||||||
|
"//packages/kbn-config-schema",
|
||||||
|
"//packages/kbn-es-errors",
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"@npm//@types/uuid",
|
||||||
|
"@npm//type-detect",
|
||||||
|
"@npm//@hapi/hapi",
|
||||||
|
"@npm//@types/hapi__hapi",
|
||||||
|
"@npm//@hapi/boom",
|
||||||
|
"@npm//rxjs",
|
||||||
|
"//packages/kbn-std:npm_module_types",
|
||||||
|
"//packages/kbn-utility-types:npm_module_types",
|
||||||
|
"//packages/kbn-config-schema:npm_module_types",
|
||||||
|
"//packages/kbn-es-errors:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-server:npm_module_types",
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,4 @@
|
||||||
|
# @kbn/core-http-router-server-internal
|
||||||
|
|
||||||
|
This package contains the internal types and implementation for Core's internal `http` router sub-domain.
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
|
rootDir: '../../../..',
|
||||||
|
roots: ['<rootDir>/packages/core/http/core-http-router-server-internal'],
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-http-router-server-internal",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import uuid from 'uuid';
|
import uuid from 'uuid';
|
||||||
import { Request, RouteOptions } from '@hapi/hapi';
|
import type { Request, RouteOptions } from '@hapi/hapi';
|
||||||
import { fromEvent, NEVER } from 'rxjs';
|
import { fromEvent, NEVER } from 'rxjs';
|
||||||
import { shareReplay, first, filter } from 'rxjs/operators';
|
import { shareReplay, first, filter } from 'rxjs/operators';
|
||||||
import { RecursiveReadonly } from '@kbn/utility-types';
|
import { RecursiveReadonly } from '@kbn/utility-types';
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.bazel.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"emitDeclarationOnly": true,
|
||||||
|
"outDir": "target_types",
|
||||||
|
"rootDir": "src",
|
||||||
|
"stripInternal": false,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
106
packages/core/http/core-http-router-server-mocks/BUILD.bazel
Normal file
106
packages/core/http/core-http-router-server-mocks/BUILD.bazel
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-http-router-server-mocks"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-http-router-server-mocks"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
"@npm//query-string",
|
||||||
|
"//packages/kbn-hapi-mocks",
|
||||||
|
"//packages/kbn-config-schema",
|
||||||
|
"//packages/core/http/core-http-router-server-internal",
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"@npm//query-string",
|
||||||
|
"//packages/kbn-hapi-mocks:npm_module_types",
|
||||||
|
"//packages/kbn-config-schema:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-server:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-router-server-internal:npm_module_types",
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
# @kbn/core-http-router-server-mocks
|
||||||
|
|
||||||
|
This package contains the mocks for Core's internal `http` router sub-domain.
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
|
rootDir: '../../../..',
|
||||||
|
roots: ['<rootDir>/packages/core/http/core-http-router-server-mocks'],
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-http-router-server-mocks",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export { mockRouter } from './router.mock';
|
||||||
|
export type { RouterMock, RequestFixtureOptions } from './router.mock';
|
|
@ -20,7 +20,7 @@ import type {
|
||||||
KibanaRequestState,
|
KibanaRequestState,
|
||||||
KibanaResponseFactory,
|
KibanaResponseFactory,
|
||||||
} from '@kbn/core-http-server';
|
} from '@kbn/core-http-server';
|
||||||
import { CoreKibanaRequest } from './request';
|
import { CoreKibanaRequest } from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
export type RouterMock = jest.Mocked<IRouter<any>>;
|
export type RouterMock = jest.Mocked<IRouter<any>>;
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.bazel.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"emitDeclarationOnly": true,
|
||||||
|
"outDir": "target_types",
|
||||||
|
"rootDir": "src",
|
||||||
|
"stripInternal": false,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
146
packages/core/http/core-http-server-internal/BUILD.bazel
Normal file
146
packages/core/http/core-http-server-internal/BUILD.bazel
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-http-server-internal"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-http-server-internal"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
"@npm//lodash",
|
||||||
|
"@npm//rxjs",
|
||||||
|
"@npm//uuid",
|
||||||
|
"@npm//moment",
|
||||||
|
"@npm//@elastic/numeral",
|
||||||
|
"@npm//@hapi/boom",
|
||||||
|
"@npm//@hapi/cookie",
|
||||||
|
"@npm//@hapi/inert",
|
||||||
|
"@npm//elastic-apm-node",
|
||||||
|
"//packages/kbn-utils",
|
||||||
|
"//packages/kbn-std",
|
||||||
|
"//packages/kbn-config-schema",
|
||||||
|
"//packages/kbn-logging",
|
||||||
|
"//packages/kbn-crypto",
|
||||||
|
"//packages/kbn-server-http-tools",
|
||||||
|
"//packages/core/http/core-http-router-server-internal",
|
||||||
|
### test dependencies
|
||||||
|
"@npm//supertest",
|
||||||
|
"@npm//chance",
|
||||||
|
"//packages/kbn-hapi-mocks",
|
||||||
|
"//packages/core/http/core-http-router-server-mocks",
|
||||||
|
"//packages/core/logging/core-logging-server-mocks",
|
||||||
|
"//packages/core/http/core-http-context-server-mocks",
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"@npm//@types/uuid",
|
||||||
|
"@npm//rxjs",
|
||||||
|
"@npm//moment",
|
||||||
|
"@npm//@elastic/numeral",
|
||||||
|
"@npm//lodash",
|
||||||
|
"@npm//@hapi/hapi",
|
||||||
|
"@npm//@hapi/boom",
|
||||||
|
"@npm//@hapi/cookie",
|
||||||
|
"@npm//@hapi/inert",
|
||||||
|
"@npm//@types/hapi__hapi",
|
||||||
|
"@npm//@types/hapi__cookie",
|
||||||
|
"@npm//@types/hapi__inert",
|
||||||
|
"@npm//elastic-apm-node",
|
||||||
|
"//packages/kbn-utils:npm_module_types",
|
||||||
|
"//packages/kbn-std:npm_module_types",
|
||||||
|
"//packages/kbn-server-http-tools:npm_module_types",
|
||||||
|
"//packages/kbn-logging:npm_module_types",
|
||||||
|
"//packages/kbn-config-schema:npm_module_types",
|
||||||
|
"//packages/kbn-crypto:npm_module_types",
|
||||||
|
"//packages/core/base/core-base-common:npm_module_types",
|
||||||
|
"//packages/core/base/core-base-server-internal:npm_module_types",
|
||||||
|
"//packages/core/execution-context/core-execution-context-server-internal:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-common:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-server:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-context-server-internal:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-router-server-internal:npm_module_types",
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
3
packages/core/http/core-http-server-internal/README.md
Normal file
3
packages/core/http/core-http-server-internal/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# @kbn/core-http-server-internal
|
||||||
|
|
||||||
|
This package contains the internal types and implementation for core's server-side `http` service
|
13
packages/core/http/core-http-server-internal/jest.config.js
Normal file
13
packages/core/http/core-http-server-internal/jest.config.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
|
rootDir: '../../../..',
|
||||||
|
roots: ['<rootDir>/packages/core/http/core-http-server-internal'],
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-http-server-internal",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"hello": "dolly"
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"foo": "bar"
|
||||||
|
}
|
|
@ -7,14 +7,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AuthHeadersStorage } from './auth_headers_storage';
|
import { AuthHeadersStorage } from './auth_headers_storage';
|
||||||
import { httpServerMock } from './http_server.mocks';
|
import { mockRouter } from '@kbn/core-http-router-server-mocks';
|
||||||
|
|
||||||
describe('AuthHeadersStorage', () => {
|
describe('AuthHeadersStorage', () => {
|
||||||
describe('stores authorization headers', () => {
|
describe('stores authorization headers', () => {
|
||||||
it('retrieves a copy of headers associated with Kibana request', () => {
|
it('retrieves a copy of headers associated with Kibana request', () => {
|
||||||
const headers = { authorization: 'token' };
|
const headers = { authorization: 'token' };
|
||||||
const storage = new AuthHeadersStorage();
|
const storage = new AuthHeadersStorage();
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = mockRouter.createKibanaRequest();
|
||||||
storage.set(request, headers);
|
storage.set(request, headers);
|
||||||
expect(storage.get(request)).toEqual(headers);
|
expect(storage.get(request)).toEqual(headers);
|
||||||
});
|
});
|
|
@ -13,7 +13,7 @@ import type {
|
||||||
IAuthHeadersStorage,
|
IAuthHeadersStorage,
|
||||||
GetAuthHeaders,
|
GetAuthHeaders,
|
||||||
} from '@kbn/core-http-server';
|
} from '@kbn/core-http-server';
|
||||||
import { ensureRawRequest } from './router';
|
import { ensureRawRequest } from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export class AuthHeadersStorage implements IAuthHeadersStorage {
|
export class AuthHeadersStorage implements IAuthHeadersStorage {
|
|
@ -5,10 +5,11 @@
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request } from '@hapi/hapi';
|
import { Request } from '@hapi/hapi';
|
||||||
import type { KibanaRequest, IsAuthenticated } from '@kbn/core-http-server';
|
import type { KibanaRequest, IsAuthenticated } from '@kbn/core-http-server';
|
||||||
import { AuthStatus } from '@kbn/core-http-server';
|
import { AuthStatus } from '@kbn/core-http-server';
|
||||||
import { ensureRawRequest } from './router';
|
import { ensureRawRequest } from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export class AuthStateStorage {
|
export class AuthStateStorage {
|
|
@ -6,8 +6,8 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { mockRouter } from '@kbn/core-http-router-server-mocks';
|
||||||
import { BasePath } from './base_path_service';
|
import { BasePath } from './base_path_service';
|
||||||
import { httpServerMock } from './http_server.mocks';
|
|
||||||
|
|
||||||
describe('BasePath', () => {
|
describe('BasePath', () => {
|
||||||
describe('serverBasePath', () => {
|
describe('serverBasePath', () => {
|
||||||
|
@ -36,7 +36,7 @@ describe('BasePath', () => {
|
||||||
|
|
||||||
describe('#get()', () => {
|
describe('#get()', () => {
|
||||||
it('returns base path associated with an incoming KibanaRequest', () => {
|
it('returns base path associated with an incoming KibanaRequest', () => {
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = mockRouter.createKibanaRequest();
|
||||||
const basePath = new BasePath();
|
const basePath = new BasePath();
|
||||||
|
|
||||||
basePath.set(request, '/baz/');
|
basePath.set(request, '/baz/');
|
||||||
|
@ -44,7 +44,7 @@ describe('BasePath', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is based on server base path', () => {
|
it('is based on server base path', () => {
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = mockRouter.createKibanaRequest();
|
||||||
const basePath = new BasePath('/foo/bar');
|
const basePath = new BasePath('/foo/bar');
|
||||||
|
|
||||||
basePath.set(request, '/baz/');
|
basePath.set(request, '/baz/');
|
||||||
|
@ -54,7 +54,7 @@ describe('BasePath', () => {
|
||||||
|
|
||||||
describe('#set()', () => {
|
describe('#set()', () => {
|
||||||
it('#set() cannot be set twice for one request', () => {
|
it('#set() cannot be set twice for one request', () => {
|
||||||
const request = httpServerMock.createKibanaRequest();
|
const request = mockRouter.createKibanaRequest();
|
||||||
const basePath = new BasePath('/foo/bar');
|
const basePath = new BasePath('/foo/bar');
|
||||||
|
|
||||||
const setPath = () => basePath.set(request, 'baz/');
|
const setPath = () => basePath.set(request, 'baz/');
|
|
@ -9,7 +9,7 @@
|
||||||
import { modifyUrl } from '@kbn/std';
|
import { modifyUrl } from '@kbn/std';
|
||||||
import { Request } from '@hapi/hapi';
|
import { Request } from '@hapi/hapi';
|
||||||
import type { KibanaRequest, IBasePath } from '@kbn/core-http-server';
|
import type { KibanaRequest, IBasePath } from '@kbn/core-http-server';
|
||||||
import { ensureRawRequest } from './router';
|
import { ensureRawRequest } from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core internal implementation of {@link IBasePath}
|
* Core internal implementation of {@link IBasePath}
|
|
@ -16,7 +16,7 @@ import type {
|
||||||
SessionStorage,
|
SessionStorage,
|
||||||
SessionStorageCookieOptions,
|
SessionStorageCookieOptions,
|
||||||
} from '@kbn/core-http-server';
|
} from '@kbn/core-http-server';
|
||||||
import { ensureRawRequest } from './router';
|
import { ensureRawRequest } from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
class ScopedCookieSessionStorage<T extends Record<string, any>> implements SessionStorage<T> {
|
class ScopedCookieSessionStorage<T extends Record<string, any>> implements SessionStorage<T> {
|
||||||
constructor(
|
constructor(
|
|
@ -22,8 +22,8 @@ import type {
|
||||||
RouteValidationFunction,
|
RouteValidationFunction,
|
||||||
RequestHandlerContextBase,
|
RequestHandlerContextBase,
|
||||||
} from '@kbn/core-http-server';
|
} from '@kbn/core-http-server';
|
||||||
|
import { Router } from '@kbn/core-http-router-server-internal';
|
||||||
import { HttpConfig } from './http_config';
|
import { HttpConfig } from './http_config';
|
||||||
import { Router } from './router';
|
|
||||||
import { HttpServer } from './http_server';
|
import { HttpServer } from './http_server';
|
||||||
import { Readable } from 'stream';
|
import { Readable } from 'stream';
|
||||||
import { KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils';
|
import { KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils';
|
||||||
|
@ -1410,7 +1410,7 @@ describe('setup contract', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#registerStaticDir', () => {
|
describe('#registerStaticDir', () => {
|
||||||
const assetFolder = join(__dirname, 'integration_tests', 'fixtures', 'static');
|
const assetFolder = join(__dirname, '__fixtures', 'static');
|
||||||
let tempDir: string;
|
let tempDir: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
|
@ -16,7 +16,6 @@ import {
|
||||||
getServerOptions,
|
getServerOptions,
|
||||||
getRequestId,
|
getRequestId,
|
||||||
} from '@kbn/server-http-tools';
|
} from '@kbn/server-http-tools';
|
||||||
import agent from 'elastic-apm-node';
|
|
||||||
|
|
||||||
import type { Duration } from 'moment';
|
import type { Duration } from 'moment';
|
||||||
import { firstValueFrom, Observable } from 'rxjs';
|
import { firstValueFrom, Observable } from 'rxjs';
|
||||||
|
@ -24,6 +23,7 @@ import { take } from 'rxjs/operators';
|
||||||
import apm from 'elastic-apm-node';
|
import apm from 'elastic-apm-node';
|
||||||
import type { Logger, LoggerFactory } from '@kbn/logging';
|
import type { Logger, LoggerFactory } from '@kbn/logging';
|
||||||
import type { InternalExecutionContextSetup } from '@kbn/core-execution-context-server-internal';
|
import type { InternalExecutionContextSetup } from '@kbn/core-execution-context-server-internal';
|
||||||
|
import { isSafeMethod } from '@kbn/core-http-router-server-internal';
|
||||||
import type {
|
import type {
|
||||||
IRouter,
|
IRouter,
|
||||||
RouteConfigOptions,
|
RouteConfigOptions,
|
||||||
|
@ -47,7 +47,6 @@ import { adoptToHapiOnPreAuth } from './lifecycle/on_pre_auth';
|
||||||
import { adoptToHapiOnPostAuthFormat } from './lifecycle/on_post_auth';
|
import { adoptToHapiOnPostAuthFormat } from './lifecycle/on_post_auth';
|
||||||
import { adoptToHapiOnRequest } from './lifecycle/on_pre_routing';
|
import { adoptToHapiOnRequest } from './lifecycle/on_pre_routing';
|
||||||
import { adoptToHapiOnPreResponseFormat } from './lifecycle/on_pre_response';
|
import { adoptToHapiOnPreResponseFormat } from './lifecycle/on_pre_response';
|
||||||
import { isSafeMethod } from './router';
|
|
||||||
import { createCookieSessionStorageFactory } from './cookie_session_storage';
|
import { createCookieSessionStorageFactory } from './cookie_session_storage';
|
||||||
import { AuthStateStorage } from './auth_state_storage';
|
import { AuthStateStorage } from './auth_state_storage';
|
||||||
import { AuthHeadersStorage } from './auth_headers_storage';
|
import { AuthHeadersStorage } from './auth_headers_storage';
|
||||||
|
@ -359,7 +358,7 @@ export class HttpServer {
|
||||||
requestUuid: uuid.v4(),
|
requestUuid: uuid.v4(),
|
||||||
// Kibana stores trace.id until https://github.com/elastic/apm-agent-nodejs/issues/2353 is resolved
|
// Kibana stores trace.id until https://github.com/elastic/apm-agent-nodejs/issues/2353 is resolved
|
||||||
// The current implementation of the APM agent ends a request transaction before "response" log is emitted.
|
// The current implementation of the APM agent ends a request transaction before "response" log is emitted.
|
||||||
traceId: agent.currentTraceIds['trace.id'],
|
traceId: apm.currentTraceIds['trace.id'],
|
||||||
} as KibanaRequestState;
|
} as KibanaRequestState;
|
||||||
return responseToolkit.continue;
|
return responseToolkit.continue;
|
||||||
});
|
});
|
|
@ -16,12 +16,12 @@ import { ConfigService, Env } from '@kbn/config';
|
||||||
import { getEnvOptions } from '@kbn/config-mocks';
|
import { getEnvOptions } from '@kbn/config-mocks';
|
||||||
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
|
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
|
||||||
import { executionContextServiceMock } from '@kbn/core-execution-context-server-mocks';
|
import { executionContextServiceMock } from '@kbn/core-execution-context-server-mocks';
|
||||||
import { HttpService } from '.';
|
import { contextServiceMock } from '@kbn/core-http-context-server-mocks';
|
||||||
|
import { Router } from '@kbn/core-http-router-server-internal';
|
||||||
|
import { HttpService } from './http_service';
|
||||||
import { HttpConfigType, config } from './http_config';
|
import { HttpConfigType, config } from './http_config';
|
||||||
import { contextServiceMock } from '../context/context_service.mock';
|
|
||||||
import { cspConfig } from './csp';
|
import { cspConfig } from './csp';
|
||||||
import { externalUrlConfig, ExternalUrlConfig } from './external_url';
|
import { externalUrlConfig, ExternalUrlConfig } from './external_url';
|
||||||
import { Router } from './router';
|
|
||||||
|
|
||||||
const logger = loggingSystemMock.create();
|
const logger = loggingSystemMock.create();
|
||||||
const env = Env.createDefault(REPO_ROOT, getEnvOptions());
|
const env = Env.createDefault(REPO_ROOT, getEnvOptions());
|
|
@ -21,21 +21,21 @@ import type {
|
||||||
IContextContainer,
|
IContextContainer,
|
||||||
IContextProvider,
|
IContextProvider,
|
||||||
} from '@kbn/core-http-server';
|
} from '@kbn/core-http-server';
|
||||||
|
import type {
|
||||||
|
InternalContextSetup,
|
||||||
|
InternalContextPreboot,
|
||||||
|
} from '@kbn/core-http-context-server-internal';
|
||||||
|
import { Router } from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
import { InternalContextSetup, InternalContextPreboot } from '../context';
|
|
||||||
import { CspConfigType, cspConfig } from './csp';
|
import { CspConfigType, cspConfig } from './csp';
|
||||||
|
|
||||||
import { Router } from './router';
|
|
||||||
import { HttpConfig, HttpConfigType, config as httpConfig } from './http_config';
|
import { HttpConfig, HttpConfigType, config as httpConfig } from './http_config';
|
||||||
import { HttpServer } from './http_server';
|
import { HttpServer } from './http_server';
|
||||||
import { HttpsRedirectServer } from './https_redirect_server';
|
import { HttpsRedirectServer } from './https_redirect_server';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
InternalHttpServicePreboot,
|
InternalHttpServicePreboot,
|
||||||
InternalHttpServiceSetup,
|
InternalHttpServiceSetup,
|
||||||
InternalHttpServiceStart,
|
InternalHttpServiceStart,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
import { registerCoreHandlers } from './lifecycle_handlers';
|
import { registerCoreHandlers } from './lifecycle_handlers';
|
||||||
import { ExternalUrlConfigType, externalUrlConfig, ExternalUrlConfig } from './external_url';
|
import { ExternalUrlConfigType, externalUrlConfig, ExternalUrlConfig } from './external_url';
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
export { config, HttpConfig } from './http_config';
|
export { config, HttpConfig } from './http_config';
|
||||||
export type { HttpConfigType } from './http_config';
|
export type { HttpConfigType } from './http_config';
|
||||||
export { HttpService } from './http_service';
|
export { HttpService } from './http_service';
|
||||||
export { isKibanaRequest, isRealRequest, CoreKibanaRequest, kibanaResponseFactory } from './router';
|
export { HttpServer } from './http_server';
|
||||||
|
export type { HttpServerSetup, LifecycleRegistrar } from './http_server';
|
||||||
export type {
|
export type {
|
||||||
InternalHttpServicePreboot,
|
InternalHttpServicePreboot,
|
||||||
InternalHttpServiceSetup,
|
InternalHttpServiceSetup,
|
||||||
|
@ -20,3 +21,5 @@ export { BasePath } from './base_path_service';
|
||||||
export { cspConfig, CspConfig } from './csp';
|
export { cspConfig, CspConfig } from './csp';
|
||||||
|
|
||||||
export { externalUrlConfig, ExternalUrlConfig } from './external_url';
|
export { externalUrlConfig, ExternalUrlConfig } from './external_url';
|
||||||
|
|
||||||
|
export { createCookieSessionStorageFactory } from './cookie_session_storage';
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Lifecycle, Request, ResponseToolkit } from '@hapi/hapi';
|
import type { Lifecycle, Request, ResponseToolkit } from '@hapi/hapi';
|
||||||
import type { Logger } from '@kbn/logging';
|
import type { Logger } from '@kbn/logging';
|
||||||
import type {
|
import type {
|
||||||
AuthenticationHandler,
|
AuthenticationHandler,
|
||||||
|
@ -24,7 +24,7 @@ import {
|
||||||
CoreKibanaRequest,
|
CoreKibanaRequest,
|
||||||
lifecycleResponseFactory,
|
lifecycleResponseFactory,
|
||||||
isKibanaResponse,
|
isKibanaResponse,
|
||||||
} from '../router';
|
} from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
const authResult = {
|
const authResult = {
|
||||||
authenticated(data: AuthResultParams = {}): AuthResult {
|
authenticated(data: AuthResultParams = {}): AuthResult {
|
|
@ -20,7 +20,7 @@ import {
|
||||||
CoreKibanaRequest,
|
CoreKibanaRequest,
|
||||||
lifecycleResponseFactory,
|
lifecycleResponseFactory,
|
||||||
isKibanaResponse,
|
isKibanaResponse,
|
||||||
} from '../router';
|
} from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
const postAuthResult = {
|
const postAuthResult = {
|
||||||
next(): OnPostAuthResult {
|
next(): OnPostAuthResult {
|
|
@ -20,7 +20,7 @@ import {
|
||||||
CoreKibanaRequest,
|
CoreKibanaRequest,
|
||||||
isKibanaResponse,
|
isKibanaResponse,
|
||||||
lifecycleResponseFactory,
|
lifecycleResponseFactory,
|
||||||
} from '../router';
|
} from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
const preAuthResult = {
|
const preAuthResult = {
|
||||||
next(): OnPreAuthResult {
|
next(): OnPreAuthResult {
|
|
@ -25,7 +25,7 @@ import type {
|
||||||
OnPreResponseHandler,
|
OnPreResponseHandler,
|
||||||
} from '@kbn/core-http-server';
|
} from '@kbn/core-http-server';
|
||||||
import { OnPreResponseResultType } from '@kbn/core-http-server';
|
import { OnPreResponseResultType } from '@kbn/core-http-server';
|
||||||
import { HapiResponseAdapter, CoreKibanaRequest } from '../router';
|
import { HapiResponseAdapter, CoreKibanaRequest } from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
const preResponseResult = {
|
const preResponseResult = {
|
||||||
render(responseRender: OnPreResponseRender): OnPreResponseResult {
|
render(responseRender: OnPreResponseRender): OnPreResponseResult {
|
|
@ -22,7 +22,7 @@ import {
|
||||||
CoreKibanaRequest,
|
CoreKibanaRequest,
|
||||||
isKibanaResponse,
|
isKibanaResponse,
|
||||||
lifecycleResponseFactory,
|
lifecycleResponseFactory,
|
||||||
} from '../router';
|
} from '@kbn/core-http-router-server-internal';
|
||||||
|
|
||||||
const preRoutingResult = {
|
const preRoutingResult = {
|
||||||
next(): OnPreRoutingResult {
|
next(): OnPreRoutingResult {
|
|
@ -6,17 +6,34 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { KibanaRequest, RouteMethod, KibanaRouteOptions } from '@kbn/core-http-server';
|
import type {
|
||||||
|
KibanaRequest,
|
||||||
|
RouteMethod,
|
||||||
|
KibanaRouteOptions,
|
||||||
|
OnPreResponseToolkit,
|
||||||
|
OnPostAuthToolkit,
|
||||||
|
OnPreRoutingToolkit,
|
||||||
|
} from '@kbn/core-http-server';
|
||||||
|
import { mockRouter } from '@kbn/core-http-router-server-mocks';
|
||||||
import {
|
import {
|
||||||
createCustomHeadersPreResponseHandler,
|
createCustomHeadersPreResponseHandler,
|
||||||
createVersionCheckPostAuthHandler,
|
createVersionCheckPostAuthHandler,
|
||||||
createXsrfPostAuthHandler,
|
createXsrfPostAuthHandler,
|
||||||
} from './lifecycle_handlers';
|
} from './lifecycle_handlers';
|
||||||
import { httpServerMock } from './http_server.mocks';
|
|
||||||
import { HttpConfig } from './http_config';
|
import { HttpConfig } from './http_config';
|
||||||
|
|
||||||
|
type ToolkitMock = jest.Mocked<OnPreResponseToolkit & OnPostAuthToolkit & OnPreRoutingToolkit>;
|
||||||
|
|
||||||
const createConfig = (partial: Partial<HttpConfig>): HttpConfig => partial as HttpConfig;
|
const createConfig = (partial: Partial<HttpConfig>): HttpConfig => partial as HttpConfig;
|
||||||
|
|
||||||
|
const createToolkit = (): ToolkitMock => {
|
||||||
|
return {
|
||||||
|
render: jest.fn(),
|
||||||
|
next: jest.fn(),
|
||||||
|
rewriteUrl: jest.fn(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const forgeRequest = ({
|
const forgeRequest = ({
|
||||||
headers = {},
|
headers = {},
|
||||||
path = '/',
|
path = '/',
|
||||||
|
@ -28,7 +45,7 @@ const forgeRequest = ({
|
||||||
method: RouteMethod;
|
method: RouteMethod;
|
||||||
kibanaRouteOptions: KibanaRouteOptions;
|
kibanaRouteOptions: KibanaRouteOptions;
|
||||||
}>): KibanaRequest => {
|
}>): KibanaRequest => {
|
||||||
return httpServerMock.createKibanaRequest({
|
return mockRouter.createKibanaRequest({
|
||||||
headers,
|
headers,
|
||||||
path,
|
path,
|
||||||
method,
|
method,
|
||||||
|
@ -37,12 +54,12 @@ const forgeRequest = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('xsrf post-auth handler', () => {
|
describe('xsrf post-auth handler', () => {
|
||||||
let toolkit: ReturnType<typeof httpServerMock.createToolkit>;
|
let toolkit: ToolkitMock;
|
||||||
let responseFactory: ReturnType<typeof httpServerMock.createLifecycleResponseFactory>;
|
let responseFactory: ReturnType<typeof mockRouter.createResponseFactory>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
toolkit = httpServerMock.createToolkit();
|
toolkit = createToolkit();
|
||||||
responseFactory = httpServerMock.createLifecycleResponseFactory();
|
responseFactory = mockRouter.createResponseFactory();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('non destructive methods', () => {
|
describe('non destructive methods', () => {
|
||||||
|
@ -165,12 +182,12 @@ describe('xsrf post-auth handler', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('versionCheck post-auth handler', () => {
|
describe('versionCheck post-auth handler', () => {
|
||||||
let toolkit: ReturnType<typeof httpServerMock.createToolkit>;
|
let toolkit: ToolkitMock;
|
||||||
let responseFactory: ReturnType<typeof httpServerMock.createLifecycleResponseFactory>;
|
let responseFactory: ReturnType<typeof mockRouter.createResponseFactory>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
toolkit = httpServerMock.createToolkit();
|
toolkit = createToolkit();
|
||||||
responseFactory = httpServerMock.createLifecycleResponseFactory();
|
responseFactory = mockRouter.createResponseFactory();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('forward the request to the next interceptor if header matches', () => {
|
it('forward the request to the next interceptor if header matches', () => {
|
||||||
|
@ -225,10 +242,10 @@ describe('versionCheck post-auth handler', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('customHeaders pre-response handler', () => {
|
describe('customHeaders pre-response handler', () => {
|
||||||
let toolkit: ReturnType<typeof httpServerMock.createToolkit>;
|
let toolkit: ToolkitMock;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
toolkit = httpServerMock.createToolkit();
|
toolkit = createToolkit();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds the kbn-name header to the response', () => {
|
it('adds the kbn-name header to the response', () => {
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
import { Env } from '@kbn/config';
|
import { Env } from '@kbn/config';
|
||||||
import type { OnPostAuthHandler, OnPreResponseHandler } from '@kbn/core-http-server';
|
import type { OnPostAuthHandler, OnPreResponseHandler } from '@kbn/core-http-server';
|
||||||
|
import { isSafeMethod } from '@kbn/core-http-router-server-internal';
|
||||||
import { HttpConfig } from './http_config';
|
import { HttpConfig } from './http_config';
|
||||||
import { isSafeMethod } from './router';
|
|
||||||
import { LifecycleRegistrar } from './http_server';
|
import { LifecycleRegistrar } from './http_server';
|
||||||
|
|
||||||
const VERSION_HEADER = 'kbn-version';
|
const VERSION_HEADER = 'kbn-version';
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue