-
Notifications
You must be signed in to change notification settings - Fork 0
feat(mbe): Hide recovery APIs for mbe #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import 'should'; | ||
| import * as request from 'supertest'; | ||
| import nock from 'nock'; | ||
| import { app as expressApp } from '../../../masterExpressApp'; | ||
| import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types'; | ||
| import sinon from 'sinon'; | ||
| import * as middleware from '../../../shared/middleware'; | ||
| import * as masterMiddleware from '../../../api/master/middleware/middleware'; | ||
| import { BitGoRequest } from '../../../types/request'; | ||
| import { BitGoAPI } from '@bitgo-beta/sdk-api'; | ||
| import { EnclavedExpressClient } from '../../../api/master/clients/enclavedExpressClient'; | ||
|
|
||
| describe('Non Recovery Tests', () => { | ||
| let agent: request.SuperAgentTest; | ||
| let mockBitgo: BitGoAPI; | ||
| const enclavedExpressUrl = 'http://enclaved.invalid'; | ||
| const accessToken = 'test-token'; | ||
| const config: MasterExpressConfig = { | ||
| appMode: AppMode.MASTER_EXPRESS, | ||
| port: 0, | ||
| bind: 'localhost', | ||
| timeout: 60000, | ||
| env: 'test', | ||
| disableEnvCheck: true, | ||
| authVersion: 2, | ||
| enclavedExpressUrl: enclavedExpressUrl, | ||
| enclavedExpressCert: 'dummy-cert', | ||
| tlsMode: TlsMode.DISABLED, | ||
| httpLoggerFile: '', | ||
| allowSelfSigned: true, | ||
| recoveryMode: false, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| nock.disableNetConnect(); | ||
| nock.enableNetConnect('127.0.0.1'); | ||
|
|
||
| // Create mock BitGo instance with base functionality | ||
| mockBitgo = new BitGoAPI({ env: 'test' }); | ||
|
|
||
| // Setup middleware stubs before creating app | ||
| sinon.stub(middleware, 'prepareBitGo').callsFake(() => (req, res, next) => { | ||
| (req as BitGoRequest<MasterExpressConfig>).bitgo = mockBitgo; | ||
| (req as BitGoRequest<MasterExpressConfig>).config = config; | ||
| next(); | ||
| }); | ||
|
|
||
| // Create app after middleware is stubbed | ||
| const app = expressApp(config); | ||
| agent = request.agent(app); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| nock.cleanAll(); | ||
| sinon.restore(); | ||
| }); | ||
|
|
||
| describe('Recovery', () => { | ||
| const coin = 'tbtc'; | ||
|
|
||
| beforeEach(() => { | ||
| sinon.stub(masterMiddleware, 'validateMasterExpressConfig').callsFake((req, res, next) => { | ||
| (req as BitGoRequest<MasterExpressConfig>).params = { coin }; | ||
| (req as BitGoRequest<MasterExpressConfig>).enclavedExpressClient = | ||
| new EnclavedExpressClient(config, coin); | ||
| next(); | ||
| return undefined; | ||
| }); | ||
| }); | ||
|
|
||
| it('should fail to run mbe recovery if not in recovery mode', async () => { | ||
| const coin = 'tbtc'; | ||
| const userPub = 'xpub_user'; | ||
| const backupPub = 'xpub_backup'; | ||
| const bitgoPub = 'xpub_bitgo'; | ||
| const recoveryDestination = 'tb1qprdy6jwxrrr2qrwgd2tzl8z99hqp29jn6f3sguxulqm448myj6jsy2nwsu'; | ||
| const response = await agent | ||
| .post(`/api/${coin}/wallet/recovery`) | ||
| .set('Authorization', `Bearer ${accessToken}`) | ||
| .send({ | ||
| multiSigRecoveryParams: { | ||
| userPub, | ||
| backupPub, | ||
| bitgoPub, | ||
| walletContractAddress: '', | ||
| }, | ||
| recoveryDestinationAddress: recoveryDestination, | ||
| coin, | ||
| apiKey: 'key', | ||
| coinSpecificParams: { | ||
| evmRecoveryOptions: { | ||
| gasPrice: 20000000000, | ||
| gasLimit: 500000, | ||
| }, | ||
| }, | ||
| }); | ||
| response.status.should.equal(500); | ||
| response.body.should.have.property('error'); | ||
| response.body.should.have.property('details'); | ||
| response.body.details.should.containEql( | ||
| 'Recovery operations are not enabled. The server must be in recovery mode to perform this action.', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Recovery Consolidation', () => { | ||
| it('should fail to run mbe recovery consolidation if not in recovery mode', async () => { | ||
| const response = await agent | ||
| .post(`/api/trx/wallet/recoveryconsolidations`) | ||
| .set('Authorization', `Bearer ${accessToken}`) | ||
| .send({ | ||
| multisigType: 'onchain', | ||
| userPub: 'user-xpub', | ||
| backupPub: 'backup-xpub', | ||
| bitgoPub: 'bitgo-xpub', | ||
| tokenContractAddress: 'tron-token', | ||
| startingScanIndex: 1, | ||
| endingScanIndex: 3, | ||
| }); | ||
|
|
||
| response.status.should.equal(500); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shoudn't be needed; you can just create a
bitgoinstance. See this for eg.advanced-wallets/src/__tests__/api/master/generateWallet.test.ts
Line 39 in 8429316
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed