Skip to content

Commit 4164293

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

File tree

10 files changed

+281
-206
lines changed

10 files changed

+281
-206
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 'should';
7+
import * as request from 'supertest';
8+
9+
describe('postMpcV2Key', () => {
10+
let cfg: EnclavedConfig;
11+
let app: express.Application;
12+
let agent: request.SuperAgentTest;
13+
14+
// test config
15+
const kmsUrl = 'http://kms.invalid';
16+
const coin = 'tsol';
17+
const accessToken = 'test-token';
18+
19+
before(() => {
20+
// nock config
21+
nock.disableNetConnect();
22+
nock.enableNetConnect('127.0.0.1');
23+
24+
// app config
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+
};
35+
36+
// app setup
37+
app = enclavedApp(cfg);
38+
agent = request.agent(app);
39+
});
40+
41+
afterEach(() => {
42+
nock.cleanAll();
43+
});
44+
45+
it('should bubble up KMS errors', async () => {
46+
nock(kmsUrl).post(/.*/).reply(400, { message: 'This is an error message' }).persist();
47+
48+
const response = await agent
49+
.post(`/api/${coin}/mpcv2/initialize`)
50+
.set('Authorization', `Bearer ${accessToken}`)
51+
.send({ source: 'user' });
52+
53+
response.status.should.equal(400);
54+
response.body.should.have.property('error', 'BadRequestError');
55+
response.body.should.have.property('details', 'This is an error message');
56+
});
57+
});

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: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as request from 'supertest';
55
import nock from 'nock';
66
import { app as expressApp } from '../../../masterExpressApp';
77
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
8-
import { ApiResponseError, Environments, Wallet } from '@bitgo-beta/sdk-core';
8+
import { Environments, Wallet } from '@bitgo-beta/sdk-core';
99
import { Tbtc } from '@bitgo-beta/sdk-coin-btc';
1010
import assert from 'assert';
1111

@@ -745,14 +745,10 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
745745
const verifyStub = sinon.stub(Tbtc.prototype, 'verifyTransaction').resolves(true);
746746

747747
// Mock enclaved express sign request to return an error
748-
const signNock = nock(enclavedExpressUrl)
749-
.post(`/api/${coin}/multisig/sign`)
750-
.replyWithError(
751-
new ApiResponseError('Custom API error', 500, {
752-
error: 'Custom API error',
753-
requestId: 'test-request-id',
754-
}),
755-
);
748+
const signNock = nock(enclavedExpressUrl).post(`/api/${coin}/multisig/sign`).reply(500, {
749+
error: 'Internal Server Error',
750+
details: 'Custom API error details',
751+
});
756752

757753
const response = await agent
758754
.post(`/api/${coin}/wallet/${walletId}/sendMany`)
@@ -772,11 +768,8 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
772768
response.status.should.equal(500);
773769
response.body.should.have.property('error');
774770
response.body.should.have.property('details');
775-
response.body.error.should.equal('BitGoApiResponseError');
776-
response.body.details.should.deepEqual({
777-
error: 'Custom API error',
778-
requestId: 'test-request-id',
779-
});
771+
response.body.error.should.equal('Internal Server Error');
772+
response.body.details.should.deepEqual('Custom API error details');
780773

781774
walletGetNock.done();
782775
keychainGetNock.done();

0 commit comments

Comments
 (0)