mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 13:14:07 -08:00
0bd4e742da
[`crypto-js` has been
discontinued](1da3dabf93
)
PS: We'll remove `crypto-js` usage from `n8n-workflow` and
`@n8n_io/license-sdk` in separate PRs.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import Container from 'typedi';
|
|
import { InstanceSettings } from '@/InstanceSettings';
|
|
import { Cipher } from '@/Cipher';
|
|
import { mockInstance } from './utils';
|
|
|
|
describe('Cipher', () => {
|
|
mockInstance(InstanceSettings, { encryptionKey: 'test_key' });
|
|
const cipher = Container.get(Cipher);
|
|
|
|
describe('encrypt', () => {
|
|
it('should encrypt strings', () => {
|
|
const encrypted = cipher.encrypt('random-string');
|
|
const decrypted = cipher.decrypt(encrypted);
|
|
expect(decrypted).toEqual('random-string');
|
|
});
|
|
|
|
it('should encrypt objects', () => {
|
|
const encrypted = cipher.encrypt({ key: 'value' });
|
|
const decrypted = cipher.decrypt(encrypted);
|
|
expect(decrypted).toEqual('{"key":"value"}');
|
|
});
|
|
});
|
|
|
|
describe('decrypt', () => {
|
|
it('should decrypt string', () => {
|
|
const decrypted = cipher.decrypt('U2FsdGVkX194VEoX27o3+y5jUd1JTTmVwkOKjVhB6Jg=');
|
|
expect(decrypted).toEqual('random-string');
|
|
});
|
|
|
|
it('should not try to decrypt if the input is shorter than 16 bytes', () => {
|
|
const decrypted = cipher.decrypt('U2FsdGVkX194VEo');
|
|
expect(decrypted).toEqual('');
|
|
});
|
|
});
|
|
});
|