25 lines
892 B
TypeScript
25 lines
892 B
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { decryptBackup, encryptBackup } from '@/lib/backup-crypto';
|
|
import { MindScopeBackup } from '@/lib/assessment-types';
|
|
|
|
const backup: MindScopeBackup = {
|
|
format: 'mindscope-backup',
|
|
version: 1,
|
|
exportedAt: '2026-06-23T00:00:00.000Z',
|
|
profiles: [],
|
|
records: [],
|
|
};
|
|
|
|
describe('encrypted backups', () => {
|
|
it('round trips a backup with the correct password', async () => {
|
|
const encrypted = await encryptBackup(backup, 'correct-password');
|
|
expect(encrypted.data).not.toContain('mindscope-backup');
|
|
await expect(decryptBackup(encrypted, 'correct-password')).resolves.toEqual(backup);
|
|
});
|
|
|
|
it('rejects an incorrect password', async () => {
|
|
const encrypted = await encryptBackup(backup, 'correct-password');
|
|
await expect(decryptBackup(encrypted, 'wrong-password')).rejects.toThrow('密码错误');
|
|
});
|
|
});
|