feat(server): deriveSecurity.encryptionKeySet and storage secret plumbing (gate, encrypt, unmask, mask, redact)

This commit is contained in:
jubnl
2026-08-20 00:50:27 +02:00
parent a6fb82833f
commit d9f6151f53
7 changed files with 309 additions and 2 deletions
@@ -7,7 +7,12 @@ vi.mock('../../../src/config', () => ({
updateJwtSecret: () => {},
}));
import { encrypt_api_key, decrypt_api_key, maybe_encrypt_api_key } from '../../../src/nest/common/crypto/apiKeyCrypto';
import {
encrypt_api_key,
decrypt_api_key,
maybe_encrypt_api_key,
is_encrypted_api_key,
} from '../../../src/nest/common/crypto/apiKeyCrypto';
describe('apiKeyCrypto', () => {
const PLAINTEXT_KEY = 'my-secret-api-key-12345';
@@ -76,4 +81,15 @@ describe('apiKeyCrypto', () => {
expect(result).toBe(encrypted);
});
});
describe('is_encrypted_api_key', () => {
it('is true exactly for enc:v1: envelopes', () => {
expect(is_encrypted_api_key(encrypt_api_key('s'))).toBe(true);
expect(is_encrypted_api_key('enc:v1:AAAA')).toBe(true);
expect(is_encrypted_api_key('plaintext')).toBe(false);
expect(is_encrypted_api_key('')).toBe(false);
expect(is_encrypted_api_key(null)).toBe(false);
expect(is_encrypted_api_key(42)).toBe(false);
});
});
});