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:
Mikhail Shustov 2020-06-18 13:02:56 +03:00 committed by GitHub
parent d2006ea8a0
commit c8c20e4ca8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 393 additions and 113 deletions

View 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',
},
};
}

View 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',
],
},
};
}

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

View file

@ -0,0 +1,7 @@
{
"id": "iframe_embedded",
"version": "1.0.0",
"kibanaVersion": "kibana",
"server": true,
"ui": false
}

View file

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

View file

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

View file

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

View 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;

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

View 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'));
});
}