Skip to content

Commit 930b886

Browse files
authored
Merge pull request #18987 from mozilla/FXA-11822
fix(auth): Send email when changing recovery phone
2 parents 597476a + cdb8fe3 commit 930b886

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

packages/fxa-auth-server/lib/routes/recovery-phone.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ class RecoveryPhoneHandler {
536536
}
537537

538538
async changePhoneNumber(request: AuthRequest) {
539-
// need to check first that there is an existing phone number
540539
const { uid } = request.auth.credentials as SessionTokenAuthCredential;
541540

542541
const { code } = request.payload as unknown as {
@@ -602,11 +601,17 @@ class RecoveryPhoneHandler {
602601

603602
const { phoneNumber, nationalFormat } =
604603
await this.recoveryPhoneService.hasConfirmed(uid);
604+
605+
recordSecurityEvent('account.recovery_phone_replace_complete', {
606+
db: this.db,
607+
request,
608+
});
609+
605610
const { acceptLanguage, geo, ua } = request.app;
606611
const account = await this.db.account(uid);
607612

608613
try {
609-
await this.mailer.postChangeRecoveryPhoneEmail(account.emails, account, {
614+
await this.mailer.sendPostChangeRecoveryPhoneEmail(account.emails, account, {
610615
acceptLanguage,
611616
timeZone: geo.timeZone,
612617
uaBrowser: ua.browser,
@@ -616,11 +621,6 @@ class RecoveryPhoneHandler {
616621
uaDeviceType: ua.deviceType,
617622
uid,
618623
});
619-
620-
recordSecurityEvent('account.recovery_phone_replace_complete', {
621-
db: this.db,
622-
request,
623-
});
624624
} catch (error) {
625625
// log error, but don't throw
626626
// user should be allowed to proceed if email or security event fails

packages/fxa-auth-server/test/local/routes/recovery-phone.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ describe('/recovery_phone', () => {
695695
});
696696

697697
it('does not reject if email does not send', async () => {
698-
mockMailer.postChangeRecoveryPhoneEmail = sinon.fake.returns(
698+
mockMailer.sendPostChangeRecoveryPhoneEmail = sinon.fake.returns(
699699
Promise.reject(new Error('BOOM'))
700700
);
701701

@@ -707,7 +707,7 @@ describe('/recovery_phone', () => {
707707
});
708708

709709
assert.isDefined(resp);
710-
assert.calledOnce(mockMailer.postChangeRecoveryPhoneEmail);
710+
assert.calledOnce(mockMailer.sendPostChangeRecoveryPhoneEmail);
711711
assert.deepEqual(resp, {
712712
status: 'success',
713713
phoneNumber,

packages/fxa-auth-server/test/mocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const MAILER_METHOD_NAMES = [
184184
'sendPostRemoveRecoveryPhoneEmail',
185185
'sendPostSigninRecoveryPhoneEmail',
186186
'sendPostSigninRecoveryCodeEmail',
187-
'postChangeRecoveryPhoneEmail',
187+
'sendPostChangeRecoveryPhoneEmail',
188188
];
189189

190190
const METRICS_CONTEXT_METHOD_NAMES = [

0 commit comments

Comments
 (0)