import assert from 'node:assert/strict'; import test from 'node:test'; import { inspectAssetFile, MAX_ASSET_MEDIA_BYTES, } from '../../src/asset-master/asset-media-file'; import { AssetMediaKind } from '../../src/database/entities'; function file(buffer: Buffer, originalname: string) { return { buffer, originalname, size: buffer.length }; } test('file inspection trusts magic bytes instead of the declared extension', () => { const result = inspectAssetFile( file(Buffer.from([0xff, 0xd8, 0xff, 0xe0, 0x00]), 'registro.pdf'), AssetMediaKind.PHOTO, ); assert.equal(result.mimeType, 'image/jpeg'); assert.equal(result.extension, '.jpg'); }); test('file inspection rejects kind mismatches and executable text', () => { assert.throws(() => inspectAssetFile( file(Buffer.from('%PDF-1.7'), 'documento.pdf'), AssetMediaKind.PHOTO, )); assert.throws(() => inspectAssetFile( file(Buffer.from(''), 'foto.jpg'), AssetMediaKind.PHOTO, )); }); test('file inspection enforces the 15 MB boundary', () => { const oversized = { buffer: Buffer.from([0xff, 0xd8, 0xff]), originalname: 'foto.jpg', size: MAX_ASSET_MEDIA_BYTES + 1, }; assert.throws(() => inspectAssetFile(oversized, AssetMediaKind.PHOTO)); });