完成80%

This commit is contained in:
2026-07-27 06:50:07 +08:00
parent 8475bbd19a
commit 1eae3bbef4
63 changed files with 13664 additions and 280 deletions
+25 -6
View File
@@ -20,10 +20,12 @@ const createHarnessFactory = (
goRootResult = true,
goRootError = null,
initialSessionToken = "",
captchaRequired = true,
) => new Function(
"goRootResult",
"goRootError",
"initialSessionToken",
"captchaRequired",
`
"use strict";
const calls = [];
@@ -56,10 +58,10 @@ const createHarnessFactory = (
async getCaptchaRequirement(payload) {
calls.push({ type: "require", payload: { ...payload } });
return {
required: true,
required: captchaRequired,
providerCode: "TIANAI",
captchaType: "SLIDER",
sceneCode: payload.sceneCode,
sceneCode: "APP_PASSWORD_LOGIN",
ttlSeconds: 300,
};
},
@@ -76,11 +78,14 @@ const createHarnessFactory = (
return { access_token: "token-sms" };
},
};
const AUTH_TAC_SCENE = Object.freeze({ SMS_LOGIN: "APP_SMS_LOGIN" });
const AUTH_VERIFICATION_OPERATION = Object.freeze({
PASSWORD_LOGIN: "password-login",
SMS_LOGIN: "sms-login",
});
const createTacRenderContext = (value) => ({ ...value });
const isAuthPhone = (value) => /^1[3-9]\\d{9}$/.test(value);
const normalizeCaptchaRequirement = (value, expectedScene) => {
if (value?.sceneCode !== expectedScene || value?.required !== true) {
const normalizeCaptchaRequirement = (value) => {
if (typeof value?.required !== "boolean") {
throw new Error("requirement invalid");
}
return value;
@@ -141,13 +146,14 @@ const createHarnessFactory = (
},
};
`,
)(goRootResult, goRootError, initialSessionToken);
)(goRootResult, goRootError, initialSessionToken, captchaRequired);
const createHarness = (options = {}) =>
createHarnessFactory(
options.goRootResult ?? true,
options.goRootError ?? null,
options.initialSessionToken ?? "",
options.captchaRequired ?? true,
);
const countCalls = (harness, type) =>
@@ -193,6 +199,7 @@ const run = async () => {
assert.deepStrictEqual(success.calls[1].payload, {
phone: "13800138000",
passwordHash: "md5:secret-1",
validToken: "ticket-1",
});
assert.strictEqual(success.calls[2].pageId, "G01");
assert.strictEqual(countCalls(success, "require"), 1);
@@ -200,6 +207,18 @@ const run = async () => {
assert.strictEqual(success.tacVisible.value, false);
assert.strictEqual(success.tacContext.value, null);
const noCaptcha = createHarness({ captchaRequired: false });
noCaptcha.phone.value = "13800138000";
noCaptcha.password.value = "secret-1";
noCaptcha.agreed.value = true;
await noCaptcha.submitLogin();
assert.deepStrictEqual(
noCaptcha.calls.map((call) => call.type),
["require", "password-login", "go-root"],
"服务端关闭 password-login TAC 时必须直接走已发布密码登录请求",
);
assert.strictEqual(noCaptcha.tacVisible.value, false);
const navigationRejected = createHarness({ goRootResult: false });
await preparePassword(navigationRejected);
await completePasswordTac(navigationRejected);