19 lines
1.2 KiB
JavaScript
19 lines
1.2 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const p = require('./direct-protocol.js');
|
|
test('direct protocol strips unexpected payload and validates file claims', () => {
|
|
const m = p.parse({ type: 'direct', action: 'invite', to: 'peer', file: { id: 'video', title: 'Song', cid: 'a'.repeat(64), size: 10, bytes: 'secret' }, bytes: 'not relayed' });
|
|
assert.equal(m.file.size, 10); assert.equal(m.bytes, undefined); assert.equal(m.file.bytes, undefined);
|
|
assert.equal(p.parse({ ...m, file: { ...m.file, size: Infinity } }), null);
|
|
assert.equal(p.parse(new Uint8Array(4)), null);
|
|
});
|
|
test('chunks retain exact resume offset and never exceed file end', () => {
|
|
assert.deepEqual(p.nextChunk(17, 100000), { start: 17, end: 65553 });
|
|
assert.deepEqual(p.nextChunk(99999, 100000), { start: 99999, end: 100000 });
|
|
for (const n of [-1, 100001, 0.5, NaN]) assert.throws(() => p.offset(n, 100000));
|
|
});
|
|
test('signalling only admits bounded SDP or ICE, never byte frames', () => {
|
|
assert.equal(p.parse({ type: 'direct', action: 'signal', token: 'abc', data: { kind: 'bytes', data: [1, 2] } }), null);
|
|
assert.equal(p.parse({ type: 'direct', action: 'signal', token: 'abc', data: { kind: 'offer', sdp: 'x'.repeat(60001) } }), null);
|
|
});
|