修复接码邮箱绑定与验证码提交超时问题

This commit is contained in:
QLHazyCoder
2026-05-16 05:40:04 +08:00
parent 31046c1116
commit 8a11b91c5a
13 changed files with 394 additions and 34 deletions
@@ -50,6 +50,7 @@ function extractFunction(name) {
test('cloudflare temp email settings normalize and expose the random-subdomain toggle', () => {
const bundle = [
extractFunction('normalizeCloudflareTempEmailLookupMode'),
extractFunction('normalizeCloudflareTempEmailReceiveMailbox'),
extractFunction('getCloudflareTempEmailConfig'),
extractFunction('normalizePersistentSettingValue'),
@@ -58,6 +59,9 @@ test('cloudflare temp email settings normalize and expose the random-subdomain t
const api = new Function(`
const DEFAULT_VERIFICATION_RESEND_COUNT = 4;
const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_RECEIVE_MAILBOX = 'receive-mailbox';
const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_REGISTRATION_EMAIL = 'registration-email';
const DEFAULT_CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE = CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_RECEIVE_MAILBOX;
const PERSISTED_SETTING_DEFAULTS = {
panelMode: 'cpa',
autoStepDelaySeconds: null,
@@ -67,6 +71,7 @@ const PERSISTED_SETTING_DEFAULTS = {
emailGenerator: 'duck',
autoDeleteUsedIcloudAlias: false,
accountRunHistoryTextEnabled: false,
cloudflareTempEmailLookupMode: 'receive-mailbox',
cloudflareTempEmailUseRandomSubdomain: false,
cloudflareTempEmailDomain: '',
cloudflareTempEmailDomains: [],
@@ -116,12 +121,16 @@ return {
`)();
assert.equal(api.normalizePersistentSettingValue('cloudflareTempEmailUseRandomSubdomain', 1), true);
assert.equal(api.normalizePersistentSettingValue('cloudflareTempEmailLookupMode', 'registration-email'), 'registration-email');
assert.equal(api.normalizePersistentSettingValue('cloudflareTempEmailLookupMode', 'bad'), 'receive-mailbox');
const payload = api.buildPersistentSettingsPayload({
cloudflareTempEmailLookupMode: 'registration-email',
cloudflareTempEmailUseRandomSubdomain: true,
cloudflareTempEmailDomain: 'mail.example.com',
cloudflareTempEmailDomains: ['mail.example.com', 'alt.example.com'],
});
assert.equal(payload.cloudflareTempEmailLookupMode, 'registration-email');
assert.equal(payload.cloudflareTempEmailUseRandomSubdomain, true);
assert.equal(payload.cloudflareTempEmailDomain, 'mail.example.com');
assert.deepEqual(payload.cloudflareTempEmailDomains, ['mail.example.com', 'alt.example.com']);
@@ -130,6 +139,7 @@ return {
cloudflareTempEmailBaseUrl: 'https://temp.example.com',
cloudflareTempEmailAdminAuth: 'admin-secret',
cloudflareTempEmailCustomAuth: 'custom-secret',
cloudflareTempEmailLookupMode: 'registration-email',
cloudflareTempEmailReceiveMailbox: 'Forward@Example.com',
cloudflareTempEmailUseRandomSubdomain: true,
cloudflareTempEmailDomain: 'mail.example.com',
@@ -139,6 +149,7 @@ return {
baseUrl: 'https://temp.example.com',
adminAuth: 'admin-secret',
customAuth: 'custom-secret',
lookupMode: 'registration-email',
receiveMailbox: 'forward@example.com',
useRandomSubdomain: true,
domain: 'mail.example.com',
+71 -5
View File
@@ -68,6 +68,7 @@ function createProviderApi(options = {}) {
const bundle = [
extractFunction('isStopError'),
extractFunction('throwIfStopped'),
extractFunction('normalizeCloudflareTempEmailLookupMode'),
extractFunction('normalizeCloudflareTempEmailReceiveMailbox'),
extractFunction('resolveCloudflareTempEmailPollTargetEmail'),
extractFunction('summarizeCloudflareTempEmailMessagesForLog'),
@@ -78,6 +79,9 @@ function createProviderApi(options = {}) {
let stopRequested = false;
const STOP_ERROR_MESSAGE = '流程已被用户停止。';
const CLOUDFLARE_TEMP_EMAIL_DEFAULT_PAGE_SIZE = 20;
const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_RECEIVE_MAILBOX = 'receive-mailbox';
const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_REGISTRATION_EMAIL = 'registration-email';
const DEFAULT_CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE = CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_RECEIVE_MAILBOX;
const logs = [];
const listCalls = [];
const messages = options.messages;
@@ -89,13 +93,29 @@ async function addLog(message, level) {
}
async function sleepWithStop() {}
function ensureCloudflareTempEmailConfig() {
return { receiveMailbox: options.receiveMailbox };
return {
receiveMailbox: options.receiveMailbox,
lookupMode: options.lookupMode || 'receive-mailbox',
};
}
async function listCloudflareTempEmailMessages(_state, config) {
listCalls.push(config.address);
listCalls.push({
address: config.address,
lookupMode: config.lookupMode,
originalRecipient: config.originalRecipient,
});
if (config.lookupMode === 'registration-email' && config.originalRecipient) {
const hasOriginalRecipient = messages.some((message) => normalizeCloudflareTempEmailReceiveMailbox(message.originalRecipient));
return {
config: {},
messages: messages.filter((message) => normalizeCloudflareTempEmailReceiveMailbox(message.originalRecipient) === normalizeCloudflareTempEmailReceiveMailbox(config.originalRecipient)),
missingOriginalRecipient: messages.length > 0 && !hasOriginalRecipient,
};
}
return {
config: {},
messages,
missingOriginalRecipient: false,
};
}
function pickVerificationMessageWithTimeFallback(currentMessages) {
@@ -145,7 +165,7 @@ test('pollCloudflareTempEmailVerificationCode returns code even if delete fails'
assert.equal(result.code, '123456');
const state = api.snapshot();
assert.equal(state.logs.some((entry) => entry.message.includes('删除 Cloudflare Temp Email 邮件失败')), true);
assert.deepEqual(state.listCalls, ['user@example.com']);
assert.deepEqual(state.listCalls.map((call) => call.address), ['user@example.com']);
});
test('pollCloudflareTempEmailVerificationCode requires target email or receive mailbox', async () => {
@@ -182,7 +202,7 @@ test('pollCloudflareTempEmailVerificationCode prefers configured receive mailbox
});
assert.equal(result.code, '654321');
assert.deepEqual(api.snapshot().listCalls, ['forward-box@email.20021108.xyz']);
assert.deepEqual(api.snapshot().listCalls.map((call) => call.address), ['forward-box@email.20021108.xyz']);
});
test('pollCloudflareTempEmailVerificationCode ignores stale receive mailbox when the field should be hidden', async () => {
@@ -210,5 +230,51 @@ test('pollCloudflareTempEmailVerificationCode ignores stale receive mailbox when
});
assert.equal(result.code, '246810');
assert.deepEqual(api.snapshot().listCalls, ['generated@email.20021108.xyz']);
assert.deepEqual(api.snapshot().listCalls.map((call) => call.address), ['generated@email.20021108.xyz']);
});
test('pollCloudflareTempEmailVerificationCode filters by original recipient in registration lookup mode', async () => {
const api = createProviderApi({
receiveMailbox: 'forward-box@email.20021108.xyz',
lookupMode: 'registration-email',
messages: [
{
id: 'mail-4',
address: 'forward-box@email.20021108.xyz',
originalRecipient: 'other@duck.com',
receivedDateTime: '2026-04-13T12:20:00.000Z',
subject: 'Other verification code',
from: { emailAddress: { address: 'noreply@tm.openai.com' } },
bodyPreview: 'Your verification code is 111111.',
},
{
id: 'mail-5',
address: 'forward-box@email.20021108.xyz',
originalRecipient: 'duck-forwarded@duck.com',
receivedDateTime: '2026-04-13T12:21:00.000Z',
subject: 'Login verification code',
from: { emailAddress: { address: 'noreply@tm.openai.com' } },
bodyPreview: 'Your verification code is 222222.',
},
],
});
const result = await api.pollCloudflareTempEmailVerificationCode(4, {
email: 'duck-forwarded@duck.com',
mailProvider: 'cloudflare-temp-email',
emailGenerator: 'duck',
cloudflareTempEmailLookupMode: 'registration-email',
cloudflareTempEmailReceiveMailbox: 'forward-box@email.20021108.xyz',
}, {
targetEmail: 'duck-forwarded@duck.com',
maxAttempts: 1,
intervalMs: 1,
});
assert.equal(result.code, '222222');
assert.deepEqual(api.snapshot().listCalls, [{
address: '',
lookupMode: 'registration-email',
originalRecipient: 'duck-forwarded@duck.com',
}]);
});
@@ -55,6 +55,7 @@ test('normalizeCloudflareTempEmailMailApiMessages extracts sender, subject, code
{
id: 'mail-1',
address: 'user@example.com',
original_recipient: 'Forwarded.User@Duck.com',
created_at: '2026-04-13T09:15:00.000Z',
raw: [
'From: OpenAI <noreply@tm.openai.com>',
@@ -70,6 +71,7 @@ test('normalizeCloudflareTempEmailMailApiMessages extracts sender, subject, code
assert.equal(messages.length, 1);
assert.equal(messages[0].id, 'mail-1');
assert.equal(messages[0].address, 'user@example.com');
assert.equal(messages[0].originalRecipient, 'forwarded.user@duck.com');
assert.equal(messages[0].subject, 'OpenAI verification code');
assert.equal(messages[0].from.emailAddress.address, 'OpenAI <noreply@tm.openai.com>');
assert.match(messages[0].bodyPreview, /654321/);
@@ -63,6 +63,10 @@ test('sidepanel html places cloudflare temp email controls in a standalone secti
assert.match(html, /id="cloudflare-temp-email-section"/);
assert.match(html, /id="btn-cloudflare-temp-email-usage-guide"/);
assert.match(html, /id="btn-cloudflare-temp-email-github"/);
assert.match(html, /btn-cloudflare-temp-email-github"[^>]*>部署</);
assert.match(html, /id="row-temp-email-lookup-mode"/);
assert.match(html, /data-temp-email-lookup-mode="receive-mailbox"/);
assert.match(html, /data-temp-email-lookup-mode="registration-email"/);
assert.match(html, /id="row-temp-email-random-subdomain-toggle"/);
assert.match(html, /id="input-temp-email-use-random-subdomain"/);
assert.match(html, /id="btn-temp-email-domain-mode"[^>]*>更新</);
@@ -111,12 +115,12 @@ return {
assert.deepEqual(api.openedUrls, []);
});
test('openCloudflareTempEmailRepositoryPage opens the upstream repository', () => {
test('openCloudflareTempEmailRepositoryPage opens the extension author repository', () => {
const bundle = extractFunction('openCloudflareTempEmailRepositoryPage');
const api = new Function(`
const calls = [];
const CLOUDFLARE_TEMP_EMAIL_REPOSITORY_URL = 'https://github.com/dreamhunter2333/cloudflare_temp_email';
const CLOUDFLARE_TEMP_EMAIL_REPOSITORY_URL = 'https://github.com/QLHazyCoder/cloudflare_temp_email';
function openExternalUrl(url) { calls.push(url); }
${bundle}
return {
@@ -126,7 +130,7 @@ return {
`)();
api.openCloudflareTempEmailRepositoryPage();
assert.deepEqual(api.calls, ['https://github.com/dreamhunter2333/cloudflare_temp_email']);
assert.deepEqual(api.calls, ['https://github.com/QLHazyCoder/cloudflare_temp_email']);
});
test('applyCloudflareTempEmailSettingsState restores the random subdomain toggle and temp domain list', () => {
@@ -141,9 +145,11 @@ const inputTempEmailUseRandomSubdomain = { checked: false };
const calls = {
domainOptions: [],
domainEditMode: [],
lookupModes: [],
};
function renderCloudflareTempEmailDomainOptions(value) { calls.domainOptions.push(value); }
function setCloudflareTempEmailDomainEditMode(editing, options) { calls.domainEditMode.push({ editing, options }); }
function setCloudflareTempEmailLookupMode(value) { calls.lookupModes.push(value); }
${bundle}
return {
applyCloudflareTempEmailSettingsState,
@@ -160,6 +166,7 @@ return {
cloudflareTempEmailBaseUrl: 'https://temp.example.com',
cloudflareTempEmailAdminAuth: 'admin-secret',
cloudflareTempEmailCustomAuth: 'custom-secret',
cloudflareTempEmailLookupMode: 'registration-email',
cloudflareTempEmailReceiveMailbox: 'relay@example.com',
cloudflareTempEmailUseRandomSubdomain: true,
cloudflareTempEmailDomain: 'mail.example.com',
@@ -170,6 +177,7 @@ return {
assert.equal(api.inputTempEmailCustomAuth.value, 'custom-secret');
assert.equal(api.inputTempEmailReceiveMailbox.value, 'relay@example.com');
assert.equal(api.inputTempEmailUseRandomSubdomain.checked, true);
assert.deepEqual(api.calls.lookupModes, ['registration-email']);
assert.deepEqual(api.calls.domainOptions, ['mail.example.com']);
assert.deepEqual(api.calls.domainEditMode, [{ editing: false, options: { clearInput: true } }]);
});
@@ -394,6 +402,7 @@ let cloudflareTempEmailDomainEditMode = false;
const ICLOUD_PROVIDER = 'icloud';
const GMAIL_PROVIDER = 'gmail';
const LUCKMAIL_PROVIDER = 'luckmail-api';
const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_REGISTRATION_EMAIL = 'registration-email';
const rowMail2925Mode = ${JSON.stringify(createRow('none'))};
const rowMail2925PoolSettings = ${JSON.stringify(createRow('none'))};
const rowEmailPrefix = ${JSON.stringify(createRow('none'))};
@@ -404,6 +413,7 @@ const rowCfDomain = ${JSON.stringify(createRow('none'))};
const rowTempEmailBaseUrl = ${JSON.stringify(createRow('none'))};
const rowTempEmailAdminAuth = ${JSON.stringify(createRow('none'))};
const rowTempEmailCustomAuth = ${JSON.stringify(createRow('none'))};
const rowTempEmailLookupMode = ${JSON.stringify(createRow('none'))};
const rowTempEmailReceiveMailbox = ${JSON.stringify(createRow('none'))};
const rowTempEmailRandomSubdomainToggle = ${JSON.stringify(createRow('none'))};
const rowTempEmailDomain = ${JSON.stringify(createRow('none'))};
@@ -435,6 +445,8 @@ function isCustomMailProvider() { return false; }
function isIcloudMailProvider() { return false; }
function usesGeneratedAliasMailProvider() { return false; }
function getSelectedMail2925Mode() { return 'provide'; }
let selectedCloudflareTempEmailLookupMode = 'receive-mailbox';
function getSelectedCloudflareTempEmailLookupMode() { return selectedCloudflareTempEmailLookupMode; }
function getManagedAliasProviderUiCopy() { return null; }
function getCurrentRegistrationEmailUiCopy() {
return {
@@ -462,9 +474,16 @@ ${bundle}
return {
updateMailProviderUI,
cloudflareTempEmailSection,
rowTempEmailLookupMode,
rowTempEmailReceiveMailbox,
rowTempEmailRandomSubdomainToggle,
rowTempEmailDomain,
inputTempEmailUseRandomSubdomain,
selectMailProvider,
selectEmailGenerator,
setLookupMode(value) {
selectedCloudflareTempEmailLookupMode = value;
},
autoHintText,
calls,
};
@@ -475,6 +494,20 @@ return {
assert.equal(api.rowTempEmailRandomSubdomainToggle.style.display, '');
assert.equal(api.rowTempEmailDomain.style.display, '');
api.selectMailProvider.value = 'cloudflare-temp-email';
api.selectEmailGenerator.value = 'duck';
api.setLookupMode('receive-mailbox');
api.updateMailProviderUI();
assert.equal(api.rowTempEmailLookupMode.style.display, '');
assert.equal(api.rowTempEmailReceiveMailbox.style.display, '');
api.setLookupMode('registration-email');
api.updateMailProviderUI();
assert.equal(api.rowTempEmailLookupMode.style.display, '');
assert.equal(api.rowTempEmailReceiveMailbox.style.display, 'none');
api.selectMailProvider.value = '163';
api.selectEmailGenerator.value = 'cloudflare-temp-email';
api.inputTempEmailUseRandomSubdomain.checked = true;
api.updateMailProviderUI();
assert.equal(api.cloudflareTempEmailSection.style.display, '');
+6 -4
View File
@@ -79,6 +79,7 @@ test('step definitions module exposes ordered normal and Plus step metadata', ()
'oauth-login',
'fetch-login-code',
'bind-email',
'fetch-bind-email-code',
'relogin-bound-email',
'fetch-bound-email-login-code',
'post-bound-email-phone-verification',
@@ -87,7 +88,7 @@ test('step definitions module exposes ordered normal and Plus step metadata', ()
]
);
assert.equal(phoneReloginSteps.find((step) => step.key === 'relogin-bound-email')?.title, '绑定邮箱后刷新 OAuth 并登录(邮箱)');
assert.equal(phoneReloginSteps.some((step) => step.key === 'fetch-bind-email-code'), false);
assert.equal(phoneReloginSteps.find((step) => step.key === 'fetch-bind-email-code')?.title, '获取绑定邮箱验证码');
assert.deepStrictEqual(
plusSteps.map((step) => step.key),
@@ -134,11 +135,12 @@ test('step definitions module exposes ordered normal and Plus step metadata', ()
]
);
assert.deepStrictEqual(
plusPhoneReloginSteps.map((step) => step.key).slice(-8),
plusPhoneReloginSteps.map((step) => step.key).slice(-9),
[
'oauth-login',
'fetch-login-code',
'bind-email',
'fetch-bind-email-code',
'relogin-bound-email',
'fetch-bound-email-login-code',
'post-bound-email-phone-verification',
@@ -153,8 +155,8 @@ test('step definitions module exposes ordered normal and Plus step metadata', ()
assert.equal(api.getLastStepId({ plusModeEnabled: true }), 14);
assert.deepStrictEqual(api.getStepIds({ plusModeEnabled: true, signupMethod: 'phone' }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
assert.equal(api.getLastStepId({ plusModeEnabled: true, signupMethod: 'phone' }), 15);
assert.deepStrictEqual(api.getStepIds({ plusModeEnabled: true, signupMethod: 'phone', phoneSignupReloginAfterBindEmailEnabled: true }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]);
assert.equal(api.getLastStepId({ plusModeEnabled: true, signupMethod: 'phone', phoneSignupReloginAfterBindEmailEnabled: true }), 17);
assert.deepStrictEqual(api.getStepIds({ plusModeEnabled: true, signupMethod: 'phone', phoneSignupReloginAfterBindEmailEnabled: true }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]);
assert.equal(api.getLastStepId({ plusModeEnabled: true, signupMethod: 'phone', phoneSignupReloginAfterBindEmailEnabled: true }), 18);
assert.equal(api.hasFlow('openai'), true);
assert.equal(api.hasFlow('site-a'), false);
assert.deepStrictEqual(api.getRegisteredFlowIds(), ['openai']);
+6
View File
@@ -45,6 +45,12 @@ assert.strictEqual(
'普通内容脚本超时也应沿用可重试分支'
);
assert.strictEqual(
api.isRetryableContentScriptTransportError(new Error('认证页 内容脚本 1 秒内未响应,请刷新页面后重试。')),
true,
'中文内容脚本超时也应沿用可重试分支'
);
assert.strictEqual(
api.isRetryableContentScriptTransportError(new Error('按钮不存在')),
false,
+51
View File
@@ -1682,6 +1682,57 @@ test('verification flow does not replay step 8 code submit after transient auth-
assert.deepStrictEqual(resilientMessages, ['GET_LOGIN_AUTH_STATE']);
});
test('verification flow keeps step 8 code submit response timeout above local floor when flow budget is nearly exhausted', async () => {
const directCalls = [];
const helpers = api.createVerificationFlowHelpers({
addLog: async () => {},
chrome: {
tabs: {
update: async () => {},
},
},
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
completeNodeFromBackground: 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, options) => {
directCalls.push({ message, options });
return { success: true };
},
sendToContentScriptResilient: async () => {
throw new Error('step 8 code submit should use the direct channel once');
},
sendToMailContentScriptResilient: async () => ({}),
setState: async () => {},
setStepStatus: async () => {},
sleepWithStop: async () => {},
throwIfStopped: () => {},
VERIFICATION_POLL_MAX_ROUNDS: 5,
});
const result = await helpers.submitVerificationCode(8, '478910', {
completionStep: 11,
getRemainingTimeMs: async () => 1000,
});
assert.deepStrictEqual(result, { success: true });
assert.equal(directCalls.length, 1);
assert.equal(directCalls[0].message.type, 'FILL_CODE');
assert.equal(directCalls[0].options.responseTimeoutMs, 15000);
});
test('verification flow requests a new code immediately after Cloudflare Temp Email code is rejected', async () => {
const events = [];
const pollPayloads = [];