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

Licensing plugin #49345

Merged
merged 44 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6e96f55
Add x-pack plugin for new platform browser licensing information
eliperelman Sep 5, 2019
8d088cb
Address next round of reviews
eliperelman Sep 27, 2019
d0814c1
Remove poller functionality in favor of inline observables
eliperelman Oct 1, 2019
d43abcf
More observable changes from review comments
eliperelman Oct 2, 2019
fe3a08d
Fix outstanding tests
eliperelman Oct 3, 2019
258ce8d
More changes from review, adding additional testing
eliperelman Oct 7, 2019
0443de0
Add additional tests for license comparisons and sessions
eliperelman Oct 8, 2019
6f30fec
Update test snapshot due to sessionstorage mock
eliperelman Oct 8, 2019
3f3210e
Next round of review feedback from restrry
eliperelman Oct 9, 2019
86983f8
Fix more review requests from restrry, add additional tests
eliperelman Oct 10, 2019
9d20c1f
Pass correct sign mock to license info changed test
eliperelman Oct 10, 2019
1cb0900
Improve doc comments, switch to I-interface pattern
eliperelman Oct 14, 2019
84df2a8
Test error polling sanity, do not expose signature, do not poll on cl…
eliperelman Oct 15, 2019
a4678bc
Fix type check issues from rebase
eliperelman Oct 17, 2019
9f7892d
Fix build error from rebase
eliperelman Oct 18, 2019
d17aa56
minimize config
mshustov Oct 25, 2019
80b873a
move all types to server with consistency with other code
mshustov Oct 25, 2019
3bccb47
implement License
mshustov Oct 25, 2019
532fc9c
implement license update & refactor has License changed check
mshustov Oct 25, 2019
40f238a
update tests for licensing extending route handler context
mshustov Oct 25, 2019
74f2f13
update testing harness
mshustov Oct 25, 2019
47ea081
implement client side side license plugin
mshustov Oct 25, 2019
a76af93
implement server side licensing plugin
mshustov Oct 25, 2019
7fefe4d
remove old code
mshustov Oct 25, 2019
2dfaedb
update types for license status
mshustov Oct 25, 2019
c3aca1b
remove jest-localstorage-mock
mshustov Oct 25, 2019
9f0e3e9
Merge branch 'master' into pr/44922
mshustov Oct 25, 2019
b31262d
fix tests
mshustov Oct 29, 2019
10d1d20
Merge branch 'master' into pr/44922
mshustov Oct 29, 2019
83e1204
Merge branch 'master' into pr/44922
mshustov Nov 13, 2019
2e3cf89
update license in security
mshustov Nov 13, 2019
727a685
address comments. first pass
mshustov Nov 13, 2019
184c892
error is a part of signature. pass error message to License
mshustov Nov 13, 2019
883e79e
move common license types under common folder
mshustov Nov 13, 2019
f9fad7c
rename feature props for BWC and unify name with ILicense
mshustov Nov 13, 2019
af46c8b
Merge branch 'master' into pr/44922
mshustov Nov 14, 2019
bdb6785
test should work in any timezone
mshustov Nov 14, 2019
f9a04b2
make prettier happy
mshustov Nov 14, 2019
f73ed6d
remove obsolete comment
mshustov Nov 14, 2019
94c5509
Merge branch 'master' into pr/44922
mshustov Nov 18, 2019
1e06de4
address Pierre comments
mshustov Nov 18, 2019
1798239
use sha256 for security reasons
mshustov Nov 18, 2019
41b4935
use stable stringify to avoid churn
mshustov Nov 19, 2019
85f54eb
Merge branch 'master' into pr/44922
mshustov Nov 19, 2019
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
13 changes: 13 additions & 0 deletions src/core/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,22 @@ function createCoreContext(): CoreContext {
};
}

function createStorageMock() {
const storageMock: jest.Mocked<Storage> = {
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),
clear: jest.fn(),
key: jest.fn(),
length: 10,
};
return storageMock;
}

export const coreMock = {
createCoreContext,
createSetup: createCoreSetupMock,
createStart: createCoreStartMock,
createPluginInitializerContext: pluginInitializerContextMock,
createStorage: createStorageMock,
};
71 changes: 0 additions & 71 deletions src/core/utils/poller.test.ts

This file was deleted.

55 changes: 0 additions & 55 deletions src/core/utils/poller.ts

