Skip to content

Commit

Permalink
properly recognize enterprise licenses (#85849) (#85921)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet authored Dec 15, 2020
1 parent 6726a72 commit d3ce8ae
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
19 changes: 19 additions & 0 deletions x-pack/plugins/licensing/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/licensing/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class LicensingPlugin implements Plugin<LicensingPluginSetup, LicensingPl
try {
const response = await clusterClient.callAsInternalUser('transport.request', {
method: 'GET',
path: '/_xpack',
path: '/_xpack?accept_enterprise=true',
});

const normalizedLicense = response.license
Expand Down
25 changes: 25 additions & 0 deletions x-pack/test/licensing_plugin/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,31 @@ export function createScenario({ getService, getPageObjects }: FtrProviderContex
expect(response.body.trial_was_started).to.be(true);
},

async startEnterprise() {
const response = await esSupertestWithoutAuth
.post('/_license/?acknowledge=true')
.send({
license: {
uid: '00000000-d3ad-7357-c0d3-000000000000',
type: 'enterprise',
issue_date_in_millis: 1577836800000,
start_date_in_millis: 1577836800000,
// expires 2022-12-31
expiry_date_in_millis: 1672531199999,
max_resource_units: 250,
max_nodes: null,
issued_to: 'Elastic Internal Use (development environments)',
issuer: 'Elastic',
signature:
'AAAABQAAAA1gHUVis7hel8b8nNCAAAAAIAo5/x6hrsGh1GqqrJmy4qgmEC7gK0U4zQ6q5ZEMhm4jAAABAKMR+w3KZsMJfG5jNWgZXJLwRmiNqN7k94vKFgRdj1yM+gA9ufhXIn9d01OvFhPjilIqm+fxVjCxXwGKbFRiwtTWnTYjXPuNml+qCFGgUWguWEcVoIW6VU7/lYOqMJ4EB4zOMLe93P267iaDm542aelQrW1OJ69lGGuPBik8v9r1bNZzKBQ99VUr/qoosGDAm0udh2HxWzYoCL5lDML5Niy87xlVCubSSBXdUXzUgdZKKk6pKaMdHswB1gjvEfnwqPxEWAyrV0BCr/T1WehXd7U4p6/zt6sJ6cPh+34AZe9g4+3WPKrZhX4iaSHMDDHn4HNjO72CZ2oi42ZDNnJ37tA=',
},
})
.auth('license_manager_user', 'license_manager_user-password')
.expect(200);

expect(response.body.license_status).to.be('valid');
},

async deleteLicense() {
const response = await esSupertestWithoutAuth
.delete('/_license')
Expand Down
8 changes: 8 additions & 0 deletions x-pack/test/licensing_plugin/server/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,13 @@ export default function (ftrContext: FtrProviderContext) {
// banner shown only when license expired not just deleted
await testSubjects.missingOrFail('licenseExpiredBanner');
});

it('properly recognize an enterprise license', async () => {
await scenario.startEnterprise();
await scenario.waitForPluginToDetectLicenseUpdate();

const enterpriseLicense = await scenario.getLicense();
expect(enterpriseLicense.license?.type).to.be('enterprise');
});
});
}

0 comments on commit d3ce8ae

Please sign in to comment.