archive-fallback.spec.ts 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import { describe, expect, it } from 'vitest';
  2. import { isLikelyEncryptedArchive } from '../packages/renderers/archive/src/archiveFallback';
  3. const createZipHeader = (signature: number, encrypted: boolean) => {
  4. const bytes = new Uint8Array(64);
  5. const view = new DataView(bytes.buffer);
  6. view.setUint32(0, signature, true);
  7. view.setUint16(signature === 0x02014b50 ? 8 : 6, encrypted ? 1 : 0, true);
  8. return bytes.buffer;
  9. };
  10. describe('archive fallback encryption guard', () => {
  11. it('detects encrypted ZIP central directory entries', () => {
  12. const archive = createZipHeader(0x02014b50, true);
  13. expect(isLikelyEncryptedArchive(archive, 'secure.zip')).toBe(true);
  14. });
  15. it('detects encrypted ZIP local file headers', () => {
  16. const archive = createZipHeader(0x04034b50, true);
  17. expect(isLikelyEncryptedArchive(archive, 'secure.cbz')).toBe(true);
  18. });
  19. it('does not mark plain ZIP or non-ZIP formats as encrypted', () => {
  20. expect(isLikelyEncryptedArchive(createZipHeader(0x02014b50, false), 'plain.zip')).toBe(false);
  21. expect(isLikelyEncryptedArchive(createZipHeader(0x02014b50, true), 'plain.tar')).toBe(false);
  22. });
  23. });