Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(unblock): rethrow customs server error when account is unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Nov 16, 2016
1 parent a69dfe6 commit b5bda6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/routes/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ module.exports = function (
email: email,
errno: err.errno
})
if (customsErr) {
throw customsErr
}
}
throw err
}
Expand Down
22 changes: 22 additions & 0 deletions test/local/account_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,11 @@ describe('/account/login', function () {
mockCustoms.check = () => P.reject(error.requestBlocked(true))
})

beforeEach(() => {
mockLog.activityEvent.reset()
mockLog.flowEvent.reset()
})

after(() => {
mockCustoms.check = oldCheck
})
Expand Down Expand Up @@ -1516,6 +1521,15 @@ describe('/account/login', function () {
describe('with unblock code', () => {
mockLog.flowEvent.reset()

let previousEmailRecord
before(() => {
previousEmailRecord = mockDB.emailRecord
})

afterEach(() => {
mockDB.emailRecord = previousEmailRecord
})

it('invalid code', () => {
mockDB.consumeUnblockCode = () => P.reject(error.invalidUnblockCode())
return runTest(route, mockRequestWithUnblockCode).then(() => assert.ok(false), err => {
Expand All @@ -1542,6 +1556,14 @@ describe('/account/login', function () {
})
})

it('unknown account', () => {
mockDB.emailRecord = () => P.reject(new error.unknownAccount())
return runTest(route, mockRequestWithUnblockCode).then(() => assert(false), err => {
assert.equal(err.errno, error.ERRNO.REQUEST_BLOCKED)
assert.equal(err.output.statusCode, 400)
})
})

it('valid code', () => {
mockDB.consumeUnblockCode = () => P.resolve({ createdAt: Date.now() })
return runTest(route, mockRequestWithUnblockCode, (res) => {
Expand Down

0 comments on commit b5bda6b

Please sign in to comment.