summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/testdata/run/websocket_test.ts2
-rw-r--r--cli/tests/unit/websocket_test.ts48
2 files changed, 49 insertions, 1 deletions
diff --git a/cli/tests/testdata/run/websocket_test.ts b/cli/tests/testdata/run/websocket_test.ts
index d80f03c92..43db15cce 100644
--- a/cli/tests/testdata/run/websocket_test.ts
+++ b/cli/tests/testdata/run/websocket_test.ts
@@ -163,7 +163,7 @@ Deno.test("websocket error", async () => {
// Error message got changed because we don't use warp in test_util
assertEquals(
err.message,
- "InvalidData: received corrupt message of type InvalidContentType",
+ "InvalidData: invalid data",
);
promise1.resolve();
};
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;
+});