From b5bda6b6fcd1abe9e04949431db12f8481d72ead Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 15 Nov 2016 14:10:04 -0800 Subject: [PATCH] fix(unblock): rethrow customs server error when account is unknown --- lib/routes/account.js | 3 +++ test/local/account_routes.js | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/routes/account.js b/lib/routes/account.js index 6f46ee01..8a087ec2 100644 --- a/lib/routes/account.js +++ b/lib/routes/account.js @@ -512,6 +512,9 @@ module.exports = function ( email: email, errno: err.errno }) + if (customsErr) { + throw customsErr + } } throw err } diff --git a/test/local/account_routes.js b/test/local/account_routes.js index 5d9a9c5a..0c8be01d 100644 --- a/test/local/account_routes.js +++ b/test/local/account_routes.js @@ -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 }) @@ -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 => { @@ -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) => {