This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restrict message sizes to 16kb
- Loading branch information
1 parent
4f1840e
commit f15207e
Showing
2 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
import { expect } from 'aegir/chai' | ||
import { Uint8ArrayList } from 'uint8arraylist' | ||
import * as underTest from '../src/stream' | ||
|
||
const setup = (cb: { send: (bytes: Uint8Array) => void }): underTest.WebRTCStream => { | ||
const datachannel = { | ||
readyState: 'open', | ||
send: cb.send | ||
|
||
} | ||
return new underTest.WebRTCStream({ channel: datachannel as RTCDataChannel, stat: underTest.defaultStat('outbound') }) | ||
} | ||
|
||
const MAX_MESSAGE_SIZE = 16 * 1024 | ||
describe('MessageProcessor', () => { | ||
it(`sends messages smaller or equal to ${MAX_MESSAGE_SIZE} bytes in one`, () => { | ||
const sent: Uint8Array[] = [] | ||
const webrtcStream = setup({ send: (bytes) => sent.push(bytes) }) | ||
webrtcStream.messageProcessor.send(new Uint8ArrayList(new Uint8Array(MAX_MESSAGE_SIZE))) | ||
expect(sent).to.deep.equals([new Uint8Array(MAX_MESSAGE_SIZE)]) | ||
}) | ||
|
||
it(`sends messages large than ${MAX_MESSAGE_SIZE} bytes in parts`, () => { | ||
const sent: Uint8Array[] = [] | ||
const webrtcStream = setup({ send: (bytes) => sent.push(bytes) }) | ||
webrtcStream.messageProcessor.send(new Uint8ArrayList(new Uint8Array(MAX_MESSAGE_SIZE + 1))) | ||
expect(sent).to.deep.equals([new Uint8Array(MAX_MESSAGE_SIZE), new Uint8Array(1)]) | ||
}) | ||
}) |