Skip to content

Commit

Permalink
Review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Bulychev committed Sep 7, 2023
1 parent c024abd commit 5733f11
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 35 deletions.
45 changes: 45 additions & 0 deletions packages/devextreme/js/core/__tests__/license.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { verifyLicense } from '../component';

const token231 = 'ewogICJmb3JtYXQiOiAxLAogICJjdXN0b21lcklkIjogImIxMTQwYjQ2LWZkZTEtNDFiZC1hMjgwLTRkYjlmOGU3ZDliZCIsCiAgIm1heFZlcnNpb25BbGxvd2VkIjogMjMxCn0=.DiDceRbil4IzXl5av7pNkKieyqHHhRf+CM477zDu4N9fyrhkQsjRourYvgVfkbSm+EQplkXhlMBc3s8Vm9n+VtPaMbeWXis92cdW/6HiT+Dm54xw5vZ5POGunKRrNYUzd9zTbYcz0bYA/dc/mHFeUdXA0UlKcx1uMaXmtJrkK74=';
const token232 = 'ewogICJmb3JtYXQiOiAxLAogICJjdXN0b21lcklkIjogIjYxMjFmMDIyLTFjMTItNDNjZC04YWE0LTkwNzJkNDU4YjYxNCIsCiAgIm1heFZlcnNpb25BbGxvd2VkIjogMjMyCn0=.RENyZ3Ga5rCB7/XNKYbk2Ffv1n9bUexYNhyOlqcAD02YVnPw6XyQcN+ZORScKDU9gOInJ4o7vPxkgh10KvMZNn+FuBK8UcUR7kchk7z0CHGuOcIn2jD5X2hG6SYJ0UCBG/JDG35AL09T7Uv/pGj4PolRsANxtuMpoqmvX2D2vkU=';
const tokenUnverified = 'ewogICJmb3JtYXQiOiAxLAogICJjdXN0b21lcklkIjogImIxMTQwYjQ2LWZkZTEtNDFiZC1hMjgwLTRkYjlmOGU3ZDliZCIsCiAgIm1heFZlcnNpb25BbGxvd2VkIjogMjMxCn0=.NVsilC5uWlD5QGS6bocLMlsVVK0VpZXYwU2DstUiLRpEI79/onuR8dGWasCLBo4PORDHPkNA/Ej8XeCHzJ0EkXRRZ7E2LrP/xlEfHRXTruvW4IEbZt3LiwJBt6/isLz+wzXtYtjV7tpE07/Y0TFoy+mWpHoU11GVtwKh6weRxkg=';
const tokenInvalidJson = 'YWJj.vjx6wAI9jVkHJAnKcsuYNZ5UvCq3UhypQ+0f+kZ37/Qc1uj4BM6//Kfi4SVsXGOaOTFYWgzesROnHCp3jZRqphJwal4yXHD1sGFi6FEdB4MgdgNZvsZSnxNWLs/7s07CzuHLTpJrAG7sTdHVkQWZNnSCKjzV7909c/Stl9+hkLo=';
const tokenInvalidBase64 = 'ewogICJmb3JtYXQiOiAxLAogICJjdXN0b21lcklkIjogIjM3Yjg4ZjBmLWQ0MmMtNDJiZS05YjhkLTU1ZGMwYzUzYzAxZiIsCiAgIm1heFZlcnNpb25BbGxvd2VkIjogMjIxCn0-.EnP/RDKg0eSyaPU1eDUFll1lqOdYbhN3u73LhN1op8vjNwA0P1vKiT1DfQRmXudlleGWgDkLA2OmJYUER8j7I3LSFf3hLkBAoWoBErgveTb2zkbz8P1i9lE+XmzIXeYHyZBYUt0IPkNfajF9zzbSDDin1CvW7pnADi0vIeZ5ICQ=';
const tokenMissingField1 = 'ewogICJmb3JtYXQiOiAxLAogICJtYXhWZXJzaW9uQWxsb3dlZCI6IDIzMQp9.WH30cajUFcKqw/fwt4jITM/5tzVwPpbdbezhhdBi5oeOvU06zKY0J4M8gQy8GQ++RPYVCAo2md6vI9D80FD2CC4w+hpQLJNJJgNUHYPrgG6CX1yAB3M+NKHsPP9S71bXAgwvignb5uPo0R5emQzr4RKDhWQMKtgqEcRe+yme2mU=';
const tokenMissingField2 = 'ewogICJjdXN0b21lcklkIjogImIxMTQwYjQ2LWZkZTEtNDFiZC1hMjgwLTRkYjlmOGU3ZDliZCIsCiAgIm1heFZlcnNpb25BbGxvd2VkIjogMjMxCn0=.ok32DBaAgf3ijLmNQb+A0kUV2AiSivqvZJADdF607qqlAaduAVnotJtgdwm/Ib3MErfaGrDohCYoFMnKQevkRxFkA7tK3kOBnTZPUnZY0r3wyulMQmr4Qo+Sjf/fyXs4IYpGsC7/uJjgrCos8uzBegfmgfM93XSt6pKl9+c5xvc=';
const tokenMissingField3 = 'ewogICJmb3JtYXQiOiAxLAogICJjdXN0b21lcklkIjogImIxMTQwYjQ2LWZkZTEtNDFiZC1hMjgwLTRkYjlmOGU3ZDliZCIKfQ==.resgTqmazrorRNw7mmtV31XQnmTSw0uLEArsmpzCjWMQJLocBfAjpFvKBf+SAG9q+1iOSFySj64Uv2xBVqHnyeNVBRbouOKOnAB8RpkKvN4sc5SDc8JAG5TkwPVSzK/VLBpQxpqbxlcrRfHwz9gXqQoPt4/ZVATn285iw3DW0CU=';
const tokenUnsupportedVersion = 'ewogICJmb3JtYXQiOiAyLAogICJjdXN0b21lcklkIjogImIxMTQwYjQ2LWZkZTEtNDFiZC1hMjgwLTRkYjlmOGU3ZDliZCIsCiAgIm1heFZlcnNpb25BbGxvd2VkIjogMjMxCn0=.tTBymZMROsYyMiP6ldXFqGurbzqjhSQIu/pjyEUJA3v/57VgToomYl7FVzBj1asgHpadvysyTUiX3nFvPxbp166L3+LB3Jybw9ueMnwePu5vQOO0krqKLBqRq+TqHKn7k76uYRbkCIo5UajNfzetHhlkin3dJf3x2K/fcwbPW5A=';

