Skip to content

Commit

Permalink
License Management to New Platform (elastic#51886)
Browse files Browse the repository at this point in the history
* License Management public -> NP

* - Server to NP
- Slight update to filepicker style (center it)

* Fix snapshots and types

* Server-side: separate new and legacy dependencies [skip ci]

* Fix license upload route after refactor

* Client side: separate new from legacy dependencies

* xpackInfo -> xPackInfo

* Fix types [skip ci]

* Remove kbnUrl, autoLogout. Add history and update paths.

* Update upload license test

* Remove use of legacy chrome, remove use of k7breadcrumbs, replace some common strings with variable and use NP i18n
  • Loading branch information
jloleysens authored Dec 9, 2019
1 parent 3d2db42 commit 3d36356
Show file tree
Hide file tree
Showing 93 changed files with 1,349 additions and 907 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AddLicense } from '../public/sections/license_dashboard/add_license';
import { AddLicense } from '../public/np_ready/application/sections/license_dashboard/add_license';
import { createMockLicense, getComponent } from './util';
jest.mock(`@elastic/eui/lib/components/form/form_row/make_id`, () => () => `generated-id`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { LicenseStatus } from '../public/sections/license_dashboard/license_status';
import { LicenseStatus } from '../public/np_ready/application/sections/license_dashboard/license_status';
import { createMockLicense, getComponent } from './util';

describe('LicenseStatus component', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { RequestTrialExtension } from '../public/sections/license_dashboard/request_trial_extension';
import { RequestTrialExtension } from '../public/np_ready/application/sections/license_dashboard/request_trial_extension';
import { createMockLicense, getComponent } from './util';
jest.mock(`@elastic/eui/lib/components/form/form_row/make_id`, () => () => `generated-id`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { RevertToBasic } from '../public/sections/license_dashboard/revert_to_basic';
import { RevertToBasic } from '../public/np_ready/application/sections/license_dashboard/revert_to_basic';
import { createMockLicense, getComponent } from './util';
jest.mock(`@elastic/eui/lib/components/form/form_row/make_id`, () => () => `generated-id`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { StartTrial } from '../public/sections/license_dashboard/start_trial';
import { StartTrial } from '../public/np_ready/application/sections/license_dashboard/start_trial';
import { createMockLicense, getComponent } from './util';
jest.mock(`@elastic/eui/lib/components/form/form_row/make_id`, () => () => `generated-id`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import { setTelemetryEnabled, setTelemetryOptInService } from '../public/lib/telemetry';
import { TelemetryOptIn } from '../public/components/telemetry_opt_in';
import { setTelemetryEnabled, setTelemetryOptInService } from '../public/np_ready/application/lib/telemetry';
import { TelemetryOptIn } from '../public/np_ready/application/components/telemetry_opt_in';
import { mountWithIntl } from '../../../../test_utils/enzyme_helpers';

jest.mock('ui/capabilities', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,101 +4,113 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { httpServiceMock, chromeServiceMock } from '../../../../../src/core/public/mocks';
import { mountWithIntl } from '../../../../test_utils/enzyme_helpers';
import React from 'react';
import { Provider } from 'react-redux';
import { uploadLicense } from '../public/store/actions/upload_license';
import { licenseManagementStore } from '../public/store/store';
import { UploadLicense } from '../public/sections/upload_license';
import { BASE_PATH } from '../common/constants';

// @ts-ignore
import { uploadLicense } from '../public/np_ready/application/store/actions/upload_license';

// @ts-ignore
import { licenseManagementStore } from '../public/np_ready/application/store/store';

// @ts-ignore
import { UploadLicense } from '../public/np_ready/application/sections/upload_license';

import {
UPLOAD_LICENSE_EXPIRED,
UPLOAD_LICENSE_REQUIRES_ACK,
UPLOAD_LICENSE_SUCCESS,
UPLOAD_LICENSE_TLS_NOT_ENABLED,
UPLOAD_LICENSE_INVALID,
// @ts-ignore
} from './api_responses';

import sinon from 'sinon';
window.location.reload = () => {};
let server = null;
let store = null;
let component = null;

let store: any = null;
let component: any = null;
const services = {
kbnUrl: {
change: jest.fn()
legacy: {
xPackInfo: {
refresh: jest.fn(),
get: () => {
return { license: { type: 'basic' } };
},
},
refreshXpack: jest.fn(),
},
http: httpServiceMock.createSetupContract(),
chrome: chromeServiceMock.createStartContract(),
history: {
replace: jest.fn(),
},
autoLogout: () => {},
xPackInfo: {
refresh: jest.fn(),
get: () => {
return { license: { type: 'basic' } };
}
}
};

describe('UploadLicense', () => {
beforeEach(() => {
server = sinon.fakeServer.create();
server.respondImmediately = true;
store = licenseManagementStore({}, services);
component = (
<Provider store={store}>
<UploadLicense />
</Provider>
);
});

afterEach(() => {
server.restore();
services.xPackInfo.refresh.mockReset();
services.kbnUrl.change.mockReset();
services.legacy.xPackInfo.refresh.mockReset();
services.history.replace.mockReset();
jest.clearAllMocks();
});

it('should display an error when submitting invalid JSON', async () => {
const rendered = mountWithIntl(component);
store.dispatch(uploadLicense('INVALID', 'trial'));
rendered.update();
expect(rendered).toMatchSnapshot();
});

it('should display an error when ES says license is invalid', async () => {
services.http.put.mockResolvedValue(JSON.parse(UPLOAD_LICENSE_INVALID[2]));
const rendered = mountWithIntl(component);
const invalidLicense = JSON.stringify({ license: { type: 'basic' } });
server.respond(UPLOAD_LICENSE_INVALID);
await uploadLicense(invalidLicense)(store.dispatch, null, services);
rendered.update();
expect(rendered).toMatchSnapshot();
});

it('should display an error when ES says license is expired', async () => {
services.http.put.mockResolvedValue(JSON.parse(UPLOAD_LICENSE_EXPIRED[2]));
const rendered = mountWithIntl(component);
const invalidLicense = JSON.stringify({ license: { type: 'basic' } });
server.respond(UPLOAD_LICENSE_EXPIRED);
await uploadLicense(invalidLicense)(store.dispatch, null, services);
rendered.update();
expect(rendered).toMatchSnapshot();
});

it('should display a modal when license requires acknowledgement', async () => {
services.http.put.mockResolvedValue(JSON.parse(UPLOAD_LICENSE_REQUIRES_ACK[2]));
const unacknowledgedLicense = JSON.stringify({
license: { type: 'basic' }
license: { type: 'basic' },
});
server.respond(UPLOAD_LICENSE_REQUIRES_ACK);
await uploadLicense(unacknowledgedLicense, 'trial')(
store.dispatch,
null,
services
);
await uploadLicense(unacknowledgedLicense, 'trial')(store.dispatch, null, services);
const rendered = mountWithIntl(component);
expect(rendered).toMatchSnapshot();
});

it('should refresh xpack info and navigate to BASE_PATH when ES accepts new license', async () => {
services.http.put.mockResolvedValue(JSON.parse(UPLOAD_LICENSE_SUCCESS[2]));
const validLicense = JSON.stringify({ license: { type: 'basic' } });
server.respond(UPLOAD_LICENSE_SUCCESS);
await uploadLicense(validLicense)(store.dispatch, null, services);
expect(services.xPackInfo.refresh).toHaveBeenCalled();
expect(services.kbnUrl.change).toHaveBeenCalledWith(BASE_PATH);
expect(services.legacy.refreshXpack).toHaveBeenCalled();
expect(services.history.replace).toHaveBeenCalled();
});

it('should display error when ES returns error', async () => {
services.http.put.mockResolvedValue(JSON.parse(UPLOAD_LICENSE_TLS_NOT_ENABLED[2]));
const rendered = mountWithIntl(component);
const license = JSON.stringify({ license: { type: 'basic' } });
server.respond(UPLOAD_LICENSE_TLS_NOT_ENABLED);
await uploadLicense(license)(store.dispatch, null, services);
rendered.update();
expect(rendered).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/

import { Provider } from 'react-redux';
import { licenseManagementStore } from '../../public/store/store';
import { licenseManagementStore } from '../../public/np_ready/application/store/store';
import React from 'react';
import { mountWithIntl } from '../../../../../test_utils/enzyme_helpers';
import { httpServiceMock } from '../../../../../../src/core/public/mocks';

const highExpirationMillis = new Date('October 13, 2099 00:00:00Z').getTime();

Expand All @@ -22,7 +23,10 @@ export const createMockLicense = (
};
};
export const getComponent = (initialState, Component) => {
const store = licenseManagementStore(initialState);
const services = {
http: httpServiceMock.createSetupContract()
};
const store = licenseManagementStore(initialState, services);
return mountWithIntl(
<Provider store={store}>
<Component />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ const ELASTIC_BASE_URL = 'https://www.elastic.co/';
export const EXTERNAL_LINKS = {
SUBSCRIPTIONS: `${ELASTIC_BASE_URL}subscriptions`,
TRIAL_EXTENSION: `${ELASTIC_BASE_URL}trialextension`,
TRIAL_LICENSE: `${ELASTIC_BASE_URL}legal/trial_license`
TRIAL_LICENSE: `${ELASTIC_BASE_URL}legal/trial_license`,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { i18n } from '@kbn/i18n';

export const PLUGIN = {
TITLE: i18n.translate('xpack.licenseMgmt.managementSectionDisplayName', {
defaultMessage: 'License Management',
}),
ID: 'license_management',
};
38 changes: 0 additions & 38 deletions x-pack/legacy/plugins/license_management/index.js

This file was deleted.

32 changes: 32 additions & 0 deletions x-pack/legacy/plugins/license_management/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { resolve } from 'path';
import { PLUGIN } from './common/constants';
import { Legacy } from '../../../../kibana';
import { plugin } from './server/np_ready';

export function licenseManagement(kibana: any) {
return new kibana.Plugin({
id: PLUGIN.ID,
configPrefix: 'xpack.license_management',
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch'],
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/np_ready/application/index.scss'),
managementSections: ['plugins/license_management/legacy'],
},
init: (server: Legacy.Server) => {
plugin({} as any).setup(server.newPlatform.setup.core, {
...server.newPlatform.setup.plugins,
__LEGACY: {
xpackMain: server.plugins.xpack_main,
elasticsearch: server.plugins.elasticsearch,
},
});
},
});
}
71 changes: 0 additions & 71 deletions x-pack/legacy/plugins/license_management/public/lib/es.js

This file was deleted.

3 changes: 0 additions & 3 deletions x-pack/legacy/plugins/license_management/public/main.html

This file was deleted.

Loading

0 comments on commit 3d36356

Please sign in to comment.