This file was deleted.

93 changes: 93 additions & 0 deletions x-pack/plugins/licensing/common/has_license_info_changed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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 { License } from './license';
import { PublicLicense } from './types';
import { hasLicenseInfoChanged } from './has_license_info_changed';

function license({ error, ...customLicense }: { error?: string; [key: string]: any } = {}) {
const defaultLicense: PublicLicense = {
uid: 'uid-000000001234',
status: 'active',
type: 'basic',
expiryDateInMillis: 1000,
};

return new License({
error,
license: Object.assign(defaultLicense, customLicense),
signature: 'aaaaaaa',
});
}

// Each test should ensure that left-to-right and right-to-left comparisons are captured.
describe('has license info changed', () => {
describe('License', () => {
test('undefined <-> License', async () => {
expect(hasLicenseInfoChanged(undefined, license())).toBe(true);
});

test('the same License', async () => {
const licenseInstance = license();
expect(hasLicenseInfoChanged(licenseInstance, licenseInstance)).toBe(false);
});

test('type License <-> type License | mismatched type', async () => {
expect(hasLicenseInfoChanged(license({ type: 'basic' }), license({ type: 'gold' }))).toBe(
true
);
expect(hasLicenseInfoChanged(license({ type: 'gold' }), license({ type: 'basic' }))).toBe(
true
);
});

test('status License <-> status License | mismatched status', async () => {
expect(
hasLicenseInfoChanged(license({ status: 'active' }), license({ status: 'inactive' }))
).toBe(true);
expect(
hasLicenseInfoChanged(license({ status: 'inactive' }), license({ status: 'active' }))
).toBe(true);
});

test('expiry License <-> expiry License | mismatched expiry', async () => {
expect(
hasLicenseInfoChanged(
license({ expiryDateInMillis: 100 }),
license({ expiryDateInMillis: 200 })
)
).toBe(true);
expect(
hasLicenseInfoChanged(
license({ expiryDateInMillis: 200 }),
license({ expiryDateInMillis: 100 })
)
).toBe(true);
});
});

describe('error License', () => {
test('License <-> error License', async () => {
expect(hasLicenseInfoChanged(license({ error: 'reason' }), license())).toBe(true);
expect(hasLicenseInfoChanged(license(), license({ error: 'reason' }))).toBe(true);
});

test('error License <-> error License | matched messages', async () => {
expect(
hasLicenseInfoChanged(license({ error: 'reason-1' }), license({ error: 'reason-1' }))
).toBe(false);
});

test('error License <-> error License | mismatched messages', async () => {
expect(
hasLicenseInfoChanged(license({ error: 'reason-1' }), license({ error: 'reason-2' }))
).toBe(true);
expect(
hasLicenseInfoChanged(license({ error: 'reason-2' }), license({ error: 'reason-1' }))
).toBe(true);
});
});
});
24 changes: 24 additions & 0 deletions x-pack/plugins/licensing/common/has_license_info_changed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { ILicense } from './types';

/**
* Check if 2 potential license instances have changes between them
* @internal
*/
export function hasLicenseInfoChanged(currentLicense: ILicense | undefined, newLicense: ILicense) {
if (currentLicense === newLicense) return false;
if (!currentLicense) return true;

return (
newLicense.error !== currentLicense.error ||
newLicense.type !== currentLicense.type ||
newLicense.status !== currentLicense.status ||
newLicense.expiryDateInMillis !== currentLicense.expiryDateInMillis ||
newLicense.isAvailable !== currentLicense.isAvailable
);
}
44 changes: 44 additions & 0 deletions x-pack/plugins/licensing/common/license.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 { PublicLicense, PublicFeatures } from './types';
import { License } from './license';

function createLicense({
license = {},
features = {},
signature = 'xxxxxxxxx',
}: {
license?: Partial<PublicLicense>;
features?: PublicFeatures;
signature?: string;
} = {}) {
const defaultLicense = {
uid: 'uid-000000001234',
status: 'active',
type: 'basic',
expiryDateInMillis: 5000,
};

const defaultFeatures = {
ccr: {
isEnabled: true,
isAvailable: true,
},
ml: {
isEnabled: false,
isAvailable: true,
},
};
return new License({
license: Object.assign(defaultLicense, license),
features: Object.assign(defaultFeatures, features),
signature,
});
}

export const licenseMock = {
create: createLicense,
};
Loading