describe('verifyLicense', () => {
it('Empty license', () => {
expect(verifyLicense()).toEqual('W0019');
expect(verifyLicense(null, '1.2.3')).toEqual('W0019');
expect(verifyLicense(undefined)).toEqual('W0019');
});

it('Valid license', () => {
expect(verifyLicense(token231, '23.1')).toBeUndefined();
expect(verifyLicense(token231, '12.3')).toBeUndefined();
expect(verifyLicense(token232, '23.1')).toBeUndefined();
expect(verifyLicense(token232, '23.2')).toBeUndefined();
});

it('Expired license', () => {
expect(verifyLicense(token231, '23.2')).toEqual('W0020');
expect(verifyLicense(token232, '42.4')).toEqual('W0020');
});

it('Corrupted token', () => {
expect(verifyLicense(tokenUnverified, '1.2.3')).toEqual('W0021');
expect(verifyLicense(tokenInvalidJson, '1.2.3')).toEqual('W0021');
expect(verifyLicense(tokenInvalidBase64, '1.2.3')).toEqual('W0021');
expect(verifyLicense(tokenMissingField1, '1.2.3')).toEqual('W0021');
expect(verifyLicense(tokenMissingField2, '1.2.3')).toEqual('W0021');
expect(verifyLicense(tokenMissingField3, '1.2.3')).toEqual('W0021');
expect(verifyLicense(tokenUnsupportedVersion, '1.2.3')).toEqual('W0021');
expect(verifyLicense('Another', '1.2.3')).toEqual('W0021');
expect(verifyLicense('str@nge')).toEqual('W0021');
expect(verifyLicense('in.put')).toEqual('W0021');
expect(verifyLicense('3.2.1', '1.2.3')).toEqual('W0021');
});
});
53 changes: 23 additions & 30 deletions packages/devextreme/js/core/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ const isInnerOption = (optionName) => {
return optionName.indexOf('_', 0) === 0;
};

