mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 20:27:12 +00:00
Merge pull request #604 from Infisical/revised-encryption-key
Update dummy variables in test
This commit is contained in:
@@ -8,3 +8,5 @@ process.env.JWT_SIGNUP_SECRET= "38ea90fb7998b92176080f457d890392"
|
|||||||
process.env.JWT_REFRESH_SECRET= "7764c7bbf3928ad501591a3e005eb364"
|
process.env.JWT_REFRESH_SECRET= "7764c7bbf3928ad501591a3e005eb364"
|
||||||
process.env.JWT_AUTH_SECRET= "5239fea3a4720c0e524f814a540e14a2"
|
process.env.JWT_AUTH_SECRET= "5239fea3a4720c0e524f814a540e14a2"
|
||||||
process.env.JWT_SERVICE_SECRET= "8509fb8b90c9b53e9e61d1e35826dcb5"
|
process.env.JWT_SERVICE_SECRET= "8509fb8b90c9b53e9e61d1e35826dcb5"
|
||||||
|
process.env.ENCRYPTION_KEY="e05f54dffd58b5ab9b09e4c6fca7aff7"
|
||||||
|
process.env.ROOT_ENCRYPTION_KEY="MJA3DWJXjHiL6xjkUI2QCQuy/D+/SAbRNU1+rEo9gvQ="
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { describe, test, expect } from '@jest/globals';
|
import { describe, test, expect } from '@jest/globals';
|
||||||
import {
|
import {
|
||||||
decryptAsymmetric,
|
decryptAsymmetric,
|
||||||
decryptSymmetric,
|
|
||||||
encryptAsymmetric,
|
encryptAsymmetric,
|
||||||
encryptSymmetric
|
|
||||||
} from '../../../src/utils/crypto';
|
} from '../../../src/utils/crypto';
|
||||||
|
|
||||||
describe('Crypto', () => {
|
describe('Crypto', () => {
|
||||||
@@ -153,99 +151,4 @@ describe('Crypto', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('encryptSymmetric', () => {
|
|
||||||
let plaintext: string;
|
|
||||||
const key = '7e8ee7e5cc667b9c1829783ad31f36f4';
|
|
||||||
|
|
||||||
test('should encrypt plaintext with the given key', () => {
|
|
||||||
plaintext = 'secret-message';
|
|
||||||
const { ciphertext, iv, tag } = encryptSymmetric({ plaintext, key });
|
|
||||||
expect(ciphertext).toBeDefined();
|
|
||||||
expect(iv).toBeDefined();
|
|
||||||
expect(tag).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should throw an error when plaintext is undefined', () => {
|
|
||||||
const invalidKey = 'invalid-key';
|
|
||||||
expect(() => {
|
|
||||||
encryptSymmetric({ plaintext, key: invalidKey });
|
|
||||||
}).toThrowError('Invalid key length');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should throw an error when invalid key is provided', () => {
|
|
||||||
plaintext = 'secret-message';
|
|
||||||
const invalidKey = 'invalid-key';
|
|
||||||
|
|
||||||
expect(() => {
|
|
||||||
encryptSymmetric({ plaintext, key: invalidKey });
|
|
||||||
}).toThrowError('Invalid key length');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('decryptSymmetric', () => {
|
|
||||||
const plaintext = 'secret-message';
|
|
||||||
const key = '7e8ee7e5cc667b9c1829783ad31f36f4';
|
|
||||||
const { ciphertext, iv, tag } = encryptSymmetric({ plaintext, key });
|
|
||||||
|
|
||||||
test('should decrypt encrypted plaintext', () => {
|
|
||||||
const result = decryptSymmetric({
|
|
||||||
ciphertext,
|
|
||||||
iv,
|
|
||||||
tag,
|
|
||||||
key
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
|
||||||
expect(result).toEqual(plaintext);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should fail if ciphertext is modified', () => {
|
|
||||||
const modifieldCiphertext = 'abcdefghijklmnopqrstuvwxyz';
|
|
||||||
expect(() => {
|
|
||||||
decryptSymmetric({
|
|
||||||
ciphertext: modifieldCiphertext,
|
|
||||||
iv,
|
|
||||||
tag,
|
|
||||||
key
|
|
||||||
});
|
|
||||||
}).toThrowError('Unsupported state or unable to authenticate data');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should fail if iv is modified', () => {
|
|
||||||
const modifiedIv = 'abcdefghijklmnopqrstuvwxyz';
|
|
||||||
expect(() => {
|
|
||||||
decryptSymmetric({
|
|
||||||
ciphertext,
|
|
||||||
iv: modifiedIv,
|
|
||||||
tag,
|
|
||||||
key
|
|
||||||
});
|
|
||||||
}).toThrowError('Unsupported state or unable to authenticate data');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should fail if tag is modified', () => {
|
|
||||||
const modifiedTag = 'abcdefghijklmnopqrstuvwxyz';
|
|
||||||
expect(() => {
|
|
||||||
decryptSymmetric({
|
|
||||||
ciphertext,
|
|
||||||
iv,
|
|
||||||
tag: modifiedTag,
|
|
||||||
key
|
|
||||||
});
|
|
||||||
}).toThrowError(/Invalid authentication tag length: \d+/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should throw an error when decryption fails', () => {
|
|
||||||
const invalidKey = 'invalid-key';
|
|
||||||
expect(() => {
|
|
||||||
decryptSymmetric({
|
|
||||||
ciphertext,
|
|
||||||
iv,
|
|
||||||
tag,
|
|
||||||
key: invalidKey
|
|
||||||
});
|
|
||||||
}).toThrowError('Invalid key length');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user