fix: preserve phone identity during Step 8 retries
- 吸收 PR #245 的核心改动:手机号注册账号在 Step 8 重试、add-email 和后续 OAuth 登录恢复时保留手机号主身份。 - 本地补充修复:在 oauth-login stepKey 分支提前同步 Step 7 completion payload,避免真实运行路径提前 return 后跳过身份保存。 - 影响范围:Step 7 OAuth 登录、Step 8 登录验证码/add-email 恢复、2925 邮箱轮询重发计划。
This commit is contained in:
+57
-10
@@ -3181,14 +3181,22 @@ function isPhoneActivationForNumber(activation, phoneNumber) {
|
|||||||
|
|
||||||
async function setEmailStateSilently(email, options = {}) {
|
async function setEmailStateSilently(email, options = {}) {
|
||||||
const currentState = await getState();
|
const currentState = await getState();
|
||||||
const updates = buildRegistrationEmailStateUpdates(currentState, {
|
const preserveAccountIdentity = Boolean(options?.preserveAccountIdentity);
|
||||||
currentEmail: email,
|
const updates = preserveAccountIdentity
|
||||||
preservePrevious: Boolean(options?.preservePrevious),
|
? buildFlowRegistrationEmailStateUpdates(currentState, {
|
||||||
source: options?.source || '',
|
currentEmail: email,
|
||||||
});
|
preservePrevious: Boolean(options?.preservePrevious),
|
||||||
|
preserveAccountIdentity: true,
|
||||||
|
source: options?.source || '',
|
||||||
|
})
|
||||||
|
: buildRegistrationEmailStateUpdates(currentState, {
|
||||||
|
currentEmail: email,
|
||||||
|
preservePrevious: Boolean(options?.preservePrevious),
|
||||||
|
source: options?.source || '',
|
||||||
|
});
|
||||||
const normalizedEmail = updates.email;
|
const normalizedEmail = updates.email;
|
||||||
|
|
||||||
if (normalizedEmail) {
|
if (!preserveAccountIdentity && normalizedEmail) {
|
||||||
updates.accountIdentifierType = 'email';
|
updates.accountIdentifierType = 'email';
|
||||||
updates.accountIdentifier = normalizedEmail;
|
updates.accountIdentifier = normalizedEmail;
|
||||||
updates.phoneNumber = '';
|
updates.phoneNumber = '';
|
||||||
@@ -3197,7 +3205,7 @@ async function setEmailStateSilently(email, options = {}) {
|
|||||||
updates.signupPhoneCompletedActivation = null;
|
updates.signupPhoneCompletedActivation = null;
|
||||||
updates.signupPhoneVerificationRequestedAt = null;
|
updates.signupPhoneVerificationRequestedAt = null;
|
||||||
updates.signupPhoneVerificationPurpose = '';
|
updates.signupPhoneVerificationPurpose = '';
|
||||||
} else if (String(currentState?.accountIdentifierType || '').trim().toLowerCase() === 'email') {
|
} else if (!preserveAccountIdentity && String(currentState?.accountIdentifierType || '').trim().toLowerCase() === 'email') {
|
||||||
updates.accountIdentifierType = null;
|
updates.accountIdentifierType = null;
|
||||||
updates.accountIdentifier = '';
|
updates.accountIdentifier = '';
|
||||||
}
|
}
|
||||||
@@ -9165,6 +9173,34 @@ async function handleStepData(step, payload) {
|
|||||||
return messageRouter.handleStepData(step, payload);
|
return messageRouter.handleStepData(step, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldPreservePhoneIdentityForStepEmailPayload(state = {}, stepPayload = {}) {
|
||||||
|
if (String(stepPayload.accountIdentifierType || '').trim().toLowerCase() === 'email') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Boolean(
|
||||||
|
String(state.signupPhoneNumber || '').trim()
|
||||||
|
|| (String(state.accountIdentifierType || '').trim().toLowerCase() === 'phone'
|
||||||
|
&& String(state.accountIdentifier || '').trim())
|
||||||
|
|| state.signupPhoneActivation
|
||||||
|
|| state.signupPhoneCompletedActivation
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function persistStepEmailPayload(email, stepPayload = {}, source = 'step_identity') {
|
||||||
|
if (!email) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const currentState = await getState();
|
||||||
|
if (shouldPreservePhoneIdentityForStepEmailPayload(currentState, stepPayload)) {
|
||||||
|
await persistRegistrationEmailState(currentState, email, {
|
||||||
|
source,
|
||||||
|
preserveAccountIdentity: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await setEmailState(email);
|
||||||
|
}
|
||||||
|
|
||||||
switch (step) {
|
switch (step) {
|
||||||
case 1: {
|
case 1: {
|
||||||
const updates = {};
|
const updates = {};
|
||||||
@@ -9193,8 +9229,8 @@ async function handleStepData(step, payload) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
if (payload.email) await setEmailState(payload.email);
|
await persistStepEmailPayload(payload.email, payload, 'step2_identity');
|
||||||
if (payload.accountIdentifierType || payload.accountIdentifier || payload.signupPhoneNumber || payload.signupPhoneActivation) {
|
if (!payload.email && (payload.accountIdentifierType || payload.accountIdentifier || payload.signupPhoneNumber || payload.signupPhoneActivation)) {
|
||||||
await setState({
|
await setState({
|
||||||
accountIdentifierType: payload.accountIdentifierType || null,
|
accountIdentifierType: payload.accountIdentifierType || null,
|
||||||
accountIdentifier: String(payload.accountIdentifier || '').trim(),
|
accountIdentifier: String(payload.accountIdentifier || '').trim(),
|
||||||
@@ -9213,7 +9249,7 @@ async function handleStepData(step, payload) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (payload.email) await setEmailState(payload.email);
|
await persistStepEmailPayload(payload.email, payload, 'step3_identity');
|
||||||
if (payload.signupVerificationRequestedAt) {
|
if (payload.signupVerificationRequestedAt) {
|
||||||
await setState({ signupVerificationRequestedAt: payload.signupVerificationRequestedAt });
|
await setState({ signupVerificationRequestedAt: payload.signupVerificationRequestedAt });
|
||||||
}
|
}
|
||||||
@@ -9230,6 +9266,15 @@ async function handleStepData(step, payload) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
|
if (payload.accountIdentifierType || payload.accountIdentifier || payload.signupPhoneNumber || payload.signupPhoneActivation || payload.signupPhoneCompletedActivation) {
|
||||||
|
await setState({
|
||||||
|
accountIdentifierType: payload.accountIdentifierType || null,
|
||||||
|
accountIdentifier: String(payload.accountIdentifier || '').trim(),
|
||||||
|
signupPhoneNumber: String(payload.signupPhoneNumber || '').trim(),
|
||||||
|
signupPhoneActivation: payload.signupPhoneActivation || null,
|
||||||
|
signupPhoneCompletedActivation: payload.signupPhoneCompletedActivation || null,
|
||||||
|
});
|
||||||
|
}
|
||||||
if (payload.loginVerificationRequestedAt) {
|
if (payload.loginVerificationRequestedAt) {
|
||||||
await setState({ loginVerificationRequestedAt: payload.loginVerificationRequestedAt });
|
await setState({ loginVerificationRequestedAt: payload.loginVerificationRequestedAt });
|
||||||
}
|
}
|
||||||
@@ -11737,6 +11782,7 @@ const step8Executor = self.MultiPageBackgroundStep8?.createStep8Executor({
|
|||||||
LUCKMAIL_PROVIDER,
|
LUCKMAIL_PROVIDER,
|
||||||
resolveVerificationStep: verificationFlowHelpers.resolveVerificationStep,
|
resolveVerificationStep: verificationFlowHelpers.resolveVerificationStep,
|
||||||
resolveSignupEmailForFlow,
|
resolveSignupEmailForFlow,
|
||||||
|
persistRegistrationEmailState,
|
||||||
phoneVerificationHelpers,
|
phoneVerificationHelpers,
|
||||||
rerunStep7ForStep8Recovery: (...args) => rerunStep7ForStep8Recovery(...args),
|
rerunStep7ForStep8Recovery: (...args) => rerunStep7ForStep8Recovery(...args),
|
||||||
resolveSignupMethod,
|
resolveSignupMethod,
|
||||||
@@ -11982,6 +12028,7 @@ const messageRouter = self.MultiPageBackgroundMessageRouter?.createMessageRouter
|
|||||||
setContributionMode,
|
setContributionMode,
|
||||||
setEmailState,
|
setEmailState,
|
||||||
setEmailStateSilently,
|
setEmailStateSilently,
|
||||||
|
persistRegistrationEmailState,
|
||||||
setFreeReusablePhoneActivation,
|
setFreeReusablePhoneActivation,
|
||||||
setSignupPhoneState,
|
setSignupPhoneState,
|
||||||
setSignupPhoneStateSilently,
|
setSignupPhoneStateSilently,
|
||||||
|
|||||||
@@ -158,6 +158,7 @@
|
|||||||
setContributionMode,
|
setContributionMode,
|
||||||
setEmailState,
|
setEmailState,
|
||||||
setEmailStateSilently,
|
setEmailStateSilently,
|
||||||
|
persistRegistrationEmailState,
|
||||||
setFreeReusablePhoneActivation,
|
setFreeReusablePhoneActivation,
|
||||||
setSignupPhoneState,
|
setSignupPhoneState,
|
||||||
setSignupPhoneStateSilently,
|
setSignupPhoneStateSilently,
|
||||||
@@ -264,6 +265,42 @@
|
|||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasPhoneSignupIdentity(state = {}) {
|
||||||
|
const identifierType = String(state?.accountIdentifierType || '').trim().toLowerCase();
|
||||||
|
return Boolean(
|
||||||
|
String(state?.signupPhoneNumber || '').trim()
|
||||||
|
|| (identifierType === 'phone' && String(state?.accountIdentifier || '').trim())
|
||||||
|
|| state?.signupPhoneActivation
|
||||||
|
|| state?.signupPhoneCompletedActivation
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldPreservePhoneIdentityForEmailPayload(payload = {}, state = {}) {
|
||||||
|
const identifierType = String(payload?.accountIdentifierType || '').trim().toLowerCase();
|
||||||
|
if (identifierType === 'email') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return hasPhoneSignupIdentity(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function persistEmailIdentityFromStepPayload(email, payload = {}, source = 'step_payload') {
|
||||||
|
if (!email) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const state = await getState();
|
||||||
|
const preserveAccountIdentity = shouldPreservePhoneIdentityForEmailPayload(payload, state);
|
||||||
|
if (preserveAccountIdentity && typeof persistRegistrationEmailState === 'function') {
|
||||||
|
await persistRegistrationEmailState(state, email, {
|
||||||
|
source,
|
||||||
|
preserveAccountIdentity: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await setEmailState(email, preserveAccountIdentity
|
||||||
|
? { source, preserveAccountIdentity: true }
|
||||||
|
: { source });
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeAutomationWindowId(value) {
|
function normalizeAutomationWindowId(value) {
|
||||||
if (value === null || value === undefined || value === '') {
|
if (value === null || value === undefined || value === '') {
|
||||||
return null;
|
return null;
|
||||||
@@ -316,7 +353,10 @@
|
|||||||
const email = resolveEmailIdentityPayload(payload);
|
const email = resolveEmailIdentityPayload(payload);
|
||||||
if (identifierType === 'email' || email) {
|
if (identifierType === 'email' || email) {
|
||||||
if (email) {
|
if (email) {
|
||||||
await setEmailState(email);
|
await persistEmailIdentityFromStepPayload(email, payload, 'step_identity');
|
||||||
|
}
|
||||||
|
if (email) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const updates = {
|
const updates = {
|
||||||
phoneNumber: '',
|
phoneNumber: '',
|
||||||
@@ -454,6 +494,7 @@
|
|||||||
const stepKey = getStepKeyForState(step, stateForStep);
|
const stepKey = getStepKeyForState(step, stateForStep);
|
||||||
|
|
||||||
if (stepKey === 'oauth-login') {
|
if (stepKey === 'oauth-login') {
|
||||||
|
await syncStepAccountIdentityFromPayload(payload);
|
||||||
if (payload.skipLoginVerificationStep) {
|
if (payload.skipLoginVerificationStep) {
|
||||||
await setState({ loginVerificationRequestedAt: null });
|
await setState({ loginVerificationRequestedAt: null });
|
||||||
const latestState = await getState();
|
const latestState = await getState();
|
||||||
@@ -591,6 +632,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 7:
|
||||||
|
await syncStepAccountIdentityFromPayload(payload);
|
||||||
|
if (payload.loginVerificationRequestedAt) {
|
||||||
|
await setState({ loginVerificationRequestedAt: payload.loginVerificationRequestedAt });
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
await setState({
|
await setState({
|
||||||
...(payload.phoneVerification || payload.loginPhoneVerification ? {
|
...(payload.phoneVerification || payload.loginPhoneVerification ? {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
reuseOrCreateTab,
|
reuseOrCreateTab,
|
||||||
sendToContentScriptResilient,
|
sendToContentScriptResilient,
|
||||||
buildRegistrationEmailStateUpdates = null,
|
buildRegistrationEmailStateUpdates = null,
|
||||||
|
persistRegistrationEmailState = null,
|
||||||
phoneVerificationHelpers = null,
|
phoneVerificationHelpers = null,
|
||||||
setState,
|
setState,
|
||||||
shouldUseCustomRegistrationEmail,
|
shouldUseCustomRegistrationEmail,
|
||||||
@@ -181,14 +182,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const displayedEmail = normalizeStep8VerificationTargetEmail(result?.displayedEmail || resolvedEmail);
|
const displayedEmail = normalizeStep8VerificationTargetEmail(result?.displayedEmail || resolvedEmail);
|
||||||
await setState({
|
let persistedState = latestState;
|
||||||
email: resolvedEmail,
|
if (typeof persistRegistrationEmailState === 'function') {
|
||||||
step8VerificationTargetEmail: displayedEmail,
|
await persistRegistrationEmailState(latestState, resolvedEmail, {
|
||||||
});
|
source: 'step8_add_email',
|
||||||
|
preserveAccountIdentity: true,
|
||||||
|
});
|
||||||
|
persistedState = typeof getState === 'function' ? await getState() : latestState;
|
||||||
|
} else {
|
||||||
|
await setState({
|
||||||
|
email: resolvedEmail,
|
||||||
|
step8VerificationTargetEmail: displayedEmail,
|
||||||
|
});
|
||||||
|
persistedState = {
|
||||||
|
...latestState,
|
||||||
|
email: resolvedEmail,
|
||||||
|
step8VerificationTargetEmail: displayedEmail,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
state: {
|
state: {
|
||||||
...latestState,
|
...persistedState,
|
||||||
email: resolvedEmail,
|
email: resolvedEmail,
|
||||||
step8VerificationTargetEmail: displayedEmail,
|
step8VerificationTargetEmail: displayedEmail,
|
||||||
},
|
},
|
||||||
@@ -535,6 +550,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
targetEmail: fixedTargetEmail,
|
targetEmail: fixedTargetEmail,
|
||||||
|
maxResendRequests: mail.provider === '2925' ? 2 : undefined,
|
||||||
|
initialPollMaxAttempts: mail.provider === '2925' ? 5 : undefined,
|
||||||
|
pollAttemptPlan: mail.provider === '2925' ? [2, 3, 15] : undefined,
|
||||||
resendIntervalMs: mail.provider === LUCKMAIL_PROVIDER
|
resendIntervalMs: mail.provider === LUCKMAIL_PROVIDER
|
||||||
? 15000
|
? 15000
|
||||||
: ((mail.provider === HOTMAIL_PROVIDER || mail.provider === '2925')
|
: ((mail.provider === HOTMAIL_PROVIDER || mail.provider === '2925')
|
||||||
|
|||||||
@@ -71,9 +71,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function shouldPreferStep7PhoneSignupIdentity(state = {}) {
|
function shouldPreferStep7PhoneSignupIdentity(state = {}) {
|
||||||
const frozenSignupMethod = normalizeStep7IdentifierType(state?.resolvedSignupMethod);
|
|
||||||
return canUseConfiguredPhoneSignup(state)
|
return canUseConfiguredPhoneSignup(state)
|
||||||
&& frozenSignupMethod !== 'email'
|
|
||||||
&& hasStep7PhoneSignupIdentity(state);
|
&& hasStep7PhoneSignupIdentity(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,6 +263,13 @@
|
|||||||
const completionPayload = {
|
const completionPayload = {
|
||||||
loginVerificationRequestedAt: result.loginVerificationRequestedAt || null,
|
loginVerificationRequestedAt: result.loginVerificationRequestedAt || null,
|
||||||
};
|
};
|
||||||
|
if (currentIdentifierType === 'phone') {
|
||||||
|
completionPayload.accountIdentifierType = 'phone';
|
||||||
|
completionPayload.accountIdentifier = currentPhoneNumber;
|
||||||
|
completionPayload.signupPhoneNumber = currentPhoneNumber;
|
||||||
|
completionPayload.signupPhoneCompletedActivation = currentState?.signupPhoneCompletedActivation || null;
|
||||||
|
completionPayload.signupPhoneActivation = currentState?.signupPhoneActivation || null;
|
||||||
|
}
|
||||||
if (Object.prototype.hasOwnProperty.call(result || {}, 'skipLoginVerificationStep')) {
|
if (Object.prototype.hasOwnProperty.call(result || {}, 'skipLoginVerificationStep')) {
|
||||||
completionPayload.skipLoginVerificationStep = Boolean(result.skipLoginVerificationStep);
|
completionPayload.skipLoginVerificationStep = Boolean(result.skipLoginVerificationStep);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -873,6 +873,8 @@
|
|||||||
onResendRequestedAt,
|
onResendRequestedAt,
|
||||||
maxRounds: _ignoredMaxRounds,
|
maxRounds: _ignoredMaxRounds,
|
||||||
maxResendRequests: _ignoredMaxResendRequests,
|
maxResendRequests: _ignoredMaxResendRequests,
|
||||||
|
initialPollMaxAttempts: _ignoredInitialPollMaxAttempts,
|
||||||
|
pollAttemptPlan: _ignoredPollAttemptPlan,
|
||||||
...cleanPollOverrides
|
...cleanPollOverrides
|
||||||
} = pollOverrides;
|
} = pollOverrides;
|
||||||
const basePayload = {
|
const basePayload = {
|
||||||
@@ -926,6 +928,8 @@
|
|||||||
onResendRequestedAt,
|
onResendRequestedAt,
|
||||||
maxRounds: _ignoredMaxRounds,
|
maxRounds: _ignoredMaxRounds,
|
||||||
maxResendRequests: _ignoredMaxResendRequests,
|
maxResendRequests: _ignoredMaxResendRequests,
|
||||||
|
initialPollMaxAttempts: _ignoredInitialPollMaxAttempts,
|
||||||
|
pollAttemptPlan: _ignoredPollAttemptPlan,
|
||||||
...cleanPollOverrides
|
...cleanPollOverrides
|
||||||
} = pollOverrides;
|
} = pollOverrides;
|
||||||
|
|
||||||
@@ -981,6 +985,13 @@
|
|||||||
let filterAfterTimestamp = cleanPollOverrides.filterAfterTimestamp ?? getVerificationPollPayload(step, state).filterAfterTimestamp;
|
let filterAfterTimestamp = cleanPollOverrides.filterAfterTimestamp ?? getVerificationPollPayload(step, state).filterAfterTimestamp;
|
||||||
const maxResendRequests = resolveMaxResendRequests(pollOverrides);
|
const maxResendRequests = resolveMaxResendRequests(pollOverrides);
|
||||||
const maxRounds = maxResendRequests + 1;
|
const maxRounds = maxResendRequests + 1;
|
||||||
|
const initialPollMaxAttempts = Math.max(0, Math.floor(Number(pollOverrides.initialPollMaxAttempts) || 0));
|
||||||
|
const configuredPollAttemptPlan = Array.isArray(pollOverrides.pollAttemptPlan)
|
||||||
|
? pollOverrides.pollAttemptPlan
|
||||||
|
.map((value) => Math.floor(Number(value) || 0))
|
||||||
|
.filter((value) => value > 0)
|
||||||
|
: [];
|
||||||
|
const pollAttemptPlan = rejectedCodes.size > 0 ? [] : configuredPollAttemptPlan;
|
||||||
let usedResendRequests = 0;
|
let usedResendRequests = 0;
|
||||||
|
|
||||||
for (let round = 1; round <= maxRounds; round++) {
|
for (let round = 1; round <= maxRounds; round++) {
|
||||||
@@ -1001,6 +1012,12 @@
|
|||||||
filterAfterTimestamp,
|
filterAfterTimestamp,
|
||||||
excludeCodes: [...rejectedCodes],
|
excludeCodes: [...rejectedCodes],
|
||||||
});
|
});
|
||||||
|
const plannedPollMaxAttempts = pollAttemptPlan[round - 1] || 0;
|
||||||
|
if (plannedPollMaxAttempts > 0) {
|
||||||
|
payload.maxAttempts = plannedPollMaxAttempts;
|
||||||
|
} else if (round === 1 && initialPollMaxAttempts > 0) {
|
||||||
|
payload.maxAttempts = initialPollMaxAttempts;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const timedPoll = await applyMailPollingTimeBudget(
|
const timedPoll = await applyMailPollingTimeBudget(
|
||||||
@@ -1306,6 +1323,12 @@
|
|||||||
disableTimeBudgetCap: Boolean(options.disableTimeBudgetCap),
|
disableTimeBudgetCap: Boolean(options.disableTimeBudgetCap),
|
||||||
getRemainingTimeMs: options.getRemainingTimeMs,
|
getRemainingTimeMs: options.getRemainingTimeMs,
|
||||||
maxResendRequests: remainingAutomaticResendCount,
|
maxResendRequests: remainingAutomaticResendCount,
|
||||||
|
initialPollMaxAttempts: mail.provider === '2925' && rejectedCodes.size > 0
|
||||||
|
? undefined
|
||||||
|
: options.initialPollMaxAttempts,
|
||||||
|
pollAttemptPlan: mail.provider === '2925' && rejectedCodes.size > 0
|
||||||
|
? undefined
|
||||||
|
: options.pollAttemptPlan,
|
||||||
resendIntervalMs,
|
resendIntervalMs,
|
||||||
lastResendAt,
|
lastResendAt,
|
||||||
onResendRequestedAt: updateFilterAfterTimestampForVerificationStep,
|
onResendRequestedAt: updateFilterAfterTimestampForVerificationStep,
|
||||||
|
|||||||
+60
-19
@@ -269,6 +269,48 @@ function findMailItems() {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isLikelyMail2925MailboxPage() {
|
||||||
|
const pageText = getPageTextSample(3000);
|
||||||
|
if (!pageText) {
|
||||||
|
return /#\/mailList/i.test(location.hash || location.href || '');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (findRefreshButton() || findInboxLink()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return /#\/mailList/i.test(location.hash || location.href || '')
|
||||||
|
&& /收件箱|刷新|删除|写信|邮件|mail/i.test(pageText)
|
||||||
|
&& !(/欢迎使用邮箱|登录|login/i.test(pageText) && /密码|password/i.test(pageText));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitForMailboxReady(timeoutMs = 12000) {
|
||||||
|
const startedAt = Date.now();
|
||||||
|
while (Date.now() - startedAt <= timeoutMs) {
|
||||||
|
if (typeof throwIfMail2925LimitReached === 'function') {
|
||||||
|
throwIfMail2925LimitReached();
|
||||||
|
}
|
||||||
|
const items = findMailItems();
|
||||||
|
if (items.length > 0) {
|
||||||
|
return { ready: true, items, empty: false };
|
||||||
|
}
|
||||||
|
if (getMail2925DisplayedMailboxEmail() || isLikelyMail2925MailboxPage()) {
|
||||||
|
return { ready: true, items: [], empty: true };
|
||||||
|
}
|
||||||
|
await sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = findMailItems();
|
||||||
|
if (items.length > 0) {
|
||||||
|
return { ready: true, items, empty: false };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
ready: Boolean(getMail2925DisplayedMailboxEmail() || isLikelyMail2925MailboxPage()),
|
||||||
|
items,
|
||||||
|
empty: items.length === 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function findActionBySelectors(selectors = []) {
|
function findActionBySelectors(selectors = []) {
|
||||||
for (const selector of selectors) {
|
for (const selector of selectors) {
|
||||||
const candidates = document.querySelectorAll(selector);
|
const candidates = document.querySelectorAll(selector);
|
||||||
@@ -518,7 +560,7 @@ function detectMail2925ViewState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mailboxEmail = getMail2925DisplayedMailboxEmail();
|
const mailboxEmail = getMail2925DisplayedMailboxEmail();
|
||||||
if (findMailItems().length > 0 || mailboxEmail) {
|
if (findMailItems().length > 0 || mailboxEmail || isLikelyMail2925MailboxPage()) {
|
||||||
return { view: 'mailbox', limitMessage: '', mailboxEmail };
|
return { view: 'mailbox', limitMessage: '', mailboxEmail };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -988,7 +1030,8 @@ async function sleepRandom(minMs, maxMs = minMs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function returnToInbox() {
|
async function returnToInbox() {
|
||||||
if (findMailItems().length > 0) {
|
const currentMailbox = await waitForMailboxReady(1500);
|
||||||
|
if (currentMailbox.ready) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1000,7 +1043,8 @@ async function returnToInbox() {
|
|||||||
simulateClick(inboxLink);
|
simulateClick(inboxLink);
|
||||||
for (let attempt = 0; attempt < 20; attempt += 1) {
|
for (let attempt = 0; attempt < 20; attempt += 1) {
|
||||||
await sleep(250);
|
await sleep(250);
|
||||||
if (findMailItems().length > 0) {
|
const mailbox = await waitForMailboxReady(250);
|
||||||
|
if (mailbox.ready) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1261,27 +1305,20 @@ async function handlePollEmail(step, payload) {
|
|||||||
let initialItems = [];
|
let initialItems = [];
|
||||||
let initialLoadUsedRefresh = false;
|
let initialLoadUsedRefresh = false;
|
||||||
|
|
||||||
for (let i = 0; i < 20; i += 1) {
|
const initialMailbox = await waitForMailboxReady(10000);
|
||||||
initialItems = findMailItems();
|
initialItems = initialMailbox.items;
|
||||||
if (initialItems.length > 0) {
|
if (!initialMailbox.ready || initialItems.length === 0) {
|
||||||
break;
|
|
||||||
}
|
|
||||||
await sleep(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (initialItems.length === 0) {
|
|
||||||
initialLoadUsedRefresh = true;
|
initialLoadUsedRefresh = true;
|
||||||
await returnToInbox();
|
await returnToInbox();
|
||||||
await refreshInbox();
|
await refreshInbox();
|
||||||
await sleep(2000);
|
const refreshedMailbox = await waitForMailboxReady(12000);
|
||||||
if (typeof throwIfMail2925LimitReached === 'function') {
|
if (typeof throwIfMail2925LimitReached === 'function') {
|
||||||
throwIfMail2925LimitReached();
|
throwIfMail2925LimitReached();
|
||||||
}
|
}
|
||||||
initialItems = findMailItems();
|
if (!refreshedMailbox.ready) {
|
||||||
}
|
throw new Error('2925 邮箱列表未加载完成,请确认当前已打开收件箱。');
|
||||||
|
}
|
||||||
if (initialItems.length === 0) {
|
initialItems = refreshedMailbox.items;
|
||||||
throw new Error('2925 邮箱列表未加载完成,请确认当前已打开收件箱。');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log(`步骤 ${step}:邮件列表已加载,共 ${initialItems.length} 封邮件`);
|
log(`步骤 ${step}:邮件列表已加载,共 ${initialItems.length} 封邮件`);
|
||||||
@@ -1298,7 +1335,11 @@ async function handlePollEmail(step, payload) {
|
|||||||
await sleepRandom(900, 1500);
|
await sleepRandom(900, 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = findMailItems();
|
const mailbox = await waitForMailboxReady(3000);
|
||||||
|
if (!mailbox.ready) {
|
||||||
|
throw new Error('2925 邮箱列表未加载完成,请确认当前已打开收件箱。');
|
||||||
|
}
|
||||||
|
const items = mailbox.items;
|
||||||
if (items.length > 0) {
|
if (items.length > 0) {
|
||||||
for (let index = 0; index < items.length; index += 1) {
|
for (let index = 0; index < items.length; index += 1) {
|
||||||
const item = items[index];
|
const item = items[index];
|
||||||
|
|||||||
@@ -83,6 +83,65 @@ const defaultStepDefinitions = {
|
|||||||
10: { key: 'platform-verify' },
|
10: { key: 'platform-verify' },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const PHONE_IDENTITY_STATE_KEYS = [
|
||||||
|
'phoneNumber',
|
||||||
|
'signupPhoneNumber',
|
||||||
|
'signupPhoneActivation',
|
||||||
|
'signupPhoneCompletedActivation',
|
||||||
|
'signupPhoneVerificationRequestedAt',
|
||||||
|
'signupPhoneVerificationPurpose',
|
||||||
|
'accountIdentifierType',
|
||||||
|
'accountIdentifier',
|
||||||
|
];
|
||||||
|
|
||||||
|
function createDownstreamResetHarness(stepKey = '') {
|
||||||
|
return new Function(`
|
||||||
|
function getStepExecutionKeyForState() {
|
||||||
|
return ${JSON.stringify(stepKey)};
|
||||||
|
}
|
||||||
|
${extractFunction('getDownstreamStateResets')}
|
||||||
|
return { getDownstreamStateResets };
|
||||||
|
`)();
|
||||||
|
}
|
||||||
|
|
||||||
|
test('downstream restarts after account creation preserve phone signup identity fields', () => {
|
||||||
|
const numericResetHarness = createDownstreamResetHarness('');
|
||||||
|
const stepKeyResetHarnesses = [
|
||||||
|
createDownstreamResetHarness('oauth-login'),
|
||||||
|
createDownstreamResetHarness('fetch-login-code'),
|
||||||
|
createDownstreamResetHarness('confirm-oauth'),
|
||||||
|
];
|
||||||
|
const phoneState = {
|
||||||
|
accountIdentifierType: 'phone',
|
||||||
|
accountIdentifier: '+447780579093',
|
||||||
|
signupPhoneNumber: '+447780579093',
|
||||||
|
signupPhoneActivation: { activationId: 'active', phoneNumber: '+447780579093' },
|
||||||
|
signupPhoneCompletedActivation: { activationId: 'done', phoneNumber: '+447780579093' },
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const step of [5, 6, 7, 8, 9]) {
|
||||||
|
const resets = numericResetHarness.getDownstreamStateResets(step, phoneState);
|
||||||
|
for (const key of PHONE_IDENTITY_STATE_KEYS) {
|
||||||
|
assert.equal(
|
||||||
|
Object.prototype.hasOwnProperty.call(resets, key),
|
||||||
|
false,
|
||||||
|
`step ${step} reset must not clear ${key}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const harness of stepKeyResetHarnesses) {
|
||||||
|
const resets = harness.getDownstreamStateResets(10, phoneState);
|
||||||
|
for (const key of PHONE_IDENTITY_STATE_KEYS) {
|
||||||
|
assert.equal(
|
||||||
|
Object.prototype.hasOwnProperty.call(resets, key),
|
||||||
|
false,
|
||||||
|
`${key} must not be cleared by step-key reset`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function createHarness(options = {}) {
|
function createHarness(options = {}) {
|
||||||
const {
|
const {
|
||||||
startStep = 7,
|
startStep = 7,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ function createRouter(overrides = {}) {
|
|||||||
broadcasts: [],
|
broadcasts: [],
|
||||||
balanceRefreshes: [],
|
balanceRefreshes: [],
|
||||||
emailStates: [],
|
emailStates: [],
|
||||||
|
persistedRegistrationEmails: [],
|
||||||
signupPhoneStates: [],
|
signupPhoneStates: [],
|
||||||
signupPhoneSilentStates: [],
|
signupPhoneSilentStates: [],
|
||||||
finalizePayloads: [],
|
finalizePayloads: [],
|
||||||
@@ -123,6 +124,9 @@ function createRouter(overrides = {}) {
|
|||||||
events.emailStates.push(email);
|
events.emailStates.push(email);
|
||||||
},
|
},
|
||||||
setEmailStateSilently: async () => {},
|
setEmailStateSilently: async () => {},
|
||||||
|
persistRegistrationEmailState: async (state, email, options) => {
|
||||||
|
events.persistedRegistrationEmails.push({ state, email, options });
|
||||||
|
},
|
||||||
setSignupPhoneState: async (phoneNumber) => {
|
setSignupPhoneState: async (phoneNumber) => {
|
||||||
events.signupPhoneStates.push(phoneNumber);
|
events.signupPhoneStates.push(phoneNumber);
|
||||||
},
|
},
|
||||||
@@ -206,14 +210,68 @@ test('message router clears stale signup phone runtime when step 2 resolves emai
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert.deepStrictEqual(events.emailStates, ['user@example.com']);
|
assert.deepStrictEqual(events.emailStates, ['user@example.com']);
|
||||||
assert.deepStrictEqual(events.signupPhoneSilentStates, [null]);
|
assert.deepStrictEqual(events.signupPhoneSilentStates, []);
|
||||||
assert.ok(events.stateUpdates.some((updates) => (
|
assert.deepStrictEqual(events.stateUpdates, []);
|
||||||
updates.accountIdentifierType === 'email'
|
});
|
||||||
&& updates.accountIdentifier === 'user@example.com'
|
|
||||||
&& updates.signupPhoneNumber === ''
|
test('message router preserves phone signup identity when step payload only reports registration email', async () => {
|
||||||
&& updates.signupPhoneActivation === null
|
const { router, events } = createRouter({
|
||||||
&& updates.signupPhoneCompletedActivation === null
|
state: {
|
||||||
)));
|
stepStatuses: { 3: 'pending' },
|
||||||
|
accountIdentifierType: 'phone',
|
||||||
|
accountIdentifier: '+66959916439',
|
||||||
|
signupPhoneNumber: '+66959916439',
|
||||||
|
signupPhoneActivation: { activationId: 'active', phoneNumber: '+66959916439' },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await router.handleStepData(3, {
|
||||||
|
email: 'bound@example.com',
|
||||||
|
signupVerificationRequestedAt: 123456,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepStrictEqual(events.emailStates, []);
|
||||||
|
assert.equal(events.persistedRegistrationEmails.length, 1);
|
||||||
|
assert.equal(events.persistedRegistrationEmails[0].email, 'bound@example.com');
|
||||||
|
assert.deepStrictEqual(events.persistedRegistrationEmails[0].options, {
|
||||||
|
source: 'step_identity',
|
||||||
|
preserveAccountIdentity: true,
|
||||||
|
});
|
||||||
|
assert.equal(events.persistedRegistrationEmails[0].state.signupPhoneNumber, '+66959916439');
|
||||||
|
assert.equal(events.persistedRegistrationEmails[0].state.accountIdentifierType, 'phone');
|
||||||
|
assert.equal(events.signupPhoneSilentStates.length, 0);
|
||||||
|
assert.ok(!events.stateUpdates.some((updates) => updates.signupPhoneNumber === ''));
|
||||||
|
assert.ok(events.stateUpdates.some((updates) => updates.signupVerificationRequestedAt === 123456));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('message router persists phone signup identity from step 7 completion payload', async () => {
|
||||||
|
const completedActivation = {
|
||||||
|
activationId: 'signup-done',
|
||||||
|
phoneNumber: '+5511917097811',
|
||||||
|
};
|
||||||
|
const { router, events } = createRouter({
|
||||||
|
state: { stepStatuses: { 7: 'completed', 8: 'pending' } },
|
||||||
|
getStepDefinitionForState: (step) => (
|
||||||
|
step === 7
|
||||||
|
? { key: 'oauth-login' }
|
||||||
|
: (step === 8 ? { key: 'fetch-login-code' } : null)
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
await router.handleStepData(7, {
|
||||||
|
loginVerificationRequestedAt: 123456,
|
||||||
|
accountIdentifierType: 'phone',
|
||||||
|
accountIdentifier: '+5511917097811',
|
||||||
|
signupPhoneNumber: '+5511917097811',
|
||||||
|
signupPhoneActivation: null,
|
||||||
|
signupPhoneCompletedActivation: completedActivation,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepStrictEqual(events.signupPhoneSilentStates, ['+5511917097811']);
|
||||||
|
assert.ok(events.stateUpdates.some((updates) => updates.signupPhoneActivation === null));
|
||||||
|
assert.ok(events.stateUpdates.some((updates) => updates.signupPhoneCompletedActivation === completedActivation));
|
||||||
|
assert.ok(events.stateUpdates.some((updates) => updates.loginVerificationRequestedAt === 123456));
|
||||||
|
assert.deepStrictEqual(events.emailStates, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('message router does not overwrite a completed step 3 when step 2 is replayed', async () => {
|
test('message router does not overwrite a completed step 3 when step 2 is replayed', async () => {
|
||||||
|
|||||||
@@ -463,12 +463,15 @@ test('step 7 forwards phone login identity payload when account identifier is ph
|
|||||||
const api = new Function('self', `${source}; return self.MultiPageBackgroundStep7;`)(globalScope);
|
const api = new Function('self', `${source}; return self.MultiPageBackgroundStep7;`)(globalScope);
|
||||||
|
|
||||||
const events = {
|
const events = {
|
||||||
|
completions: [],
|
||||||
payloads: [],
|
payloads: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const executor = api.createStep7Executor({
|
const executor = api.createStep7Executor({
|
||||||
addLog: async () => {},
|
addLog: async () => {},
|
||||||
completeStepFromBackground: async () => {},
|
completeStepFromBackground: async (step, payload) => {
|
||||||
|
events.completions.push({ step, payload });
|
||||||
|
},
|
||||||
getErrorMessage: (error) => error?.message || String(error || ''),
|
getErrorMessage: (error) => error?.message || String(error || ''),
|
||||||
getLoginAuthStateLabel: (state) => state || 'unknown',
|
getLoginAuthStateLabel: (state) => state || 'unknown',
|
||||||
getState: async () => ({
|
getState: async () => ({
|
||||||
@@ -524,6 +527,24 @@ test('step 7 forwards phone login identity payload when account identifier is ph
|
|||||||
visibleStep: 7,
|
visibleStep: 7,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
assert.deepStrictEqual(events.completions, [
|
||||||
|
{
|
||||||
|
step: 7,
|
||||||
|
payload: {
|
||||||
|
loginVerificationRequestedAt: 123456,
|
||||||
|
accountIdentifierType: 'phone',
|
||||||
|
accountIdentifier: '66959916439',
|
||||||
|
signupPhoneNumber: '66959916439',
|
||||||
|
signupPhoneCompletedActivation: {
|
||||||
|
activationId: 'signup-done',
|
||||||
|
phoneNumber: '66959916439',
|
||||||
|
countryId: 52,
|
||||||
|
countryLabel: 'Thailand',
|
||||||
|
},
|
||||||
|
signupPhoneActivation: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('step 7 keeps Plus email login even when phone sms runtime exists', async () => {
|
test('step 7 keeps Plus email login even when phone sms runtime exists', async () => {
|
||||||
@@ -592,7 +613,7 @@ test('step 7 keeps phone login after step 8 stores an unbound email for phone si
|
|||||||
const phoneSignupState = {
|
const phoneSignupState = {
|
||||||
phoneVerificationEnabled: true,
|
phoneVerificationEnabled: true,
|
||||||
signupMethod: 'phone',
|
signupMethod: 'phone',
|
||||||
resolvedSignupMethod: 'phone',
|
resolvedSignupMethod: 'email',
|
||||||
email: 'bound.step8@example.com',
|
email: 'bound.step8@example.com',
|
||||||
accountIdentifierType: 'email',
|
accountIdentifierType: 'email',
|
||||||
accountIdentifier: 'bound.step8@example.com',
|
accountIdentifier: 'bound.step8@example.com',
|
||||||
@@ -737,6 +758,11 @@ test('step 7 can start from a manually filled signup phone without completed ste
|
|||||||
step: 7,
|
step: 7,
|
||||||
payload: {
|
payload: {
|
||||||
loginVerificationRequestedAt: 987654,
|
loginVerificationRequestedAt: 987654,
|
||||||
|
accountIdentifierType: 'phone',
|
||||||
|
accountIdentifier: '+447780579093',
|
||||||
|
signupPhoneNumber: '+447780579093',
|
||||||
|
signupPhoneCompletedActivation: null,
|
||||||
|
signupPhoneActivation: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ test('step 8 submits add-email before polling the email verification code', asyn
|
|||||||
resolvedStates: [],
|
resolvedStates: [],
|
||||||
setStates: [],
|
setStates: [],
|
||||||
mailStates: [],
|
mailStates: [],
|
||||||
|
persistCalls: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const executor = api.createStep8Executor({
|
const executor = api.createStep8Executor({
|
||||||
@@ -300,6 +301,9 @@ test('step 8 submits add-email before polling the email verification code', asyn
|
|||||||
isTabAlive: async () => true,
|
isTabAlive: async () => true,
|
||||||
isVerificationMailPollingError: () => false,
|
isVerificationMailPollingError: () => false,
|
||||||
LUCKMAIL_PROVIDER: 'luckmail-api',
|
LUCKMAIL_PROVIDER: 'luckmail-api',
|
||||||
|
persistRegistrationEmailState: async (state, email, options) => {
|
||||||
|
calls.persistCalls.push({ state, email, options });
|
||||||
|
},
|
||||||
resolveSignupEmailForFlow: async (state, options = {}) => {
|
resolveSignupEmailForFlow: async (state, options = {}) => {
|
||||||
calls.resolvedStates.push(state);
|
calls.resolvedStates.push(state);
|
||||||
calls.resolveOptions = options;
|
calls.resolveOptions = options;
|
||||||
@@ -338,14 +342,14 @@ test('step 8 submits add-email before polling the email verification code', asyn
|
|||||||
assert.equal(calls.contentMessages.length, 1);
|
assert.equal(calls.contentMessages.length, 1);
|
||||||
assert.equal(calls.resolvedStates.length, 1);
|
assert.equal(calls.resolvedStates.length, 1);
|
||||||
assert.equal(calls.resolveOptions.preserveAccountIdentity, true);
|
assert.equal(calls.resolveOptions.preserveAccountIdentity, true);
|
||||||
|
assert.equal(calls.persistCalls.length, 1);
|
||||||
|
assert.equal(calls.persistCalls[0].email, 'new.user@example.com');
|
||||||
|
assert.equal(calls.persistCalls[0].options.preserveAccountIdentity, true);
|
||||||
|
assert.equal(calls.persistCalls[0].options.source, 'step8_add_email');
|
||||||
assert.equal(calls.mailStates[0].email, 'new.user@example.com');
|
assert.equal(calls.mailStates[0].email, 'new.user@example.com');
|
||||||
assert.equal(calls.resolvedVerification.state.email, 'new.user@example.com');
|
assert.equal(calls.resolvedVerification.state.email, 'new.user@example.com');
|
||||||
assert.equal(calls.resolvedVerification.options.targetEmail, 'new.user@example.com');
|
assert.equal(calls.resolvedVerification.options.targetEmail, 'new.user@example.com');
|
||||||
assert.deepStrictEqual(calls.setStates, [
|
assert.deepStrictEqual(calls.setStates, [
|
||||||
{
|
|
||||||
email: 'new.user@example.com',
|
|
||||||
step8VerificationTargetEmail: 'new.user@example.com',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
step8VerificationTargetEmail: 'new.user@example.com',
|
step8VerificationTargetEmail: 'new.user@example.com',
|
||||||
},
|
},
|
||||||
@@ -407,6 +411,14 @@ test('step 8 reruns step 7 with preserved phone login identity after add-email v
|
|||||||
isTabAlive: async () => true,
|
isTabAlive: async () => true,
|
||||||
isVerificationMailPollingError: () => false,
|
isVerificationMailPollingError: () => false,
|
||||||
LUCKMAIL_PROVIDER: 'luckmail-api',
|
LUCKMAIL_PROVIDER: 'luckmail-api',
|
||||||
|
persistRegistrationEmailState: async (_state, email, options) => {
|
||||||
|
assert.equal(email, 'new.user@example.com');
|
||||||
|
assert.equal(options.preserveAccountIdentity, true);
|
||||||
|
runtimeState = {
|
||||||
|
...runtimeState,
|
||||||
|
email,
|
||||||
|
};
|
||||||
|
},
|
||||||
resolveSignupEmailForFlow: async (_state, options = {}) => {
|
resolveSignupEmailForFlow: async (_state, options = {}) => {
|
||||||
assert.equal(options.preserveAccountIdentity, true);
|
assert.equal(options.preserveAccountIdentity, true);
|
||||||
runtimeState = {
|
runtimeState = {
|
||||||
@@ -460,6 +472,106 @@ test('step 8 reruns step 7 with preserved phone login identity after add-email v
|
|||||||
assert.equal(calls.rerunStates[0].signupPhoneNumber, '+447780579093');
|
assert.equal(calls.rerunStates[0].signupPhoneNumber, '+447780579093');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('step 8 add-email rereads persisted phone identity before rerunning step 7', async () => {
|
||||||
|
const calls = {
|
||||||
|
resolveCalls: 0,
|
||||||
|
rerunStates: [],
|
||||||
|
};
|
||||||
|
let runtimeState = {
|
||||||
|
visibleStep: 8,
|
||||||
|
email: '',
|
||||||
|
password: 'secret',
|
||||||
|
oauthUrl: 'https://oauth.example/latest',
|
||||||
|
accountIdentifierType: 'email',
|
||||||
|
accountIdentifier: 'stale@example.com',
|
||||||
|
signupMethod: 'phone',
|
||||||
|
resolvedSignupMethod: 'phone',
|
||||||
|
phoneVerificationEnabled: true,
|
||||||
|
signupPhoneNumber: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
const executor = api.createStep8Executor({
|
||||||
|
addLog: async () => {},
|
||||||
|
chrome: {
|
||||||
|
tabs: {
|
||||||
|
update: async () => {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
|
||||||
|
confirmCustomVerificationStepBypass: async () => {},
|
||||||
|
ensureStep8VerificationPageReady: async () => ({ state: 'add_email_page', url: 'https://auth.openai.com/add-email' }),
|
||||||
|
getOAuthFlowRemainingMs: async () => 8000,
|
||||||
|
getOAuthFlowStepTimeoutMs: async (defaultTimeoutMs) => Math.min(defaultTimeoutMs, 8000),
|
||||||
|
getMailConfig: () => ({
|
||||||
|
provider: 'qq',
|
||||||
|
label: 'QQ 邮箱',
|
||||||
|
source: 'mail-qq',
|
||||||
|
url: 'https://mail.qq.com',
|
||||||
|
navigateOnReuse: false,
|
||||||
|
}),
|
||||||
|
getState: async () => ({ ...runtimeState }),
|
||||||
|
getTabId: async (sourceName) => (sourceName === 'signup-page' ? 1 : 2),
|
||||||
|
HOTMAIL_PROVIDER: 'hotmail-api',
|
||||||
|
isTabAlive: async () => true,
|
||||||
|
isVerificationMailPollingError: () => false,
|
||||||
|
LUCKMAIL_PROVIDER: 'luckmail-api',
|
||||||
|
persistRegistrationEmailState: async (_state, email, options) => {
|
||||||
|
assert.equal(email, 'new.user@example.com');
|
||||||
|
assert.equal(options.preserveAccountIdentity, true);
|
||||||
|
runtimeState = {
|
||||||
|
...runtimeState,
|
||||||
|
email,
|
||||||
|
accountIdentifierType: 'phone',
|
||||||
|
accountIdentifier: '+447780579093',
|
||||||
|
signupPhoneNumber: '+447780579093',
|
||||||
|
signupPhoneCompletedActivation: {
|
||||||
|
activationId: 'signup-done',
|
||||||
|
phoneNumber: '+447780579093',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
resolveSignupEmailForFlow: async (_state, options = {}) => {
|
||||||
|
assert.equal(options.preserveAccountIdentity, true);
|
||||||
|
return 'new.user@example.com';
|
||||||
|
},
|
||||||
|
resolveVerificationStep: async (_step, state) => {
|
||||||
|
calls.resolveCalls += 1;
|
||||||
|
assert.equal(state.accountIdentifierType, 'phone');
|
||||||
|
assert.equal(state.signupPhoneNumber, '+447780579093');
|
||||||
|
throw new Error('STEP8_RESTART_STEP7::step 8 verification page fell into login timeout retry state');
|
||||||
|
},
|
||||||
|
rerunStep7ForStep8Recovery: async () => {
|
||||||
|
calls.rerunStates.push({ ...runtimeState });
|
||||||
|
},
|
||||||
|
reuseOrCreateTab: async () => {},
|
||||||
|
sendToContentScriptResilient: async () => ({
|
||||||
|
submitted: true,
|
||||||
|
displayedEmail: 'new.user@example.com',
|
||||||
|
url: 'https://auth.openai.com/email-verification',
|
||||||
|
}),
|
||||||
|
setState: async (payload) => {
|
||||||
|
runtimeState = {
|
||||||
|
...runtimeState,
|
||||||
|
...payload,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
shouldUseCustomRegistrationEmail: () => false,
|
||||||
|
STANDARD_MAIL_VERIFICATION_RESEND_INTERVAL_MS: 25000,
|
||||||
|
STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS: 2,
|
||||||
|
throwIfStopped: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
await assert.rejects(
|
||||||
|
() => executor.executeStep8({ ...runtimeState }),
|
||||||
|
/STEP8_RESTART_STEP7::/
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(calls.resolveCalls, 2);
|
||||||
|
assert.equal(calls.rerunStates.length, 1);
|
||||||
|
assert.equal(calls.rerunStates[0].accountIdentifierType, 'phone');
|
||||||
|
assert.equal(calls.rerunStates[0].signupPhoneNumber, '+447780579093');
|
||||||
|
});
|
||||||
|
|
||||||
test('step 8 email_in_use recovery preserves the previous registration baseline', async () => {
|
test('step 8 email_in_use recovery preserves the previous registration baseline', async () => {
|
||||||
const calls = {
|
const calls = {
|
||||||
contentCalls: 0,
|
contentCalls: 0,
|
||||||
@@ -944,7 +1056,7 @@ test('step 8 completes when polling fails but recovery probe shows oauth consent
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('step 8 uses a fixed 10-minute lookback window and disables resend interval for 2925 mailbox polling', async () => {
|
test('step 8 uses a fixed 10-minute lookback window and plans 2925 polling as 2/3/15', async () => {
|
||||||
let capturedOptions = null;
|
let capturedOptions = null;
|
||||||
let ensureCalls = 0;
|
let ensureCalls = 0;
|
||||||
let ensureOptions = null;
|
let ensureOptions = null;
|
||||||
@@ -1036,6 +1148,9 @@ test('step 8 uses a fixed 10-minute lookback window and disables resend interval
|
|||||||
]);
|
]);
|
||||||
assert.equal(capturedOptions.filterAfterTimestamp, 300000);
|
assert.equal(capturedOptions.filterAfterTimestamp, 300000);
|
||||||
assert.equal(capturedOptions.resendIntervalMs, 0);
|
assert.equal(capturedOptions.resendIntervalMs, 0);
|
||||||
|
assert.equal(capturedOptions.maxResendRequests, 2);
|
||||||
|
assert.equal(capturedOptions.initialPollMaxAttempts, 5);
|
||||||
|
assert.deepStrictEqual(capturedOptions.pollAttemptPlan, [2, 3, 15]);
|
||||||
assert.equal(capturedOptions.targetEmail, '');
|
assert.equal(capturedOptions.targetEmail, '');
|
||||||
assert.equal(capturedOptions.beforeSubmit, undefined);
|
assert.equal(capturedOptions.beforeSubmit, undefined);
|
||||||
assert.equal(typeof capturedOptions.getRemainingTimeMs, 'function');
|
assert.equal(typeof capturedOptions.getRemainingTimeMs, 'function');
|
||||||
|
|||||||
@@ -179,6 +179,10 @@ function extractVerificationCode(text) {
|
|||||||
|
|
||||||
async function sleep() {}
|
async function sleep() {}
|
||||||
async function sleepRandom() {}
|
async function sleepRandom() {}
|
||||||
|
async function waitForMailboxReady() {
|
||||||
|
const items = findMailItems();
|
||||||
|
return { ready: true, items, empty: items.length === 0 };
|
||||||
|
}
|
||||||
|
|
||||||
async function returnToInbox() {
|
async function returnToInbox() {
|
||||||
clickOrder.push('inbox');
|
clickOrder.push('inbox');
|
||||||
@@ -277,6 +281,10 @@ function extractVerificationCode(text) {
|
|||||||
|
|
||||||
async function sleep() {}
|
async function sleep() {}
|
||||||
async function sleepRandom() {}
|
async function sleepRandom() {}
|
||||||
|
async function waitForMailboxReady() {
|
||||||
|
const items = findMailItems();
|
||||||
|
return { ready: true, items, empty: items.length === 0 };
|
||||||
|
}
|
||||||
async function returnToInbox() {
|
async function returnToInbox() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -371,6 +379,10 @@ function extractVerificationCode(text) {
|
|||||||
|
|
||||||
async function sleep() {}
|
async function sleep() {}
|
||||||
async function sleepRandom() {}
|
async function sleepRandom() {}
|
||||||
|
async function waitForMailboxReady() {
|
||||||
|
const items = findMailItems();
|
||||||
|
return { ready: true, items, empty: items.length === 0 };
|
||||||
|
}
|
||||||
async function returnToInbox() {
|
async function returnToInbox() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -488,6 +500,10 @@ function extractVerificationCode(text) {
|
|||||||
|
|
||||||
async function sleep() {}
|
async function sleep() {}
|
||||||
async function sleepRandom() {}
|
async function sleepRandom() {}
|
||||||
|
async function waitForMailboxReady() {
|
||||||
|
const items = findMailItems();
|
||||||
|
return { ready: true, items, empty: items.length === 0 };
|
||||||
|
}
|
||||||
async function returnToInbox() {
|
async function returnToInbox() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -691,6 +707,10 @@ function simulateClick(node) {
|
|||||||
|
|
||||||
async function sleep() {}
|
async function sleep() {}
|
||||||
async function sleepRandom() {}
|
async function sleepRandom() {}
|
||||||
|
async function waitForMailboxReady() {
|
||||||
|
const items = findMailItems();
|
||||||
|
return { ready: items.length > 0, items, empty: items.length === 0 };
|
||||||
|
}
|
||||||
|
|
||||||
${bundle}
|
${bundle}
|
||||||
|
|
||||||
@@ -764,6 +784,10 @@ function simulateClick(node) {
|
|||||||
|
|
||||||
async function sleep() {}
|
async function sleep() {}
|
||||||
async function sleepRandom() {}
|
async function sleepRandom() {}
|
||||||
|
async function waitForMailboxReady() {
|
||||||
|
const items = findMailItems();
|
||||||
|
return { ready: items.length > 0, items, empty: items.length === 0 };
|
||||||
|
}
|
||||||
const console = { warn() {} };
|
const console = { warn() {} };
|
||||||
const MAIL2925_PREFIX = '[MultiPage:mail-2925]';
|
const MAIL2925_PREFIX = '[MultiPage:mail-2925]';
|
||||||
|
|
||||||
|
|||||||
@@ -872,6 +872,153 @@ test('verification flow keeps 2925 mailbox polling at 15 refresh attempts even w
|
|||||||
assert.ok(pollCall.options.timeoutMs >= 250000);
|
assert.ok(pollCall.options.timeoutMs >= 250000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('verification flow can run a 2/3/15 2925 resend polling plan', async () => {
|
||||||
|
const events = [];
|
||||||
|
const pollMaxAttempts = [];
|
||||||
|
let pollCalls = 0;
|
||||||
|
|
||||||
|
const helpers = api.createVerificationFlowHelpers({
|
||||||
|
addLog: async () => {},
|
||||||
|
chrome: { tabs: { update: async () => {} } },
|
||||||
|
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
|
||||||
|
completeStepFromBackground: async () => {},
|
||||||
|
confirmCustomVerificationStepBypassRequest: async () => ({ confirmed: true }),
|
||||||
|
getHotmailVerificationPollConfig: () => ({}),
|
||||||
|
getHotmailVerificationRequestTimestamp: () => 0,
|
||||||
|
getState: async () => ({}),
|
||||||
|
getTabId: async () => 1,
|
||||||
|
HOTMAIL_PROVIDER: 'hotmail-api',
|
||||||
|
isStopError: () => false,
|
||||||
|
LUCKMAIL_PROVIDER: 'luckmail-api',
|
||||||
|
MAIL_2925_VERIFICATION_INTERVAL_MS: 15000,
|
||||||
|
MAIL_2925_VERIFICATION_MAX_ATTEMPTS: 15,
|
||||||
|
pollCloudflareTempEmailVerificationCode: async () => ({}),
|
||||||
|
pollHotmailVerificationCode: async () => ({}),
|
||||||
|
pollLuckmailVerificationCode: async () => ({}),
|
||||||
|
sendToContentScript: async (_source, message) => {
|
||||||
|
if (message.type === 'RESEND_VERIFICATION_CODE') {
|
||||||
|
events.push('resend');
|
||||||
|
return { resent: true };
|
||||||
|
}
|
||||||
|
if (message.type === 'FILL_CODE') {
|
||||||
|
events.push('fill');
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
sendToContentScriptResilient: async () => ({}),
|
||||||
|
sendToMailContentScriptResilient: async (_mail, message) => {
|
||||||
|
events.push('poll');
|
||||||
|
pollMaxAttempts.push(message.payload.maxAttempts);
|
||||||
|
pollCalls += 1;
|
||||||
|
return pollCalls <= 2
|
||||||
|
? { error: '步骤 8:邮箱轮询结束,但未获取到验证码。' }
|
||||||
|
: { code: '654321', emailTimestamp: 123 };
|
||||||
|
},
|
||||||
|
setState: async () => {},
|
||||||
|
setStepStatus: async () => {},
|
||||||
|
sleepWithStop: async () => {},
|
||||||
|
throwIfStopped: () => {},
|
||||||
|
VERIFICATION_POLL_MAX_ROUNDS: 5,
|
||||||
|
});
|
||||||
|
|
||||||
|
await helpers.resolveVerificationStep(
|
||||||
|
8,
|
||||||
|
{
|
||||||
|
email: 'user@example.com',
|
||||||
|
mailProvider: '2925',
|
||||||
|
lastLoginCode: null,
|
||||||
|
},
|
||||||
|
{ provider: '2925', label: '2925 邮箱' },
|
||||||
|
{
|
||||||
|
maxResendRequests: 2,
|
||||||
|
initialPollMaxAttempts: 5,
|
||||||
|
pollAttemptPlan: [2, 3, 15],
|
||||||
|
requestFreshCodeFirst: false,
|
||||||
|
filterAfterTimestamp: 123,
|
||||||
|
resendIntervalMs: 0,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepStrictEqual(events.slice(0, 5), ['poll', 'resend', 'poll', 'resend', 'poll']);
|
||||||
|
assert.deepStrictEqual(pollMaxAttempts.slice(0, 3), [2, 3, 15]);
|
||||||
|
assert.equal(events.filter((event) => event === 'resend').length, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('verification flow uses full 2925 polling window after a rejected login code', async () => {
|
||||||
|
const pollMaxAttempts = [];
|
||||||
|
const submittedCodes = [];
|
||||||
|
let pollCalls = 0;
|
||||||
|
|
||||||
|
const helpers = api.createVerificationFlowHelpers({
|
||||||
|
addLog: async () => {},
|
||||||
|
chrome: { tabs: { update: async () => {} } },
|
||||||
|
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
|
||||||
|
completeStepFromBackground: async () => {},
|
||||||
|
confirmCustomVerificationStepBypassRequest: async () => ({ confirmed: true }),
|
||||||
|
getHotmailVerificationPollConfig: () => ({}),
|
||||||
|
getHotmailVerificationRequestTimestamp: () => 0,
|
||||||
|
getState: async () => ({}),
|
||||||
|
getTabId: async () => 1,
|
||||||
|
HOTMAIL_PROVIDER: 'hotmail-api',
|
||||||
|
isStopError: () => false,
|
||||||
|
LUCKMAIL_PROVIDER: 'luckmail-api',
|
||||||
|
MAIL_2925_VERIFICATION_INTERVAL_MS: 15000,
|
||||||
|
MAIL_2925_VERIFICATION_MAX_ATTEMPTS: 15,
|
||||||
|
pollCloudflareTempEmailVerificationCode: async () => ({}),
|
||||||
|
pollHotmailVerificationCode: async () => ({}),
|
||||||
|
pollLuckmailVerificationCode: async () => ({}),
|
||||||
|
sendToContentScript: async (_source, message) => {
|
||||||
|
if (message.type === 'RESEND_VERIFICATION_CODE') {
|
||||||
|
return { resent: true };
|
||||||
|
}
|
||||||
|
if (message.type === 'FILL_CODE') {
|
||||||
|
submittedCodes.push(message.payload.code);
|
||||||
|
return message.payload.code === '111111'
|
||||||
|
? { invalidCode: true, errorText: 'Incorrect code' }
|
||||||
|
: { success: true };
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
sendToContentScriptResilient: async () => ({}),
|
||||||
|
sendToMailContentScriptResilient: async (_mail, message) => {
|
||||||
|
if (message.type !== 'POLL_EMAIL') {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
pollCalls += 1;
|
||||||
|
pollMaxAttempts.push(message.payload.maxAttempts);
|
||||||
|
return pollCalls === 1
|
||||||
|
? { code: '111111', emailTimestamp: 1 }
|
||||||
|
: { code: '222222', emailTimestamp: 2 };
|
||||||
|
},
|
||||||
|
setState: async () => {},
|
||||||
|
setStepStatus: async () => {},
|
||||||
|
sleepWithStop: async () => {},
|
||||||
|
throwIfStopped: () => {},
|
||||||
|
VERIFICATION_POLL_MAX_ROUNDS: 5,
|
||||||
|
});
|
||||||
|
|
||||||
|
await helpers.resolveVerificationStep(
|
||||||
|
8,
|
||||||
|
{
|
||||||
|
email: 'user@example.com',
|
||||||
|
mailProvider: '2925',
|
||||||
|
lastLoginCode: null,
|
||||||
|
},
|
||||||
|
{ provider: '2925', label: '2925 邮箱' },
|
||||||
|
{
|
||||||
|
maxResendRequests: 0,
|
||||||
|
initialPollMaxAttempts: 5,
|
||||||
|
pollAttemptPlan: [2, 3, 15],
|
||||||
|
requestFreshCodeFirst: false,
|
||||||
|
filterAfterTimestamp: 123,
|
||||||
|
resendIntervalMs: 0,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepStrictEqual(pollMaxAttempts, [2, 15]);
|
||||||
|
assert.deepStrictEqual(submittedCodes, ['111111', '222222']);
|
||||||
|
});
|
||||||
|
|
||||||
test('verification flow keeps Hotmail request timestamp filtering on the first poll', async () => {
|
test('verification flow keeps Hotmail request timestamp filtering on the first poll', async () => {
|
||||||
const pollPayloads = [];
|
const pollPayloads = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user