Skip to content

Commit de32c41

Browse files
committed
feat(ebe, mbe): added error handling between expresses and kms
Ticket: WP-5241
1 parent b9a0d1d commit de32c41

File tree

10 files changed

+375
-193
lines changed

10 files changed

+375
-193
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// import { AppMode, EnclavedConfig, TlsMode } from "../../../initConfig";
2+
// import { app as enclavedApp } from "../../../enclavedApp";
3+
4+
// import express from 'express';
5+
// import nock from "nock";
6+
// import * as request from 'supertest';
7+
// import * as sinon from 'sinon';
8+
// import * as configModule from '../../../initConfig';
9+
10+
// describe('KMS Client', () => {
11+
// let cfg: EnclavedConfig;
12+
// let app: express.Application;
13+
// let agent: request.SuperAgentTest;
14+
15+
// const kmsUrl = 'https://kms.invalid';
16+
// const coin = 'tsol';
17+
// const accessToken = 'test-token';
18+
19+
// let configStub: sinon.SinonStub;
20+
21+
// before (() => {
22+
// nock.disableNetConnect();
23+
// nock.enableNetConnect('127.0.0.1');
24+
25+
// cfg = {
26+
// appMode: AppMode.ENCLAVED,
27+
// port: 0, // Let OS assign a free port
28+
// bind: 'localhost',
29+
// timeout: 60000,
30+
// httpLoggerFile: '',
31+
// kmsUrl: kmsUrl,
32+
// tlsMode: TlsMode.DISABLED,
33+
// allowSelfSigned: true,
34+
// recoveryMode: true,
35+
// };
36+
37+
// // configStub = sinon.stub(configModule, 'initConfig').returns(cfg);
38+
39+
// // app setup
40+
// app = enclavedApp(cfg);
41+
// agent = request.agent(app);
42+
// });
43+
44+
// after(() => {
45+
// // configStub.restore();
46+
// });
47+
48+
// afterEach(() => {
49+
// nock.cleanAll();
50+
// });
51+
52+
// it('should bubble up KMS errors', async () => {
53+
// nock(kmsUrl)
54+
// .get(/.*/)
55+
// .reply(400, { message: 'This is an error message' });
56+
57+
// const response = await agent
58+
// .get(`/api/${coin}/mpc/initialize`)
59+
// .set('Authorization', `Bearer ${accessToken}`)
60+
// .send({ source: 'user' });
61+
62+
// console.log(response.body);
63+
64+
// response.status.should.equal(400);
65+
// response.body.should.have.property('error', 'BadRequestError');
66+
// response.body.should.have.property('details', 'This is an error message');
67+
// });
68+
69+
// it('should cast unknown KMS error codes into 500', async () => {
70+
// nock(kmsUrl)
71+
// .post(/.*/)
72+
// .reply(418, { error: 'I am a teapot' });
73+
74+
// const response = await agent
75+
// .post(`/api/${coin}/mpc/sign/mpcv2round1`)
76+
// .set('Authorization', `Bearer ${accessToken}`)
77+
// .send({
78+
// source: 'user',
79+
// pub: 'test-pub',
80+
// txRequest: {},
81+
// bitgoPublicGpgKey: 'test-bitgo-pub'
82+
// });
83+
84+
// console.log(response.body);
85+
86+
// // response.status.should.equal(500);
87+
// response.body.should.have.property('error', 'InternalServerError');
88+
// response.body.should.have.property('details', 'KMS returned unexpected response. 418: I am a teapot');
89+
// });
90+
// });
91+
92+
import { AppMode, EnclavedConfig, TlsMode } from '../../../initConfig';
93+
import { app as enclavedApp } from '../../../enclavedApp';
94+
95+
import express from 'express';
96+
import nock from 'nock';
97+
import 'should';
98+
import * as request from 'supertest';
99+
import * as sinon from 'sinon';
100+
import * as configModule from '../../../initConfig';
101+
import * as bitgoSdk from '@bitgo-beta/sdk-core';
102+
import { DklsComms, DklsDkg, DklsTypes } from '@bitgo-beta/sdk-lib-mpc';
103+
import { MPCv2PartiesEnum } from '@bitgo-beta/sdk-core/dist/src/bitgo/utils/tss/ecdsa';
104+
105+
describe('postMpcV2Key', () => {
106+
let cfg: EnclavedConfig;
107+
let app: express.Application;
108+
let agent: request.SuperAgentTest;
109+
110+
// test config
111+
const kmsUrl = 'http://kms.invalid';
112+
const coin = 'tsol';
113+
const accessToken = 'test-token';
114+
115+
// sinon stubs
116+
let configStub: sinon.SinonStub;
117+
118+
before(() => {
119+
// nock config
120+
nock.disableNetConnect();
121+
nock.enableNetConnect('127.0.0.1');
122+
123+
// app config
124+
cfg = {
125+
appMode: AppMode.ENCLAVED,
126+
port: 0, // Let OS assign a free port
127+
bind: 'localhost',
128+
timeout: 60000,
129+
httpLoggerFile: '',
130+
kmsUrl: kmsUrl,
131+
tlsMode: TlsMode.DISABLED,
132+
allowSelfSigned: true,
133+
};
134+
135+
// configStub = sinon.stub(configModule, 'initConfig').returns(cfg);
136+
137+
// app setup
138+
app = enclavedApp(cfg);
139+
agent = request.agent(app);
140+
});
141+
142+
afterEach(() => {
143+
nock.cleanAll();
144+
});
145+
146+
after(() => {
147+
// configStub.restore();
148+
});
149+
150+
it('should bubble up KMS errors', async () => {
151+
nock(kmsUrl)
152+
.post(/.*/)
153+
.reply(400, { message: 'This is an error message' })
154+
.persist();
155+
156+
const response = await agent
157+
.post(`/api/${coin}/mpcv2/initialize`)
158+
.set('Authorization', `Bearer ${accessToken}`)
159+
.send({ source: 'user' });
160+
161+
response.status.should.equal(400);
162+
response.body.should.have.property('error', 'BadRequestError');
163+
response.body.should.have.property('details', 'This is an error message');
164+
});
165+
});

src/__tests__/api/enclaved/recoveryMpcV2.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ describe('recoveryMpcV2', async () => {
155155

156156
signatureResponse.status.should.equal(400);
157157
signatureResponse.body.should.have.property('error');
158-
signatureResponse.body.error.should.startWith(
158+
signatureResponse.body.error.should.equal('BadRequestError');
159+
signatureResponse.body.should.have.property('details');
160+
signatureResponse.body.details.should.startWith(
159161
'Failed to construct eth transaction from message hex',
160162
);
161163
});

src/__tests__/api/master/recoveryWalletMpcV2.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ describe('MBE mpcv2 recovery', () => {
202202

203203
response.status.should.equal(422);
204204
response.body.should.have.property('error');
205-
response.body.error.should.equal(
205+
response.body.error.should.equal('ValidationError');
206+
response.body.should.have.property('details');
207+
response.body.details.should.equal(
206208
'ECDSA ETH-like recovery specific parameters are required for MPC recovery',
207209
);
208210
});

src/__tests__/api/master/sendMany.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
772772
response.status.should.equal(500);
773773
response.body.should.have.property('error');
774774
response.body.should.have.property('details');
775-
response.body.error.should.equal('BitGoApiResponseError');
775+
response.body.error.should.equal('Internal Server Error');
776776
response.body.details.should.deepEqual({
777777
error: 'Custom API error',
778778
requestId: 'test-request-id',

0 commit comments

Comments
 (0)