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

Commit

Permalink
fix(logging): emit flow events for sign-in unblock, not activity even…
Browse files Browse the repository at this point in the history
…ts (#1508); r=seanmonstar,rfk
  • Loading branch information
philbooth authored and rfk committed Oct 18, 2016
1 parent 82e579c commit 9a4e89c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 0 additions & 2 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ var ACTIVITY_FLOW_EVENTS = Object.keys(ALWAYS_ACTIVITY_FLOW_EVENTS)
}, {
// These activity events are flow events when there is a flowId
'account.keyfetch': true,
'account.login.sentUnblockCode': true,
'account.login.confirmedUnblockCode': true,
'account.signed': true
})

Expand Down
8 changes: 2 additions & 6 deletions lib/routes/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,7 @@ module.exports = function (
throw error.invalidUnblockCode()
}
didSigninUnblock = true
return log.activityEvent('account.login.confirmedUnblockCode', request, {
uid: emailRecord.uid.toString('hex')
})
return log.flowEvent('account.login.confirmedUnblockCode', request)
}
)
.catch(
Expand Down Expand Up @@ -1627,9 +1625,7 @@ module.exports = function (
.then(lookupAccount)
.then(createUnblockCode)
.then(mailUnblockCode)
.then(() => log.activityEvent('account.login.sentUnblockCode', request, {
uid: emailRecord.uid.toString('hex')
}))
.then(() => log.flowEvent('account.login.sentUnblockCode', request))
.done(() => {
reply({})
}, reply)
Expand Down
24 changes: 21 additions & 3 deletions test/local/account_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,9 @@ test('/account/login', function (t) {
mockLog.activityEvent = sinon.spy(function () {
return P.resolve()
})
mockLog.flowEvent = sinon.spy(function () {
return P.resolve()
})
var mockMailer = mocks.mockMailer()
var mockPush = mocks.mockPush()
var mockCustoms = {
Expand Down Expand Up @@ -1355,10 +1358,15 @@ test('/account/login', function (t) {
})

t.test('valid code', (t) => {
t.plan(1)
t.plan(4)
mockDB.consumeUnblockCode = () => P.resolve({ createdAt: Date.now() })
return runTest(route, mockRequestWithUnblockCode, (res) => {
t.ok(!(res instanceof Error), 'successful login')
t.equal(mockLog.flowEvent.callCount, 1, 'log.flowEvent was called once')
const args = mockLog.flowEvent.args[0]
t.equal(args.length, 2, 'log.flowEvent was passed two arguments')
t.equal(args[0], 'account.login.confirmedUnblockCode', 'first argument was event name')
mockLog.flowEvent.reset()
})
})
})
Expand Down Expand Up @@ -1738,15 +1746,17 @@ test('/account/login/send_unblock_code', function (t) {
allowedEmailAddresses: /^.*$/
}
}
const mockLog = mocks.spyLog()
var accountRoutes = makeRoutes({
config: config,
db: mockDb,
log: mockLog,
mailer: mockMailer
})
var route = getRoute(accountRoutes, '/account/login/send_unblock_code')

t.test('signin unblock enabled', function (t) {
t.plan(9)
t.plan(12)
config.signinUnblock.enabled = true
return runTest(route, mockRequest, function (response) {
t.ok(!(response instanceof Error), response.stack)
Expand All @@ -1763,16 +1773,24 @@ test('/account/login/send_unblock_code', function (t) {
t.equal(mockMailer.sendUnblockCode.callCount, 1, 'called mailer.sendUnblockCode')
var args = mockMailer.sendUnblockCode.args[0]
t.equal(args.length, 3, 'mailer.sendUnblockCode called with 3 args')

t.equal(mockLog.flowEvent.callCount, 1, 'log.flowEvent was called once')
args = mockLog.flowEvent.args[0]
t.equal(args.length, 2, 'log.flowEvent was passed two arguments')
t.equal(args[0], 'account.login.sentUnblockCode', 'first argument was event name')
mockLog.flowEvent.reset()
})
})

t.test('signin unblock disabled', function (t) {
t.plan(2)
t.plan(3)
config.signinUnblock.enabled = false

return runTest(route, mockRequest, function (err) {
t.equal(err.output.statusCode, 503, 'correct status code is returned')
t.equal(err.errno, error.ERRNO.FEATURE_NOT_ENABLED, 'correct errno is returned')

t.equal(mockLog.flowEvent.callCount, 0, 'log.flowEvent was not called')
})
})
})
Expand Down

0 comments on commit 9a4e89c

Please sign in to comment.