UNPKG

@unito/integration-cli

Version:

Integration CLI

78 lines (77 loc) 3.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const strict_1 = tslib_1.__importDefault(require("node:assert/strict")); const sinon_1 = tslib_1.__importDefault(require("sinon")); const IntegrationsPlatformResources = tslib_1.__importStar(require("../../src/resources/integrationsPlatform")); const IntegrationsPlatform = tslib_1.__importStar(require("../../src/services/integrationsPlatform")); const GlobalConfiguration = tslib_1.__importStar(require("../../src/resources/globalConfiguration")); const configuration_1 = require("../../src/resources/configuration"); const decryptionHelper = tslib_1.__importStar(require("../../src/resources/decryption")); describe('decryption helper', () => { const configuration = { name: 'a', baseUrl: 'b', secrets: { encryptedSecret1: `${configuration_1.ENCRYPTION_PREFIX}decrypt-me`, encryptedSecret2: `${configuration_1.ENCRYPTION_PREFIX}decrypt-me`, }, testAccounts: { compliance: { accessToken: 'token', encryptedToken: `${configuration_1.ENCRYPTION_PREFIX}decrypt-me`, }, development: { accessToken: 'developmentToken', }, }, }; beforeEach(() => { sinon_1.default.stub(GlobalConfiguration, 'read'); sinon_1.default.stub(IntegrationsPlatformResources, 'validateAuthenticated'); sinon_1.default.stub(IntegrationsPlatform, 'decryptData').resolves({ decryptedData: 'decrypted-me' }); }); afterEach(() => { sinon_1.default.restore(); }); describe('decryptEntries', () => { it('support unencrypted entries', async () => { const decryptionResult = await decryptionHelper.decryptEntries(configuration.name, GlobalConfiguration.Environment.Local, '/path/to/config', { accessToken: 'developmentToken', accessToken1: 'developmentToken1', }); strict_1.default.deepEqual(decryptionResult.failed, []); strict_1.default.deepEqual(decryptionResult.successful, { accessToken1: 'developmentToken1', accessToken: 'developmentToken', }); }); it('support mixed encrypted and not encrypted entries', async () => { const decryptionResult = await decryptionHelper.decryptEntries(configuration.name, GlobalConfiguration.Environment.Local, '/path/to/config', { accessToken: 'token', encryptedToken: `${configuration_1.ENCRYPTION_PREFIX}decrypt-me`, }); strict_1.default.deepEqual(decryptionResult.failed, []); strict_1.default.deepEqual(decryptionResult.successful, { accessToken: 'token', encryptedToken: `decrypted-me`, }); }); it('support multiple encrypted entries', async () => { const decryptionResult = await decryptionHelper.decryptEntries(configuration.name, GlobalConfiguration.Environment.Local, '/path/to/config', { encryptedSecret1: `${configuration_1.ENCRYPTION_PREFIX}decrypt-me`, encryptedSecret2: `${configuration_1.ENCRYPTION_PREFIX}decrypt-me`, }); strict_1.default.deepEqual(decryptionResult.failed, []); strict_1.default.deepEqual(decryptionResult.successful, { encryptedSecret1: 'decrypted-me', encryptedSecret2: 'decrypted-me', }); }); it('support empty object', async () => { const decryptionResult = await decryptionHelper.decryptEntries(configuration.name, GlobalConfiguration.Environment.Local, '/path/to/config', {}); strict_1.default.deepEqual(decryptionResult.failed, []); strict_1.default.deepEqual(decryptionResult.successful, {}); }); }); });