Merge pull request #13520 from mozilla/fxa-5052/unnecessary-reminder-emails

fix(auth): user Sent Unnecessary Finish Setting Up Account Reminder Email
This commit is contained in:
Ivo Plamenac 2022-07-06 09:10:41 -07:00 коммит произвёл GitHub
Родитель 37dc446b77 097baedb9e
Коммит 82f1382b50
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 86 добавлений и 18 удалений

Просмотреть файл

@ -578,12 +578,13 @@ export class AccountHandler {
this.log.begin('Account.finishSetup', request);
const form = request.payload as any;
const authPW = form.authPW;
let uid;
try {
const payload = (await jwt.verify(form.token, {
typ: 'fin+JWT',
ignoreExpiration: true,
})) as any;
const uid = payload.uid;
uid = payload.uid;
form.uid = payload.uid;
const account = await this.db.account(uid);
// Only proceed if the account is in the stub state.
@ -628,6 +629,16 @@ export class AccountHandler {
this.log.error('Account.finish_setup.error', {
err,
});
// if it errored out after verifiying the account
// remove the uid from the list of accounts to send reminders to.
if (!!uid) {
const account = await this.db.account(uid);
if (account.verifierSetAt > 0) {
await this.subscriptionAccountReminders.delete(uid);
}
}
throw err;
}
}

Просмотреть файл

@ -658,6 +658,7 @@ module.exports = function (log, config, bounces) {
flowId,
flowBeginTime,
deviceId,
accountVerified,
} = message;
log.trace(`mailer.${template}`, { email, uid });
@ -682,22 +683,24 @@ module.exports = function (log, config, bounces) {
'X-Link': links.link,
};
return this.send({
...message,
headers,
layout: 'subscription',
template,
templateValues: {
email,
...links,
oneClickLink: links.oneClickLink,
privacyUrl: links.privacyUrl,
termsOfServiceDownloadURL: links.termsOfServiceDownloadURL,
supportUrl: links.supportUrl,
supportLinkAttributes: links.supportLinkAttributes,
reminderShortForm: true,
},
});
if (!accountVerified) {
return this.send({
...message,
headers,
layout: 'subscription',
template,
templateValues: {
email,
...links,
oneClickLink: links.oneClickLink,
privacyUrl: links.privacyUrl,
termsOfServiceDownloadURL: links.termsOfServiceDownloadURL,
supportUrl: links.supportUrl,
supportLinkAttributes: links.supportLinkAttributes,
reminderShortForm: true,
},
});
}
};
});

Просмотреть файл

@ -182,6 +182,7 @@ async function run() {
acceptLanguage: account.locale,
code: account.emailCode,
email: account.email,
accountVerified: account.verifierSetAt > 0,
token: token,
flowBeginTime,
flowId,

Просмотреть файл

@ -1595,6 +1595,20 @@ describe('/account/finish_setup', () => {
assert.equal(err.errno, 110);
}
});
it('removes the reminder if it errors after account is verified', async () => {
const { route, mockRequest, subscriptionAccountReminders } = setup({
verifierSetAt: Date.now(),
});
try {
await runTest(route, mockRequest);
assert.fail('should have errored');
} catch (err) {
assert.equal(err.errno, 110);
assert.calledOnce(subscriptionAccountReminders.delete);
}
});
});
describe('/account/login', () => {

Просмотреть файл

@ -241,7 +241,10 @@ describe('lib/senders/index', () => {
return email.sendPostAddLinkedAccountEmail(EMAILS, acct, {});
})
.then(() => {
assert.equal(email._ungatedMailer.postAddLinkedAccountEmail.callCount, 1);
assert.equal(
email._ungatedMailer.postAddLinkedAccountEmail.callCount,
1
);
const args =
email._ungatedMailer.postAddLinkedAccountEmail.getCall(0).args;
@ -461,5 +464,41 @@ describe('lib/senders/index', () => {
});
});
});
describe('subscriptionAccountReminder Emails', () => {
it('should send an email if the account is unverified', async () => {
const mailer = await createSender(config);
await mailer.sendSubscriptionAccountReminderFirstEmail(EMAILS, acct, {
email: 'test@test.com',
uid: '123',
productId: 'abc',
productName: 'testProduct',
token: 'token',
flowId: '456',
lowBeginTime: 123,
deviceId: 'xyz',
accountVerified: false,
});
assert.equal(mailer._ungatedMailer.mailer.sendMail.callCount, 1);
});
it('should not send an email if the account is verified', async () => {
const mailer = await createSender(config);
await mailer.sendSubscriptionAccountReminderFirstEmail(EMAILS, acct, {
email: 'test@test.com',
uid: '123',
productId: 'abc',
productName: 'testProduct',
token: 'token',
flowId: '456',
lowBeginTime: 123,
deviceId: 'xyz',
accountVerified: true,
});
assert.equal(mailer._ungatedMailer.mailer.sendMail.callCount, 0);
});
});
});
});