зеркало из https://github.com/mozilla/fxa.git
feat(email): include count in low recovery codes email
This commit is contained in:
Родитель
abd5d5030f
Коммит
1c2c3df858
|
@ -187,6 +187,7 @@ module.exports = (log, db, config, customs, mailer) => {
|
|||
account,
|
||||
{
|
||||
acceptLanguage: request.app.acceptLanguage,
|
||||
numberRemaining: remainingRecoveryCodes,
|
||||
uid: sessionToken.uid,
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1579,9 +1579,12 @@ module.exports = function(log, config, oauthdb) {
|
|||
};
|
||||
|
||||
Mailer.prototype.lowRecoveryCodesEmail = function(message) {
|
||||
const { numberRemaining } = message;
|
||||
|
||||
log.trace('mailer.lowRecoveryCodesEmail', {
|
||||
email: message.email,
|
||||
uid: message.uid,
|
||||
numberRemaining,
|
||||
});
|
||||
|
||||
const templateName = 'lowRecoveryCodesEmail';
|
||||
|
@ -1591,15 +1594,23 @@ module.exports = function(log, config, oauthdb) {
|
|||
'X-Link': links.link,
|
||||
};
|
||||
|
||||
let subject;
|
||||
if (numberRemaining === 1) {
|
||||
subject = gettext('1 Recovery Code Remaining');
|
||||
} else {
|
||||
subject = gettext('%(numberRemaining)s Recovery Codes Remaining');
|
||||
}
|
||||
|
||||
return this.send(
|
||||
Object.assign({}, message, {
|
||||
headers,
|
||||
subject: gettext('Low Recovery Codes Remaining'),
|
||||
subject,
|
||||
template: templateName,
|
||||
templateValues: {
|
||||
androidLink: links.androidLink,
|
||||
iosLink: links.iosLink,
|
||||
link: links.link,
|
||||
numberRemaining,
|
||||
privacyUrl: links.privacyUrl,
|
||||
passwordChangeLinkAttributes: links.passwordChangeLinkAttributes,
|
||||
passwordChangeLink: links.passwordChangeLink,
|
||||
|
|
|
@ -123,6 +123,7 @@ function sendMail(mailer, messageToSend) {
|
|||
country: 'Spain',
|
||||
},
|
||||
locations: [],
|
||||
numberRemaining: 2,
|
||||
productId: '0123456789abcdef',
|
||||
redirectTo: 'https://redirect.com/',
|
||||
resume:
|
||||
|
|
|
@ -16,7 +16,12 @@ const TEST_EMAIL = 'test@email.com';
|
|||
const UID = 'uid';
|
||||
|
||||
function runTest(routePath, requestOptions) {
|
||||
const config = { recoveryCodes: {} };
|
||||
const config = {
|
||||
recoveryCodes: {
|
||||
count: 8,
|
||||
notifyLowCount: 2,
|
||||
},
|
||||
};
|
||||
routes = require('../../../lib/routes/recovery-codes')(
|
||||
log,
|
||||
db,
|
||||
|
@ -87,6 +92,17 @@ describe('recovery codes', () => {
|
|||
});
|
||||
|
||||
describe('/session/verify/recoveryCode', () => {
|
||||
it('sends email if recovery codes are low', async () => {
|
||||
db.consumeRecoveryCode = sinon.spy(code => {
|
||||
return P.resolve({ remaining: 1 });
|
||||
});
|
||||
await runTest('/session/verify/recoveryCode', requestOptions);
|
||||
assert.equal(mailer.sendLowRecoveryCodeNotification.callCount, 1);
|
||||
const args = mailer.sendLowRecoveryCodeNotification.args[0];
|
||||
assert.lengthOf(args, 3);
|
||||
assert.equal(args[2].numberRemaining, 1);
|
||||
});
|
||||
|
||||
it('should rate-limit attempts to use a recovery code via customs', () => {
|
||||
requestOptions.payload.code = '1234567890';
|
||||
db.consumeRecoveryCode = sinon.spy(code => {
|
||||
|
|
|
@ -234,6 +234,7 @@ describe('lib/senders/email:', () => {
|
|||
deviceId: 'foo',
|
||||
email: 'a@b.com',
|
||||
locations: [],
|
||||
numberRemaining: 2,
|
||||
productId: 'wibble',
|
||||
service: 'sync',
|
||||
tokenCode: 'abc123',
|
||||
|
@ -568,6 +569,10 @@ describe('lib/senders/email:', () => {
|
|||
assert.include(emailConfig.text, url);
|
||||
assert.notInclude(emailConfig.html, 'utm_source=email');
|
||||
assert.notInclude(emailConfig.text, 'utm_source=email');
|
||||
|
||||
if (type === 'lowRecoveryCodesEmail') {
|
||||
assert.equal(emailConfig.subject, '2 Recovery Codes Remaining');
|
||||
}
|
||||
});
|
||||
return mailer[type](message);
|
||||
});
|
||||
|
|
|
@ -123,25 +123,27 @@ const LOG_METHOD_NAMES = [
|
|||
|
||||
const MAILER_METHOD_NAMES = [
|
||||
'sendDownloadSubscription',
|
||||
'sendLowRecoveryCodeNotification',
|
||||
'sendNewDeviceLoginNotification',
|
||||
'sendPasswordChangedNotification',
|
||||
'sendPasswordResetAccountRecoveryNotification',
|
||||
'sendPasswordResetNotification',
|
||||
'sendPostAddAccountRecoveryNotification',
|
||||
'sendPostAddTwoStepAuthNotification',
|
||||
'sendPostChangePrimaryEmail',
|
||||
'sendPostConsumeRecoveryCodeNotification',
|
||||
'sendPostNewRecoveryCodesNotification',
|
||||
'sendPostRemoveAccountRecoveryNotification',
|
||||
'sendPostRemoveSecondaryEmail',
|
||||
'sendPostVerifyEmail',
|
||||
'sendPostRemoveTwoStepAuthNotification',
|
||||
'sendPostVerifySecondaryEmail',
|
||||
'sendRecoveryCode',
|
||||
'sendUnblockCode',
|
||||
'sendVerifyCode',
|
||||
'sendVerifyLoginEmail',
|
||||
'sendVerifyLoginCodeEmail',
|
||||
'sendVerifySecondaryEmail',
|
||||
'sendRecoveryCode',
|
||||
'sendPostAddAccountRecoveryNotification',
|
||||
'sendPostRemoveAccountRecoveryNotification',
|
||||
'sendPasswordResetAccountRecoveryNotification',
|
||||
];
|
||||
|
||||
const METRICS_CONTEXT_METHOD_NAMES = [
|
||||
|
|
Загрузка…
Ссылка в новой задаче