-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add x-pack plugin for new platform browser licensing information * Address next round of reviews * Remove poller functionality in favor of inline observables * More observable changes from review comments * Fix outstanding tests * More changes from review, adding additional testing * Add additional tests for license comparisons and sessions * Update test snapshot due to sessionstorage mock * Next round of review feedback from restrry * Fix more review requests from restrry, add additional tests * Pass correct sign mock to license info changed test * Improve doc comments, switch to I-interface pattern * Test error polling sanity, do not expose signature, do not poll on client * Fix type check issues from rebase * Fix build error from rebase * minimize config * move all types to server with consistency with other code * implement License * implement license update & refactor has License changed check * update tests for licensing extending route handler context * implement client side side license plugin * implement server side licensing plugin * remove old code * update testing harness * update types for license status * remove jest-localstorage-mock * fix tests * update license in security * address comments. first pass * error is a part of signature. pass error message to License * move common license types under common folder * rename feature props for BWC and unify name with ILicense * test should work in any timezone * make prettier happy * remove obsolete comment * address Pierre comments * use sha256 for security reasons * use stable stringify to avoid churn
- Loading branch information
Showing
39 changed files
with
1,783 additions
and
1,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
x-pack/plugins/licensing/common/has_license_info_changed.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
x-pack/plugins/licensing/common/has_license_info_changed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
Oops, something went wrong.