From 9483684cebfc872d25d93cf037d71d306c94ad62 Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Fri, 13 Dec 2019 17:17:54 +0100 Subject: [PATCH] add 3 scenario for licensing plugins: server, client, legacy --- x-pack/test/licensing_plugin/apis/changes.ts | 177 ------------------ x-pack/test/licensing_plugin/config.legacy.ts | 15 ++ x-pack/test/licensing_plugin/config.public.ts | 26 +++ x-pack/test/licensing_plugin/config.ts | 4 +- x-pack/test/licensing_plugin/legacy/index.ts | 16 ++ .../test/licensing_plugin/legacy/updates.ts | 71 +++++++ x-pack/test/licensing_plugin/public/index.ts | 16 ++ .../test/licensing_plugin/public/updates.ts | 117 ++++++++++++ x-pack/test/licensing_plugin/scenario.ts | 87 +++++++++ .../{apis => server}/header.ts | 1 + .../{apis => server}/index.ts | 5 +- .../licensing_plugin/{apis => server}/info.ts | 1 + .../test/licensing_plugin/server/updates.ts | 81 ++++++++ 13 files changed, 436 insertions(+), 181 deletions(-) delete mode 100644 x-pack/test/licensing_plugin/apis/changes.ts create mode 100644 x-pack/test/licensing_plugin/config.legacy.ts create mode 100644 x-pack/test/licensing_plugin/config.public.ts create mode 100644 x-pack/test/licensing_plugin/legacy/index.ts create mode 100644 x-pack/test/licensing_plugin/legacy/updates.ts create mode 100644 x-pack/test/licensing_plugin/public/index.ts create mode 100644 x-pack/test/licensing_plugin/public/updates.ts create mode 100644 x-pack/test/licensing_plugin/scenario.ts rename x-pack/test/licensing_plugin/{apis => server}/header.ts (93%) rename x-pack/test/licensing_plugin/{apis => server}/index.ts (76%) rename x-pack/test/licensing_plugin/{apis => server}/info.ts (95%) create mode 100644 x-pack/test/licensing_plugin/server/updates.ts diff --git a/x-pack/test/licensing_plugin/apis/changes.ts b/x-pack/test/licensing_plugin/apis/changes.ts deleted file mode 100644 index 4fd7e0bef7052e..00000000000000 --- a/x-pack/test/licensing_plugin/apis/changes.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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'; - -const delay = (ms: number) => new Promise(res => setTimeout(res, ms)); - -export default function({ getService, getPageObjects }: FtrProviderContext) { - const supertest = getService('supertest'); - const esSupertestWithoutAuth = getService('esSupertestWithoutAuth'); - const security = getService('security'); - const PageObjects = getPageObjects(['common', 'security']); - const testSubjects = getService('testSubjects'); - - 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'); - }, - - async teardown() { - await security.role.delete('license_manager-role'); - }, - - 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); - }, - - 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 { - // > --xpack.licensing.api_polling_frequency set in test config - // to wait for Kibana server to re-fetch the license from Elasticsearch - await delay(1000); - - const { body } = await supertest.get('/api/licensing/info').expect(200); - return body; - }, - }; - - describe('changes in license types', () => { - after(async () => { - await scenario.startBasic(); - }); - - it('provides changes in license types', async () => { - await scenario.setup(); - const initialLicense = await scenario.getLicense(); - expect(initialLicense.license?.type).to.be('basic'); - // security enabled explicitly in test config - expect(initialLicense.features?.security).to.eql({ - isAvailable: true, - isEnabled: true, - }); - - const { - body: legacyInitialLicense, - headers: legacyInitialLicenseHeaders, - } = await supertest.get('/api/xpack/v1/info').expect(200); - - expect(legacyInitialLicense.license?.type).to.be('basic'); - expect(legacyInitialLicense.features).to.have.property('security'); - expect(legacyInitialLicenseHeaders['kbn-xpack-sig']).to.be.a('string'); - - // license hasn't changed - const refetchedLicense = await scenario.getLicense(); - expect(refetchedLicense.license?.type).to.be('basic'); - expect(refetchedLicense.signature).to.be(initialLicense.signature); - - const { - body: legacyRefetchedLicense, - headers: legacyRefetchedLicenseHeaders, - } = await supertest.get('/api/xpack/v1/info').expect(200); - - expect(legacyRefetchedLicense.license?.type).to.be('basic'); - expect(legacyRefetchedLicenseHeaders['kbn-xpack-sig']).to.be( - legacyInitialLicenseHeaders['kbn-xpack-sig'] - ); - - // server allows to request trial only once. - // other attempts will throw 403 - await scenario.startTrial(); - const trialLicense = await scenario.getLicense(); - expect(trialLicense.license?.type).to.be('trial'); - expect(trialLicense.signature).to.not.be(initialLicense.signature); - - expect(trialLicense.features?.security).to.eql({ - isAvailable: true, - isEnabled: true, - }); - - const { body: legacyTrialLicense, headers: legacyTrialLicenseHeaders } = await supertest - .get('/api/xpack/v1/info') - .expect(200); - - expect(legacyTrialLicense.license?.type).to.be('trial'); - expect(legacyTrialLicense.features).to.have.property('security'); - expect(legacyTrialLicenseHeaders['kbn-xpack-sig']).to.not.be( - legacyInitialLicenseHeaders['kbn-xpack-sig'] - ); - - await scenario.startBasic(); - const basicLicense = await scenario.getLicense(); - expect(basicLicense.license?.type).to.be('basic'); - expect(basicLicense.signature).not.to.be(initialLicense.signature); - - expect(basicLicense.features?.security).to.eql({ - isAvailable: true, - isEnabled: true, - }); - - const { body: legacyBasicLicense, headers: legacyBasicLicenseHeaders } = await supertest - .get('/api/xpack/v1/info') - .expect(200); - expect(legacyBasicLicense.license?.type).to.be('basic'); - expect(legacyBasicLicense.features).to.have.property('security'); - expect(legacyBasicLicenseHeaders['kbn-xpack-sig']).to.not.be( - legacyInitialLicenseHeaders['kbn-xpack-sig'] - ); - - await scenario.deleteLicense(); - const inactiveLicense = await scenario.getLicense(); - expect(inactiveLicense.signature).to.not.be(initialLicense.signature); - expect(inactiveLicense).to.not.have.property('license'); - expect(inactiveLicense.features?.security).to.eql({ - isAvailable: false, - isEnabled: true, - }); - // banner shown only when license expired not just deleted - await testSubjects.missingOrFail('licenseExpiredBanner'); - }); - }); -} diff --git a/x-pack/test/licensing_plugin/config.legacy.ts b/x-pack/test/licensing_plugin/config.legacy.ts new file mode 100644 index 00000000000000..27dc3df9944ad8 --- /dev/null +++ b/x-pack/test/licensing_plugin/config.legacy.ts @@ -0,0 +1,15 @@ +/* + * 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 commonConfig = await readConfigFile(require.resolve('./config')); + + return { + ...commonConfig.getAll(), + testFiles: [require.resolve('./legacy')], + }; +} diff --git a/x-pack/test/licensing_plugin/config.public.ts b/x-pack/test/licensing_plugin/config.public.ts new file mode 100644 index 00000000000000..01b0eefa32f2af --- /dev/null +++ b/x-pack/test/licensing_plugin/config.public.ts @@ -0,0 +1,26 @@ +/* + * 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 path from 'path'; +import { KIBANA_ROOT } from '@kbn/test'; +import { FtrConfigProviderContext } from '@kbn/test/types/ftr'; + +export default async function({ readConfigFile }: FtrConfigProviderContext) { + const commonConfig = await readConfigFile(require.resolve('./config')); + + return { + ...commonConfig.getAll(), + testFiles: [require.resolve('./public')], + kbnTestServer: { + serverArgs: [ + ...commonConfig.get('kbnTestServer.serverArgs'), + `--plugin-path=${path.resolve( + KIBANA_ROOT, + 'test/plugin_functional/plugins/core_provider_plugin' + )}`, + ], + }, + }; +} diff --git a/x-pack/test/licensing_plugin/config.ts b/x-pack/test/licensing_plugin/config.ts index 9a83a6f6b5a0b9..60d44cbd4c47fb 100644 --- a/x-pack/test/licensing_plugin/config.ts +++ b/x-pack/test/licensing_plugin/config.ts @@ -22,7 +22,7 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) { }; return { - testFiles: [require.resolve('./apis')], + testFiles: [require.resolve('./server')], servers, services, pageObjects, @@ -43,7 +43,7 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) { ...functionalTestsConfig.get('kbnTestServer'), serverArgs: [ ...functionalTestsConfig.get('kbnTestServer.serverArgs'), - '--xpack.licensing.api_polling_frequency=300', + '--xpack.licensing.api_polling_frequency=100', ], }, diff --git a/x-pack/test/licensing_plugin/legacy/index.ts b/x-pack/test/licensing_plugin/legacy/index.ts new file mode 100644 index 00000000000000..5c45b8f097baf0 --- /dev/null +++ b/x-pack/test/licensing_plugin/legacy/index.ts @@ -0,0 +1,16 @@ +/* + * 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 '../services'; + +// eslint-disable-next-line import/no-default-export +export default function({ loadTestFile }: FtrProviderContext) { + describe('Legacy licensing plugin', function() { + this.tags('ciGroup2'); + // MUST BE LAST! CHANGES LICENSE TYPE! + loadTestFile(require.resolve('./updates')); + }); +} diff --git a/x-pack/test/licensing_plugin/legacy/updates.ts b/x-pack/test/licensing_plugin/legacy/updates.ts new file mode 100644 index 00000000000000..cc1002e297cc6d --- /dev/null +++ b/x-pack/test/licensing_plugin/legacy/updates.ts @@ -0,0 +1,71 @@ +/* + * 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 { createScenario } from '../scenario'; +import '../../../../test/plugin_functional/plugins/core_provider_plugin/types'; + +// eslint-disable-next-line import/no-default-export +export default function(ftrContext: FtrProviderContext) { + const { getService } = ftrContext; + const supertest = getService('supertest'); + const testSubjects = getService('testSubjects'); + + const scenario = createScenario(ftrContext); + + describe('changes in license types', () => { + after(async () => { + await scenario.startBasic(); + }); + + it('provides changes in license types', async () => { + await scenario.setup(); + await scenario.waitForPluginToDetectLicenseUpdate(); + + const { + body: legacyInitialLicense, + headers: legacyInitialLicenseHeaders, + } = await supertest.get('/api/xpack/v1/info').expect(200); + + expect(legacyInitialLicense.license?.type).to.be('basic'); + expect(legacyInitialLicense.features).to.have.property('security'); + expect(legacyInitialLicenseHeaders['kbn-xpack-sig']).to.be.a('string'); + + // server allows to request trial only once. + // other attempts will throw 403 + await scenario.startTrial(); + await scenario.waitForPluginToDetectLicenseUpdate(); + + const { body: legacyTrialLicense, headers: legacyTrialLicenseHeaders } = await supertest + .get('/api/xpack/v1/info') + .expect(200); + + expect(legacyTrialLicense.license?.type).to.be('trial'); + expect(legacyTrialLicense.features).to.have.property('security'); + expect(legacyTrialLicenseHeaders['kbn-xpack-sig']).to.not.be( + legacyInitialLicenseHeaders['kbn-xpack-sig'] + ); + + await scenario.startBasic(); + await scenario.waitForPluginToDetectLicenseUpdate(); + + const { body: legacyBasicLicense, headers: legacyBasicLicenseHeaders } = await supertest + .get('/api/xpack/v1/info') + .expect(200); + expect(legacyBasicLicense.license?.type).to.be('basic'); + expect(legacyBasicLicense.features).to.have.property('security'); + expect(legacyBasicLicenseHeaders['kbn-xpack-sig']).to.not.be( + legacyInitialLicenseHeaders['kbn-xpack-sig'] + ); + + await scenario.deleteLicense(); + await scenario.waitForPluginToDetectLicenseUpdate(); + + // banner shown only when license expired not just deleted + await testSubjects.missingOrFail('licenseExpiredBanner'); + }); + }); +} diff --git a/x-pack/test/licensing_plugin/public/index.ts b/x-pack/test/licensing_plugin/public/index.ts new file mode 100644 index 00000000000000..3e1445d9a4aab6 --- /dev/null +++ b/x-pack/test/licensing_plugin/public/index.ts @@ -0,0 +1,16 @@ +/* + * 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 '../services'; + +// eslint-disable-next-line import/no-default-export +export default function({ loadTestFile }: FtrProviderContext) { + describe('Licensing plugin public client', function() { + this.tags('ciGroup2'); + // MUST BE LAST! CHANGES LICENSE TYPE! + loadTestFile(require.resolve('./updates')); + }); +} diff --git a/x-pack/test/licensing_plugin/public/updates.ts b/x-pack/test/licensing_plugin/public/updates.ts new file mode 100644 index 00000000000000..5d09400a412af2 --- /dev/null +++ b/x-pack/test/licensing_plugin/public/updates.ts @@ -0,0 +1,117 @@ +/* + * 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 { LicensingPluginSetup } from '../../../plugins/licensing/public'; +import { createScenario } from '../scenario'; +import '../../../../test/plugin_functional/plugins/core_provider_plugin/types'; + +// eslint-disable-next-line import/no-default-export +export default function(ftrContext: FtrProviderContext) { + const { getService } = ftrContext; + const testSubjects = getService('testSubjects'); + const browser = getService('browser'); + + const scenario = createScenario(ftrContext); + + describe('changes in license types', () => { + after(async () => { + await scenario.startBasic(); + }); + + it('provides changes in license types', async () => { + await scenario.setup(); + await scenario.waitForPluginToDetectLicenseUpdate(); + + expect( + await browser.executeAsync(async (cb: Function) => { + // this call enforces signature check to detect license update + // and causes license re-fetch + await window.np.setup.core.http.get('/'); + await window.np.testUtils.delay(100); + + const licensing: LicensingPluginSetup = window.np.setup.plugins.licensing; + let licenseType; + licensing.license$.subscribe(license => (licenseType = license.type)); + cb(licenseType); + }) + ).to.be('basic'); + + // license hasn't changed + await scenario.waitForPluginToDetectLicenseUpdate(); + + expect( + await browser.executeAsync(async (cb: Function) => { + // this call enforces signature check to detect license update + // and causes license re-fetch + await window.np.setup.core.http.get('/'); + await window.np.testUtils.delay(100); + + const licensing: LicensingPluginSetup = window.np.setup.plugins.licensing; + let licenseType; + licensing.license$.subscribe(license => (licenseType = license.type)); + cb(licenseType); + }) + ).to.be('basic'); + + // server allows to request trial only once. + // other attempts will throw 403 + await scenario.startTrial(); + await scenario.waitForPluginToDetectLicenseUpdate(); + + expect( + await browser.executeAsync(async (cb: Function) => { + // this call enforces signature check to detect license update + // and causes license re-fetch + await window.np.setup.core.http.get('/'); + await window.np.testUtils.delay(100); + + const licensing: LicensingPluginSetup = window.np.setup.plugins.licensing; + let licenseType; + licensing.license$.subscribe(license => (licenseType = license.type)); + cb(licenseType); + }) + ).to.be('trial'); + + await scenario.startBasic(); + await scenario.waitForPluginToDetectLicenseUpdate(); + + expect( + await browser.executeAsync(async (cb: Function) => { + // this call enforces signature check to detect license update + // and causes license re-fetch + await window.np.setup.core.http.get('/'); + await window.np.testUtils.delay(100); + + const licensing: LicensingPluginSetup = window.np.setup.plugins.licensing; + let licenseType; + licensing.license$.subscribe(license => (licenseType = license.type)); + cb(licenseType); + }) + ).to.be('basic'); + + await scenario.deleteLicense(); + await scenario.waitForPluginToDetectLicenseUpdate(); + + expect( + await browser.executeAsync(async (cb: Function) => { + // this call enforces signature check to detect license update + // and causes license re-fetch + await window.np.setup.core.http.get('/'); + await window.np.testUtils.delay(100); + + const licensing: LicensingPluginSetup = window.np.setup.plugins.licensing; + let licenseType; + licensing.license$.subscribe(license => (licenseType = license.type)); + cb(licenseType); + }) + ).to.be(null); + + // banner shown only when license expired not just deleted + await testSubjects.missingOrFail('licenseExpiredBanner'); + }); + }); +} diff --git a/x-pack/test/licensing_plugin/scenario.ts b/x-pack/test/licensing_plugin/scenario.ts new file mode 100644 index 00000000000000..47d8ae63131a9c --- /dev/null +++ b/x-pack/test/licensing_plugin/scenario.ts @@ -0,0 +1,87 @@ +/* + * 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'); + }, + + async teardown() { + await security.role.delete('license_manager-role'); + }, + + 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); + }, + + 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 { + 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; +} diff --git a/x-pack/test/licensing_plugin/apis/header.ts b/x-pack/test/licensing_plugin/server/header.ts similarity index 93% rename from x-pack/test/licensing_plugin/apis/header.ts rename to x-pack/test/licensing_plugin/server/header.ts index 8d95054feaaf23..d2073e8773f185 100644 --- a/x-pack/test/licensing_plugin/apis/header.ts +++ b/x-pack/test/licensing_plugin/server/header.ts @@ -7,6 +7,7 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../services'; +// eslint-disable-next-line import/no-default-export export default function({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test/licensing_plugin/apis/index.ts b/x-pack/test/licensing_plugin/server/index.ts similarity index 76% rename from x-pack/test/licensing_plugin/apis/index.ts rename to x-pack/test/licensing_plugin/server/index.ts index fbc0449dcd8fcf..374bfcc0aa6b4a 100644 --- a/x-pack/test/licensing_plugin/apis/index.ts +++ b/x-pack/test/licensing_plugin/server/index.ts @@ -6,13 +6,14 @@ import { FtrProviderContext } from '../services'; +// eslint-disable-next-line import/no-default-export export default function({ loadTestFile }: FtrProviderContext) { - describe('Licensing plugin', function() { + describe('Licensing plugin server client', function() { this.tags('ciGroup2'); loadTestFile(require.resolve('./info')); loadTestFile(require.resolve('./header')); // MUST BE LAST! CHANGES LICENSE TYPE! - loadTestFile(require.resolve('./changes')); + loadTestFile(require.resolve('./updates')); }); } diff --git a/x-pack/test/licensing_plugin/apis/info.ts b/x-pack/test/licensing_plugin/server/info.ts similarity index 95% rename from x-pack/test/licensing_plugin/apis/info.ts rename to x-pack/test/licensing_plugin/server/info.ts index 7ec009d85cd094..cce042c718b7b0 100644 --- a/x-pack/test/licensing_plugin/apis/info.ts +++ b/x-pack/test/licensing_plugin/server/info.ts @@ -7,6 +7,7 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../services'; +// eslint-disable-next-line import/no-default-export export default function({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test/licensing_plugin/server/updates.ts b/x-pack/test/licensing_plugin/server/updates.ts new file mode 100644 index 00000000000000..2994dc5de5b079 --- /dev/null +++ b/x-pack/test/licensing_plugin/server/updates.ts @@ -0,0 +1,81 @@ +/* + * 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 { LicensingPluginSetup } from '../../../plugins/licensing/public'; +import { createScenario } from '../scenario'; +import '../../../../test/plugin_functional/plugins/core_provider_plugin/types'; + +// eslint-disable-next-line import/no-default-export +export default function(ftrContext: FtrProviderContext) { + const { getService } = ftrContext; + const supertest = getService('supertest'); + const testSubjects = getService('testSubjects'); + const browser = getService('browser'); + + const scenario = createScenario(ftrContext); + + describe('changes in license types', () => { + after(async () => { + await scenario.startBasic(); + }); + + it('provides changes in license types', async () => { + await scenario.setup(); + await scenario.waitForPluginToDetectLicenseUpdate(); + const initialLicense = await scenario.getLicense(); + expect(initialLicense.license?.type).to.be('basic'); + // security enabled explicitly in test config + expect(initialLicense.features?.security).to.eql({ + isAvailable: true, + isEnabled: true, + }); + + // license hasn't changed + await scenario.waitForPluginToDetectLicenseUpdate(); + const refetchedLicense = await scenario.getLicense(); + expect(refetchedLicense.license?.type).to.be('basic'); + expect(refetchedLicense.signature).to.be(initialLicense.signature); + + // server allows to request trial only once. + // other attempts will throw 403 + await scenario.startTrial(); + await scenario.waitForPluginToDetectLicenseUpdate(); + const trialLicense = await scenario.getLicense(); + expect(trialLicense.license?.type).to.be('trial'); + expect(trialLicense.signature).to.not.be(initialLicense.signature); + + expect(trialLicense.features?.security).to.eql({ + isAvailable: true, + isEnabled: true, + }); + + await scenario.startBasic(); + await scenario.waitForPluginToDetectLicenseUpdate(); + const basicLicense = await scenario.getLicense(); + expect(basicLicense.license?.type).to.be('basic'); + expect(basicLicense.signature).not.to.be(initialLicense.signature); + + expect(basicLicense.features?.security).to.eql({ + isAvailable: true, + isEnabled: true, + }); + + await scenario.deleteLicense(); + await scenario.waitForPluginToDetectLicenseUpdate(); + const inactiveLicense = await scenario.getLicense(); + expect(inactiveLicense.signature).to.not.be(initialLicense.signature); + expect(inactiveLicense).to.not.have.property('license'); + expect(inactiveLicense.features?.security).to.eql({ + isAvailable: false, + isEnabled: true, + }); + + // banner shown only when license expired not just deleted + await testSubjects.missingOrFail('licenseExpiredBanner'); + }); + }); +}