Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 107 additions & 8 deletions masterBitgoExpress.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,23 @@
}
},
"/ping": {
"post": {
"parameters": [],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PingResponseType"
}
}
}
}
}
}
},
"/ping/enclavedExpress": {
"post": {
"parameters": [],
"responses": {
Expand All @@ -277,13 +294,35 @@
"status": {
"type": "string"
},
"timestamp": {
"type": "string"
"enclavedResponse": {
"$ref": "#/components/schemas/PingResponseType"
}
},
"required": [
"status",
"timestamp"
"enclavedResponse"
]
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"details": {
"type": "string"
}
},
"required": [
"error",
"details"
]
}
}
Expand All @@ -298,21 +337,48 @@
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VersionResponseType"
}
}
}
}
}
}
},
"/version/enclavedExpress": {
"get": {
"parameters": [],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VersionResponseType"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"version": {
"error": {
"type": "string"
},
"name": {
"details": {
"type": "string"
}
},
"required": [
"version",
"name"
"error",
"details"
]
}
}
Expand All @@ -323,6 +389,39 @@
}
},
"components": {
"schemas": {}
"schemas": {
"VersionResponseType": {
"title": "VersionResponseType",
"type": "object",
"properties": {
"version": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"version",
"name"
]
},
"PingResponseType": {
"title": "PingResponseType",
"type": "object",
"properties": {
"status": {
"type": "string"
},
"timestamp": {
"type": "string"
}
},
"required": [
"status",
"timestamp"
]
}
}
}
}
24 changes: 7 additions & 17 deletions src/__tests__/masterBitgoExpress/generateWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import nock from 'nock';
import { app as expressApp } from '../../masterExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../types';
import { Environments } from '@bitgo/sdk-core';
import assert from 'assert';

describe('POST /api/:coin/wallet/generate', () => {
let agent: request.SuperAgentTest;
Expand Down Expand Up @@ -45,8 +46,6 @@ describe('POST /api/:coin/wallet/generate', () => {
const userKeychainNock = nock(enclavedExpressUrl)
.post(`/api/${coin}/key/independent`, {
source: 'user',
coin: coin,
type: 'independent',
})
.reply(200, {
pub: 'xpub_user',
Expand All @@ -57,8 +56,6 @@ describe('POST /api/:coin/wallet/generate', () => {
const backupKeychainNock = nock(enclavedExpressUrl)
.post(`/api/${coin}/key/independent`, {
source: 'backup',
coin: coin,
type: 'independent',
Comment on lines -60 to -61

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it's not used in the actual request. Look at the Api spec for Enclaved Express.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  'v1.key.independent': {
    post: httpRoute({
      method: 'POST',
      path: '/api/{coin}/key/independent',
      request: httpRequest({
        params: {
          coin: t.string,
        },
        body: IndependentKeyRequest,
      }),
      response: IndependentKeyResponse,
      description: 'Generate an independent key',
    }),
  },

})
.reply(200, {
pub: 'xpub_backup',
Expand Down Expand Up @@ -155,18 +152,11 @@ describe('POST /api/:coin/wallet/generate', () => {
allowSelfSigned: true,
};

const app = expressApp(invalidConfig as MasterExpressConfig);
const testAgent = request.agent(app);

const response = await testAgent
.post(`/api/${coin}/wallet/generate`)
.set('Authorization', `Bearer ${accessToken}`)
.send({
label: 'test-wallet',
});

response.status.should.equal(500);
response.body.should.have.property('error');
response.body.error.should.equal('Please configure enclaved express configs.');
try {
expressApp(invalidConfig as MasterExpressConfig);
assert(false, 'Expected error to be thrown when enclaved express client is not configured');
} catch (e) {
(e as Error).message.should.equal('enclavedExpressUrl and enclavedExpressCert are required');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait im v confused. why is this removing the calls to the actual API?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what i mean is, how is this test defining the client to make calls to generate wallet?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this case (when the config is invalid), the app won't startup. I can modify it so that the client is only created during the request, so it would fail then.

}
});
});
29 changes: 9 additions & 20 deletions src/__tests__/masterBitgoExpress/sendMany.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { app as expressApp } from '../../masterExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../types';
import { Environments, Wallet } from '@bitgo/sdk-core';
import { Coin } from 'bitgo';
import assert from 'assert';

describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
let agent: request.SuperAgentTest;
Expand Down Expand Up @@ -277,26 +278,14 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
allowSelfSigned: true,
};

const app = expressApp(invalidConfig as MasterExpressConfig);
const testAgent = request.agent(app);

const response = await testAgent
.post(`/api/${coin}/wallet/${walletId}/sendMany`)
.set('Authorization', `Bearer ${accessToken}`)
.send({
recipients: [
{
address: 'tb1qtest1',
amount: '100000',
},
],
source: 'user',
pubkey: 'xpub_user',
});

response.status.should.equal(500);
response.body.should.have.property('error');
response.body.error.should.equal('Please configure enclaved express configs.');
try {
expressApp(invalidConfig as MasterExpressConfig);
assert(false, 'Expected error to be thrown when enclaved express client is not configured');
} catch (error) {
(error as Error).message.should.equal(
'enclavedExpressUrl and enclavedExpressCert are required',
);
}
Comment on lines +281 to +288

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? why is this just calling the app?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above.

});

it('should fail when transaction verification returns false', async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/enclavedBitgoExpress/routers/enclavedApiSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const EnclavedAPiSpec = apiSpec({
'v1.multisig.sign': {
post: httpRoute({
method: 'POST',
path: '/{coin}/multisig/sign',
path: '/api/{coin}/multisig/sign',
request: httpRequest({
params: {
coin: t.string,
Expand All @@ -98,7 +98,7 @@ export const EnclavedAPiSpec = apiSpec({
'v1.multisig.recovery': {
post: httpRoute({
method: 'POST',
path: '/{coin}/multisig/recovery',
path: '/api/{coin}/multisig/recovery',
request: httpRequest({
params: {
coin: t.string,
Expand All @@ -112,7 +112,7 @@ export const EnclavedAPiSpec = apiSpec({
'v1.key.independent': {
post: httpRoute({
method: 'POST',
path: '/{coin}/key/independent',
path: '/api/{coin}/key/independent',
request: httpRequest({
params: {
coin: t.string,
Expand Down
15 changes: 4 additions & 11 deletions src/enclavedBitgoExpress/routers/healthCheck.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import * as t from 'io-ts';
import { apiSpec, httpRoute, httpRequest, HttpResponse } from '@api-ts/io-ts-http';
import { createRouter, type WrappedRouter } from '@api-ts/typed-express-router';
import { Response } from '@api-ts/response';
import pjson from '../../../package.json';
import { responseHandler } from '../../shared/middleware';
import { PingResponseType, VersionResponseType } from '../../types/health';

// Response type for /ping endpoint
// API Response types
const PingResponse: HttpResponse = {
200: t.type({
status: t.string,
timestamp: t.string,
}),
200: PingResponseType,
};

// Response type for /version endpoint
const VersionResponse: HttpResponse = {
200: t.type({
version: t.string,
name: t.string,
}),
200: VersionResponseType,
};

// API Specification
Expand Down
8 changes: 8 additions & 0 deletions src/enclavedBitgoExpress/routers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { EnclavedAPiSpec as ApiSpec } from './enclavedApiSpec';
import { HealthCheckApiSpec } from './healthCheck';

export const EnclavedApiSpec = {
...HealthCheckApiSpec,
...ApiSpec,
};
export type EnclavedApiSpec = typeof EnclavedApiSpec;
Loading