This repository was archived by the owner on Feb 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathRpcHandlerManager.test.ts
More file actions
51 lines (40 loc) · 1.78 KB
/
RpcHandlerManager.test.ts
File metadata and controls
51 lines (40 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { describe, it, expect } from 'vitest';
import { RpcHandlerManager } from '../RpcHandlerManager';
import { decodeBase64, decrypt, encodeBase64, encrypt } from '@/api/encryption';
describe('RpcHandlerManager', () => {
it('routes unscoped method names to scoped handlers', async () => {
const key = new Uint8Array(32).fill(7);
const encryptionVariant: 'legacy' = 'legacy';
const manager = new RpcHandlerManager({
scopePrefix: 'sid123',
encryptionKey: key,
encryptionVariant,
logger: () => {},
});
let seen: unknown = null;
manager.registerHandler('permission', async (params) => {
seen = params;
return { ok: true };
});
const encryptedParams = encodeBase64(encrypt(key, encryptionVariant, { id: 'p1', approved: true }));
const response = await manager.handleRequest({ method: 'permission', params: encryptedParams });
const decrypted = decrypt(key, encryptionVariant, decodeBase64(response));
expect(seen).toEqual({ id: 'p1', approved: true });
expect(decrypted).toEqual({ ok: true });
});
it('accepts already-scoped method names', async () => {
const key = new Uint8Array(32).fill(9);
const encryptionVariant: 'legacy' = 'legacy';
const manager = new RpcHandlerManager({
scopePrefix: 'sid123',
encryptionKey: key,
encryptionVariant,
logger: () => {},
});
manager.registerHandler('permission', async () => ({ ok: true }));
const encryptedParams = encodeBase64(encrypt(key, encryptionVariant, { id: 'p1', approved: true }));
const response = await manager.handleRequest({ method: 'sid123:permission', params: encryptedParams });
const decrypted = decrypt(key, encryptionVariant, decodeBase64(response));
expect(decrypted).toEqual({ ok: true });
});
});