Skip to content

Commit

Permalink
NP licensing plugin improvements (#51818)
Browse files Browse the repository at this point in the history
* add onPreResponse interceptor

* use onPreResponse interceptor to add license sign

* expose registerPreResponse to plugins

* refresh for license update get the most fresh license

* license plugin injects own header for signature:  'kbn-license-sig'

* add integration tests for license type and license header

* switch config to duration

* don't run interceptor on anon paths. add tests

* add functional tests for licensing plugin

* regen docs

* fix test in security due to updated mocks;

* update snapshots accoring to new mock implementation

* migrate license expired banner to NP

* add readme for the licensing plugin

* remove outdated import. licensing has separate functional tests

* add tag for test to run on CI

* regen docs

* Update x-pack/plugins/licensing/README.md

Co-Authored-By: Josh Dover <me@joshdover.com>

* update tests
  • Loading branch information
mshustov authored Dec 9, 2019
1 parent b66af16 commit dce893b
Show file tree
Hide file tree
Showing 33 changed files with 798 additions and 417 deletions.
1 change: 1 addition & 0 deletions src/core/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ In server code, `core` can be accessed from either `server.newPlatform` or `kbnS
| `request.getBasePath()` | [`core.http.basePath.get`](/docs/development/core/server/kibana-plugin-server.httpservicesetup.basepath.md) | |
| `server.plugins.elasticsearch.getCluster('data')` | [`core.elasticsearch.dataClient$`](/docs/development/core/server/kibana-plugin-server.elasticsearchservicesetup.dataclient_.md) | Handlers will also include a pre-configured client |
| `server.plugins.elasticsearch.getCluster('admin')` | [`core.elasticsearch.adminClient$`](/docs/development/core/server/kibana-plugin-server.elasticsearchservicesetup.adminclient_.md) | Handlers will also include a pre-configured client |
| `xpackMainPlugin.info.feature(pluginID).registerLicenseCheckResultsGenerator` | [`x-pack licensing plugin`](/x-pack/plugins/licensing/README.md) | |
_See also: [Server's CoreSetup API Docs](/docs/development/core/server/kibana-plugin-server.coresetup.md)_

Expand Down
7 changes: 5 additions & 2 deletions src/core/public/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { HttpService } from './http_service';
import { HttpSetup } from './types';
import { BehaviorSubject } from 'rxjs';
import { BasePath } from './base_path_service';
import { AnonymousPaths } from './anonymous_paths';

export type HttpSetupMock = jest.Mocked<HttpSetup> & {
basePath: BasePath;
anonymousPaths: jest.Mocked<HttpSetup['anonymousPaths']>;
};

const createServiceMock = ({ basePath = '' } = {}): HttpSetupMock => ({
Expand All @@ -37,7 +37,10 @@ const createServiceMock = ({ basePath = '' } = {}): HttpSetupMock => ({
delete: jest.fn(),
options: jest.fn(),
basePath: new BasePath(basePath),
anonymousPaths: new AnonymousPaths(new BasePath(basePath)),
anonymousPaths: {
register: jest.fn(),
isAnonymous: jest.fn(),
},
addLoadingCount: jest.fn(),
getLoadingCount$: jest.fn().mockReturnValue(new BehaviorSubject(0)),
stop: jest.fn(),
Expand Down
6 changes: 3 additions & 3 deletions src/core/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { applicationServiceMock } from './application/application_service.mock';
import { chromeServiceMock } from './chrome/chrome_service.mock';
import { CoreContext, CoreSetup, CoreStart, PluginInitializerContext, NotificationsSetup } from '.';
import { CoreContext, PluginInitializerContext } from '.';
import { docLinksServiceMock } from './doc_links/doc_links_service.mock';
import { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
import { httpServiceMock } from './http/http_service.mock';
Expand All @@ -42,7 +42,7 @@ export { overlayServiceMock } from './overlays/overlay_service.mock';
export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';

function createCoreSetupMock({ basePath = '' } = {}) {
const mock: MockedKeys<CoreSetup> & { notifications: MockedKeys<NotificationsSetup> } = {
const mock = {
application: applicationServiceMock.createSetupContract(),
context: contextServiceMock.createSetupContract(),
fatalErrors: fatalErrorsServiceMock.createSetupContract(),
Expand All @@ -58,7 +58,7 @@ function createCoreSetupMock({ basePath = '' } = {}) {
}

function createCoreStartMock({ basePath = '' } = {}) {
const mock: MockedKeys<CoreStart> & { notifications: MockedKeys<NotificationsSetup> } = {
const mock = {
application: applicationServiceMock.createStartContract(),
chrome: chromeServiceMock.createStartContract(),
docLinks: docLinksServiceMock.createStartContract(),
Expand Down
6 changes: 6 additions & 0 deletions src/core/server/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { OnPreAuthToolkit } from './lifecycle/on_pre_auth';
import { AuthToolkit } from './lifecycle/auth';
import { sessionStorageMock } from './cookie_session_storage.mocks';
import { OnPostAuthToolkit } from './lifecycle/on_post_auth';
import { OnPreResponseToolkit } from './lifecycle/on_pre_response';

export type HttpServiceSetupMock = jest.Mocked<InternalHttpServiceSetup> & {
basePath: jest.Mocked<InternalHttpServiceSetup['basePath']>;
Expand Down Expand Up @@ -93,12 +94,17 @@ const createAuthToolkitMock = (): jest.Mocked<AuthToolkit> => ({
authenticated: jest.fn(),
});

const createOnPreResponseToolkitMock = (): jest.Mocked<OnPreResponseToolkit> => ({
next: jest.fn(),
});

export const httpServiceMock = {
create: createHttpServiceMock,
createBasePath: createBasePathMock,
createSetupContract: createSetupContractMock,
createOnPreAuthToolkit: createOnPreAuthToolkitMock,
createOnPostAuthToolkit: createOnPostAuthToolkitMock,
createOnPreResponseToolkit: createOnPreResponseToolkitMock,
createAuthToolkit: createAuthToolkitMock,
createRouter: mockRouter.create,
};
1 change: 0 additions & 1 deletion src/core/server/http/integration_tests/lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,6 @@ describe('OnPreResponse', () => {
headers: { 'x-kibana-header': 'value' },
})
);

registerOnPreResponse((req, res, t) =>
t.next({
headers: { 'x-kibana-header': 'value' },
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions x-pack/legacy/plugins/xpack_main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ export const xpackMain = (kibana) => {
},

uiExports: {
hacks: [
'plugins/xpack_main/hacks/check_xpack_info_change',
],
replaceInjectedVars,
injectDefaultVars(server) {
const config = server.config();
Expand Down

This file was deleted.

Loading

0 comments on commit dce893b

Please sign in to comment.