|
|
@ -1,7 +1,6 @@ |
|
|
|
import { IntegrationsType } from 'nocodb-sdk'; |
|
|
|
import { IntegrationsType } from 'nocodb-sdk'; |
|
|
|
import { Integration } from '~/models'; |
|
|
|
import { Integration } from '~/models'; |
|
|
|
import { MetaTable } from '~/utils/globals'; |
|
|
|
import { MetaTable } from '~/utils/globals'; |
|
|
|
import Noco from '~/Noco'; |
|
|
|
|
|
|
|
import { decryptPropIfRequired } from '~/utils'; |
|
|
|
import { decryptPropIfRequired } from '~/utils'; |
|
|
|
|
|
|
|
|
|
|
|
// Mock dependencies
|
|
|
|
// Mock dependencies
|
|
|
@ -152,16 +151,18 @@ describe('Integration Model', () => { |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should create a new integration with encrypted config', async () => { |
|
|
|
describe('create with encryption', () => { |
|
|
|
// overwrite env variable
|
|
|
|
beforeAll(() => { |
|
|
|
const config = Noco.getConfig(); |
|
|
|
process.env.NC_KEY_CREDENTIAL_ENCRYPT = 'test-secret'; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Noco.getConfig = jest.fn().mockReturnValue({ |
|
|
|
afterAll(() => { |
|
|
|
...config, |
|
|
|
process.env.NC_KEY_CREDENTIAL_ENCRYPT = undefined; |
|
|
|
credentialSecret: 'test-secret', |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should create a new integration with encrypted config', async () => { |
|
|
|
const newIntegration = { |
|
|
|
const newIntegration = { |
|
|
|
id: 'new-id', |
|
|
|
id: 'new-id', |
|
|
|
title: 'New Integration', |
|
|
|
title: 'New Integration', |
|
|
@ -195,7 +196,7 @@ describe('Integration Model', () => { |
|
|
|
const calledWithArgs = mockNcMeta.metaInsert2.mock.calls[0][3]; |
|
|
|
const calledWithArgs = mockNcMeta.metaInsert2.mock.calls[0][3]; |
|
|
|
|
|
|
|
|
|
|
|
// veify the 'config' field is encrypted
|
|
|
|
// veify the 'config' field is encrypted
|
|
|
|
expect(calledWithArgs.config).not.toEqual(newIntegration.config); |
|
|
|
expect(calledWithArgs.config).not.toEqual(JSON.stringify(newIntegration.config)); |
|
|
|
|
|
|
|
|
|
|
|
// Decrypt the 'config' field
|
|
|
|
// Decrypt the 'config' field
|
|
|
|
const decryptedConfig = decryptPropIfRequired({ data: calledWithArgs }); |
|
|
|
const decryptedConfig = decryptPropIfRequired({ data: calledWithArgs }); |
|
|
|