-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
chore: add ecdh keychain creation on login
- Loading branch information
Showing
3 changed files
with
206 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -3,14 +3,14 @@ | |
// | ||
|
||
import * as crypto from 'crypto'; | ||
import * as should from 'should'; | ||
import * as nock from 'nock'; | ||
import * as should from 'should'; | ||
|
||
import * as BitGoJS from '../../src/index'; | ||
import { common } from '@bitgo/sdk-core'; | ||
const rp = require('request-promise'); | ||
import * as _ from 'lodash'; | ||
import { bip32, ECPair } from '@bitgo/utxo-lib'; | ||
import * as _ from 'lodash'; | ||
import * as BitGoJS from '../../src/index'; | ||
const rp = require('request-promise'); | ||
|
||
import { TestBitGo } from '@bitgo/sdk-test'; | ||
import { BitGo } from '../../src/bitgo'; | ||
|
@@ -129,7 +129,12 @@ describe('BitGo Prototype Methods', function () { | |
bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri: 'https://microservices.uri' } as any); | ||
const scope = nock(BitGoJS.Environments[bitgo.getEnv()].uri) | ||
.post('/api/auth/v1/session') | ||
.reply(200, { user: '[email protected]', access_token: 'token12356' }); | ||
.reply(200, { | ||
user: { | ||
username: '[email protected]', | ||
}, | ||
access_token: 'token12356', | ||
}); | ||
|
||
await bitgo.authenticate(authenticateRequest); | ||
scope.isDone().should.be.true(); | ||
|
@@ -139,7 +144,12 @@ describe('BitGo Prototype Methods', function () { | |
bitgo = TestBitGo.decorate(BitGo, { env: 'mock' }); | ||
const scope = nock(BitGoJS.Environments[bitgo.getEnv()].uri) | ||
.post('/api/auth/v1/session') | ||
.reply(200, { user: '[email protected]', access_token: 'token12356' }); | ||
.reply(200, { | ||
user: { | ||
username: '[email protected]', | ||
}, | ||
access_token: 'token12356', | ||
}); | ||
|
||
await bitgo.authenticate(authenticateRequest); | ||
scope.isDone().should.be.true(); | ||
|
@@ -609,4 +619,72 @@ describe('BitGo Prototype Methods', function () { | |
); | ||
}); | ||
}); | ||
|
||
describe('authenticate', function () { | ||
afterEach(function ensureNoPendingMocks() { | ||
nock.pendingMocks().should.be.empty(); | ||
}); | ||
|
||
it('should get the ecdhKeychain if ensureEcdhKeychain is set and user already has ecdhKeychain', async function () { | ||
nock('https://bitgo.fakeurl') | ||
.post('/api/auth/v1/session') | ||
.reply(200, { | ||
access_token: 'access_token', | ||
user: { username: '[email protected]' }, | ||
}); | ||
nock('https://bitgo.fakeurl') | ||
.get('/api/v1/user/settings') | ||
.reply(200, { | ||
settings: { | ||
ecdhKeychain: 'some-existing-xpub', | ||
}, | ||
}); | ||
|
||
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock' }); | ||
const response = await bitgo.authenticate({ | ||
username: '[email protected]', | ||
password: 'password123', | ||
otp: '000000', | ||
ensureEcdhKeychain: true, | ||
}); | ||
|
||
should.exist(response.user.ecdhKeychain); | ||
response.user.ecdhKeychain.should.equal('some-existing-xpub'); | ||
}); | ||
it('should create the ecdhKeychain if ensureEcdhKeychain is set and the user does not already have ecdhKeychain', async function () { | ||
nock('https://bitgo.fakeurl') | ||
.post('/api/auth/v1/session') | ||
.reply(200, { | ||
access_token: 'access_token', | ||
user: { username: '[email protected]' }, | ||
}); | ||
/** | ||
* This is {} because want to make sure the user has no ecdhXpub set before we set it | ||
*/ | ||
nock('https://bitgo.fakeurl').get('/api/v1/user/settings').reply(200, { | ||
settings: {}, | ||
}); | ||
nock('https://bitgo.fakeurl').post('/api/v1/keychain').reply(200, { | ||
xpub: 'some-xpub', | ||
}); | ||
nock('https://bitgo.fakeurl') | ||
.put('/api/v2/user/settings') | ||
.reply(200, { | ||
settings: { | ||
ecdhKeychain: 'some-xpub', | ||
}, | ||
}); | ||
|
||
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock' }); | ||
const response = await bitgo.authenticate({ | ||
username: '[email protected]', | ||
password: 'password123', | ||
otp: '000000', | ||
ensureEcdhKeychain: true, | ||
}); | ||
|
||
should.exist(response.user.ecdhKeychain); | ||
response.user.ecdhKeychain.should.equal('some-xpub'); | ||
}); | ||
}); | ||
}); |
This file contains 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 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