Files
binect-chrome/tests/crypto.test.ts
tegwick b09290cb83 Release 0.1: Complete BinectChrome implementation
Implements all requirements from ProductRequirementsDocument.md:
- PDF detection via Chrome Downloads API
- Secure credential storage with AES-GCM encryption
- Binect API integration for PDF uploads
- Popup UI with Binect branding
- Local transfer tracking (500 entry cap)
- Help page with tracking view and CSV export
- 60-day credential retention with auto-expiry
- Accessibility compliance (WCAG 2.1 AA)

Technical implementation:
- Chrome Extension Manifest V3
- TypeScript with strict mode
- Webpack build system
- Jest test suite (22/22 passing)
- ESLint configured (0 errors)

Build output: 13 KB total (production minified)
Test coverage: crypto, pdf-detector, tracker, binect-api

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 00:30:39 +01:00

65 lines
2.0 KiB
TypeScript

/**
* Tests for cryptographic utilities
*/
import { generateEncryptionKey, exportKey, importKey, encrypt, decrypt } from '../src/utils/crypto';
describe('Crypto utilities', () => {
test('should generate encryption key', async () => {
const key = await generateEncryptionKey();
expect(key).toBeDefined();
expect(key.type).toBe('secret');
});
test('should export and import key', async () => {
const key = await generateEncryptionKey();
const exported = await exportKey(key);
expect(typeof exported).toBe('string');
expect(exported.length).toBeGreaterThan(0);
const imported = await importKey(exported);
expect(imported).toBeDefined();
expect(imported.type).toBe('secret');
});
test('should encrypt and decrypt data', async () => {
const key = await generateEncryptionKey();
const plaintext = 'test data';
const encrypted = await encrypt(plaintext, key);
expect(encrypted.ciphertext).toBeDefined();
expect(encrypted.iv).toBeDefined();
expect(encrypted.ciphertext).not.toBe(plaintext);
const decrypted = await decrypt(encrypted, key);
expect(decrypted).toBe(plaintext);
});
test('should encrypt same data differently each time (different IV)', async () => {
const key = await generateEncryptionKey();
const plaintext = 'test data';
const encrypted1 = await encrypt(plaintext, key);
const encrypted2 = await encrypt(plaintext, key);
expect(encrypted1.ciphertext).not.toBe(encrypted2.ciphertext);
expect(encrypted1.iv).not.toBe(encrypted2.iv);
const decrypted1 = await decrypt(encrypted1, key);
const decrypted2 = await decrypt(encrypted2, key);
expect(decrypted1).toBe(plaintext);
expect(decrypted2).toBe(plaintext);
});
test('should fail to decrypt with wrong key', async () => {
const key1 = await generateEncryptionKey();
const key2 = await generateEncryptionKey();
const plaintext = 'test data';
const encrypted = await encrypt(plaintext, key1);
await expect(decrypt(encrypted, key2)).rejects.toThrow();
});
});