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

Commit b830707

Browse files
authored
fix(recovery): set assuranceLevel when verifying with recovery code (#2388), r=@rfk
1 parent 35da0bd commit b830707

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

lib/authMethods.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const METHOD_TO_AMR = {
1717
'email': 'email',
1818
'email-captcha': 'email',
1919
'email-2fa': 'email',
20-
'totp-2fa': 'otp'
20+
'totp-2fa': 'otp',
21+
'recovery-code': 'otp'
2122
}
2223

2324
// Maps AMR values to the type of authenticator they represent, e.g.

lib/tokens/session_token.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = (log, Token, config) => {
1515
[
1616
[0, 'email'],
1717
[1, 'email-2fa'],
18-
[2, 'totp-2fa']
18+
[2, 'totp-2fa'],
19+
[3, 'recovery-code']
1920
]
2021
)
2122

test/client/index.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ module.exports = config => {
135135
}
136136
return client.verifyTotpCode(client.totpAuthenticator.generate())
137137
})
138-
.then(() => {
139-
// The above enables TOTP on the account, but doesn't mark the
140-
// session as being verified via TOTP, because it was already verified
141-
// via email. Create a new session that's explicitly TOTP-verified.
142-
return client.setupCredentials(email, password)
143-
})
144-
.then(() => {
145-
return client.auth(options)
146-
})
147-
.then(() => {
148-
return client.verifyTotpCode(client.totpAuthenticator.generate())
149-
})
150138
.then(() => {
151139
return client
152140
})

test/local/authMethods.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ describe('verificationMethodToAMR', () => {
8989
assert.equal(authMethods.verificationMethodToAMR('totp-2fa'), 'otp')
9090
})
9191

92+
it('maps `recovery-code` to `otp`', () => {
93+
assert.equal(authMethods.verificationMethodToAMR('recovery-code'), 'otp')
94+
})
95+
9296
it('throws when given an unknown verification method', () => {
9397
assert.throws(() => { authMethods.verificationMethodToAMR('email-gotcha') }, /unknown verificationMethod/)
9498
})

test/remote/recovery_code_tests.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('remote recovery codes', function () {
103103
})
104104
})
105105

106-
it('should consume recovery and verify session', () => {
106+
it('should consume recovery code and verify session', () => {
107107
return client.consumeRecoveryCode(recoveryCodes[0], {metricsContext})
108108
.then((res) => {
109109
assert.equal(res.remaining, 7, 'correct remaining codes')
@@ -117,6 +117,25 @@ describe('remote recovery codes', function () {
117117
assert.equal(emailData.headers['x-template-name'], 'postConsumeRecoveryCodeEmail', 'correct template sent')
118118
})
119119
})
120+
121+
it('should consume recovery code and can remove TOTP token', () => {
122+
return client.consumeRecoveryCode(recoveryCodes[0], {metricsContext})
123+
.then((res) => {
124+
assert.equal(res.remaining, 7, 'correct remaining codes')
125+
return server.mailbox.waitForEmail(email)
126+
})
127+
.then((emailData) => {
128+
assert.equal(emailData.headers['x-template-name'], 'postConsumeRecoveryCodeEmail', 'correct template sent')
129+
return client.deleteTotpToken()
130+
})
131+
.then((result) => {
132+
assert.ok(result, 'delete totp token successfully')
133+
return server.mailbox.waitForEmail(email)
134+
})
135+
.then((emailData) => {
136+
assert.equal(emailData.headers['x-template-name'], 'postRemoveTwoStepAuthenticationEmail', 'correct template sent')
137+
})
138+
})
120139
})
121140

122141
after(() => {

0 commit comments

Comments
 (0)