Skip to content

Commit c0fa1c8

Browse files
Gustrbd-gubert
authored andcommitted
fix: Wrong marketplaceInfo value being stored in the database (#35009)
Co-authored-by: Douglas Gubert <1810309+d-gubert@users.noreply.github.com>
1 parent 561c3dd commit c0fa1c8

File tree

8 files changed

+33
-40
lines changed

8 files changed

+33
-40
lines changed

.changeset/grumpy-lemons-pull.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@rocket.chat/model-typings': patch
3+
'@rocket.chat/rest-typings': patch
4+
'@rocket.chat/apps-engine': patch
5+
'@rocket.chat/models': patch
6+
'@rocket.chat/i18n': patch
7+
'@rocket.chat/meteor': patch
8+
---
9+
10+
Fix an issue with apps installations via Marketplace

apps/meteor/ee/app/license/server/canEnableApp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export const _canEnableApp = async ({ Apps, License }: _canEnableAppDependencies
3838
throw new Error('license-prevented');
3939
}
4040

41-
if (app.marketplaceInfo?.isEnterpriseOnly && !License.hasValidLicense()) {
41+
const marketplaceInfo = app.marketplaceInfo?.[0];
42+
if (marketplaceInfo?.isEnterpriseOnly && !License.hasValidLicense()) {
4243
throw new Error('invalid-license');
4344
}
4445

apps/meteor/ee/server/apps/communication/rest.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AppStatus, AppStatusUtils } from '@rocket.chat/apps-engine/definition/AppStatus';
22
import type { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
33
import type { AppManager } from '@rocket.chat/apps-engine/server/AppManager';
4+
import type { IMarketplaceInfo } from '@rocket.chat/apps-engine/server/marketplace';
45
import type { IUser, IMessage } from '@rocket.chat/core-typings';
56
import { License } from '@rocket.chat/license';
67
import { Settings, Users } from '@rocket.chat/models';
@@ -314,7 +315,7 @@ export class AppsRestApi {
314315
},
315316
async post() {
316317
let buff;
317-
let marketplaceInfo;
318+
let marketplaceInfo: IMarketplaceInfo[] | undefined;
318319
let permissionsGranted;
319320

320321
if (this.bodyParams.url) {
@@ -357,7 +358,15 @@ export class AppsRestApi {
357358
}
358359

359360
buff = Buffer.from(await downloadResponse.arrayBuffer());
360-
marketplaceInfo = (await marketplaceResponse.json()) as any;
361+
marketplaceInfo = await marketplaceResponse.json();
362+
363+
// Note: marketplace responds with an array of the marketplace info on the app, but it is expected
364+
// to always have one element since we are fetching a specific app version.
365+
if (!Array.isArray(marketplaceInfo) || marketplaceInfo?.length !== 1) {
366+
orchestrator.getRocketChatLogger().error('Error getting the App information from the Marketplace:', marketplaceInfo);
367+
throw new Error('Invalid response from the Marketplace');
368+
}
369+
361370
permissionsGranted = this.bodyParams.permissionsGranted;
362371
} catch (err: any) {
363372
return API.v1.failure(err.message);

apps/meteor/ee/server/apps/marketplace/appInfo.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

apps/meteor/tests/unit/app/license/server/canEnableApp.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('canEnableApp', () => {
9595

9696
const app = getDefaultApp();
9797
app.installationSource = AppInstallationSource.MARKETPLACE;
98-
app.marketplaceInfo = { isEnterpriseOnly: true } as IMarketplaceInfo;
98+
app.marketplaceInfo = [{ isEnterpriseOnly: true } as IMarketplaceInfo];
9999

100100
const deps = { Apps: AppsMock, License };
101101

packages/apps-engine/src/server/AppManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { AppInstallationSource } from './storage/IAppStorageItem';
3939

4040
export interface IAppInstallParameters {
4141
enable: boolean;
42-
marketplaceInfo?: IMarketplaceInfo;
42+
marketplaceInfo?: IMarketplaceInfo[];
4343
permissionsGranted?: Array<IPermission>;
4444
user: IUser;
4545
}
@@ -877,13 +877,13 @@ export class AppManager {
877877
}
878878

879879
const appStorageItem = app.getStorageItem();
880-
const subscriptionInfo = appStorageItem.marketplaceInfo?.subscriptionInfo;
880+
const { subscriptionInfo } = appStorageItem.marketplaceInfo?.[0] || {};
881881

882882
if (subscriptionInfo && subscriptionInfo.license.license === appInfo.subscriptionInfo.license.license) {
883883
return;
884884
}
885885

886-
appStorageItem.marketplaceInfo.subscriptionInfo = appInfo.subscriptionInfo;
886+
appStorageItem.marketplaceInfo[0].subscriptionInfo = appInfo.subscriptionInfo;
887887

888888
return this.appMetadataStorage.update(appStorageItem);
889889
}),

packages/apps-engine/src/server/managers/AppLicenseManager.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ export class AppLicenseManager {
2121
this.userBridge = this.manager.getBridges().getUserBridge();
2222
}
2323

24-
public async validate(validationResult: AppLicenseValidationResult, appMarketplaceInfo?: IMarketplaceInfo): Promise<void> {
25-
if (!appMarketplaceInfo || appMarketplaceInfo.purchaseType !== MarketplacePurchaseType.PurchaseTypeSubscription) {
24+
public async validate(validationResult: AppLicenseValidationResult, appMarketplaceInfo?: IMarketplaceInfo[]): Promise<void> {
25+
const marketplaceInfo = appMarketplaceInfo?.[0];
26+
if (!marketplaceInfo || marketplaceInfo.purchaseType !== MarketplacePurchaseType.PurchaseTypeSubscription) {
2627
return;
2728
}
2829

2930
validationResult.setValidated(true);
3031

31-
const encryptedLicense = appMarketplaceInfo.subscriptionInfo.license.license;
32+
const encryptedLicense = marketplaceInfo.subscriptionInfo.license.license;
3233

3334
if (!encryptedLicense) {
3435
validationResult.addError('license', 'License for app is invalid');
@@ -47,7 +48,7 @@ export class AppLicenseManager {
4748

4849
switch (license.version) {
4950
case LicenseVersion.v1:
50-
await this.validateV1(appMarketplaceInfo, license, validationResult);
51+
await this.validateV1(marketplaceInfo, license, validationResult);
5152
break;
5253
}
5354
}

packages/apps-engine/src/server/storage/IAppStorageItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface IAppStorageItem {
1919
languageContent: { [key: string]: object };
2020
settings: { [id: string]: ISetting };
2121
implemented: { [int: string]: boolean };
22-
marketplaceInfo?: IMarketplaceInfo;
22+
marketplaceInfo?: IMarketplaceInfo[];
2323
permissionsGranted?: Array<IPermission>;
2424
signature?: string;
2525
migrated?: boolean;

0 commit comments

Comments
 (0)