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

Fix advanced settings API integration tests on cloud #84110

Merged
merged 3 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
78 changes: 78 additions & 0 deletions test/common/services/deployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { get } from 'lodash';
import fetch from 'node-fetch';
// @ts-ignore not TS yet
import getUrl from '../../../src/test_utils/get_url';

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

export function DeploymentProvider({ getService }: FtrProviderContext) {
const config = getService('config');

return {
/**
* Returns Kibana host URL
*/
getHostPort() {
return getUrl.baseUrl(config.get('servers.kibana'));
},

/**
* Returns ES host URL
*/
getEsHostPort() {
return getUrl.baseUrl(config.get('servers.elasticsearch'));
},

/**
* Helper to detect an OSS licensed Kibana
* Useful for functional testing in cloud environment
*/
async isOss() {
const baseUrl = this.getEsHostPort();
const username = config.get('servers.elasticsearch.username');
const password = config.get('servers.elasticsearch.password');
const response = await fetch(baseUrl + '/_xpack', {
method: 'get',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + Buffer.from(username + ':' + password).toString('base64'),
},
});
return response.status !== 200;
},

async isCloud(): Promise<boolean> {
const baseUrl = this.getHostPort();
const username = config.get('servers.kibana.username');
const password = config.get('servers.kibana.password');
const response = await fetch(baseUrl + '/api/stats?extended', {
method: 'get',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + Buffer.from(username + ':' + password).toString('base64'),
},
});
const data = await response.json();
return get(data, 'usage.cloud.is_cloud_enabled', false);
},
};
}
2 changes: 2 additions & 0 deletions test/common/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { DeploymentProvider } from './deployment';
import { LegacyEsProvider } from './legacy_es';
import { ElasticsearchProvider } from './elasticsearch';
import { EsArchiverProvider } from './es_archiver';
Expand All @@ -26,6 +27,7 @@ import { RandomnessProvider } from './randomness';
import { SecurityServiceProvider } from './security';