export const emptyLicenseMessage = 'DevExtreme: Valid license key not found.\n\n' +
'If you are using a trial version, you must uninstall all copies of DevExtreme once your 30 days trial period expires. For licensing-related information, please refer to the DevExtreme End User License Agreement: https://js.devexpress.com/EULAs/DevExtremeComplete/.\n\n' +
'To continue using DevExtreme in a project, you must purchase a license. For pricing/licensing options, please visit: https://js.devexpress.com/Buy/.\n\n' +
'If you have licensing-related questions or need help with a purchase, please email [email protected]. We will be happy to follow-up.';
export const invalidVersionLicenseMessage = 'DevExtreme: The license key is expired.\n\n' +
'A mismatch exists between license key/DevExtreme version.\n\n' +
'To proceed, you can:\n' +
' ● use a version of DevExtreme linked to your license key https://www.devexpress.com/ClientCenter/DownloadManager/\n' +
' ● renew your DevExpress Subscription (once you renew your subscription, you will be entitled to product updates and support service https://www.devexpress.com/buy/renew/)\n\n' +
'If you have licensing-related questions or need help with a renewal, please email [email protected]. We will be happy to follow-up.';
export const invalidFormatLicenseMessage = 'DevExtreme: License key verification failed.\n\n' +
'Make certain to specify a correct key in the GlobalConfig. If you continue to encounter an error, please visit https://www.devexpress.com/ClientCenter/DownloadManager/ to obtain a valid key.\n\n' +
'If you have a valid license and this problem persists, please submit a support ticket via the DevExpress Support Center. We will be happy to follow-up: https://supportcenter.devexpress.com/ticket/create';
let licenseVerified = false;

