Skip to content

Commit 7d100a5

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

10 files changed

Lines changed: 285 additions & 206 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
import * as sinon from 'sinon';
9+
10+
describe('postMpcV2Key', () => {
11+
let cfg: EnclavedConfig;
12+
let app: express.Application;
13+
let agent: request.SuperAgentTest;
14+
15+
// test config
16+
const kmsUrl = 'http://kms.invalid';
17+
const coin = 'tsol';
18+
const accessToken = 'test-token';
19+
20+
before(() => {
21+
// nock config
22+
nock.disableNetConnect();
23+
nock.enableNetConnect('127.0.0.1');
24+
25+
// app config
26+
cfg = {
27+
appMode: AppMode.ENCLAVED,
28+
port: 0, // Let OS assign a free port
29+
bind: 'localhost',
30+
timeout: 60000,
31+
httpLoggerFile: '',
32+
kmsUrl: kmsUrl,
33+
tlsMode: TlsMode.DISABLED,
34+
allowSelfSigned: true,
35+
};
36+
37+
// app setup
38+
app = enclavedApp(cfg);
39+
agent = request.agent(app);
40+
});
41+
42+
afterEach(() => {
43+
nock.cleanAll();
44+
});
45+
46+
it('should bubble up KMS errors', async () => {
47+
nock(kmsUrl)
48+
.post(/.*/)
49+
.reply(400, { message: 'This is an error message' })
50+
.persist();
51+
52+
const response = await agent
53+
.post(`/api/${coin}/mpcv2/initialize`)
54+
.set('Authorization', `Bearer ${accessToken}`)
55+
.send({ source: 'user' });
56+
57+
response.status.should.equal(400);
58+
response.body.should.have.property('error', 'BadRequestError');
59+
response.body.should.have.property('details', 'This is an error message');
60+
});
61+
});

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)