diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-10-31 09:34:45 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-31 09:34:45 -0600 |
commit | e4308aebc0a060e7210362e576e792e558384c24 (patch) | |
tree | fe3a39fe85669d1fb55811e001f6cacefdadd561 /cli/tests/unit/websocket_test.ts | |
parent | edee8ab95d28abfce5606ab35e02b7c7ace2cf8d (diff) |
feat(ext/websocket): use rustls-tokio-stream instead of tokio-rustls (#20518)
Use new https://github.com/denoland/rustls-tokio-stream project instead
of tokio-rustls for direct websocket connections. This library was
written from the ground up to be more reliable and should help with
various bugs that may occur due to underlying bugs in the old library.
Believed to fix #20355, #18977, #20948
Diffstat (limited to 'cli/tests/unit/websocket_test.ts')
-rw-r--r-- | cli/tests/unit/websocket_test.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts index b761cd118..8ae729d42 100644 --- a/cli/tests/unit/websocket_test.ts +++ b/cli/tests/unit/websocket_test.ts @@ -277,3 +277,51 @@ Deno.test( } }, ); + +Deno.test(async function websocketTlsSocketWorks() { + const cert = await Deno.readTextFile("cli/tests/testdata/tls/localhost.crt"); + const key = await Deno.readTextFile("cli/tests/testdata/tls/localhost.key"); + + const messages: string[] = [], + errors: { server?: Event; client?: Event }[] = []; + const promise = new Promise((okay, nope) => { + const ac = new AbortController(); + const server = Deno.serve({ + handler: (req) => { + const { response, socket } = Deno.upgradeWebSocket(req); + socket.onopen = () => socket.send("ping"); + socket.onmessage = (e) => { + messages.push(e.data); + socket.close(); + }; + socket.onerror = (e) => errors.push({ server: e }); + socket.onclose = () => ac.abort(); + return response; + }, + signal: ac.signal, + hostname: "localhost", + port: servePort, + cert, + key, + }); + setTimeout(() => { + const ws = new WebSocket(`wss://localhost:${servePort}`); + ws.onmessage = (e) => { + messages.push(e.data); + ws.send("pong"); + }; + ws.onerror = (e) => { + errors.push({ client: e }); + nope(); + }; + ws.onclose = () => okay(server.finished); + }, 1000); + }); + + const finished = await promise; + + assertEquals(errors, []); + assertEquals(messages, ["ping", "pong"]); + + await finished; +}); |