-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[license] Allow to limit some packages to a specific license plan #4651
Changes from 7 commits
aca1806
daf89fd
85e74e1
c39c2cf
d06402a
0ed09b9
c7dd1b9
9111bfe
43d4126
e08a004
afda9c5
2189119
f5670bf
a903f18
0f6efa7
1e18b49
4b8f75f
d348529
2cd8f7c
f78817c
9af2a9d
501769c
336bd21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './licenseErrorMessageUtils'; | ||
export * from './licenseInfo'; | ||
export * from './licenseStatus'; | ||
export * from './licenseScope'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type LicenseScope = 'pro' | 'premium'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest I was thinking to rework this to an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure Here we type the value, so we are sure that TS will complain if we put But if we use an enum, the typing is on the key of the enum, not its values. So if by mistake we switch from enum LicenseScope {
pro = 'pro',
premium = 'premium'
} To enum LicenseScope {
pro, // defaults to 0
premium, // defaults to 1
} Then all our code will still work, but we will have done a breaking change for the licenses generated. With that being said, I think both are viable as long as we follow the rule that an enum whose value can be stringified in any way must have its keys equal to its values. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,36 +8,98 @@ const oneYear = oneDayInMS * 365; | |
const RELEASE_INFO = generateReleaseInfo(); | ||
|
||
describe('License: verifyLicense', () => { | ||
const validLicense = generateLicense({ | ||
expiryDate: new Date(new Date().getTime() + oneYear), | ||
orderNumber: 'MUI-123', | ||
}); | ||
describe('key version: 1', () => { | ||
const license = | ||
'0f94d8b65161817ca5d7f7af8ac2f042T1JERVI6TVVJLVN0b3J5Ym9vayxFWFBJUlk9MTY1NDg1ODc1MzU1MCxLRVlWRVJTSU9OPTE='; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have the v1 generation anymore but it's worth testing it |
||
|
||
it('should log an error when ReleaseInfo is not valid', () => { | ||
expect(() => verifyLicense('__RELEASE_INFO__', validLicense)).to.throw( | ||
'MUI: The release information is invalid. Not able to validate license.', | ||
); | ||
}); | ||
it('should log an error when ReleaseInfo is not valid', () => { | ||
expect(() => verifyLicense('__RELEASE_INFO__', license, ['pro', 'premium'])).to.throw( | ||
'MUI: The release information is invalid. Not able to validate license.', | ||
); | ||
}); | ||
|
||
it('should verify License properly', () => { | ||
expect(verifyLicense(RELEASE_INFO, license, ['pro', 'premium'])).to.equal( | ||
LicenseStatus.Valid, | ||
); | ||
}); | ||
|
||
it('should check expired License properly', () => { | ||
const expiredLicense = generateLicense({ | ||
expiryDate: new Date(new Date().getTime() - oneDayInMS), | ||
orderNumber: 'MUI-123', | ||
}); | ||
|
||
it('should verify License properly', () => { | ||
expect(verifyLicense(RELEASE_INFO, validLicense)).to.equal(LicenseStatus.Valid); | ||
expect(verifyLicense(RELEASE_INFO, expiredLicense, ['pro', 'premium'])).to.equal( | ||
LicenseStatus.Expired, | ||
); | ||
}); | ||
|
||
it('should return Invalid for invalid license', () => { | ||
expect( | ||
verifyLicense( | ||
RELEASE_INFO, | ||
'b43ff5f9ac93f021855ff59ff0ba5220TkFNRTpNYC1VSSBTQVMsREVWRUxPUEVSX0NPVU5UPTEwLEVYUElSWT0xNTkxNzIzMDY3MDQyLFZFUlNJT049MS4yLjM', | ||
['pro', 'premium'], | ||
), | ||
).to.equal(LicenseStatus.Invalid); | ||
}); | ||
}); | ||
|
||
it('should check expired License properly', () => { | ||
const expiredLicense = generateLicense({ | ||
expiryDate: new Date(new Date().getTime() - oneDayInMS), | ||
describe('key version: 2', () => { | ||
const licensePro = generateLicense({ | ||
expiryDate: new Date(new Date().getTime() + oneYear), | ||
orderNumber: 'MUI-123', | ||
scope: 'pro', | ||
}); | ||
|
||
expect(verifyLicense(RELEASE_INFO, expiredLicense)).to.equal(LicenseStatus.Expired); | ||
}); | ||
const licensePremium = generateLicense({ | ||
expiryDate: new Date(new Date().getTime() + oneYear), | ||
orderNumber: 'MUI-123', | ||
scope: 'premium', | ||
}); | ||
|
||
it('should return Invalid for invalid license', () => { | ||
expect( | ||
verifyLicense( | ||
RELEASE_INFO, | ||
'b43ff5f9ac93f021855ff59ff0ba5220TkFNRTpNYC1VSSBTQVMsREVWRUxPUEVSX0NPVU5UPTEwLEVYUElSWT0xNTkxNzIzMDY3MDQyLFZFUlNJT049MS4yLjM', | ||
), | ||
).to.equal(LicenseStatus.Invalid); | ||
it('should log an error when ReleaseInfo is not valid', () => { | ||
expect(() => verifyLicense('__RELEASE_INFO__', licensePro, ['pro', 'premium'])).to.throw( | ||
'MUI: The release information is invalid. Not able to validate license.', | ||
); | ||
}); | ||
|
||
it('should accept pro license for pro features', () => { | ||
expect(verifyLicense(RELEASE_INFO, licensePro, ['pro', 'premium'])).to.equal( | ||
LicenseStatus.Valid, | ||
); | ||
}); | ||
|
||
it('should accept premium license for premium features', () => { | ||
expect(verifyLicense(RELEASE_INFO, licensePremium, ['premium'])).to.equal( | ||
LicenseStatus.Valid, | ||
); | ||
}); | ||
|
||
it('should not accept pro license for premium feature', () => { | ||
expect(verifyLicense(RELEASE_INFO, licensePro, ['premium'])).to.equal(LicenseStatus.Invalid); | ||
}); | ||
|
||
it('should check expired License properly', () => { | ||
const expiredLicense = generateLicense({ | ||
expiryDate: new Date(new Date().getTime() - oneDayInMS), | ||
orderNumber: 'MUI-123', | ||
}); | ||
|
||
expect(verifyLicense(RELEASE_INFO, expiredLicense, ['pro', 'premium'])).to.equal( | ||
LicenseStatus.Expired, | ||
); | ||
}); | ||
|
||
it('should return Invalid for invalid license', () => { | ||
expect( | ||
verifyLicense( | ||
RELEASE_INFO, | ||
'b43ff5f9ac93f021855ff59ff0ba5220TkFNRTpNYC1VSSBTQVMsREVWRUxPUEVSX0NPVU5UPTEwLEVYUElSWT0xNTkxNzIzMDY3MDQyLFZFUlNJT049MS4yLjM', | ||
['pro', 'premium'], | ||
), | ||
).to.equal(LicenseStatus.Invalid); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { LicenseInfo } from '@mui/x-data-grid-pro'; | ||
|
||
LicenseInfo.setLicenseKey( | ||
'0f94d8b65161817ca5d7f7af8ac2f042T1JERVI6TVVJLVN0b3J5Ym9vayxFWFBJUlk9MTY1NDg1ODc1MzU1MCxLRVlWRVJTSU9OPTE=', | ||
'e8d0d6124d6e21bee635aae6358c5bfcT1JERVI9TVVJLVN0b3J5Ym9vayxFWFBJUlk9MTY4MjUyNzMzNDQ1MixLRVlWRVJTSU9OPTIsU0NPUEU9cHJlbWl1bQ==', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic would have to become smarter if we release other plans
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So to be sure that I understand it - the goal here is to if you have
premium
you also getpro
right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
I first did a scale
const scopes = ['community', 'pro', 'premium']
and then compare the index of the current plan with the one of the licenseBut it would not work with more granular scopes if we have some in the future
Right now it's a very basic check so both options work fine.