export const Component = Class.inherit({
Expand Down Expand Up @@ -102,23 +89,9 @@ export const Component = Class.inherit({

if(!licenseVerified) {
licenseVerified = true;
const licenseToken = Config().license;
if(licenseToken) {
const license = parseToken(licenseToken);

if(license.kind === 'corrupted') {
errors.log(invalidFormatLicenseMessage);
} else {
const [majorStr, minorStr] = version.split('.');
const major = parseInt(majorStr, 10);
const minor = parseInt(minorStr, 10);

if(major * 10 + minor > license.payload.maxVersionAllowed) {
errors.log(invalidVersionLicenseMessage);
}
}
} else {
errors.log(emptyLicenseMessage);
const licenseError = verifyLicense(Config().license, version);
if(licenseError) {
errors.log(licenseError);
}
}
},
Expand Down Expand Up @@ -425,6 +398,26 @@ export const Component = Class.inherit({
}
});

export function verifyLicense(licenseToken, ver = version) {
if(licenseToken) {
const license = parseToken(licenseToken);

if(license.kind === 'corrupted') {
return 'W0021';
} else {
const [majorStr, minorStr] = ver.split('.');
const major = parseInt(majorStr, 10);
const minor = parseInt(minorStr, 10);

if(major * 10 + minor > license.payload.maxVersionAllowed) {
return 'W0020';
}
}
} else {
return 'W0019';
}
}

///#DEBUG
export function resetLicenseCheckSkipCondition() {
licenseVerified = false;
Expand Down
24 changes: 23 additions & 1 deletion packages/devextreme/js/core/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,27 @@ export default errorUtils({
/**
* @name ErrorsCore.W0018
*/
W0018: 'Setting the "position" property with a function is deprecated since v21.2'
W0018: 'Setting the "position" property with a function is deprecated since v21.2',
/**
* @name ErrorsCore.W0019
*/
W0019: 'DevExtreme: Valid license key not found.\n\n' +
'If you are using a trial version, you must uninstall all copies of DevExtreme once your 30 days trial period expires. For licensing-related information, please refer to the DevExtreme End User License Agreement: https://js.devexpress.com/EULAs/DevExtremeComplete/.\n\n' +
'To continue using DevExtreme in a project, you must purchase a license. For pricing/licensing options, please visit: https://js.devexpress.com/Buy/.\n\n' +
'If you have licensing-related questions or need help with a purchase, please email [email protected]. We will be happy to follow-up.',
/**
* @name ErrorsCore.W0019
*/
W0020: 'DevExtreme: The license key is expired.\n\n' +
'A mismatch exists between license key/DevExtreme version.\n\n' +
'To proceed, you can:\n' +
' ● use a version of DevExtreme linked to your license key https://www.devexpress.com/ClientCenter/DownloadManager/\n' +
' ● renew your DevExpress Subscription (once you renew your subscription, you will be entitled to product updates and support service https://www.devexpress.com/buy/renew/)\n\n' +
'If you have licensing-related questions or need help with a renewal, please email [email protected]. We will be happy to follow-up.',
/**
* @name ErrorsCore.W0019
*/
W0021: 'DevExtreme: License key verification failed.\n\n' +
'Make certain to specify a correct key in the GlobalConfig. If you continue to encounter an error, please visit https://www.devexpress.com/ClientCenter/DownloadManager/ to obtain a valid key.\n\n' +
'If you have a valid license and this problem persists, please submit a support ticket via the DevExpress Support Center. We will be happy to follow-up: https://supportcenter.devexpress.com/ticket/create',
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from 'core/config';
import errors from 'core/errors';
import { Component, emptyLicenseMessage, invalidVersionLicenseMessage, invalidFormatLicenseMessage, resetLicenseCheckSkipCondition } from 'core/component';
import { Component, resetLicenseCheckSkipCondition } from 'core/component';
const { test, module } = QUnit;

const validToken_23_2 = 'ewogICJmb3JtYXQiOiAxLAogICJjdXN0b21lcklkIjogIjYxMjFmMDIyLTFjMTItNDNjZC04YWE0LTkwNzJkNDU4YjYxNCIsCiAgIm1heFZlcnNpb25BbGxvd2VkIjogMjMyCn0=.RENyZ3Ga5rCB7/XNKYbk2Ffv1n9bUexYNhyOlqcAD02YVnPw6XyQcN+ZORScKDU9gOInJ4o7vPxkgh10KvMZNn+FuBK8UcUR7kchk7z0CHGuOcIn2jD5X2hG6SYJ0UCBG/JDG35AL09T7Uv/pGj4PolRsANxtuMpoqmvX2D2vkU=';
Expand Down Expand Up @@ -33,7 +33,7 @@ module('License check', {
const instance = new TestComponent();

assert.equal(log.length, 1);
assert.strictEqual(log[0][0], emptyLicenseMessage);
assert.strictEqual(log[0][0], 'W0019');
});

test('token should be verified', function(assert) {
Expand All @@ -50,7 +50,7 @@ module('License check', {
const instance = new TestComponent();

assert.equal(log.length, 1);
assert.strictEqual(log[0][0], invalidVersionLicenseMessage);
assert.strictEqual(log[0][0], 'W0020');
});

test('token check should be failed - wrong format', function(assert) {
Expand All @@ -59,6 +59,6 @@ module('License check', {
const instance = new TestComponent();

assert.equal(log.length, 1);
assert.strictEqual(log[0][0], invalidFormatLicenseMessage);
assert.strictEqual(log[0][0], 'W0021');
});
});

0 comments on commit 5733f11

Please sign in to comment.