|
| 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 | +}); |
0 commit comments