add frontend AES-GCM and base64 helpers with Vitest coverage.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { base64ToBytes } from '@/utils/encoding/base64ToBytes';
|
||||
|
||||
describe('base64ToBytes', () => {
|
||||
it('decodes RFC 4648 examples', () => {
|
||||
expect(base64ToBytes('Zg==')).toEqual(new Uint8Array([102]));
|
||||
expect(base64ToBytes('Zm8=')).toEqual(new Uint8Array([102, 111]));
|
||||
expect(base64ToBytes('Zm9v')).toEqual(new Uint8Array([102, 111, 111]));
|
||||
expect(base64ToBytes('Zm9vYg==')).toEqual(new Uint8Array([102, 111, 111, 98]));
|
||||
});
|
||||
|
||||
it('decodes empty input', () => {
|
||||
expect(base64ToBytes('')).toEqual(new Uint8Array([]));
|
||||
});
|
||||
|
||||
it('decodes every byte value via roundtrip with btoa', () => {
|
||||
const bytes = new Uint8Array(256);
|
||||
|
||||
for (let i = 0; i < 256; i++) {
|
||||
bytes[i] = i;
|
||||
}
|
||||
|
||||
const binary = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
|
||||
const base64 = btoa(binary);
|
||||
|
||||
expect(base64ToBytes(base64)).toEqual(bytes);
|
||||
});
|
||||
|
||||
it('rejects invalid base64', () => {
|
||||
expect(() => base64ToBytes('not!!!valid')).toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user