Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

/live closes any text frame over 4096 bytes with 1009 - the three-line cap plus its boundary tests #199

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

smith/arm:smith/188-live-closes-any-text-frame-over-4096-byt → main 1 commit fork

  • Merged. smith/188-live-closes-any-text-frame-over-4096-byt was merged into main as 1e81d4c.

Review

Sign in to review this change.
2 files changed +43 −0
Software/so101/src/lobby.test.ts +41
@@ -661,4 +661,45 @@ describe("lobby", () => {
661661 arm.close();
662662 }
663663 });
664
665 describe("/live frame size", () => {
666 /** A JSON object of exactly `bytes` bytes, its padding made of `ch` (of `width` bytes each). */
667 const padded = (bytes: number, ch = "a", width = 1) => {
668 const head = '{"type":"nope","pad":"';
669 const fill = bytes - head.length - 2;
670 return head + ch.repeat(Math.floor(fill / width)) + "a".repeat(fill % width) + '"}';
671 };
672 const closing = (ws: WebSocket) => new Promise<number>((resolve) => ws.once("close", (code) => resolve(code)));
673
674 test("4096 bytes are handled and the socket stays open", async () => {
675 const port = await start();
676 const c = await join(port);
677 const text = padded(4096);
678 expect(Buffer.byteLength(text)).toBe(4096);
679 c.ws.send(text);
680 await c.next((m) => m.type === "error");
681 expect(c.ws.readyState).toBe(WebSocket.OPEN);
682 });
683
684 test("4097 bytes close with 1009", async () => {
685 const port = await start();
686 const c = await join(port);
687 const text = padded(4097);
688 expect(Buffer.byteLength(text)).toBe(4097);
689 const code = closing(c.ws);
690 c.ws.send(text);
691 expect(await code).toBe(1009);
692 });
693
694 test("1366 three-byte characters (4098 bytes) close with 1009", async () => {
695 const port = await start();
696 const c = await join(port);
697 const text = "€".repeat(1366);
698 expect(text.length).toBeLessThan(4096);
699 expect(Buffer.byteLength(text)).toBe(4098);
700 const code = closing(c.ws);
701 c.ws.send(text);
702 expect(await code).toBe(1009);
703 });
704 });
664705 });
Software/so101/src/lobby.ts +2
@@ -34,6 +34,7 @@ import type { Duplex } from "node:stream";
3434 import WebSocket, { WebSocketServer } from "ws";
3535 import { Accounts, visitor, type Visitor } from "./accounts.ts";
3636 import { Admin, AdminError } from "./admin.ts";
37 import { frameBytes, TOO_BIG_CLOSE } from "./frame-limit.ts";
3738 import { Chat, ChatError } from "./chat.ts";
3839 import { Moderator } from "./moderator.ts";
3940 import { WordFilter } from "./word-filter.ts";
@@ -261,6 +262,7 @@ export class Lobby {
261262 ws.on("message", (data, binary) => {
262263 seat.heard = Date.now();
263264 if (binary) return;
265 if (frameBytes(data) > MAX_FRAME) return ws.close(TOO_BIG_CLOSE, "message too big");
264266 let message: unknown;
265267 try {
266268 message = JSON.parse(String(data));

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs