From f463dc3d83aa0d524aea711b30a90913c388511d Mon Sep 17 00:00:00 2001 From: raj pandey Date: Sat, 7 Mar 2026 13:50:36 +0530 Subject: [PATCH] fix: Removed the multiple prompt for marketplace encryption key --- .../src/export/modules/marketplace-apps.ts | 3 --- .../export/modules/marketplace-apps.test.ts | 21 ++++++++++++++++ .../import/modules/marketplace-apps.test.ts | 25 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/packages/contentstack-export/src/export/modules/marketplace-apps.ts b/packages/contentstack-export/src/export/modules/marketplace-apps.ts index 42944383..cb6fd1fd 100644 --- a/packages/contentstack-export/src/export/modules/marketplace-apps.ts +++ b/packages/contentstack-export/src/export/modules/marketplace-apps.ts @@ -27,7 +27,6 @@ import { MODULE_NAMES, PROCESS_NAMES, PROCESS_STATUS, - askEncryptionKey, } from '../../utils'; import { ModuleClassParams, MarketplaceAppsConfig, ExportConfig, Installation, Manifest } from '../../types'; @@ -78,9 +77,7 @@ export default class ExportMarketplaceApps extends BaseClass { if (!this.exportConfig.forceStopMarketplaceAppsPrompt) { log.debug('Validating security configuration before progress start', this.exportConfig.context); cliux.print('\n'); - await askEncryptionKey(this.exportConfig); this.nodeCrypto = await createNodeCryptoInstance(this.exportConfig); - cliux.print('\n'); } diff --git a/packages/contentstack-export/test/unit/export/modules/marketplace-apps.test.ts b/packages/contentstack-export/test/unit/export/modules/marketplace-apps.test.ts index 07656a2c..b522d4d7 100644 --- a/packages/contentstack-export/test/unit/export/modules/marketplace-apps.test.ts +++ b/packages/contentstack-export/test/unit/export/modules/marketplace-apps.test.ts @@ -273,6 +273,27 @@ describe('ExportMarketplaceApps', () => { exportAppsStub.restore(); configHandlerGetStub.restore(); }); + + it('should call createNodeCryptoInstance exactly once when prompting for encryption key before progress', async () => { + mockExportConfig.forceStopMarketplaceAppsPrompt = false; + const configHandlerGetStub = sinon.stub(utilities.configHandler, 'get'); + configHandlerGetStub.withArgs('authorisationType').returns('BASIC'); + const getAppsCountStub = sinon.stub(exportMarketplaceApps, 'getAppsCount').resolves(1); + const exportAppsStub = sinon.stub(exportMarketplaceApps, 'exportApps').resolves(); + const getAppManifestAndAppConfigStub = sinon.stub( + exportMarketplaceApps, + 'getAppManifestAndAppConfig', + ).resolves(); + + await exportMarketplaceApps.start(); + + expect((marketplaceAppHelper.createNodeCryptoInstance as sinon.SinonStub).calledOnce).to.be.true; + + getAppsCountStub.restore(); + exportAppsStub.restore(); + getAppManifestAndAppConfigStub.restore(); + configHandlerGetStub.restore(); + }); }); describe('exportApps() method', () => { diff --git a/packages/contentstack-import/test/unit/import/modules/marketplace-apps.test.ts b/packages/contentstack-import/test/unit/import/modules/marketplace-apps.test.ts index 33fe98c5..bd67144e 100644 --- a/packages/contentstack-import/test/unit/import/modules/marketplace-apps.test.ts +++ b/packages/contentstack-import/test/unit/import/modules/marketplace-apps.test.ts @@ -1652,6 +1652,31 @@ describe('ImportMarketplaceApps', () => { expect(completeProgressStub.called).to.be.true; expect(completeProgressStub.calledWith(false, 'Start process failed')).to.be.true; }); + + it('should call getAndValidateEncryptionKey exactly once when prompt is not forced and start runs', async () => { + mockImportConfig.forceStopMarketplaceAppsPrompt = false; + importMarketplaceApps = new ImportMarketplaceApps(mockModuleClassParams); + importMarketplaceApps.importConfig = mockImportConfig; + + const configHandler = require('@contentstack/cli-utilities').configHandler; + sandbox.stub(configHandler, 'get').callsFake((key) => { + if (key === 'authorisationType') { + return 'OAUTH'; + } + return 'some-value'; + }); + + const getAndValidateEncryptionKeyStub = sandbox + .stub(importMarketplaceApps, 'getAndValidateEncryptionKey') + .resolves(); + sandbox.stub(importMarketplaceApps as any, 'setupMarketplaceEnvironment').resolves(); + sandbox.stub(importMarketplaceApps, 'handleAllPrivateAppsCreationProcess').resolves(); + sandbox.stub(importMarketplaceApps, 'importMarketplaceApps').resolves(); + + await importMarketplaceApps.start(); + + expect(getAndValidateEncryptionKeyStub.calledOnce).to.be.true; + }); }); describe('importMarketplaceApps()', () => {