mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Add functional test for Kibana embedded in iframe (#68544)
* convert kbn test config into TS * add test for Kibana embedded in iframe * run embedded tests in functional suite * ignore tls errors in functional tests by default * switch test to https * remove env vars mutation * allow to pass ssl config to Kibana * pass ssl config to axios * adopt KbnClient interfaces * adopt KibanaServer * use KbnRequester in security service * set sameSiteCookies:None in test * acceptInsecureCerts in chrome * remove leftovers * fix type error * remove unnecessary field * address comments * refactor plugin * refactor test * make acceptInsecureCerts configurable * run firefox tests on ci * up TS version * fix firefox.sh script * fix path Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
d2006ea8a0
commit
c8c20e4ca8
30 changed files with 393 additions and 113 deletions
27
x-pack/test/functional_embedded/config.firefox.ts
Normal file
27
x-pack/test/functional_embedded/config.firefox.ts
Normal file
|
@ -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;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { FtrConfigProviderContext } from '@kbn/test/types/ftr';
|
||||
|
||||
export default async function ({ readConfigFile }: FtrConfigProviderContext) {
|
||||
const chromeConfig = await readConfigFile(require.resolve('./config'));
|
||||
|
||||
return {
|
||||
...chromeConfig.getAll(),
|
||||
|
||||
browser: {
|
||||
type: 'firefox',
|
||||
acceptInsecureCerts: true,
|
||||
},
|
||||
|
||||
suiteTags: {
|
||||
exclude: ['skipFirefox'],
|
||||
},
|
||||
|
||||
junit: {
|
||||
reportName: 'Firefox Kibana Embedded in iframe with X-Pack Security',
|
||||
},
|
||||
};
|
||||
}
|
67
x-pack/test/functional_embedded/config.ts
Normal file
67
x-pack/test/functional_embedded/config.ts
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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 Fs from 'fs';
|
||||
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',
|
||||
ssl: {
|
||||
enabled: true,
|
||||
key: Fs.readFileSync(KBN_KEY_PATH).toString('utf8'),
|
||||
certificate: Fs.readFileSync(KBN_CERT_PATH).toString('utf8'),
|
||||
certificateAuthorities: Fs.readFileSync(CA_CERT_PATH).toString('utf8'),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
testFiles: [require.resolve('./tests')],
|
||||
servers,
|
||||
services: kibanaFunctionalConfig.get('services'),
|
||||
pageObjects,
|
||||
browser: {
|
||||
acceptInsecureCerts: true,
|
||||
},
|
||||
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=${CA_CERT_PATH}`,
|
||||
|
||||
'--xpack.security.sameSiteCookies=None',
|
||||
'--xpack.security.secureCookies=true',
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
12
x-pack/test/functional_embedded/ftr_provider_context.d.ts
vendored
Normal file
12
x-pack/test/functional_embedded/ftr_provider_context.d.ts
vendored
Normal file
|
@ -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 };
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"id": "iframe_embedded",
|
||||
"version": "1.0.0",
|
||||
"kibanaVersion": "kibana",
|
||||
"server": true,
|
||||
"ui": false
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "iframe_embedded",
|
||||
"version": "0.0.0",
|
||||
"kibana": {
|
||||
"version": "kibana"
|
||||
},
|
||||
"scripts": {
|
||||
"kbn": "node ../../../../../scripts/kbn.js",
|
||||
"build": "rm -rf './target' && tsc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "3.9.5"
|
||||
}
|
||||
}
|
|
@ -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);
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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';
|
||||
|
||||
function renderBody(iframeUrl: string) {
|
||||
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) {
|
||||
core.http.resources.register(
|
||||
{
|
||||
path: '/iframe_embedded',
|
||||
validate: false,
|
||||
},
|
||||
async (context, request, response) => {
|
||||
const { protocol, port, host } = core.http.getServerInfo();
|
||||
|
||||
const kibanaUrl = Url.format({ protocol, hostname: host, port });
|
||||
|
||||
return response.renderHtml({
|
||||
body: renderBody(kibanaUrl),
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
public start() {}
|
||||
public stop() {}
|
||||
}
|
9
x-pack/test/functional_embedded/services.ts
Normal file
9
x-pack/test/functional_embedded/services.ts
Normal file
|
@ -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;
|
42
x-pack/test/functional_embedded/tests/iframe_embedded.ts
Normal file
42
x-pack/test/functional_embedded/tests/iframe_embedded.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 expect from '@kbn/expect';
|
||||
|
||||
import { FtrProviderContext } from '../ftr_provider_context';
|
||||
|
||||
export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
||||
const PageObjects = getPageObjects(['security', 'common']);
|
||||
const browser = getService('browser');
|
||||
const config = getService('config');
|
||||
const testSubjects = getService('testSubjects');
|
||||
|
||||
describe('in iframe', () => {
|
||||
it('should open Kibana for logged-in user', async () => {
|
||||
const isChromeHiddenBefore = await PageObjects.common.isChromeHidden();
|
||||
expect(isChromeHiddenBefore).to.be(true);
|
||||
|
||||
await PageObjects.security.login();
|
||||
|
||||
const { protocol, hostname, port } = config.get('servers.kibana');
|
||||
|
||||
const url = Url.format({
|
||||
protocol,
|
||||
hostname,
|
||||
port,
|
||||
pathname: 'iframe_embedded',
|
||||
});
|
||||
|
||||
await browser.navigateTo(url);
|
||||
|
||||
const iframe = await testSubjects.find('iframe_embedded');
|
||||
await browser.switchToFrame(iframe);
|
||||
|
||||
const isChromeHidden = await PageObjects.common.isChromeHidden();
|
||||
expect(isChromeHidden).to.be(false);
|
||||
});
|
||||
});
|
||||
}
|
14
x-pack/test/functional_embedded/tests/index.ts
Normal file
14
x-pack/test/functional_embedded/tests/index.ts
Normal file
|
@ -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('Kibana embedded', function () {
|
||||
this.tags('ciGroup2');
|
||||
loadTestFile(require.resolve('./iframe_embedded'));
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue