The observability release gave every request an id and lost it at the process boundary — in the one place a distributed trace is the entire point. The RPC envelope now carries requestId, traceId and url, and the teapot adopts them instead of opening its own investigation. Both fields are optional on the wire, so the protocol version does not move. That decision needed a rule rather than a judgement call, so the rule is now written beside the constant: bump when an old peer would misparse or misbehave silently, not when work happened. Bumping per change would make the number mean the opposite of what it is for. Three things found while in here: - mesh:rpc:error emitted the per-link counter where every other emitter puts a name, so the two sides of one failure could not be matched up. - The teapot had no handshake deadline, so an unauthenticated peer could hold a socket by saying nothing, and no frame size cap, so it could make the process JSON.parse up to whatever the socket layer allowed — 100 MiB with the ws defaults, before authenticating. - The remote-route envelope was cast from the internal request object, putting ip and protocol on the wire as fields the protocol never declared. The cleartext warning is a warning and not a refusal on purpose: a private network already doing mutual TLS is legitimate, and green-tea cannot tell it apart from an exposed one. 4 of the 8 new tests verified to fail against the old code; the rest are the negative cases, which should pass both before and after. The Deno test drives the teapot's frame loop with a raw client, because server-side close codes are where these runtimes have already differed once. 431 vitest / 12 Deno / 7 Bun / edge / JSR dry run. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
// The teapot's frame loop under Deno, driven by a raw client rather than by another green-tea.
|
|
//
|
|
// The two guards here are close-code behaviour, and close codes are exactly where the runtimes
|
|
// have already differed once — a client may only send 1000 or 3000-4999, which is why the mesh
|
|
// heartbeat uses 4011 instead of 1011. Server-side closes deserve the same suspicion.
|
|
//
|
|
// Run with: npm run test:deno
|
|
import 'npm:reflect-metadata';
|
|
import { assertEquals } from 'jsr:@std/assert';
|
|
import { createApp, Step, Module } from '../../src/index.ts';
|
|
import { serveDeno } from '../../src/deno.ts';
|
|
|
|
@Step({ provides: 'auth', needs: [], export: true })
|
|
class Auth {
|
|
run() {
|
|
return { auth: { ok: true } };
|
|
}
|
|
}
|
|
@Module({ mountpoint: '/api', steps: [Auth] })
|
|
class TeapotModule {}
|
|
|
|
async function startTeapot() {
|
|
const app = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: 'good' } });
|
|
let port = 0;
|
|
const server = serveDeno(app, { port: 0, onListen: (addr) => (port = addr.port) });
|
|
await new Promise((r) => setTimeout(r, 50));
|
|
|
|
return { port: () => port, stop: async () => { await server.shutdown(); await app.close(); } };
|
|
}
|
|
|
|
/** Opens a raw control-channel socket and resolves with how it ended. */
|
|
function rawClient(port: number, send: string): Promise<{ code: number }> {
|
|
return new Promise((resolve, reject) => {
|
|
const ws = new WebSocket(`ws://127.0.0.1:${port}/__mesh__/control`);
|
|
ws.onopen = () => ws.send(send);
|
|
ws.onclose = (event) => resolve({ code: event.code });
|
|
ws.onerror = () => reject(new Error('socket errored'));
|
|
});
|
|
}
|
|
|
|
Deno.test('mesh on Deno: the teapot hangs up on an oversized control frame', async () => {
|
|
const teapot = await startTeapot();
|
|
|
|
try {
|
|
// over the 4,000,000-character cap, and sent by a peer that has not authenticated
|
|
const oversized = `{"type":"hello","v":1,"secret":"${'a'.repeat(4_000_001)}"}`;
|
|
const { code } = await rawClient(teapot.port(), oversized);
|
|
|
|
assertEquals(code, 1009);
|
|
} finally {
|
|
await teapot.stop();
|
|
}
|
|
});
|