diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/websocket/receive.js | |
parent | Initial commit. (diff) | |
download | node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/websocket/receive.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/websocket/receive.js b/test/websocket/receive.js new file mode 100644 index 0000000..a669022 --- /dev/null +++ b/test/websocket/receive.js @@ -0,0 +1,60 @@ +'use strict' + +const { test } = require('tap') +const { WebSocketServer } = require('ws') +const { WebSocket } = require('../..') + +test('Receiving a frame with a payload length > 2^31-1 bytes', (t) => { + t.plan(1) + + const server = new WebSocketServer({ port: 0 }) + + server.on('connection', (ws) => { + const socket = ws._socket + + socket.write(Buffer.from([0x81, 0x7F, 0xCA, 0xE5, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00])) + }) + + const ws = new WebSocket(`ws://localhost:${server.address().port}`) + + t.teardown(() => { + ws.close() + server.close() + }) + + ws.onmessage = t.fail + + ws.addEventListener('error', (event) => { + t.type(event.error, Error) // error event is emitted + }) +}) + +test('Receiving an ArrayBuffer', (t) => { + t.plan(3) + + const server = new WebSocketServer({ port: 0 }) + + server.on('connection', (ws) => { + ws.on('message', (data, isBinary) => { + ws.send(data, { binary: true }) + + ws.close(1000) + }) + }) + + t.teardown(server.close.bind(server)) + const ws = new WebSocket(`ws://localhost:${server.address().port}`) + + ws.addEventListener('open', () => { + ws.binaryType = 'what' + t.equal(ws.binaryType, 'blob') + + ws.binaryType = 'arraybuffer' // <-- + ws.send('Hello') + }) + + ws.addEventListener('message', ({ data }) => { + t.type(data, ArrayBuffer) + t.same(Buffer.from(data), Buffer.from('Hello')) + }) +}) |