Added auth and request storage

This commit is contained in:
2026-08-31 12:28:18 +00:00
parent 6febaf327a
commit 1ca9648c09
21 changed files with 634 additions and 117 deletions
+23 -6
View File
@@ -13,19 +13,36 @@ describe('WebSocket request decoding', (): void => {
id: 'request-1',
path: '/data/write',
body: { value: new Uint8Array([ 1, 2, 3 ]) },
headers: { 'X-Request-Token': 'ws-token' },
}))).resolves.toEqual({
requestId: 'request-1',
path: '/data/write',
body: { value: new Uint8Array([ 1, 2, 3 ]) },
headers: { 'x-request-token': 'ws-token' },
});
});
it.each([ '{}', '{"path":42}', '{"path":"/data/get","id":1}', '{"path":"/data/get","method":"POST"}' ])(
'rejects an invalid envelope: %s',
async (payload) => {
await expect(WsTransportRouter.decodeWebSocketRequest(payload)).rejects.toBeInstanceOf(z.ZodError);
},
);
it('allows the optional headers object to be omitted', async (): Promise<void> => {
await expect(WsTransportRouter.decodeWebSocketRequest('{"path":"/data/get"}')).resolves.toEqual({ path: '/data/get' });
});
it.each([
'{}',
'{"path":42}',
'{"path":"/data/get","id":1}',
'{"path":"/data/get","method":"POST"}',
'{"path":"/data/get","headers":{"x-request-token":1}}',
])('rejects an invalid envelope: %s', async (payload) => {
await expect(WsTransportRouter.decodeWebSocketRequest(payload)).rejects.toBeInstanceOf(z.ZodError);
});
it.each([
'{"path":"/data/get","headers":{"bad header":"value"}}',
'{"path":"/data/get","headers":{"x-request-token":"first","X-Request-Token":"second"}}',
'{"path":"/data/get","headers":{"x-request-token":"first\\r\\nsecond"}}',
])('rejects malformed request headers: %s', async (payload): Promise<void> => {
await expect(WsTransportRouter.decodeWebSocketRequest(payload)).rejects.toMatchObject({ statusCode: 400 });
});
it('rejects malformed JSON', async (): Promise<void> => {
await expect(WsTransportRouter.decodeWebSocketRequest('{')).rejects.toMatchObject({