fix(auth): preserve phone login identity across step8 retries

This commit is contained in:
InkCrow
2026-05-12 16:41:09 +08:00
parent ff38933ce4
commit 1ed128e118
7 changed files with 127 additions and 19 deletions
+1 -1
View File
@@ -592,7 +592,7 @@ test('step 7 keeps phone login after step 8 stores an unbound email for phone si
const phoneSignupState = {
phoneVerificationEnabled: true,
signupMethod: 'phone',
resolvedSignupMethod: 'phone',
resolvedSignupMethod: 'email',
email: 'bound.step8@example.com',
accountIdentifierType: 'email',
accountIdentifier: 'bound.step8@example.com',
+19 -5
View File
@@ -266,6 +266,7 @@ test('step 8 submits add-email before polling the email verification code', asyn
resolvedStates: [],
setStates: [],
mailStates: [],
persistCalls: [],
};
const executor = api.createStep8Executor({
@@ -300,6 +301,9 @@ test('step 8 submits add-email before polling the email verification code', asyn
isTabAlive: async () => true,
isVerificationMailPollingError: () => false,
LUCKMAIL_PROVIDER: 'luckmail-api',
persistRegistrationEmailState: async (state, email, options) => {
calls.persistCalls.push({ state, email, options });
},
resolveSignupEmailForFlow: async (state, options = {}) => {
calls.resolvedStates.push(state);
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.resolvedStates.length, 1);
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.resolvedVerification.state.email, 'new.user@example.com');
assert.equal(calls.resolvedVerification.options.targetEmail, 'new.user@example.com');
assert.deepStrictEqual(calls.setStates, [
{
email: '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,
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,
};
},
resolveSignupEmailForFlow: async (_state, options = {}) => {
assert.equal(options.preserveAccountIdentity, true);
runtimeState = {
@@ -944,7 +956,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 delays 2925 resend until after one full poll', async () => {
let capturedOptions = null;
let ensureCalls = 0;
let ensureOptions = null;
@@ -1036,6 +1048,8 @@ test('step 8 uses a fixed 10-minute lookback window and disables resend interval
]);
assert.equal(capturedOptions.filterAfterTimestamp, 300000);
assert.equal(capturedOptions.resendIntervalMs, 0);
assert.equal(capturedOptions.maxResendRequests, 1);
assert.equal(capturedOptions.initialPollMaxAttempts, 5);
assert.equal(capturedOptions.targetEmail, '');
assert.equal(capturedOptions.beforeSubmit, undefined);
assert.equal(typeof capturedOptions.getRemainingTimeMs, 'function');
+71
View File
@@ -835,6 +835,77 @@ test('verification flow keeps 2925 mailbox polling at 15 refresh attempts even w
assert.ok(pollCall.options.timeoutMs >= 250000);
});
test('verification flow delays 2925 login resend until after the first full mailbox poll fails', 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 === 1
? { 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: 1,
initialPollMaxAttempts: 5,
requestFreshCodeFirst: false,
filterAfterTimestamp: 123,
resendIntervalMs: 0,
}
);
assert.deepStrictEqual(events.slice(0, 3), ['poll', 'resend', 'poll']);
assert.deepStrictEqual(pollMaxAttempts.slice(0, 2), [5, 15]);
assert.equal(events.filter((event) => event === 'resend').length, 1);
});
test('verification flow keeps Hotmail request timestamp filtering on the first poll', async () => {
const pollPayloads = [];