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

Commit

Permalink
fix(unblock): Use normalized email address for feature-flag calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfk committed Dec 21, 2016
1 parent 0c4beb7 commit 83ef76a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/routes/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ module.exports = function (
.then(
function (result) {
emailRecord = result
allowSigninUnblock = features.isSigninUnblockEnabledForUser(emailRecord.uid, email, request)
allowSigninUnblock = features.isSigninUnblockEnabledForUser(emailRecord.uid, emailRecord.email, request)
},
function (err) {
if (err.errno === error.ERRNO.ACCOUNT_UNKNOWN) {
Expand Down Expand Up @@ -1770,7 +1770,7 @@ module.exports = function (

function createUnblockCode(uid) {

if (features.isSigninUnblockEnabledForUser(uid, email, request)) {
if (features.isSigninUnblockEnabledForUser(uid, emailRecord.email, request)) {
return db.createUnblockCode(uid)
} else {
throw error.featureNotEnabled()
Expand Down
30 changes: 26 additions & 4 deletions test/local/account_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1847,11 +1847,12 @@ describe('/account/devices', function () {

describe('/account/login/send_unblock_code', function () {
var uid = uuid.v4('binary').toString('hex')
var email = 'unblock@example.com'
const mockLog = mocks.spyLog()
var mockRequest = mocks.mockRequest({
log: mockLog,
payload: {
email: TEST_EMAIL,
email: email,
metricsContext: {
flowBeginTime: Date.now(),
flowId: 'F1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF103'
Expand All @@ -1861,11 +1862,11 @@ describe('/account/login/send_unblock_code', function () {
var mockMailer = mocks.mockMailer()
var mockDb = mocks.mockDB({
uid: uid,
email: TEST_EMAIL
email: email
})
var config = {
signinUnblock: {
allowedEmailAddresses: /^.*$/
allowedEmailAddresses: /unblock.*$/
}
}
var accountRoutes = makeRoutes({
Expand All @@ -1876,14 +1877,20 @@ describe('/account/login/send_unblock_code', function () {
})
var route = getRoute(accountRoutes, '/account/login/send_unblock_code')

afterEach(function () {
mockDb.emailRecord.reset()
mockDb.createUnblockCode.reset()
mockMailer.sendUnblockCode.reset()
})

it('signin unblock enabled', function () {
config.signinUnblock.enabled = true
return runTest(route, mockRequest, function (response) {
assert.ok(!(response instanceof Error), response.stack)
assert.deepEqual(response, {}, 'response has no keys')

assert.equal(mockDb.emailRecord.callCount, 1, 'db.emailRecord called')
assert.equal(mockDb.emailRecord.args[0][0], TEST_EMAIL)
assert.equal(mockDb.emailRecord.args[0][0], email)

assert.equal(mockDb.createUnblockCode.callCount, 1, 'db.createUnblockCode called')
var dbArgs = mockDb.createUnblockCode.args[0]
Expand Down Expand Up @@ -1912,6 +1919,21 @@ describe('/account/login/send_unblock_code', function () {
assert.equal(mockLog.flowEvent.callCount, 0, 'log.flowEvent was not called')
})
})

it('uses normalized email address for feature flag', function () {
config.signinUnblock.enabled = true
mockRequest.payload.email = 'UNBLOCK@example.com'

return runTest(route, mockRequest, function(response) {
assert.ok(!(response instanceof Error), response.stack)
assert.deepEqual(response, {}, 'response has no keys')

assert.equal(mockDb.emailRecord.callCount, 1, 'db.emailRecord called')
assert.equal(mockDb.emailRecord.args[0][0], mockRequest.payload.email)
assert.equal(mockDb.createUnblockCode.callCount, 1, 'db.createUnblockCode called')
assert.equal(mockMailer.sendUnblockCode.callCount, 1, 'called mailer.sendUnblockCode')
})
})
})

describe('/account/login/reject_unblock_code', function () {
Expand Down

0 comments on commit 83ef76a

Please sign in to comment.