kibana/x-pack/test/licensing_plugin/scenario.ts
Mikhail Shustov a4c5b13400
NP licensing add functional tests (#53002)
* fix comment

* introduce core provider plugin for integration tests

* platform functional tests use core_provider_plugin for testing

* add 3 scenario for licensing plugins: server, client, legacy

* remove unused code

* run all licensing_plugin tests on CI

* remove duplicated config

* address comments

* declare global type for core provider
2019-12-19 10:59:27 +01:00

91 lines
3.2 KiB
TypeScript

/*
* 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 expect from '@kbn/expect';
import { FtrProviderContext } from './services';
import { PublicLicenseJSON } from '../../plugins/licensing/server';
import '../../../test/plugin_functional/plugins/core_provider_plugin/types';
const delay = (ms: number) => new Promise(res => setTimeout(res, ms));
export function createScenario({ getService, getPageObjects }: FtrProviderContext) {
const supertest = getService('supertest');
const esSupertestWithoutAuth = getService('esSupertestWithoutAuth');
const security = getService('security');
const PageObjects = getPageObjects(['common', 'security']);
const scenario = {
async setup() {
await security.role.create('license_manager-role', {
elasticsearch: {
cluster: ['all'],
},
kibana: [
{
base: ['all'],
spaces: ['*'],
},
],
});
await security.user.create('license_manager_user', {
password: 'license_manager_user-password',
roles: ['license_manager-role'],
full_name: 'license_manager user',
});
// ensure we're logged out so we can login as the appropriate users
await PageObjects.security.logout();
await PageObjects.security.login('license_manager_user', 'license_manager_user-password');
},
// make sure a license is present, otherwise the security is not available anymore.
async teardown() {
await security.role.delete('license_manager-role');
await security.user.delete('license_manager_user');
},
// elasticsearch allows to downgrade a license only once. other attempts will throw 403.
async startBasic() {
const response = await esSupertestWithoutAuth
.post('/_license/start_basic?acknowledge=true')
.auth('license_manager_user', 'license_manager_user-password')
.expect(200);
expect(response.body.basic_was_started).to.be(true);
},
// elasticsearch allows to request trial only once. other attempts will throw 403.
async startTrial() {
const response = await esSupertestWithoutAuth
.post('/_license/start_trial?acknowledge=true')
.auth('license_manager_user', 'license_manager_user-password')
.expect(200);
expect(response.body.trial_was_started).to.be(true);
},
async deleteLicense() {
const response = await esSupertestWithoutAuth
.delete('/_license')
.auth('license_manager_user', 'license_manager_user-password')
.expect(200);
expect(response.body.acknowledged).to.be(true);
},
async getLicense(): Promise<PublicLicenseJSON> {
const { body } = await supertest.get('/api/licensing/info').expect(200);
return body;
},
async waitForPluginToDetectLicenseUpdate() {
// > --xpack.licensing.api_polling_frequency set in test config
// to wait for Kibana server to re-fetch the license from Elasticsearch
await delay(500);
},
};
return scenario;
}