Preserve the current Alpha source and artwork snapshot. See handoff/alpha-1.0.0.3 for actual deployed hashes, checks, staged follow-ups and the production pause. This checkpoint does not claim every source feature is deployed.
7 lines
1.9 KiB
JavaScript
7 lines
1.9 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';import {evidenceMime,evidenceFileResponse,ticketEvidenceFile} from '../control-panel/evidence-media.mjs';
|
|
const movie=Buffer.concat([Buffer.from([0,0,0,24]),Buffer.from('ftypisom'),Buffer.alloc(24)]);
|
|
test('supported video signatures are recognized and HTML remains unknown',()=>{assert.equal(evidenceMime(movie),'video/mp4');assert.equal(evidenceMime(Buffer.concat([Buffer.from('1a45dfa3','hex'),Buffer.from('webm')])),'video/webm');assert.equal(evidenceMime(Buffer.from('<html>')) ,null);});
|
|
test('video seeking returns exact partial bytes with private headers',async()=>{const r=evidenceFileResponse(new Request('https://cp.test/file',{headers:{Range:'bytes=4-11'}}),movie,'clip.mp4',true);assert.equal(r.status,206);assert.equal(r.headers.get('Content-Range'),'bytes 4-11/'+movie.length);assert.match(r.headers.get('Content-Disposition'),/^inline/);assert.equal(Buffer.from(await r.arrayBuffer()).toString(),'ftypisom');assert.match(r.headers.get('Cache-Control'),/private/);});
|
|
test('invalid or multiple byte ranges are rejected',()=>{for(const range of ['bytes=999-','bytes=1-2,4-5','bytes=-','bytes=10-2'])assert.equal(evidenceFileResponse(new Request('https://cp.test/file',{headers:{Range:range}}),movie,'clip.mp4',true).status,416);});
|
|
test('unknown content never gets inline disposition even if requested',()=>{const r=evidenceFileResponse(new Request('https://cp.test/file'),Buffer.from('<script/>'),'file.html',true);assert.match(r.headers.get('Content-Disposition'),/^attachment/);assert.equal(r.headers.get('X-Content-Type-Options'),'nosniff');});
|
|
test('native attachment lookup is bound to both original ban and attachment ID',async()=>{let bound;const db={prepare(sql){assert.match(sql,/n.ban_id=\? AND a.id=\?/);return{bind(...v){bound=v;return this;},async first(){return null;}};}};assert.equal(await ticketEvidenceFile(db,'ban-fixture','42'),null);assert.deepEqual(bound,['ban-fixture','42']);});
|

Staff