properly recognize enterprise licenses (#85849)

This commit is contained in:
Pierre Gayvallet 2020-12-15 10:26:43 +01:00 committed by GitHub
parent 5febe5fa7e
commit bd7e7090a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 1 deletions

View file

@ -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'];

View file

@ -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

View file

@ -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')

View file

@ -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');
});
});
}