add more tests to encryption

This commit is contained in:
Bassel Kanso 2022-10-21 15:07:04 +03:00
parent cef2f0ff69
commit 0eb9ecbeab

View File

@ -7,7 +7,7 @@ describe('Encryption', () => {
const encryptedData = cipher.update(textToEncrypt);
expect(cipher).toBeDefined();
expect(encryptedData).not.toBe(textToEncrypt);
expect(encryptedData.toString()).not.toBe(textToEncrypt);
expect(encryptedData).toBeInstanceOf(Buffer);
});
@ -17,7 +17,7 @@ describe('Encryption', () => {
const encryptedData = cipher.update(textToEncrypt);
expect(cipher).toBeDefined();
expect(encryptedData).not.toBe(textToEncrypt);
expect(encryptedData.toString()).not.toBe(textToEncrypt);
expect(encryptedData).toBeInstanceOf(Buffer);
});
@ -27,7 +27,7 @@ describe('Encryption', () => {
const encryptedData = cipher.update(textToEncrypt);
expect(cipher).toBeDefined();
expect(encryptedData).not.toBe(textToEncrypt);
expect(encryptedData.toString()).not.toBe(textToEncrypt);
expect(encryptedData).toBeInstanceOf(Buffer);
});
@ -37,7 +37,31 @@ describe('Encryption', () => {
const encryptedData = cipher.update(textToEncrypt);
expect(cipher).toBeDefined();
expect(encryptedData).not.toBe(textToEncrypt);
expect(encryptedData.toString()).not.toBe(textToEncrypt);
expect(encryptedData).toBeInstanceOf(Buffer);
});
test('data encrypted with different algorithms should have different results', () => {
const cipherAES256 = createCipher('password', 'aes256');
const cipherAES192 = createCipher('password', 'aes192');
const cipherDefault = createCipher('password');
const textToEncrypt = 'something ate an apple';
const encryptedDataAES256 = cipherAES256.update(textToEncrypt).toString();
const encryptedDataAES192 = cipherAES192.update(textToEncrypt).toString();
const encryptedDataDefault = cipherDefault.update(textToEncrypt).toString();
expect(encryptedDataAES256).not.toBe(encryptedDataDefault);
expect(encryptedDataAES256).not.toBe(encryptedDataAES192);
expect(encryptedDataDefault).not.toBe(encryptedDataAES192);
});
test('data encrypted with different key should be different', () => {
const cipher1 = createCipher('password');
const cipher2 = createCipher('differentpassword');
const textToEncrypt = 'something ate an apple';
const encryptedData1 = cipher1.update(textToEncrypt).toString();
const encryptedData2 = cipher2.update(textToEncrypt).toString();
expect(encryptedData1).not.toBe(encryptedData2);
});
});