Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly recognize enterprise licenses #85849

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Comment on lines +79 to +80
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test will break in 2 years, but we don't have any dev license with a longer lifespan. Should I create an issue or write this down somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈 We can schedule a slackbot reminder for 2022-12-01?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can store it in a separate file to import in a script to run validation. Not a blocker for the current PR.

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 () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the file affects the environment already, so it's fine

await scenario.startEnterprise();
await scenario.waitForPluginToDetectLicenseUpdate();

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