export const services = {
deployment: DeploymentProvider,
legacyEs: LegacyEsProvider,
es: ElasticsearchProvider,
esArchiver: EsArchiverProvider,
Expand Down
3 changes: 2 additions & 1 deletion test/examples/state_sync/todo_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide
const browser = getService('browser');
const PageObjects = getPageObjects(['common']);
const log = getService('log');
const deployment = getService('deployment');

describe('TODO app', () => {
describe("TODO app with browser history (platform's ScopedHistory)", async () => {
const appId = 'stateContainersExampleBrowserHistory';
let base: string;

before(async () => {
base = await PageObjects.common.getHostPort();
base = await deployment.getHostPort();
await PageObjects.common.navigateToApp(appId, { insertTimestamp: false });
});

Expand Down
3 changes: 2 additions & 1 deletion test/functional/apps/dashboard/url_field_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const browser = getService('browser');
const fieldName = 'clientip';
const deployment = getService('deployment');

const clickFieldAndCheckUrl = async (fieldLink: WebElementWrapper) => {
const fieldValue = await fieldLink.getVisibleText();
Expand All @@ -42,7 +43,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(windowHandlers.length).to.equal(2);
await browser.switchToWindow(windowHandlers[1]);
const currentUrl = await browser.getCurrentUrl();
const fieldUrl = common.getHostPort() + '/app/' + fieldValue;
const fieldUrl = deployment.getHostPort() + '/app/' + fieldValue;
expect(currentUrl).to.equal(fieldUrl);
};

Expand Down
3 changes: 2 additions & 1 deletion test/functional/apps/discover/_shared_links.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['common', 'discover', 'share', 'timePicker']);
const browser = getService('browser');
const toasts = getService('toasts');
const deployment = getService('deployment');

// FLAKY: https://github.com/elastic/kibana/issues/80104
describe.skip('shared links', function describeIndexTests() {
let baseUrl;

async function setup({ storeStateInSessionStorage }) {
baseUrl = PageObjects.common.getHostPort();
baseUrl = deployment.getHostPort();
log.debug('baseUrl = ' + baseUrl);
// browsers don't show the ':port' if it's 80 or 443 so we have to
// remove that part so we can get a match in the tests.
Expand Down
5 changes: 3 additions & 2 deletions test/functional/apps/home/_newsfeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const globalNav = getService('globalNav');
const PageObjects = getPageObjects(['common', 'newsfeed']);
const deployment = getService('deployment');
const PageObjects = getPageObjects(['newsfeed']);

describe('Newsfeed', () => {
before(async () => {
Expand All @@ -48,7 +49,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
it('shows all news from newsfeed', async () => {
const objects = await PageObjects.newsfeed.getNewsfeedList();

if (await PageObjects.common.isOss()) {
if (await deployment.isOss()) {
expect(objects).to.eql([
'21 June 2019\nYou are functionally testing the newsfeed widget with fixtures!\nSee test/common/fixtures/plugins/newsfeed/newsfeed_simulation\nGeneric feed-viewer could go here',
'21 June 2019\nStaging too!\nHello world\nGeneric feed-viewer could go here',
Expand Down
9 changes: 5 additions & 4 deletions test/functional/apps/management/_scripted_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function ({ getService, getPageObjects }) {
const inspector = getService('inspector');
const testSubjects = getService('testSubjects');
const filterBar = getService('filterBar');
const deployment = getService('deployment');
const PageObjects = getPageObjects([
'common',
'header',
Expand Down Expand Up @@ -202,7 +203,7 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.discover.clickFieldListItemVisualize(scriptedPainlessFieldName);
await PageObjects.header.waitUntilLoadingHasFinished();

if (await PageObjects.common.isOss()) {
if (await deployment.isOss()) {
// OSS renders a vertical bar chart and we check the data in the Inspect panel
const expectedChartValues = [
['14', '31'],
Expand Down Expand Up @@ -318,7 +319,7 @@ export default function ({ getService, getPageObjects }) {
it('should visualize scripted field in vertical bar chart', async function () {
await PageObjects.discover.clickFieldListItemVisualize(scriptedPainlessFieldName2);
await PageObjects.header.waitUntilLoadingHasFinished();
if (await PageObjects.common.isOss()) {
if (await deployment.isOss()) {
// OSS renders a vertical bar chart and we check the data in the Inspect panel
await inspector.open();
await inspector.expectTableData([
Expand Down Expand Up @@ -414,7 +415,7 @@ export default function ({ getService, getPageObjects }) {
it('should visualize scripted field in vertical bar chart', async function () {
await PageObjects.discover.clickFieldListItemVisualize(scriptedPainlessFieldName2);
await PageObjects.header.waitUntilLoadingHasFinished();
if (await PageObjects.common.isOss()) {
if (await deployment.isOss()) {
// OSS renders a vertical bar chart and we check the data in the Inspect panel
await inspector.open();
await inspector.expectTableData([
Expand Down Expand Up @@ -514,7 +515,7 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.discover.clickFieldListItemVisualize(scriptedPainlessFieldName2);
await PageObjects.header.waitUntilLoadingHasFinished();

if (await PageObjects.common.isOss()) {
if (await deployment.isOss()) {
// OSS renders a vertical bar chart and we check the data in the Inspect panel
await inspector.open();
await inspector.setTablePageSize(50);
Expand Down
5 changes: 3 additions & 2 deletions test/functional/apps/visualize/_chart_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const deployment = getService('deployment');
const log = getService('log');
const PageObjects = getPageObjects(['common', 'visualize']);
const PageObjects = getPageObjects(['visualize']);
let isOss = true;

describe('chart types', function () {
before(async function () {
log.debug('navigateToApp visualize');
isOss = await PageObjects.common.isOss();
isOss = await deployment.isOss();
await PageObjects.visualize.navigateToNewVisualization();
});

Expand Down
6 changes: 3 additions & 3 deletions test/functional/apps/visualize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import { FtrProviderContext } from '../../ftr_provider_context.d';
import { UI_SETTINGS } from '../../../../src/plugins/data/common';

export default function ({ getService, getPageObjects, loadTestFile }: FtrProviderContext) {
export default function ({ getService, loadTestFile }: FtrProviderContext) {
const browser = getService('browser');
const log = getService('log');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const PageObjects = getPageObjects(['common']);
const deployment = getService('deployment');
let isOss = true;

describe('visualize app', () => {
Expand All @@ -39,7 +39,7 @@ export default function ({ getService, getPageObjects, loadTestFile }: FtrProvid
defaultIndex: 'logstash-*',
[UI_SETTINGS.FORMAT_BYTES_DEFAULT_PATTERN]: '0,0.[000]b',
});
isOss = await PageObjects.common.isOss();
isOss = await deployment.isOss();
});

describe('', function () {
Expand Down
48 changes: 0 additions & 48 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import { delay } from 'bluebird';
import expect from '@kbn/expect';
import { get } from 'lodash';
// @ts-ignore
import fetch from 'node-fetch';
import { FtrProviderContext } from '../ftr_provider_context';
Expand Down Expand Up @@ -48,20 +47,6 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
}

class CommonPage {
/**
* Returns Kibana host URL
*/
public getHostPort() {
return getUrl.baseUrl(config.get('servers.kibana'));
}

/**
* Returns ES host URL
*/
public getEsHostPort() {
return getUrl.baseUrl(config.get('servers.elasticsearch'));
}

/**
* Logins to Kibana as default user and navigates to provided app
* @param appUrl Kibana URL
Expand Down Expand Up @@ -455,39 +440,6 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
return await body.getVisibleText();
}

/**
* Helper to detect an OSS licensed Kibana
* Useful for functional testing in cloud environment
*/
async isOss() {
const baseUrl = this.getEsHostPort();
const username = config.get('servers.elasticsearch.username');
const password = config.get('servers.elasticsearch.password');
const response = await fetch(baseUrl + '/_xpack', {
method: 'get',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + Buffer.from(username + ':' + password).toString('base64'),
},
});
return response.status !== 200;
}

async isCloud(): Promise<boolean> {
const baseUrl = this.getHostPort();
const username = config.get('servers.kibana.username');
const password = config.get('servers.kibana.password');
const response = await fetch(baseUrl + '/api/stats?extended', {
method: 'get',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + Buffer.from(username + ':' + password).toString('base64'),
},
});
const data = await response.json();
return get(data, 'usage.cloud.is_cloud_enabled', false);
}

async waitForSaveModalToClose() {
log.debug('Waiting for save modal to close');
await retry.try(async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/page_objects/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function HomePageProvider({ getService, getPageObjects }: FtrProviderCont
const testSubjects = getService('testSubjects');
const retry = getService('retry');
const find = getService('find');
const deployment = getService('deployment');
const PageObjects = getPageObjects(['common']);
let isOss = true;

Expand Down Expand Up @@ -82,7 +83,7 @@ export function HomePageProvider({ getService, getPageObjects }: FtrProviderCont

async launchSampleDashboard(id: string) {
await this.launchSampleDataSet(id);
isOss = await PageObjects.common.isOss();
isOss = await deployment.isOss();
if (!isOss) {
await find.clickByLinkText('Dashboard');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide
const testSubjects = getService('testSubjects');
const find = getService('find');
const retry = getService('retry');
const deployment = getService('deployment');

const loadingScreenNotShown = async () =>
expect(await testSubjects.exists('kbnLoadingMessage')).to.be(false);
Expand Down Expand Up @@ -55,7 +56,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide
};

const navigateTo = async (path: string) =>
await browser.navigateTo(`${PageObjects.common.getHostPort()}${path}`);
await browser.navigateTo(`${deployment.getHostPort()}${path}`);

describe('ui applications', function describeIndexTests() {
before(async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ declare global {
}
}

export default function ({ getService, getPageObjects }: PluginFunctionalProviderContext) {
const PageObjects = getPageObjects(['common']);
export default function ({ getService }: PluginFunctionalProviderContext) {
const appsMenu = getService('appsMenu');
const browser = getService('browser');
const deployment = getService('deployment');
const find = getService('find');
const testSubjects = getService('testSubjects');

const navigateTo = async (path: string) =>
await browser.navigateTo(`${PageObjects.common.getHostPort()}${path}`);
await browser.navigateTo(`${deployment.getHostPort()}${path}`);
const navigateToApp = async (title: string) => {
await appsMenu.clickLink(title);
return browser.execute(() => {
Expand Down
7 changes: 3 additions & 4 deletions test/plugin_functional/test_suites/core_plugins/top_nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
import expect from '@kbn/expect';
import { PluginFunctionalProviderContext } from '../../services';

export default function ({ getService, getPageObjects }: PluginFunctionalProviderContext) {
const PageObjects = getPageObjects(['common']);

export default function ({ getService }: PluginFunctionalProviderContext) {
const browser = getService('browser');
const deployment = getService('deployment');
const testSubjects = getService('testSubjects');

describe.skip('top nav', function describeIndexTests() {
before(async () => {
const url = `${PageObjects.common.getHostPort()}/app/kbn_tp_top_nav/`;
const url = `${deployment.getHostPort()}/app/kbn_tp_top_nav/`;
await browser.get(url);
});

Expand Down
Loading