Files
core/test/adapter-tls.test.ts
T
chrnx 870cdb25e9 fix(adapters): reject createApp({ tls }) on Deno and Bun
Only Node's listen() reads tls. serveDeno and serveBun serve through
the runtime's own listener, so an app created with tls came up as
plain HTTP without warning, for a caller who had asked for HTTPS.

createApp now marks the app with a symbol, following the MARK_EDGE
pattern. Both adapters throw on that mark before they boot or bind.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-30 08:53:52 -05:00

31 lines
1.1 KiB
TypeScript

import { afterEach, expect, it, vi } from 'vitest';
import { createApp } from '../src';
import { serveDeno } from '../src/deno';
import { serveBun } from '../src/bun';
afterEach(() => {
vi.unstubAllGlobals();
});
// Only Node's `listen()` reads `tls`. Deno and Bun serve through their own listener, so an app
// created with `tls` would come up as plain HTTP there — refused before anything binds.
it.each([
['serveDeno', 'Deno', serveDeno],
['serveBun', 'Bun', serveBun],
] as const)('%s refuses an app created with tls', async (name, global, serve) => {
const listen = vi.fn();
vi.stubGlobal(global, { serve: listen });
const app = createApp({ modules: [], tls: { key: 'k', cert: 'c' } });
await expect(serve(app)).rejects.toThrow(`${name} does not support createApp({ tls })`);
expect(listen).not.toHaveBeenCalled();
});
it('an app without tls is not refused', async () => {
const listen = vi.fn(() => ({ port: 0, stop: vi.fn() }));
vi.stubGlobal('Bun', { serve: listen });
await serveBun(createApp({ modules: [] }));
expect(listen).toHaveBeenCalledOnce();
});