From 0112057aef399a599bd11de73516bf36eab94780 Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Mon, 8 Jun 2020 19:08:16 +0200 Subject: [PATCH 01/24] convert kbn test config into TS --- .../kbn-test/src/kbn/{index.js => index.ts} | 0 ...{kbn_test_config.js => kbn_test_config.ts} | 28 ++++++++++++------- .../kbn-test/src/kbn/{users.js => users.ts} | 0 3 files changed, 18 insertions(+), 10 deletions(-) rename packages/kbn-test/src/kbn/{index.js => index.ts} (100%) rename packages/kbn-test/src/kbn/{kbn_test_config.js => kbn_test_config.ts} (75%) rename packages/kbn-test/src/kbn/{users.js => users.ts} (100%) diff --git a/packages/kbn-test/src/kbn/index.js b/packages/kbn-test/src/kbn/index.ts similarity index 100% rename from packages/kbn-test/src/kbn/index.js rename to packages/kbn-test/src/kbn/index.ts diff --git a/packages/kbn-test/src/kbn/kbn_test_config.js b/packages/kbn-test/src/kbn/kbn_test_config.ts similarity index 75% rename from packages/kbn-test/src/kbn/kbn_test_config.js rename to packages/kbn-test/src/kbn/kbn_test_config.ts index c43efabb4b747..3c96086920941 100644 --- a/packages/kbn-test/src/kbn/kbn_test_config.js +++ b/packages/kbn-test/src/kbn/kbn_test_config.ts @@ -16,26 +16,34 @@ * specific language governing permissions and limitations * under the License. */ - -import { kibanaTestUser } from './users'; import url from 'url'; +import { kibanaTestUser } from './users'; + +interface UrlParts { + protocol: string; + hostname: string; + port: number; + auth: string; + username: string; + password: string; +} export const kbnTestConfig = new (class KbnTestConfig { getPort() { return this.getUrlParts().port; } - getUrlParts() { + getUrlParts(): UrlParts { // allow setting one complete TEST_KIBANA_URL for ES like https://elastic:changeme@example.com:9200 if (process.env.TEST_KIBANA_URL) { const testKibanaUrl = url.parse(process.env.TEST_KIBANA_URL); return { - protocol: testKibanaUrl.protocol.slice(0, -1), - hostname: testKibanaUrl.hostname, - port: parseInt(testKibanaUrl.port, 10), - auth: testKibanaUrl.auth, - username: testKibanaUrl.auth.split(':')[0], - password: testKibanaUrl.auth.split(':')[1], + protocol: testKibanaUrl.protocol!.slice(0, -1), + hostname: testKibanaUrl.hostname!, + port: parseInt(testKibanaUrl.port!, 10), + auth: testKibanaUrl.auth!, + username: testKibanaUrl.auth!.split(':')[0], + password: testKibanaUrl.auth!.split(':')[1], }; } @@ -44,7 +52,7 @@ export const kbnTestConfig = new (class KbnTestConfig { return { protocol: process.env.TEST_KIBANA_PROTOCOL || 'http', hostname: process.env.TEST_KIBANA_HOSTNAME || 'localhost', - port: parseInt(process.env.TEST_KIBANA_PORT, 10) || 5620, + port: parseInt(process.env.TEST_KIBANA_PORT!, 10) || 5620, auth: `${username}:${password}`, username, password, diff --git a/packages/kbn-test/src/kbn/users.js b/packages/kbn-test/src/kbn/users.ts similarity index 100% rename from packages/kbn-test/src/kbn/users.js rename to packages/kbn-test/src/kbn/users.ts From e3653653f7ee7544128c3fb9a0ba461f1c130e0a Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Mon, 8 Jun 2020 19:22:26 +0200 Subject: [PATCH 02/24] add test for Kibana embedded in iframe --- x-pack/test/functional_embedded/config.ts | 58 +++++++++++++++++++ .../ftr_provider_context.d.ts | 12 ++++ .../plugins/iframe_embedded/kibana.json | 7 +++ .../plugins/iframe_embedded/package.json | 15 +++++ .../plugins/iframe_embedded/server/index.ts | 11 ++++ .../plugins/iframe_embedded/server/plugin.ts | 48 +++++++++++++++ x-pack/test/functional_embedded/services.ts | 9 +++ .../tests/iframe_embedded.ts | 41 +++++++++++++ .../test/functional_embedded/tests/index.ts | 14 +++++ 9 files changed, 215 insertions(+) create mode 100644 x-pack/test/functional_embedded/config.ts create mode 100644 x-pack/test/functional_embedded/ftr_provider_context.d.ts create mode 100644 x-pack/test/functional_embedded/plugins/iframe_embedded/kibana.json create mode 100644 x-pack/test/functional_embedded/plugins/iframe_embedded/package.json create mode 100644 x-pack/test/functional_embedded/plugins/iframe_embedded/server/index.ts create mode 100644 x-pack/test/functional_embedded/plugins/iframe_embedded/server/plugin.ts create mode 100644 x-pack/test/functional_embedded/services.ts create mode 100644 x-pack/test/functional_embedded/tests/iframe_embedded.ts create mode 100644 x-pack/test/functional_embedded/tests/index.ts diff --git a/x-pack/test/functional_embedded/config.ts b/x-pack/test/functional_embedded/config.ts new file mode 100644 index 0000000000000..b407cc58e685d --- /dev/null +++ b/x-pack/test/functional_embedded/config.ts @@ -0,0 +1,58 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { resolve } from 'path'; +// import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils'; +import { FtrConfigProviderContext } from '@kbn/test/types/ftr'; +import { pageObjects } from '../functional/page_objects'; + +export default async function ({ readConfigFile }: FtrConfigProviderContext) { + const kibanaFunctionalConfig = await readConfigFile(require.resolve('../functional/config.js')); + + const iframeEmbeddedPlugin = resolve(__dirname, './plugins/iframe_embedded'); + + const servers = { + ...kibanaFunctionalConfig.get('servers'), + elasticsearch: { + ...kibanaFunctionalConfig.get('servers.elasticsearch'), + }, + kibana: { + ...kibanaFunctionalConfig.get('servers.kibana'), + // protocol: 'https', + }, + }; + + return { + testFiles: [require.resolve('./tests')], + servers, + services: kibanaFunctionalConfig.get('services'), + pageObjects, + junit: { + reportName: 'Kibana Embedded in iframe with X-Pack Security', + }, + + esTestCluster: kibanaFunctionalConfig.get('esTestCluster'), + apps: { + ...kibanaFunctionalConfig.get('apps'), + }, + + kbnTestServer: { + ...kibanaFunctionalConfig.get('kbnTestServer'), + serverArgs: [ + ...kibanaFunctionalConfig.get('kbnTestServer.serverArgs'), + `--plugin-path=${iframeEmbeddedPlugin}`, + // '--server.ssl.enabled=true', + // `--server.ssl.key=${KBN_KEY_PATH}`, + // `--server.ssl.certificate=${KBN_CERT_PATH}`, + // `--server.ssl.certificateAuthorities=${JSON.stringify([CA_CERT_PATH])}`, + // `--server.ssl.clientAuthentication=optional`, + + // '--xpack.security.sameSiteCookies=None', + // '--xpack.security.secureCookies=true', + ], + }, + }; +} diff --git a/x-pack/test/functional_embedded/ftr_provider_context.d.ts b/x-pack/test/functional_embedded/ftr_provider_context.d.ts new file mode 100644 index 0000000000000..5646c06a3cd30 --- /dev/null +++ b/x-pack/test/functional_embedded/ftr_provider_context.d.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { GenericFtrProviderContext } from '@kbn/test/types/ftr'; +import { pageObjects } from '../functional/page_objects'; +import { services } from './services'; + +export type FtrProviderContext = GenericFtrProviderContext; +export { pageObjects }; diff --git a/x-pack/test/functional_embedded/plugins/iframe_embedded/kibana.json b/x-pack/test/functional_embedded/plugins/iframe_embedded/kibana.json new file mode 100644 index 0000000000000..ea9f55bd21c6e --- /dev/null +++ b/x-pack/test/functional_embedded/plugins/iframe_embedded/kibana.json @@ -0,0 +1,7 @@ +{ + "id": "iframe_embedded", + "version": "1.0.0", + "kibanaVersion": "kibana", + "server": true, + "ui": false +} diff --git a/x-pack/test/functional_embedded/plugins/iframe_embedded/package.json b/x-pack/test/functional_embedded/plugins/iframe_embedded/package.json new file mode 100644 index 0000000000000..11ddde91459a4 --- /dev/null +++ b/x-pack/test/functional_embedded/plugins/iframe_embedded/package.json @@ -0,0 +1,15 @@ +{ + "name": "iframe_embedded", + "version": "0.0.0", + "kibana": { + "version": "kibana" + }, + "main": "target/test/plugin_api_integration/plugins/event_log", + "scripts": { + "kbn": "node ../../../../../scripts/kbn.js", + "build": "rm -rf './target' && tsc" + }, + "devDependencies": { + "typescript": "3.7.2" + } +} diff --git a/x-pack/test/functional_embedded/plugins/iframe_embedded/server/index.ts b/x-pack/test/functional_embedded/plugins/iframe_embedded/server/index.ts new file mode 100644 index 0000000000000..976ef19d4d8a7 --- /dev/null +++ b/x-pack/test/functional_embedded/plugins/iframe_embedded/server/index.ts @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ + +import { PluginInitializerContext } from 'kibana/server'; +import { IframeEmbeddedPlugin } from './plugin'; + +export const plugin = (initContext: PluginInitializerContext) => + new IframeEmbeddedPlugin(initContext); diff --git a/x-pack/test/functional_embedded/plugins/iframe_embedded/server/plugin.ts b/x-pack/test/functional_embedded/plugins/iframe_embedded/server/plugin.ts new file mode 100644 index 0000000000000..ca787cd84784a --- /dev/null +++ b/x-pack/test/functional_embedded/plugins/iframe_embedded/server/plugin.ts @@ -0,0 +1,48 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import Url from 'url'; +import { Plugin, CoreSetup, PluginInitializerContext } from 'src/core/server'; +import { kbnTestConfig } from '@kbn/test'; + +function renderBody(iframeUrl: string = 'https://localhost:5601') { + return ` + + + + + Kibana embedded in iframe + + +