Files
ChatApp/packages/shared/src/crypto/recoveryCode.test.ts
T

30 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it, beforeAll } from 'vitest';
import { setCryptoBackend } from './backend';
import { makeWasmTestBackend } from './testBackend';
import { generateRecoveryCode, normalizeRecoveryCode, RECOVERY_CODE_LEN } from './recoveryCode';
beforeAll(async () => { setCryptoBackend(await makeWasmTestBackend()); });
describe('recoveryCode', () => {
it('generates a 24-char alphabet-restricted code grouped 4×6 with dashes', async () => {
const code = await generateRecoveryCode();
expect(code).toHaveLength(27);
const groups = code.split('-');
expect(groups).toHaveLength(4);
for (const g of groups) expect(g).toMatch(/^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/);
});
it('normalizeRecoveryCode strips dashes/spaces and uppercases', () => {
expect(normalizeRecoveryCode(' abcdef-ghjklm-npqrst-uvwxyz ')).toBe('ABCDEFGHJKLMNPQRSTUVWXYZ');
});
it('normalizeRecoveryCode drops characters outside the alphabet', () => {
expect(normalizeRecoveryCode('AB1OD-EF0H1J')).toBe('ABDEFHJ');
});
it('RECOVERY_CODE_LEN matches alphabet length', () => {
expect(RECOVERY_CODE_LEN).toBe(24);
});
});