From d3ce8ae568bfd763ece653a9a3c45c77e8374c31 Mon Sep 17 00:00:00 2001 From: Pierre Gayvallet Date: Tue, 15 Dec 2020 13:15:12 +0100 Subject: [PATCH] properly recognize enterprise licenses (#85849) (#85921) --- .../plugins/licensing/server/plugin.test.ts | 19 ++++++++++++++ x-pack/plugins/licensing/server/plugin.ts | 2 +- x-pack/test/licensing_plugin/scenario.ts | 25 +++++++++++++++++++ .../test/licensing_plugin/server/updates.ts | 8 ++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/licensing/server/plugin.test.ts b/x-pack/plugins/licensing/server/plugin.test.ts index b1669db00f227..7aec81f84f978 100644 --- a/x-pack/plugins/licensing/server/plugin.test.ts +++ b/x-pack/plugins/licensing/server/plugin.test.ts @@ -81,6 +81,25 @@ describe('licensing plugin', () => { expect(license.isAvailable).toBe(true); }); + it('calls `callAsInternalUser` with the correct parameters', async () => { + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); + esClient.callAsInternalUser.mockResolvedValue({ + license: buildRawLicense(), + features: {}, + }); + + const coreSetup = createCoreSetupWith(esClient); + await plugin.setup(coreSetup); + const { license$ } = await plugin.start(); + await license$.pipe(take(1)).toPromise(); + + expect(esClient.callAsInternalUser).toHaveBeenCalledTimes(1); + expect(esClient.callAsInternalUser).toHaveBeenCalledWith('transport.request', { + method: 'GET', + path: '/_xpack?accept_enterprise=true', + }); + }); + it('observable receives updated licenses', async () => { const types: LicenseType[] = ['basic', 'gold', 'platinum']; diff --git a/x-pack/plugins/licensing/server/plugin.ts b/x-pack/plugins/licensing/server/plugin.ts index 2ee8d26419571..3823f251fb7fb 100644 --- a/x-pack/plugins/licensing/server/plugin.ts +++ b/x-pack/plugins/licensing/server/plugin.ts @@ -182,7 +182,7 @@ export class LicensingPlugin implements Plugin { + await scenario.startEnterprise(); + await scenario.waitForPluginToDetectLicenseUpdate(); + + const enterpriseLicense = await scenario.getLicense(); + expect(enterpriseLicense.license?.type).to.be('enterprise'); + }); }); }