mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
39d5e0ff87
Some checks failed
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Benchmark Docker Image CI / build (push) Has been cancelled
Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { Container } from '@n8n/di';
|
|
|
|
import { Cipher } from '@/Cipher';
|
|
import { InstanceSettings } from '@/InstanceSettings';
|
|
|
|
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('');
|
|
});
|
|
});
|
|
});
|