-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkmsClient.test.ts
More file actions
112 lines (90 loc) · 3.54 KB
/
Copy pathkmsClient.test.ts
File metadata and controls
112 lines (90 loc) · 3.54 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { AppMode, AdvancedWalletManagerConfig, TlsMode } from '../../../initConfig';
import { app as expressApp } from '../../../advancedWalletManagerApp';
import express from 'express';
import nock from 'nock';
import 'should';
import * as request from 'supertest';
describe('postMpcV2Key', () => {
let cfg: AdvancedWalletManagerConfig;
let app: express.Application;
let agent: request.SuperAgentTest;
// test config
const kmsUrl = 'http://kms.invalid';
const coin = 'tsol';
const accessToken = 'test-token';
before(() => {
// nock config
nock.disableNetConnect();
nock.enableNetConnect('127.0.0.1');
// app config
cfg = {
appMode: AppMode.ADVANCED_WALLET_MANAGER,
port: 0, // Let OS assign a free port
bind: 'localhost',
timeout: 60000,
httpLoggerFile: '',
kmsUrl: kmsUrl,
tlsMode: TlsMode.DISABLED,
allowSelfSigned: true,
};
// app setup
app = expressApp(cfg);
agent = request.agent(app);
});
afterEach(() => {
nock.cleanAll();
});
it('should bubble up 400 KMS errors', async () => {
nock(kmsUrl).post(/.*/).reply(400, { message: 'This is an error message' }).persist();
const response = await agent
.post(`/api/${coin}/mpcv2/initialize`)
.set('Authorization', `Bearer ${accessToken}`)
.send({ source: 'user' });
response.status.should.equal(400);
response.body.should.have.property('error', 'BadRequestError');
response.body.should.have.property('details', 'This is an error message');
});
it('should bubble up 404 KMS errors', async () => {
nock(kmsUrl).post(/.*/).reply(404, { message: 'This is an error message' }).persist();
const response = await agent
.post(`/api/${coin}/mpcv2/initialize`)
.set('Authorization', `Bearer ${accessToken}`)
.send({ source: 'user' });
response.status.should.equal(404);
response.body.should.have.property('error', 'NotFoundError');
response.body.should.have.property('details', 'This is an error message');
});
it('should bubble up 409 KMS errors', async () => {
nock(kmsUrl).post(/.*/).reply(409, { message: 'This is an error message' }).persist();
const response = await agent
.post(`/api/${coin}/mpcv2/initialize`)
.set('Authorization', `Bearer ${accessToken}`)
.send({ source: 'user' });
response.status.should.equal(409);
response.body.should.have.property('error', 'ConflictError');
response.body.should.have.property('details', 'This is an error message');
});
it('should bubble up 500 KMS errors', async () => {
nock(kmsUrl).post(/.*/).reply(500, { message: 'This is an error message' }).persist();
const response = await agent
.post(`/api/${coin}/mpcv2/initialize`)
.set('Authorization', `Bearer ${accessToken}`)
.send({ source: 'user' });
response.status.should.equal(500);
response.body.should.have.property('error', 'Internal Server Error');
response.body.should.have.property('details', 'This is an error message');
});
it('should handle unexpected KMS errors', async () => {
nock(kmsUrl).post(/.*/).reply(502, { message: 'Unexpected error' }).persist();
const response = await agent
.post(`/api/${coin}/mpcv2/initialize`)
.set('Authorization', `Bearer ${accessToken}`)
.send({ source: 'user' });
response.status.should.equal(500);
response.body.should.have.property('error', 'Internal Server Error');
response.body.should.have.property(
'details',
'KMS returned unexpected response. 502: Unexpected error',
);
});
});