Merge pull request #18277 from mozilla/fxa-sms-testing

fix(testing): Update mail helper to print sms codes
This commit is contained in:
Vijay Budhram 2025-01-27 13:49:24 -05:00 коммит произвёл GitHub
Родитель bc62e1f479 824d399ab5
Коммит f2704196b8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 39 добавлений и 3 удалений

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

@ -7,11 +7,46 @@
'use strict';
const MailParser = require('mailparser').MailParser;
const simplesmtp = require('simplesmtp');
const Redis = require('ioredis');
const config = require('../config').default.getProperties();
const TEMPLATES_WITH_NO_CODE = new Set(['passwordResetEmail']);
// SMS polling
const redis = new Redis(config.redis);
const usersLastSms = {};
async function printMatchingKeys(startUp = false) {
const redisKeyPattern = 'recovery-phone:sms-attempt:*:*';
try {
const keys = await redis.keys(redisKeyPattern);
if (keys.length > 0) {
for (const key of keys) {
const keyParts = key.split(':');
const uid = keyParts[2];
const code = keyParts[3];
if (!usersLastSms[uid]) {
usersLastSms[uid] = {};
}
// Check if this code was already printed for this user
if (!usersLastSms[uid][code]) {
if (!startUp) {
console.log('\x1B[36mRecovery Phone Otp:', code, '\x1B[39m');
}
usersLastSms[uid][code] = true;
}
}
}
} catch (error) {
console.error('Failed to retrieve keys:', error);
} finally {
// 1s delay seems reasonable
setTimeout(printMatchingKeys, 1000);
}
}
// SMTP half
const users = {};
@ -147,14 +182,15 @@ module.exports = (printLogs) => {
},
]);
api.start().then(() => {
api.start().then(async () => {
console.log('mail_helper started...');
printMatchingKeys(true);
return resolve({
close() {
return new Promise((resolve, reject) => {
let smtpClosed = false;
let apiClosed = false;
redis.quit();
smtp.server.end(() => {
smtpClosed = true;
if (apiClosed) {