@canton-network/wallet-gateway-remote 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -29
- package/dist/auth/jwt-auth-service.d.ts.map +1 -1
- package/dist/auth/jwt-auth-service.js +150 -77
- package/dist/config/Config.d.ts +146 -22
- package/dist/config/Config.d.ts.map +1 -1
- package/dist/config/Config.js +120 -6
- package/dist/config/ConfigUtils.d.ts.map +1 -1
- package/dist/config/ConfigUtils.js +3 -1
- package/dist/dapp-api/controller.d.ts.map +1 -1
- package/dist/dapp-api/controller.js +14 -19
- package/dist/dapp-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/dapp-api/rpc-gen/typings.d.ts +3 -3
- package/dist/dapp-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/dapp-api/server.d.ts.map +1 -1
- package/dist/dapp-api/sse-sink.d.ts.map +1 -1
- package/dist/env.d.ts +1 -24
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +0 -23
- package/dist/example-config.d.ts +40 -4
- package/dist/example-config.d.ts.map +1 -1
- package/dist/example-config.js +44 -8
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +75 -28
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +24 -110
- package/dist/ledger/party-allocation-service.d.ts +1 -4
- package/dist/ledger/party-allocation-service.d.ts.map +1 -1
- package/dist/ledger/party-allocation-service.js +1 -3
- package/dist/ledger/self-issued-auth-service.d.ts +15 -15
- package/dist/ledger/self-issued-auth-service.d.ts.map +1 -1
- package/dist/ledger/self-issued-auth-service.js +44 -43
- package/dist/ledger/wallet-allocation/signing-providers/bitgo-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/bitgo-wallet-allocator.js +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/blockdaemon-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/dfns-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/kernel-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/participant-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/securosys-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts +2 -2
- package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/wallet-allocation-service.js +2 -2
- package/dist/ledger/wallet-sync-service.d.ts +3 -0
- package/dist/ledger/wallet-sync-service.d.ts.map +1 -1
- package/dist/ledger/wallet-sync-service.js +143 -28
- package/dist/middleware/apiKeyAuth.d.ts.map +1 -1
- package/dist/middleware/apiKeyAuth.js +4 -8
- package/dist/middleware/errorHandler.d.ts +1 -1
- package/dist/middleware/errorHandler.d.ts.map +1 -1
- package/dist/middleware/jsonRpcHandler.d.ts.map +1 -1
- package/dist/middleware/jsonRpcHandler.js +3 -3
- package/dist/middleware/jwtAuth.d.ts +1 -1
- package/dist/middleware/jwtAuth.d.ts.map +1 -1
- package/dist/middleware/jwtAuth.js +17 -2
- package/dist/middleware/securityHeaders.d.ts.map +1 -1
- package/dist/middleware/sessionHandler.d.ts +3 -3
- package/dist/middleware/sessionHandler.d.ts.map +1 -1
- package/dist/middleware/sessionHandler.js +8 -8
- package/dist/signing/service-account-session.d.ts.map +1 -1
- package/dist/signing/service-account-session.js +1 -1
- package/dist/signing/signing-worker.d.ts +1 -1
- package/dist/signing/signing-worker.d.ts.map +1 -1
- package/dist/signing/signing-worker.js +2 -5
- package/dist/signing-providers-registration.d.ts +6 -0
- package/dist/signing-providers-registration.d.ts.map +1 -0
- package/dist/signing-providers-registration.js +216 -0
- package/dist/user-api/controller.d.ts +6 -3
- package/dist/user-api/controller.d.ts.map +1 -1
- package/dist/user-api/controller.js +218 -94
- package/dist/user-api/rpc-gen/index.d.ts +18 -9
- package/dist/user-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/index.js +6 -3
- package/dist/user-api/rpc-gen/schemas.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/schemas.js +42 -10
- package/dist/user-api/rpc-gen/typings.d.ts +67 -45
- package/dist/user-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/user-api/server.d.ts.map +1 -1
- package/dist/web/frontend/404/index.html +2 -2
- package/dist/web/frontend/activities/index.html +3 -3
- package/dist/web/frontend/api-keys/add/index.html +2 -2
- package/dist/web/frontend/api-keys/index.html +2 -2
- package/dist/web/frontend/approve/index.html +4 -3
- package/dist/web/frontend/assets/404-D6hNG1H8.js +5 -0
- package/dist/web/frontend/assets/{activities-HZnPjlMp.js → activities-CSaNJ4Bw.js} +2 -2
- package/dist/web/frontend/assets/{addApiKey-BvkCtUF3.js → addApiKey-IKOYP6lC.js} +3 -3
- package/dist/web/frontend/assets/addIdentityProvider-CnRS1C3U.js +28 -0
- package/dist/web/frontend/assets/addNetwork-Wq0K3t5Z.js +38 -0
- package/dist/web/frontend/assets/{addParty-Cdoed_Yx.js → addParty-B0GaqKvG.js} +3 -2
- package/dist/web/frontend/assets/{apiKeys-BwV6ylWL.js → apiKeys-BgJyxg5r.js} +2 -2
- package/dist/web/frontend/assets/approve-kKlT_54l.js +27 -0
- package/dist/web/frontend/assets/callback-83Lr1QFW.js +7 -0
- package/dist/web/frontend/assets/common-BkYw_tO_.js +31 -0
- package/dist/web/frontend/assets/{editParty-OOjTHFay.js → editParty-DU9eMclk.js} +3 -2
- package/dist/web/frontend/assets/{identityProviders-BxJAq1Ne.js → identityProviders-sWmbKlSu.js} +2 -2
- package/dist/web/frontend/assets/{index-D1Brmwbg.js → index-AvzB2hln.js} +3 -3
- package/dist/web/frontend/assets/index-BF3EIXoM.js +2 -0
- package/dist/web/frontend/assets/{index-CG_aFABR.js → index-CGK8ht7_.js} +1 -1
- package/dist/web/frontend/assets/index-DRQ0oWml.js +4814 -0
- package/dist/web/frontend/assets/index-NgSpx7q_.js +3 -0
- package/dist/web/frontend/assets/login-BqK1nbQm.js +11 -0
- package/dist/web/frontend/assets/{networks-CBprjUF5.js → networks-C62lWsP4.js} +3 -3
- package/dist/web/frontend/assets/{reviewIdentityProvider-CCmKgN8N.js → reviewIdentityProvider-pILqo6EV.js} +4 -4
- package/dist/web/frontend/assets/{reviewNetwork-CX8Bmuf3.js → reviewNetwork-DZOWqkuG.js} +3 -3
- package/dist/web/frontend/assets/selfIssuedLogin-DarXIpvS.js +81 -0
- package/dist/web/frontend/assets/signMessage-k9b_lLxh.js +23 -0
- package/dist/web/frontend/callback/index.html +3 -2
- package/dist/web/frontend/identity-providers/add/index.html +2 -2
- package/dist/web/frontend/identity-providers/index.html +2 -2
- package/dist/web/frontend/identity-providers/review/index.html +2 -2
- package/dist/web/frontend/index.html +1 -1
- package/dist/web/frontend/login/index.html +3 -2
- package/dist/web/frontend/networks/add/index.html +2 -2
- package/dist/web/frontend/networks/index.html +2 -2
- package/dist/web/frontend/networks/review/index.html +2 -2
- package/dist/web/frontend/parties/add/index.html +5 -5
- package/dist/web/frontend/parties/edit/index.html +5 -5
- package/dist/web/frontend/parties/index.html +3 -3
- package/dist/web/frontend/{onboarding → self-issued-login}/index.html +6 -5
- package/dist/web/frontend/sign-message/index.html +2 -2
- package/dist/web/route-inputs.js +1 -1
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +1 -1
- package/package.json +49 -51
- package/dist/auth/jwt-auth-service.test.d.ts +0 -2
- package/dist/auth/jwt-auth-service.test.d.ts.map +0 -1
- package/dist/auth/jwt-auth-service.test.js +0 -659
- package/dist/config/Config.test.d.ts +0 -2
- package/dist/config/Config.test.d.ts.map +0 -1
- package/dist/config/Config.test.js +0 -26
- package/dist/dapp-api/controller.test.d.ts +0 -2
- package/dist/dapp-api/controller.test.d.ts.map +0 -1
- package/dist/dapp-api/controller.test.js +0 -531
- package/dist/dapp-api/server.test.d.ts +0 -2
- package/dist/dapp-api/server.test.d.ts.map +0 -1
- package/dist/dapp-api/server.test.js +0 -79
- package/dist/dapp-api/sse-sink.test.d.ts +0 -2
- package/dist/dapp-api/sse-sink.test.d.ts.map +0 -1
- package/dist/dapp-api/sse-sink.test.js +0 -30
- package/dist/ledger/party-allocation-service.test.d.ts +0 -2
- package/dist/ledger/party-allocation-service.test.d.ts.map +0 -1
- package/dist/ledger/party-allocation-service.test.js +0 -105
- package/dist/ledger/self-issued-auth-service.test.d.ts +0 -2
- package/dist/ledger/self-issued-auth-service.test.d.ts.map +0 -1
- package/dist/ledger/self-issued-auth-service.test.js +0 -454
- package/dist/ledger/wallet-allocation/wallet-allocation-service.test.d.ts +0 -2
- package/dist/ledger/wallet-allocation/wallet-allocation-service.test.d.ts.map +0 -1
- package/dist/ledger/wallet-allocation/wallet-allocation-service.test.js +0 -1005
- package/dist/ledger/wallet-sync-service.test.d.ts +0 -2
- package/dist/ledger/wallet-sync-service.test.d.ts.map +0 -1
- package/dist/ledger/wallet-sync-service.test.js +0 -1017
- package/dist/middleware/apiKeyAuth.test.d.ts +0 -2
- package/dist/middleware/apiKeyAuth.test.d.ts.map +0 -1
- package/dist/middleware/apiKeyAuth.test.js +0 -126
- package/dist/middleware/errorHandler.test.d.ts +0 -2
- package/dist/middleware/errorHandler.test.d.ts.map +0 -1
- package/dist/middleware/errorHandler.test.js +0 -138
- package/dist/middleware/jsonRpcHandler.test.d.ts +0 -2
- package/dist/middleware/jsonRpcHandler.test.d.ts.map +0 -1
- package/dist/middleware/jsonRpcHandler.test.js +0 -377
- package/dist/middleware/jwtAuth.test.d.ts +0 -2
- package/dist/middleware/jwtAuth.test.d.ts.map +0 -1
- package/dist/middleware/jwtAuth.test.js +0 -100
- package/dist/middleware/rateLimit.test.d.ts +0 -2
- package/dist/middleware/rateLimit.test.d.ts.map +0 -1
- package/dist/middleware/rateLimit.test.js +0 -56
- package/dist/middleware/securityHeaders.test.d.ts +0 -2
- package/dist/middleware/securityHeaders.test.d.ts.map +0 -1
- package/dist/middleware/securityHeaders.test.js +0 -18
- package/dist/middleware/sessionHandler.test.d.ts +0 -2
- package/dist/middleware/sessionHandler.test.d.ts.map +0 -1
- package/dist/middleware/sessionHandler.test.js +0 -215
- package/dist/signing/service-account-session.test.d.ts +0 -2
- package/dist/signing/service-account-session.test.d.ts.map +0 -1
- package/dist/signing/service-account-session.test.js +0 -88
- package/dist/signing/signing-worker.test.d.ts +0 -2
- package/dist/signing/signing-worker.test.d.ts.map +0 -1
- package/dist/signing/signing-worker.test.js +0 -158
- package/dist/user-api/controller.test.d.ts +0 -2
- package/dist/user-api/controller.test.d.ts.map +0 -1
- package/dist/user-api/controller.test.js +0 -1228
- package/dist/user-api/server.test.d.ts +0 -2
- package/dist/user-api/server.test.d.ts.map +0 -1
- package/dist/user-api/server.test.js +0 -117
- package/dist/user-api/token-network-matching.test.d.ts +0 -2
- package/dist/user-api/token-network-matching.test.d.ts.map +0 -1
- package/dist/user-api/token-network-matching.test.js +0 -66
- package/dist/utils.test.d.ts +0 -2
- package/dist/utils.test.d.ts.map +0 -1
- package/dist/utils.test.js +0 -24
- package/dist/web/frontend/assets/404-B1XXXMXN.js +0 -5
- package/dist/web/frontend/assets/addIdentityProvider-Dvjma837.js +0 -28
- package/dist/web/frontend/assets/addNetwork-Cahac0uo.js +0 -38
- package/dist/web/frontend/assets/approve-B0nIfe2y.js +0 -26
- package/dist/web/frontend/assets/callback-BieW5Ux2.js +0 -7
- package/dist/web/frontend/assets/common-Bv9twGrA.js +0 -31
- package/dist/web/frontend/assets/index-Bo6MnlYI.js +0 -2
- package/dist/web/frontend/assets/index-pMOoiNFq.js +0 -4887
- package/dist/web/frontend/assets/login-BHxgJEz_.js +0 -11
- package/dist/web/frontend/assets/onboarding-ChmWs-TC.js +0 -84
- package/dist/web/frontend/assets/signMessage-BN_6S5FV.js +0 -79
- package/dist/web/route-inputs.test.d.ts +0 -2
- package/dist/web/route-inputs.test.d.ts.map +0 -1
- package/dist/web/route-inputs.test.js +0 -30
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apiKeyAuth.test.d.ts","sourceRoot":"","sources":["../../src/middleware/apiKeyAuth.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
4
|
-
import { apiKeyAuth } from './apiKeyAuth.js';
|
|
5
|
-
import { pino } from 'pino';
|
|
6
|
-
import { sink } from 'pino-test';
|
|
7
|
-
import crypto from 'crypto';
|
|
8
|
-
vi.mock('@canton-network/core-wallet-auth', async () => {
|
|
9
|
-
const actual = await vi.importActual('@canton-network/core-wallet-auth');
|
|
10
|
-
return {
|
|
11
|
-
...actual,
|
|
12
|
-
AuthTokenProvider: {
|
|
13
|
-
fromGatewayConfig: vi.fn().mockReturnValue({
|
|
14
|
-
getAuthContext: vi.fn().mockResolvedValue({
|
|
15
|
-
userId: 'service_account',
|
|
16
|
-
accessToken: 'abc',
|
|
17
|
-
}),
|
|
18
|
-
}),
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
describe('apiKeyAuth', () => {
|
|
23
|
-
const getApiKey = vi.fn();
|
|
24
|
-
const logger = pino({ level: 'silent' }, sink());
|
|
25
|
-
const store = {
|
|
26
|
-
getApiKey,
|
|
27
|
-
getNetwork: vi.fn().mockResolvedValue({
|
|
28
|
-
id: 'canton:local-oauth',
|
|
29
|
-
identityProviderId: 'idp-mock-oauth',
|
|
30
|
-
serviceAccountAuth: {
|
|
31
|
-
method: 'client_credentials',
|
|
32
|
-
scope: 'daml_ledger_api',
|
|
33
|
-
audience: 'aud',
|
|
34
|
-
clientId: 'service_account',
|
|
35
|
-
clientSecret: 'service-account-secret',
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
38
|
-
getIdp: vi.fn().mockResolvedValue({
|
|
39
|
-
id: 'idp-mock-oauth',
|
|
40
|
-
type: 'oauth',
|
|
41
|
-
issuer: 'http://127.0.0.1:8889',
|
|
42
|
-
configUrl: 'http://127.0.0.1:8889/.well-known/openid-configuration',
|
|
43
|
-
}),
|
|
44
|
-
setSession: vi.fn(),
|
|
45
|
-
authContext: undefined,
|
|
46
|
-
withAuthContext(context) {
|
|
47
|
-
this.authContext = context;
|
|
48
|
-
return this;
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
let next;
|
|
52
|
-
let status;
|
|
53
|
-
let json;
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
getApiKey.mockReset();
|
|
56
|
-
next = vi.fn();
|
|
57
|
-
status = vi.fn().mockReturnThis();
|
|
58
|
-
json = vi.fn();
|
|
59
|
-
});
|
|
60
|
-
function makeReq(partial) {
|
|
61
|
-
return {
|
|
62
|
-
baseUrl: '/api/v0/dapp',
|
|
63
|
-
path: '/',
|
|
64
|
-
headers: {},
|
|
65
|
-
query: {},
|
|
66
|
-
...partial,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function makeRes() {
|
|
70
|
-
return { status, json };
|
|
71
|
-
}
|
|
72
|
-
it('skips processing if using JWT auth', async () => {
|
|
73
|
-
const req = makeReq({
|
|
74
|
-
headers: { authorization: 'Bearer abc' },
|
|
75
|
-
});
|
|
76
|
-
const res = makeRes();
|
|
77
|
-
const middleware = apiKeyAuth(store, '/api/v0/dapp', logger);
|
|
78
|
-
await middleware(req, res, next);
|
|
79
|
-
expect(getApiKey).not.toHaveBeenCalled();
|
|
80
|
-
expect(req.authContext).toBeUndefined();
|
|
81
|
-
expect(next).toHaveBeenCalledOnce();
|
|
82
|
-
});
|
|
83
|
-
it('sets authContext and calls next when verification succeeds', async () => {
|
|
84
|
-
const ctx = {
|
|
85
|
-
userId: 'alice',
|
|
86
|
-
ledgerUserId: 'service_account',
|
|
87
|
-
accessToken: 'abc',
|
|
88
|
-
isApiKey: true,
|
|
89
|
-
email: undefined,
|
|
90
|
-
};
|
|
91
|
-
getApiKey.mockResolvedValue({
|
|
92
|
-
id: 'key1',
|
|
93
|
-
digest: crypto.createHash('sha256').update('abc').digest('hex'),
|
|
94
|
-
userId: 'alice',
|
|
95
|
-
});
|
|
96
|
-
const req = makeReq({
|
|
97
|
-
headers: { authorization: 'ApiKey abc' },
|
|
98
|
-
});
|
|
99
|
-
const res = makeRes();
|
|
100
|
-
const middleware = apiKeyAuth(store, '/api/v0/dapp', logger);
|
|
101
|
-
await middleware(req, res, next);
|
|
102
|
-
expect(getApiKey).toHaveBeenCalled();
|
|
103
|
-
expect(req.authContext).toEqual(ctx);
|
|
104
|
-
expect(next).toHaveBeenCalledOnce();
|
|
105
|
-
expect(status).not.toHaveBeenCalled();
|
|
106
|
-
});
|
|
107
|
-
it('returns 401 JSON when no matching API key is found', async () => {
|
|
108
|
-
getApiKey.mockResolvedValue(null);
|
|
109
|
-
const req = makeReq({
|
|
110
|
-
headers: { authorization: 'ApiKey invalid' },
|
|
111
|
-
});
|
|
112
|
-
const res = makeRes();
|
|
113
|
-
const middleware = apiKeyAuth(store, '/api/v0/dapp', logger);
|
|
114
|
-
await middleware(req, res, next);
|
|
115
|
-
expect(next).not.toHaveBeenCalled();
|
|
116
|
-
expect(status).toHaveBeenCalledWith(401);
|
|
117
|
-
expect(json).toHaveBeenCalledWith({
|
|
118
|
-
error: {
|
|
119
|
-
code: -32600,
|
|
120
|
-
message: 'API Key is invalid',
|
|
121
|
-
},
|
|
122
|
-
id: null,
|
|
123
|
-
jsonrpc: '2.0',
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.test.d.ts","sourceRoot":"","sources":["../../src/middleware/errorHandler.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import { pino } from 'pino';
|
|
5
|
-
import { sink } from 'pino-test';
|
|
6
|
-
import { providerErrors, rpcErrors } from '@canton-network/core-rpc-errors';
|
|
7
|
-
import { errorHandler, errorLogLevel } from './errorHandler.js';
|
|
8
|
-
describe('errorHandler', () => {
|
|
9
|
-
const logger = pino({ level: 'silent' }, sink());
|
|
10
|
-
const isApiPath = (path) => path.startsWith('/api/');
|
|
11
|
-
let next;
|
|
12
|
-
let status;
|
|
13
|
-
let json;
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
next = vi.fn();
|
|
16
|
-
status = vi.fn().mockReturnThis();
|
|
17
|
-
json = vi.fn();
|
|
18
|
-
});
|
|
19
|
-
function makeReq(partial = {}) {
|
|
20
|
-
return {
|
|
21
|
-
path: '/api/v0/user',
|
|
22
|
-
body: { id: 1 },
|
|
23
|
-
...partial,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function makeRes(headersSent = false) {
|
|
27
|
-
return { status, json, headersSent };
|
|
28
|
-
}
|
|
29
|
-
it('maps a JsonRpcError to its HTTP status and keeps the message', () => {
|
|
30
|
-
const err = providerErrors.unauthorized({
|
|
31
|
-
message: 'User is not connected',
|
|
32
|
-
});
|
|
33
|
-
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
34
|
-
expect(status).toHaveBeenCalledWith(401);
|
|
35
|
-
expect(json).toHaveBeenCalledWith({
|
|
36
|
-
jsonrpc: '2.0',
|
|
37
|
-
id: 1,
|
|
38
|
-
error: {
|
|
39
|
-
code: providerErrors.unauthorized().code,
|
|
40
|
-
message: 'User is not connected',
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
it('replaces an unexpected error with a generic JSON-RPC 500 on API paths', () => {
|
|
45
|
-
const err = new Error('connect ECONNREFUSED 127.0.0.1:5432');
|
|
46
|
-
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
47
|
-
expect(status).toHaveBeenCalledWith(500);
|
|
48
|
-
expect(json).toHaveBeenCalledWith({
|
|
49
|
-
jsonrpc: '2.0',
|
|
50
|
-
id: 1,
|
|
51
|
-
error: {
|
|
52
|
-
code: rpcErrors.internal().code,
|
|
53
|
-
message: 'Something went wrong',
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
it('never sends the stack trace to the client', () => {
|
|
58
|
-
const err = new Error('internal detail');
|
|
59
|
-
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
60
|
-
const body = JSON.stringify(json.mock.calls[0][0]);
|
|
61
|
-
expect(body).not.toContain('internal detail');
|
|
62
|
-
expect(body).not.toContain('at '); // stack trace
|
|
63
|
-
});
|
|
64
|
-
it('keeps the 413 from express.json() for err.status', () => {
|
|
65
|
-
const err = Object.assign(new Error('request too large'), {
|
|
66
|
-
status: 413,
|
|
67
|
-
});
|
|
68
|
-
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
69
|
-
expect(status).toHaveBeenCalledWith(413);
|
|
70
|
-
expect(json).toHaveBeenCalledWith({ error: 'Payload Too Large' });
|
|
71
|
-
});
|
|
72
|
-
it('keeps the 413 from express.json() for err.statusCode', () => {
|
|
73
|
-
const err = Object.assign(new Error('request too large'), {
|
|
74
|
-
statusCode: 413,
|
|
75
|
-
});
|
|
76
|
-
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
77
|
-
expect(status).toHaveBeenCalledWith(413);
|
|
78
|
-
expect(json).toHaveBeenCalledWith({ error: 'Payload Too Large' });
|
|
79
|
-
});
|
|
80
|
-
it('leaves an error without a 413 status as a generic 500', () => {
|
|
81
|
-
const err = Object.assign(new Error('not a 413 error'), {
|
|
82
|
-
status: 404,
|
|
83
|
-
});
|
|
84
|
-
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
85
|
-
expect(status).toHaveBeenCalledWith(500);
|
|
86
|
-
});
|
|
87
|
-
it('returns a generic error body for non-API paths', () => {
|
|
88
|
-
const req = makeReq({ path: '/login' });
|
|
89
|
-
errorHandler(logger, isApiPath)(new Error('internal detail'), req, makeRes(), next);
|
|
90
|
-
expect(status).toHaveBeenCalledWith(500);
|
|
91
|
-
expect(json).toHaveBeenCalledWith({ error: 'Internal Server Error' });
|
|
92
|
-
});
|
|
93
|
-
it('delegates to express when the response has already started', () => {
|
|
94
|
-
const err = new Error('error that some middleware started res on, but still passed error down');
|
|
95
|
-
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(true), next);
|
|
96
|
-
expect(next).toHaveBeenCalledWith(err);
|
|
97
|
-
expect(status).not.toHaveBeenCalled();
|
|
98
|
-
expect(json).not.toHaveBeenCalled();
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
describe('errorLogLevel', () => {
|
|
102
|
-
function makeJsCantonError(errorCategory) {
|
|
103
|
-
return {
|
|
104
|
-
code: 'DAML_FAILURE',
|
|
105
|
-
cause: 'some ledger rejection',
|
|
106
|
-
errorCategory,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
it('logs client-caused JsonRpcErrors (HTTP < 500) at info', () => {
|
|
110
|
-
const err = rpcErrors.invalidParams({ message: 'bad params' });
|
|
111
|
-
expect(errorLogLevel(err)).toBe('info');
|
|
112
|
-
});
|
|
113
|
-
it('logs server-caused JsonRpcErrors (HTTP 500) at error', () => {
|
|
114
|
-
const err = rpcErrors.internal({ message: 'boom' });
|
|
115
|
-
expect(errorLogLevel(err)).toBe('error');
|
|
116
|
-
});
|
|
117
|
-
it('logs a JsCantonError in a non-alerting Canton category at info', () => {
|
|
118
|
-
// 9 = InvalidGivenCurrentSystemStateOther, e.g. a failed Daml
|
|
119
|
-
// `requirement`/assertion - an expected business rejection.
|
|
120
|
-
const err = makeJsCantonError(9);
|
|
121
|
-
expect(errorLogLevel(err)).toBe('info');
|
|
122
|
-
});
|
|
123
|
-
it('logs a JsCantonError in a system-fault Canton category at error', () => {
|
|
124
|
-
// 4 = SystemInternalAssumptionViolated - a genuine internal bug.
|
|
125
|
-
const err = makeJsCantonError(4);
|
|
126
|
-
expect(errorLogLevel(err)).toBe('error');
|
|
127
|
-
});
|
|
128
|
-
it('logs a JsCantonError with an unrecognized category at error', () => {
|
|
129
|
-
const err = makeJsCantonError(999);
|
|
130
|
-
expect(errorLogLevel(err)).toBe('error');
|
|
131
|
-
});
|
|
132
|
-
it('logs a plain Error at error', () => {
|
|
133
|
-
expect(errorLogLevel(new Error('boom'))).toBe('error');
|
|
134
|
-
});
|
|
135
|
-
it('logs an unrecognized error shape at error', () => {
|
|
136
|
-
expect(errorLogLevel({ foo: 'bar' })).toBe('error');
|
|
137
|
-
});
|
|
138
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonRpcHandler.test.d.ts","sourceRoot":"","sources":["../../src/middleware/jsonRpcHandler.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import { pino } from 'pino';
|
|
5
|
-
import { sink } from 'pino-test';
|
|
6
|
-
import { rpcErrors, toHttpErrorCode } from '@canton-network/core-rpc-errors';
|
|
7
|
-
import { handleRpcError, jsonRpcHandler } from './jsonRpcHandler.js';
|
|
8
|
-
import { paramSchemas as dappParamSchemas } from '../dapp-api/rpc-gen/schemas.js';
|
|
9
|
-
import { z } from 'zod';
|
|
10
|
-
function errorPayload(body) {
|
|
11
|
-
if (!('error' in body)) {
|
|
12
|
-
throw new Error('expected JSON-RPC error response');
|
|
13
|
-
}
|
|
14
|
-
return body.error;
|
|
15
|
-
}
|
|
16
|
-
async function waitForRpcResponse(res) {
|
|
17
|
-
const json = res.json;
|
|
18
|
-
await vi.waitUntil(() => json.mock.calls.length > 0);
|
|
19
|
-
}
|
|
20
|
-
describe('jsonRpcHandler', () => {
|
|
21
|
-
const logger = pino({ level: 'silent' }, sink());
|
|
22
|
-
const resolve = vi.fn(async () => 'response');
|
|
23
|
-
const reject = vi.fn(async () => {
|
|
24
|
-
throw new Error('error');
|
|
25
|
-
});
|
|
26
|
-
const rpcError = vi.fn(async () => {
|
|
27
|
-
throw rpcErrors.invalidParams({ message: 'bad params' });
|
|
28
|
-
});
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
resolve.mockClear();
|
|
31
|
-
reject.mockClear();
|
|
32
|
-
rpcError.mockClear();
|
|
33
|
-
});
|
|
34
|
-
function makeHandler() {
|
|
35
|
-
return jsonRpcHandler({
|
|
36
|
-
controller: { resolve, reject, rpcError },
|
|
37
|
-
logger,
|
|
38
|
-
paramSchemas: {
|
|
39
|
-
resolve: z.unknown(),
|
|
40
|
-
reject: z.unknown(),
|
|
41
|
-
rpcError: z.unknown(),
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function makeRes() {
|
|
46
|
-
const res = {
|
|
47
|
-
status: vi.fn(),
|
|
48
|
-
json: vi.fn(),
|
|
49
|
-
};
|
|
50
|
-
// Express response methods are chainable, like `res.status(500).json(body)`
|
|
51
|
-
// Make the mocked status() return this fake res object so .json() can be called after it.
|
|
52
|
-
res.status.mockReturnValue(res);
|
|
53
|
-
return res;
|
|
54
|
-
}
|
|
55
|
-
describe('param validation', () => {
|
|
56
|
-
it.each([
|
|
57
|
-
[undefined, true],
|
|
58
|
-
[[], true],
|
|
59
|
-
[{}, true],
|
|
60
|
-
[[1], false],
|
|
61
|
-
[{ extra: true }, false],
|
|
62
|
-
])('generated schema for a method without params accepts %j: %s', (params, valid) => {
|
|
63
|
-
expect(dappParamSchemas.status.safeParse(params).success).toBe(valid);
|
|
64
|
-
});
|
|
65
|
-
const paramSchemas = {
|
|
66
|
-
resolve: z.strictObject({ message: z.string() }),
|
|
67
|
-
};
|
|
68
|
-
async function call(params, schemas = paramSchemas) {
|
|
69
|
-
const res = makeRes();
|
|
70
|
-
jsonRpcHandler({
|
|
71
|
-
controller: { resolve, reject, rpcError },
|
|
72
|
-
logger,
|
|
73
|
-
paramSchemas: schemas,
|
|
74
|
-
})({
|
|
75
|
-
method: 'POST',
|
|
76
|
-
body: { jsonrpc: '2.0', id: 1, method: 'resolve', params },
|
|
77
|
-
}, res, vi.fn());
|
|
78
|
-
await waitForRpcResponse(res);
|
|
79
|
-
return res;
|
|
80
|
-
}
|
|
81
|
-
it.each([
|
|
82
|
-
['missing params', undefined],
|
|
83
|
-
['a missing required property', {}],
|
|
84
|
-
['a wrongly typed property', { message: 42 }],
|
|
85
|
-
['an unknown property', { message: 'hi', extra: true }],
|
|
86
|
-
])('rejects %s with InvalidParams', async (_, params) => {
|
|
87
|
-
const res = await call(params);
|
|
88
|
-
expect(resolve).not.toHaveBeenCalled();
|
|
89
|
-
expect(res.status).toHaveBeenCalledWith(toHttpErrorCode(rpcErrors.invalidParams().code));
|
|
90
|
-
expect(errorPayload(res.json.mock
|
|
91
|
-
.calls[0][0]).code).toBe(rpcErrors.invalidParams().code);
|
|
92
|
-
});
|
|
93
|
-
it('passes valid params to the controller', async () => {
|
|
94
|
-
await call({ message: 'hi' });
|
|
95
|
-
expect(resolve).toHaveBeenCalledWith({ message: 'hi' });
|
|
96
|
-
});
|
|
97
|
-
it('passes the parsed params, without properties the schema does not describe', async () => {
|
|
98
|
-
await call({ message: 'hi', extra: true }, { resolve: z.object({ message: z.string() }) });
|
|
99
|
-
expect(resolve).toHaveBeenCalledWith({ message: 'hi' });
|
|
100
|
-
});
|
|
101
|
-
it('reports flattened field and form errors', async () => {
|
|
102
|
-
const res = await call({ message: 42, extra: true });
|
|
103
|
-
const error = errorPayload(res.json.mock
|
|
104
|
-
.calls[0][0]);
|
|
105
|
-
expect(error.message).toBe('Invalid params');
|
|
106
|
-
expect(error.data).toEqual({
|
|
107
|
-
formErrors: [expect.stringContaining('"extra"')],
|
|
108
|
-
fieldErrors: { message: [expect.any(String)] },
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
it('bounds the error payload for large invalid inputs', async () => {
|
|
112
|
-
const res = await call(Object.fromEntries(Array.from({ length: 1000 }, (_, i) => [`key${i}`, i])), {
|
|
113
|
-
resolve: z.record(z.string(), z.string()),
|
|
114
|
-
});
|
|
115
|
-
const { data } = errorPayload(res.json.mock
|
|
116
|
-
.calls[0][0]);
|
|
117
|
-
expect(Object.keys(data.fieldErrors)).toHaveLength(10);
|
|
118
|
-
});
|
|
119
|
-
it('truncates long issue messages', async () => {
|
|
120
|
-
const res = await call({
|
|
121
|
-
message: 'hi',
|
|
122
|
-
['x'.repeat(10_000)]: true,
|
|
123
|
-
});
|
|
124
|
-
const { data } = errorPayload(res.json.mock
|
|
125
|
-
.calls[0][0]);
|
|
126
|
-
const [formError] = data.formErrors;
|
|
127
|
-
expect(formError.length).toBe(200);
|
|
128
|
-
});
|
|
129
|
-
it('truncates long field names of the generated schema, which rejects unknown properties that are not null', async () => {
|
|
130
|
-
const res = await call({ message: 'hi', ['x'.repeat(10_000)]: true }, { resolve: dappParamSchemas.signMessage });
|
|
131
|
-
const { data } = errorPayload(res.json.mock
|
|
132
|
-
.calls[0][0]);
|
|
133
|
-
expect(Object.keys(data.fieldErrors)).toEqual(['x'.repeat(100)]);
|
|
134
|
-
});
|
|
135
|
-
it('passes missing params through when the param is optional', async () => {
|
|
136
|
-
await call(undefined, {
|
|
137
|
-
resolve: paramSchemas.resolve.optional(),
|
|
138
|
-
});
|
|
139
|
-
expect(resolve).toHaveBeenCalledWith(undefined);
|
|
140
|
-
});
|
|
141
|
-
it('rejects a controller method without a schema as not found', async () => {
|
|
142
|
-
const res = await call({ message: 'hi' }, {});
|
|
143
|
-
expect(resolve).not.toHaveBeenCalled();
|
|
144
|
-
expect(errorPayload(res.json.mock
|
|
145
|
-
.calls[0][0]).code).toBe(rpcErrors.methodNotFound().code);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
it('delegates to next() if method is not POST', () => {
|
|
149
|
-
const handler = makeHandler();
|
|
150
|
-
const next = vi.fn();
|
|
151
|
-
const res = makeRes();
|
|
152
|
-
const req = {
|
|
153
|
-
method: 'GET',
|
|
154
|
-
body: {},
|
|
155
|
-
};
|
|
156
|
-
handler(req, res, next);
|
|
157
|
-
expect(next).toHaveBeenCalledOnce();
|
|
158
|
-
expect(res.status).not.toHaveBeenCalled();
|
|
159
|
-
});
|
|
160
|
-
it('responds with invalid request when body is not valid JSON-RPC 2.0', async () => {
|
|
161
|
-
const handler = makeHandler();
|
|
162
|
-
const next = vi.fn();
|
|
163
|
-
const res = makeRes();
|
|
164
|
-
const req = {
|
|
165
|
-
method: 'POST',
|
|
166
|
-
body: { jsonrpc: '1.0', method: 'resolve', id: 1 },
|
|
167
|
-
};
|
|
168
|
-
handler(req, res, next);
|
|
169
|
-
await waitForRpcResponse(res);
|
|
170
|
-
expect(next).not.toHaveBeenCalled();
|
|
171
|
-
expect(res.status).toHaveBeenCalled();
|
|
172
|
-
expect(res.json).toHaveBeenCalledWith(expect.objectContaining({
|
|
173
|
-
jsonrpc: '2.0',
|
|
174
|
-
id: null,
|
|
175
|
-
error: expect.objectContaining({
|
|
176
|
-
code: expect.any(Number),
|
|
177
|
-
}),
|
|
178
|
-
}));
|
|
179
|
-
});
|
|
180
|
-
it('returns method not found when controller has no such method', async () => {
|
|
181
|
-
const handler = makeHandler();
|
|
182
|
-
const next = vi.fn();
|
|
183
|
-
const res = makeRes();
|
|
184
|
-
const req = {
|
|
185
|
-
method: 'POST',
|
|
186
|
-
body: {
|
|
187
|
-
jsonrpc: '2.0',
|
|
188
|
-
id: 42,
|
|
189
|
-
method: 'missing',
|
|
190
|
-
params: [],
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
handler(req, res, next);
|
|
194
|
-
await waitForRpcResponse(res);
|
|
195
|
-
expect(res.status).toHaveBeenCalled();
|
|
196
|
-
const payload = res.json.mock.calls[0][0];
|
|
197
|
-
expect(payload.id).toBe(42);
|
|
198
|
-
expect(payload.error.message).toContain('missing');
|
|
199
|
-
});
|
|
200
|
-
it('returns JSON-RPC success when the method resolves', async () => {
|
|
201
|
-
const handler = makeHandler();
|
|
202
|
-
const next = vi.fn();
|
|
203
|
-
const res = makeRes();
|
|
204
|
-
const req = {
|
|
205
|
-
method: 'POST',
|
|
206
|
-
body: {
|
|
207
|
-
jsonrpc: '2.0',
|
|
208
|
-
id: 7,
|
|
209
|
-
method: 'resolve',
|
|
210
|
-
params: { x: 1 },
|
|
211
|
-
},
|
|
212
|
-
authContext: { userId: 'u', accessToken: 't' },
|
|
213
|
-
};
|
|
214
|
-
handler(req, res, next);
|
|
215
|
-
await waitForRpcResponse(res);
|
|
216
|
-
expect(resolve).toHaveBeenCalledWith({ x: 1 });
|
|
217
|
-
expect(res.json).toHaveBeenCalledWith({
|
|
218
|
-
jsonrpc: '2.0',
|
|
219
|
-
id: 7,
|
|
220
|
-
result: 'response',
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
it('maps thrown Error to JSON-RPC error with HTTP 500', async () => {
|
|
224
|
-
const handler = makeHandler();
|
|
225
|
-
const next = vi.fn();
|
|
226
|
-
const res = makeRes();
|
|
227
|
-
const req = {
|
|
228
|
-
method: 'POST',
|
|
229
|
-
body: {
|
|
230
|
-
jsonrpc: '2.0',
|
|
231
|
-
id: 'rid',
|
|
232
|
-
method: 'reject',
|
|
233
|
-
params: [],
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
handler(req, res, next);
|
|
237
|
-
await waitForRpcResponse(res);
|
|
238
|
-
expect(reject).toHaveBeenCalled();
|
|
239
|
-
expect(res.status).toHaveBeenCalledWith(500);
|
|
240
|
-
expect(res.json).toHaveBeenCalledWith(expect.objectContaining({
|
|
241
|
-
jsonrpc: '2.0',
|
|
242
|
-
id: 'rid',
|
|
243
|
-
error: expect.objectContaining({
|
|
244
|
-
message: 'error',
|
|
245
|
-
}),
|
|
246
|
-
}));
|
|
247
|
-
});
|
|
248
|
-
it('maps JsonRpcError to the corresponding HTTP status', async () => {
|
|
249
|
-
const handler = makeHandler();
|
|
250
|
-
const next = vi.fn();
|
|
251
|
-
const res = makeRes();
|
|
252
|
-
const req = {
|
|
253
|
-
method: 'POST',
|
|
254
|
-
body: {
|
|
255
|
-
jsonrpc: '2.0',
|
|
256
|
-
id: 0,
|
|
257
|
-
method: 'rpcError',
|
|
258
|
-
params: [],
|
|
259
|
-
},
|
|
260
|
-
};
|
|
261
|
-
handler(req, res, next);
|
|
262
|
-
await waitForRpcResponse(res);
|
|
263
|
-
expect(rpcError).toHaveBeenCalled();
|
|
264
|
-
expect(res.status).toHaveBeenCalledWith(toHttpErrorCode(rpcErrors.invalidParams().code));
|
|
265
|
-
expect(res.json).toHaveBeenCalledWith(expect.objectContaining({
|
|
266
|
-
jsonrpc: '2.0',
|
|
267
|
-
id: 0,
|
|
268
|
-
error: expect.objectContaining({
|
|
269
|
-
message: 'bad params',
|
|
270
|
-
}),
|
|
271
|
-
}));
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
describe('handleRpcError', () => {
|
|
275
|
-
const logger = pino({ level: 'silent' }, sink());
|
|
276
|
-
const errorLog = vi.spyOn(logger, 'error');
|
|
277
|
-
it('maps JsonRpcError to HTTP status from toHttpErrorCode and does not log RPC response as error', () => {
|
|
278
|
-
const err = rpcErrors.invalidParams({ message: 'bad' });
|
|
279
|
-
const [status, body] = handleRpcError(err, 99, 'whateverMethod');
|
|
280
|
-
expect(status).toBe(toHttpErrorCode(err.code));
|
|
281
|
-
expect(status).toBe(400);
|
|
282
|
-
expect(body).toEqual({
|
|
283
|
-
jsonrpc: '2.0',
|
|
284
|
-
id: 99,
|
|
285
|
-
error: { code: err.code, message: 'bad' },
|
|
286
|
-
});
|
|
287
|
-
expect(errorLog).not.toHaveBeenCalled();
|
|
288
|
-
});
|
|
289
|
-
it('keeps the JsonRpcError message once the response is serialised', () => {
|
|
290
|
-
const err = rpcErrors.invalidParams({ message: 'error description' });
|
|
291
|
-
const [, body] = handleRpcError(err, 99);
|
|
292
|
-
expect(JSON.parse(JSON.stringify(body))).toMatchObject({
|
|
293
|
-
error: { code: err.code, message: 'error description' },
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
it('forwards data that was deliberately attached to a JsonRpcError', () => {
|
|
297
|
-
const err = rpcErrors.invalidParams({
|
|
298
|
-
message: 'bad',
|
|
299
|
-
data: { field: 'value' },
|
|
300
|
-
});
|
|
301
|
-
const [, body] = handleRpcError(err, 1);
|
|
302
|
-
expect(errorPayload(body)).toMatchObject({ data: { field: 'value' } });
|
|
303
|
-
});
|
|
304
|
-
it('forwards the Error message but not the error object itself', () => {
|
|
305
|
-
const [status, body] = handleRpcError(new Error('some error'), 'id', 'submit');
|
|
306
|
-
expect(status).toBe(500);
|
|
307
|
-
expect(body).toEqual({
|
|
308
|
-
jsonrpc: '2.0',
|
|
309
|
-
id: 'id',
|
|
310
|
-
error: {
|
|
311
|
-
code: rpcErrors.internal().code,
|
|
312
|
-
message: 'some error',
|
|
313
|
-
},
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
it('does not leak enumerable properties of runtime errors', () => {
|
|
317
|
-
const dbError = Object.assign(new Error('connect ECONNREFUSED'), {
|
|
318
|
-
code: 'ECONNREFUSED',
|
|
319
|
-
address: '127.0.0.1',
|
|
320
|
-
port: 5432,
|
|
321
|
-
});
|
|
322
|
-
const [, body] = handleRpcError(dbError, 1, 'listWallets');
|
|
323
|
-
expect(errorPayload(body)).not.toHaveProperty('data');
|
|
324
|
-
expect(JSON.stringify(body)).not.toContain('5432');
|
|
325
|
-
});
|
|
326
|
-
it('uses generic message when method name is omitted', () => {
|
|
327
|
-
const [status, body] = handleRpcError(new Error('x'), null);
|
|
328
|
-
expect(status).toBe(500);
|
|
329
|
-
expect(errorPayload(body)).toMatchObject({
|
|
330
|
-
message: 'x',
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
it('maps string errors to the error message', () => {
|
|
334
|
-
const [status, body] = handleRpcError('plain', 0);
|
|
335
|
-
expect(status).toBe(500);
|
|
336
|
-
expect(errorPayload(body)).toMatchObject({
|
|
337
|
-
message: 'plain',
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
it('accepts a full ErrorResponse object when safeParse succeeds', () => {
|
|
341
|
-
const custom = {
|
|
342
|
-
error: {
|
|
343
|
-
code: -32000,
|
|
344
|
-
message: 'from client',
|
|
345
|
-
data: { hint: 1 },
|
|
346
|
-
},
|
|
347
|
-
};
|
|
348
|
-
const [status, body] = handleRpcError(custom, 3);
|
|
349
|
-
expect(status).toBe(500);
|
|
350
|
-
expect(body).toEqual({
|
|
351
|
-
jsonrpc: '2.0',
|
|
352
|
-
id: 3,
|
|
353
|
-
error: custom.error,
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
it('maps JsCantonError objects to internal code with cause as message', () => {
|
|
357
|
-
const ledgerErr = {
|
|
358
|
-
code: 'CODE',
|
|
359
|
-
cause: 'something went wrong',
|
|
360
|
-
};
|
|
361
|
-
const [status, body] = handleRpcError(ledgerErr, null);
|
|
362
|
-
expect(status).toBe(500);
|
|
363
|
-
expect(errorPayload(body)).toMatchObject({
|
|
364
|
-
code: rpcErrors.internal().code,
|
|
365
|
-
message: 'something went wrong',
|
|
366
|
-
data: ledgerErr,
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
it('falls back to generic internal error for unknown payloads', () => {
|
|
370
|
-
const [status, body] = handleRpcError({ foo: 'bar' }, 2, 'wrongMethod');
|
|
371
|
-
expect(status).toBe(500);
|
|
372
|
-
expect(errorPayload(body)).toEqual({
|
|
373
|
-
code: rpcErrors.internal().code,
|
|
374
|
-
message: 'Something went wrong while calling wrongMethod',
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jwtAuth.test.d.ts","sourceRoot":"","sources":["../../src/middleware/jwtAuth.test.ts"],"names":[],"mappings":""}
|