Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functional test for Kibana embedded in iframe #68544

Merged
merged 31 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0112057
convert kbn test config into TS
mshustov Jun 8, 2020
e365365
add test for Kibana embedded in iframe
mshustov Jun 8, 2020
c41cf0c
run embedded tests in functional suite
mshustov Jun 8, 2020
442d6d8
Merge branch 'master' into issue-68256-iframe-FTR
mshustov Jun 10, 2020
54756f4
ignore tls errors in functional tests by default
mshustov Jun 10, 2020
d049acf
switch test to https
mshustov Jun 10, 2020
931f9a6
Merge branch 'master' into issue-68256-iframe-FTR
mshustov Jun 15, 2020
02a5dfb
remove env vars mutation
mshustov Jun 15, 2020
ab57750
allow to pass ssl config to Kibana
mshustov Jun 15, 2020
6342329
pass ssl config to axios
mshustov Jun 15, 2020
7c1b30d
adopt KbnClient interfaces
mshustov Jun 15, 2020
ffae20b
adopt KibanaServer
mshustov Jun 15, 2020
efd92e1
use KbnRequester in security service
mshustov Jun 15, 2020
31748d6
set sameSiteCookies:None in test
mshustov Jun 15, 2020
171508b
acceptInsecureCerts in chrome
mshustov Jun 15, 2020
812955c
remove leftovers
mshustov Jun 15, 2020
00d6b01
fix type error
mshustov Jun 15, 2020
690052c
remove unnecessary field
mshustov Jun 15, 2020
51dc7bb
Merge branch 'master' into issue-68256-iframe-FTR
mshustov Jun 16, 2020
42b4ce4
address comments
mshustov Jun 16, 2020
1bdd298
Merge branch 'master' into issue-68256-iframe-FTR
mshustov Jun 17, 2020
6fcf3e3
refactor plugin
mshustov Jun 17, 2020
ff6ff1d
refactor test
mshustov Jun 17, 2020
cb27f35
make acceptInsecureCerts configurable
mshustov Jun 17, 2020
8edf4ab
run firefox tests on ci
mshustov Jun 17, 2020
89bc3d8
up TS version
mshustov Jun 17, 2020
e8a025e
Merge branch 'master' into issue-68256-iframe-FTR
elasticmachine Jun 17, 2020
29021db
fix firefox.sh script
mshustov Jun 17, 2020
5d29c55
Merge branch 'master' into issue-68256-iframe-FTR
mshustov Jun 17, 2020
2b0a08b
Merge remote-tracking branch 'origin/issue-68256-iframe-FTR' into iss…
mshustov Jun 17, 2020
f53a83a
fix path
mshustov Jun 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]: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),
mshustov marked this conversation as resolved.
Show resolved Hide resolved
hostname: testKibanaUrl.hostname!,
port: parseInt(testKibanaUrl.port!, 10),
auth: testKibanaUrl.auth!,
username: testKibanaUrl.auth!.split(':')[0],
password: testKibanaUrl.auth!.split(':')[1],
};
}

Expand All @@ -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,
Expand Down
File renamed without changes.
58 changes: 58 additions & 0 deletions x-pack/test/functional_embedded/config.ts
Original file line number Diff line number Diff line change
@@ -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',
mshustov marked this conversation as resolved.
Show resolved Hide resolved
},
};

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',
],
},
};
}
12 changes: 12 additions & 0 deletions x-pack/test/functional_embedded/ftr_provider_context.d.ts
Original file line number Diff line number Diff line change
@@ -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<typeof services, typeof pageObjects>;
export { pageObjects };
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "iframe_embedded",
"version": "1.0.0",
"kibanaVersion": "kibana",
"server": true,
"ui": false
}
Original file line number Diff line number Diff line change
@@ -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"
mshustov marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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 `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Kibana embedded in iframe</title>
</head>
<body>
<iframe data-test-subj="iframe_embedded" width="1000" height="1200" src="${iframeUrl}" frameborder="0"/>
</body>
</html>
`;
}
export class IframeEmbeddedPlugin implements Plugin {
constructor(initializerContext: PluginInitializerContext) {}

public setup(core: CoreSetup) {
const router = core.http.createRouter();
mshustov marked this conversation as resolved.
Show resolved Hide resolved
router.get(
{
path: '/iframe_embedded',
validate: false,
},
async (context, request, response) => {
const { protocol, hostname, port } = kbnTestConfig.getUrlParts();
const kibanaUrl = Url.format({ protocol, hostname, port });
return response.ok({
body: renderBody(kibanaUrl),
headers: {
'content-type': 'text/html',
},
});
}
);
}
public start() {}
public stop() {}
}
9 changes: 9 additions & 0 deletions x-pack/test/functional_embedded/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 { services as functionalServices } from '../functional/services';

export const services = functionalServices;
41 changes: 41 additions & 0 deletions x-pack/test/functional_embedded/tests/iframe_embedded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 { By, until } from 'selenium-webdriver';
import testSubjSelector from '@kbn/test-subj-selector';
import { kbnTestConfig } from '@kbn/test';

import { FtrProviderContext } from '../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['security', 'common']);
const browser = getService('browser');
const testSubjects = getService('testSubjects');

const WD = getService('__webdriver__');

describe('Kibana embedded', () => {
it('should open Kibana for logged-in user', async () => {
await PageObjects.security.login();
const { protocol, hostname, port } = await kbnTestConfig.getUrlParts();
const url = Url.format({
protocol,
hostname,
port,
pathname: 'iframe_embedded',
});

await browser.navigateTo(url);

const iframe = await testSubjects.find('iframe_embedded');
WD.driver.switchTo().frame(iframe._webElement);
mshustov marked this conversation as resolved.
Show resolved Hide resolved

const selector = By.css(testSubjSelector('kibanaChrome'));
const minute = 60000;
await WD.driver.wait(until.elementLocated(selector), minute);
mshustov marked this conversation as resolved.
Show resolved Hide resolved
});
});
}
14 changes: 14 additions & 0 deletions x-pack/test/functional_embedded/tests/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 { FtrProviderContext } from '../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('apis', function () {
this.tags('ciGroup6');
mshustov marked this conversation as resolved.
Show resolved Hide resolved
loadTestFile(require.resolve('./iframe_embedded'));
});
}