修复自定义邮箱收码模式默认手动
This commit is contained in:
@@ -50,3 +50,108 @@ test('verification flow routes YYDS Mail provider to background poller', async (
|
||||
assert.equal(pollCalls[0].step, 4);
|
||||
assert.equal(pollCalls[0].payload.maxAttempts, 1);
|
||||
});
|
||||
|
||||
test('verification flow routes custom mail provider to local helper poller', async () => {
|
||||
const source = fs.readFileSync('background/verification-flow.js', 'utf8');
|
||||
const globalScope = {};
|
||||
const api = new Function('self', `${source}; return self.MultiPageBackgroundVerificationFlow;`)(globalScope);
|
||||
const pollCalls = [];
|
||||
const helpers = api.createVerificationFlowHelpers({
|
||||
addLog: async () => {},
|
||||
buildVerificationPollPayload: () => ({ maxAttempts: 1, intervalMs: 1, targetEmail: 'target@example.com' }),
|
||||
CUSTOM_MAIL_PROVIDER: 'custom',
|
||||
getState: async () => ({}),
|
||||
getTabId: async () => 1,
|
||||
isStopError: () => false,
|
||||
pollCustomMailVerificationCode: async (step, state, payload) => {
|
||||
pollCalls.push({ step, state, payload });
|
||||
return { ok: true, code: '654321', emailTimestamp: 2, mailId: 'custom-msg-1' };
|
||||
},
|
||||
sendToContentScript: async () => ({}),
|
||||
setState: async () => {},
|
||||
sleepWithStop: async () => {},
|
||||
throwIfStopped: () => {},
|
||||
});
|
||||
|
||||
const result = await helpers.pollFreshVerificationCode(
|
||||
4,
|
||||
{ mailProvider: 'custom', customMailReceiveMode: 'helper', email: 'target@example.com' },
|
||||
{ provider: 'custom', label: '自定义邮箱' },
|
||||
{ disableTimeBudgetCap: true }
|
||||
);
|
||||
|
||||
assert.equal(result.code, '654321');
|
||||
assert.equal(pollCalls.length, 1);
|
||||
assert.equal(pollCalls[0].step, 4);
|
||||
assert.equal(pollCalls[0].payload.targetEmail, 'target@example.com');
|
||||
});
|
||||
|
||||
test('background custom mail poller rejects manual mode before calling local helper', async () => {
|
||||
const source = fs.readFileSync('background.js', 'utf8');
|
||||
function extractFunction(name) {
|
||||
const markers = [`async function ${name}(`, `function ${name}(`];
|
||||
const start = markers
|
||||
.map((marker) => source.indexOf(marker))
|
||||
.find((index) => index >= 0);
|
||||
if (start < 0) {
|
||||
throw new Error(`missing function ${name}`);
|
||||
}
|
||||
|
||||
let parenDepth = 0;
|
||||
let signatureEnded = false;
|
||||
let braceStart = -1;
|
||||
for (let i = start; i < source.length; i += 1) {
|
||||
const ch = source[i];
|
||||
if (ch === '(') parenDepth += 1;
|
||||
if (ch === ')') {
|
||||
parenDepth -= 1;
|
||||
if (parenDepth === 0) signatureEnded = true;
|
||||
}
|
||||
if (ch === '{' && signatureEnded) {
|
||||
braceStart = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
let depth = 0;
|
||||
let end = braceStart;
|
||||
for (; end < source.length; end += 1) {
|
||||
const ch = source[end];
|
||||
if (ch === '{') depth += 1;
|
||||
if (ch === '}') {
|
||||
depth -= 1;
|
||||
if (depth === 0) {
|
||||
end += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return source.slice(start, end);
|
||||
}
|
||||
|
||||
const api = new Function(`
|
||||
const CUSTOM_MAIL_RECEIVE_MODE_HELPER = 'helper';
|
||||
const DEFAULT_CUSTOM_MAIL_RECEIVE_MODE = 'manual';
|
||||
function isCustomMailProvider(stateOrProvider) {
|
||||
const provider = typeof stateOrProvider === 'string' ? stateOrProvider : stateOrProvider?.mailProvider;
|
||||
return provider === 'custom';
|
||||
}
|
||||
${extractFunction('normalizeCustomMailReceiveMode')}
|
||||
${extractFunction('shouldUseCustomMailHelper')}
|
||||
async function addLog() {}
|
||||
async function sleepWithStop() {}
|
||||
function throwIfStopped() {}
|
||||
async function requestCustomMailLocalCode() {
|
||||
throw new Error('should not request helper in manual mode');
|
||||
}
|
||||
${extractFunction('pollCustomMailVerificationCode')}
|
||||
return { pollCustomMailVerificationCode };
|
||||
`)();
|
||||
|
||||
await assert.rejects(
|
||||
() => api.pollCustomMailVerificationCode(4, {
|
||||
mailProvider: 'custom',
|
||||
customMailReceiveMode: 'manual',
|
||||
}, { maxAttempts: 1, intervalMs: 1 }),
|
||||
/手动确认模式/
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user