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

fix: Prevent invocations of 'GET /rest/license' from returning an error when ephemeral licenses are used #6154

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions packages/cli/src/License.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ export class License {
}

return entitlements.find(
(entitlement) =>
(entitlement.productMetadata.terms as unknown as { isMainPlan: boolean }).isMainPlan,
(entitlement) => (entitlement.productMetadata?.terms as { isMainPlan?: boolean })?.isMainPlan,
csuermann marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down
43 changes: 40 additions & 3 deletions packages/cli/test/unit/License.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const MOCK_RENEW_OFFSET = 259200;
const MOCK_INSTANCE_ID = 'instance-id';
const MOCK_ACTIVATION_KEY = 'activation-key';
const MOCK_FEATURE_FLAG = 'feat:mock';
const MOCK_MAIN_PLAN_ID = 1234;
const MOCK_MAIN_PLAN_ID = '1b765dc4-d39d-4ffe-9885-c56dd67c4b26';

describe('License', () => {
beforeAll(() => {
Expand Down Expand Up @@ -82,12 +82,21 @@ describe('License', () => {
expect(LicenseManager.prototype.getManagementJwt).toHaveBeenCalled();
});

test('check main plan', async () => {
test('getMainPlan() returns the right entitlement', async () => {
// mock entitlements response
License.prototype.getCurrentEntitlements = jest.fn().mockReturnValue([
{
id: '84a9c852-1349-478d-9ad1-b3f55510e477',
productId: '670650f2-72d8-4397-898c-c249906e2cc2',
productMetadata: {},
features: {},
featureOverrides: {},
validFrom: new Date(),
validTo: new Date(),
},
{
id: MOCK_MAIN_PLAN_ID,
productId: '',
productId: '670650f2-72d8-4397-898c-c249906e2cc2',
productMetadata: {
terms: {
isMainPlan: true,
Expand All @@ -104,4 +113,32 @@ describe('License', () => {
const mainPlan = license.getMainPlan();
expect(mainPlan?.id).toBe(MOCK_MAIN_PLAN_ID);
});

test('getMainPlan() returns undefined if there is no main plan', async () => {
// mock entitlements response
License.prototype.getCurrentEntitlements = jest.fn().mockReturnValue([
{
id: '84a9c852-1349-478d-9ad1-b3f55510e477',
productId: '670650f2-72d8-4397-898c-c249906e2cc2',
productMetadata: {}, // has no `productMetadata.terms.isMainPlan`!
features: {},
featureOverrides: {},
validFrom: new Date(),
validTo: new Date(),
},
{
id: 'c1aae471-c24e-4874-ad88-b97107de486c',
productId: '670650f2-72d8-4397-898c-c249906e2cc2',
productMetadata: {}, // has no `productMetadata.terms.isMainPlan`!
features: {},
featureOverrides: {},
validFrom: new Date(),
validTo: new Date(),
},
]);
jest.fn(license.getMainPlan).mockReset();

const mainPlan = license.getMainPlan();
expect(mainPlan).toBeUndefined();
});
});