Many fixes
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { z } from 'zod';
|
||||
import type { WebSocketServer } from 'ws';
|
||||
|
||||
import { ApplicationRouter } from '../../../source/services/router.ts';
|
||||
import { WsTransportRouter } from '../../../source/services/transport/ws-transport.ts';
|
||||
import { Logger } from '../../../source/utils/logger.ts';
|
||||
import { toExtendedJson } from '@xo-cash/utils';
|
||||
import { AuthSecp256k1 } from '../../../source/auth/auth.ts';
|
||||
import { toRoutes } from '../../helpers/misc.ts';
|
||||
|
||||
/**
|
||||
* A mock of the AuthSecp256k1 service
|
||||
*/
|
||||
const auth = {
|
||||
verifySignature: vi.fn().mockResolvedValue(true),
|
||||
verifyUniqueRequest: vi.fn().mockResolvedValue(true),
|
||||
assertTimestampFreshness: vi.fn().mockResolvedValue(true),
|
||||
} as unknown as AuthSecp256k1;
|
||||
|
||||
describe('WebSocket request decoding', (): void => {
|
||||
it('decodes the minimal route-agnostic envelope and Extended JSON body', async (): Promise<void> => {
|
||||
@@ -38,11 +48,21 @@ describe('WebSocket request decoding', (): void => {
|
||||
describe('WsTransportRouter payload limits', (): void => {
|
||||
it("configures Hono's ws server with the requested maxPayload", async () => {
|
||||
const debug = new Logger('ws-transport-test');
|
||||
const router = await ApplicationRouter.create([]);
|
||||
const router = await ApplicationRouter.create({
|
||||
auth,
|
||||
}, [
|
||||
toRoutes([
|
||||
{
|
||||
url: '/data/write',
|
||||
handler: async (stream): Promise<void> => {
|
||||
await stream.send({});
|
||||
},
|
||||
},
|
||||
]),
|
||||
]);
|
||||
const transport = new WsTransportRouter(router, debug, 1024);
|
||||
const wsServer = transport.websocketServer as unknown as WebSocketServer;
|
||||
|
||||
expect(wsServer.options.maxPayload).toBe(1024);
|
||||
expect(transport['wsServer'].options.maxPayload).toBe(1024);
|
||||
await transport.stop();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user