[web] Send security alert email when secondary is added (#23657)

* [web] Send security alert email when secondary is added

* [web] Add test: checkSecondaryEmailConfirmationCode - sends a security alert email

* Move `_sendSecurityAlertEmail` before `addEmailAddress`

GitOrigin-RevId: 8d9c496fffd953871e03d8c7f011c42459eeb0bc
This commit is contained in:
Antoine Clausse
2025-02-17 16:56:27 +01:00
committed by Copybot
parent 1aada036f9
commit 76301e0cc8
2 changed files with 35 additions and 10 deletions
@@ -409,6 +409,31 @@ describe('UserEmailsController', function () {
}
)
})
it('sends a security alert email', async function () {
this.req.session.pendingSecondaryEmail = {
confirmCode: '123456',
email: this.newEmail,
confirmCodeExpiresTimestamp: new Date(Math.max),
affiliationOptions: {},
}
this.req.body.code = '123456'
await this.UserEmailsController.checkSecondaryEmailConfirmationCode(
this.req,
{
json: sinon.stub().resolves(),
}
)
const emailCall = this.EmailHandler.promises.sendEmail.getCall(0)
expect(emailCall.args[0]).to.equal('securityAlert')
expect(emailCall.args[1].to).to.equal(this.user.email)
expect(emailCall.args[1].actionDescribed).to.contain(
'a secondary email address'
)
expect(emailCall.args[1].message[0]).to.contain(this.newEmail)
})
})
describe('with an invalid confirmation code', function () {