Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
MODULE_NAMES,
PROCESS_NAMES,
PROCESS_STATUS,
askEncryptionKey,
} from '../../utils';
import { ModuleClassParams, MarketplaceAppsConfig, ExportConfig, Installation, Manifest } from '../../types';

Expand Down Expand Up @@ -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');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down
Loading