Cover max-length websocket request id boundaries end-to-end
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
f57cff53e6
commit
5d13d3cd61
3 files changed
+72
No files matched your search
@@ -2177,6 +2177,22 @@ async function main() {
|
||||
);
|
||||
}
|
||||
|
||||
const maxLengthHealthResponse = await sendWsRequest(ws, {
|
||||
id: "r".repeat(WS_REQUEST_ID_MAX_CHARS),
|
||||
method: "app.health",
|
||||
});
|
||||
if (
|
||||
maxLengthHealthResponse.ok !== true ||
|
||||
maxLengthHealthResponse.result?.status !== "ok" ||
|
||||
maxLengthHealthResponse.result?.launchCwd !== appRoot
|
||||
) {
|
||||
throw new Error(
|
||||
`Smoke test failed: expected healthy response for max-length request id, got ${JSON.stringify(
|
||||
maxLengthHealthResponse,
|
||||
)}.`,
|
||||
);
|
||||
}
|
||||
|
||||
const bootstrapResponse = await sendWsRequest(ws, {
|
||||
id: "smoke-bootstrap",
|
||||
method: "app.bootstrap",
|
||||
|
||||
@@ -580,6 +580,31 @@ describe("runtimeApiServer", () => {
|
||||
client.socket.close();
|
||||
});
|
||||
|
||||
it("accepts request ids at max websocket length", async () => {
|
||||
const server = await startRuntimeApiServer({
|
||||
port: 0,
|
||||
launchCwd: process.cwd(),
|
||||
});
|
||||
servers.push(server);
|
||||
|
||||
const client = await connectClient(server.wsUrl);
|
||||
await client.nextMessage();
|
||||
|
||||
const response = await sendRequest(
|
||||
client.socket,
|
||||
client.nextMessage,
|
||||
"r".repeat(WS_REQUEST_ID_MAX_CHARS),
|
||||
"todos.list",
|
||||
);
|
||||
expect(response.ok).toBe(true);
|
||||
if (!response.ok) {
|
||||
throw new Error("Expected max-length request id response to succeed.");
|
||||
}
|
||||
expect(response.id).toHaveLength(WS_REQUEST_ID_MAX_CHARS);
|
||||
|
||||
client.socket.close();
|
||||
});
|
||||
|
||||
it("responds to providers.listSessions over websocket RPC", async () => {
|
||||
const server = await startRuntimeApiServer({
|
||||
port: 0,
|
||||
|
||||
@@ -52,6 +52,16 @@ describe("wsClientMessageSchema", () => {
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("accepts request ids at max length", () => {
|
||||
const parsed = wsClientMessageSchema.parse({
|
||||
type: "request",
|
||||
id: "r".repeat(WS_REQUEST_ID_MAX_CHARS),
|
||||
method: "providers.startSession",
|
||||
});
|
||||
|
||||
expect(parsed.id).toHaveLength(WS_REQUEST_ID_MAX_CHARS);
|
||||
});
|
||||
|
||||
it("rejects overly long request methods", () => {
|
||||
expect(() =>
|
||||
wsClientMessageSchema.parse({
|
||||
@@ -62,6 +72,16 @@ describe("wsClientMessageSchema", () => {
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("accepts request methods at max length", () => {
|
||||
const parsed = wsClientMessageSchema.parse({
|
||||
type: "request",
|
||||
id: "req-1",
|
||||
method: "m".repeat(WS_METHOD_MAX_CHARS),
|
||||
});
|
||||
|
||||
expect(parsed.method).toHaveLength(WS_METHOD_MAX_CHARS);
|
||||
});
|
||||
|
||||
it("rejects unexpected request properties", () => {
|
||||
expect(() =>
|
||||
wsClientMessageSchema.parse({
|
||||
@@ -159,6 +179,17 @@ describe("wsServerMessageSchema", () => {
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("accepts response ids at max length", () => {
|
||||
const parsed = wsServerMessageSchema.parse({
|
||||
type: "response",
|
||||
id: "r".repeat(WS_REQUEST_ID_MAX_CHARS),
|
||||
ok: true,
|
||||
result: {},
|
||||
});
|
||||
|
||||
expect(parsed.type).toBe("response");
|
||||
});
|
||||
|
||||
it("accepts typed event channels", () => {
|
||||
const parsed = wsServerMessageSchema.parse({
|
||||
type: "event",
|
||||
|
||||
Reference in new issue
Block a user