chore: merge origin/main into feat/workflow-toolchain-defense
This commit is contained in:
commit
8d72e94d52
12 files changed
+890
-399
No files matched your search
@@ -814,7 +814,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"get-token": "enter"
|
||||
},
|
||||
flags: {
|
||||
...flagList("token t user name u hose-token jwt ticket ticket-id auth-code staff alias corp-name count limit n start offset state status corpid id keyword query q message msg reason matter hours hour duration", "value"),
|
||||
...flagList("token t user name u hose-token jwt ticket ticket-id auth-code staff alias corp-name count limit n start offset state status corpid id keyword query q message msg reason matter hours hour duration days day", "value"),
|
||||
...flagList("logout admin save import persist switch current overwrite", "boolean")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,4 +171,50 @@ describe("CLI Commands - assist-platform (合思协助平台)", () => {
|
||||
expect(res.stdout).toContain("ID01Xeno3GpoNV");
|
||||
expect(res.stdout).toContain("同意授权");
|
||||
});
|
||||
|
||||
it("assist-platform apply 传入超过 24 小时或多天时返回明确拒绝提示", async () => {
|
||||
saveAssistPlatformSession({
|
||||
token: "mock-token",
|
||||
userName: "测试人员",
|
||||
baseUrl: "https://unity.ekuaibao.com/api",
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "apply",
|
||||
args: ["ID01KrLMQJWdMH"],
|
||||
options: { days: 2 },
|
||||
raw: ["assist-platform", "apply", "ID01KrLMQJWdMH", "--days", "2"],
|
||||
};
|
||||
|
||||
const res = await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(res.exitCode).toBe(1);
|
||||
expect(res.stderr).toContain("申请协助时长不能超过 24 小时 (1 天)");
|
||||
expect(res.stderr).toContain("2 天 (48 小时)");
|
||||
expect(res.stderr).toContain("POST /api/assistPlatform/create");
|
||||
expect(res.stderr).toContain("单次协助工单最长有效期限为 24 小时");
|
||||
});
|
||||
|
||||
it("assist-platform apply --days 1 --dry-run 成功换算为 24 小时并预览", async () => {
|
||||
saveAssistPlatformSession({
|
||||
token: "mock-token",
|
||||
userName: "测试人员",
|
||||
baseUrl: "https://unity.ekuaibao.com/api",
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "apply",
|
||||
args: ["ID01KrLMQJWdMH"],
|
||||
options: { days: 1, dryRun: true },
|
||||
raw: ["assist-platform", "apply", "ID01KrLMQJWdMH", "--days", "1", "--dry-run"],
|
||||
};
|
||||
|
||||
const res = await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(res.stdout).toContain("[DRY-RUN]");
|
||||
expect(res.stdout).toContain("24 小时");
|
||||
});
|
||||
});
|
||||
@@ -23,11 +23,22 @@ export async function handleApply(
|
||||
};
|
||||
}
|
||||
|
||||
const hours = numberOption(parsed.options, ["hours", "hour", "duration"]) ?? 24;
|
||||
const days = numberOption(parsed.options, ["days", "day"]);
|
||||
let hours = numberOption(parsed.options, ["hours", "hour", "duration"]);
|
||||
if (days !== undefined) {
|
||||
hours = days * 24;
|
||||
}
|
||||
if (hours === undefined) {
|
||||
hours = 24;
|
||||
}
|
||||
|
||||
if (hours < 1 || hours > 24) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `[ERROR] 申请协助时长必须介于 1 到 24 小时之间,当前传入: ${hours}\n`,
|
||||
stderr:
|
||||
`[ERROR] 申请协助时长不能超过 24 小时 (1 天),当前传入: ${days !== undefined ? `${days} 天 (${hours} 小时)` : `${hours} 小时`}。\n` +
|
||||
`提示: 合思协助平台服务端(POST /api/assistPlatform/create)实施了硬性安全限制:单次协助工单最长有效期限为 24 小时 (1天),超过 24 小时服务端将直接拒绝受理。\n` +
|
||||
`如需持续协助支持,可在工单到期后再次快速发起或在端内续签。\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,12 +2,47 @@ import {
|
||||
generateAssistSession,
|
||||
importAssistSessionToLocal,
|
||||
} from "../../../domains/assist-platform/services.js";
|
||||
import type { AssistIdentityProfile } from "../../../domains/assist-platform/types.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import { booleanOption, stringOption } from "../../parser.js";
|
||||
import { printJson, printKeyValue } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { resolveAssistClient } from "./common.js";
|
||||
|
||||
function formatIdentityLines(ident?: AssistIdentityProfile): {
|
||||
profilePairs: Record<string, string>;
|
||||
warningText: string;
|
||||
} {
|
||||
const profilePairs: Record<string, string> = {};
|
||||
let warningText = "";
|
||||
|
||||
if (!ident) {
|
||||
return { profilePairs, warningText };
|
||||
}
|
||||
|
||||
profilePairs["获取员工身份"] = `${ident.staffName} (${ident.staffId || "-"})`;
|
||||
if (ident.departmentName) profilePairs["所属部门"] = ident.departmentName;
|
||||
if (ident.cellphone) profilePairs["绑定手机"] = ident.cellphone;
|
||||
if (ident.roleNames.length > 0) profilePairs["所配角色清单"] = ident.roleNames.join("、");
|
||||
if (ident.readablePermissions.length > 0) {
|
||||
const permSummary = ident.readablePermissions.slice(0, 5).join("、");
|
||||
profilePairs["核心系统权限"] = `${permSummary}${ident.readablePermissions.length > 5 ? ` 等共 ${ident.readablePermissions.length} 项` : ""}`;
|
||||
}
|
||||
|
||||
if (ident.isSeniorExecutive && ident.riskWarning) {
|
||||
const titles = ident.seniorTitles.length > 0 ? ident.seniorTitles.join(" / ") : "高级管理人员";
|
||||
warningText =
|
||||
`\n⚠️ 【高阶管理人员权限风控警示 (Executive Role Risk Warning)】\n` +
|
||||
`当前协助会话获取的是企业【${titles}】身份(${ident.staffName})。\n` +
|
||||
`防范越权与误用守则:\n` +
|
||||
` 1. 该身份在企业内具备高级审批、财务支配与全系统管理权限;\n` +
|
||||
` 2. 经理与一线实施人员严禁代用高管身份进行业务审批通过或非授权表单提交;\n` +
|
||||
` 3. 请严格将此会话权限限定在必要的系统排障、配置诊断与接口联调中!\n`;
|
||||
}
|
||||
|
||||
return { profilePairs, warningText };
|
||||
}
|
||||
|
||||
export async function handleEnter(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
@@ -62,8 +97,15 @@ export async function handleEnter(
|
||||
免密直通链接: sessionRes.loginUrl,
|
||||
};
|
||||
|
||||
const { profilePairs, warningText } = formatIdentityLines(sessionRes.identity);
|
||||
Object.assign(pairs, profilePairs);
|
||||
|
||||
return {
|
||||
stdout: `====== 协助平台免密会话生成成功 ======\n${printKeyValue(pairs)}\n\n操作提示:\n - 在浏览器中打开以上链接可直接进入协助调试工作台\n - 若要一键落盘到本地企业配置: hose-use assist-platform enter ${corpId} ${sessionRes.isAdmin ? "--admin" : `--staff "${sessionRes.staffName}"`} --save --yes\n`,
|
||||
stdout:
|
||||
`====== 协助平台免密会话生成成功 ======\n${printKeyValue(pairs)}\n` +
|
||||
`${warningText}\n操作提示:\n` +
|
||||
` - 在浏览器中打开以上链接可直接进入协助调试工作台\n` +
|
||||
` - 若要一键落盘到本地企业配置: hose-use assist-platform enter ${corpId} ${sessionRes.isAdmin ? "--admin" : `--staff "${sessionRes.staffName}"`} --save --yes\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -137,8 +179,11 @@ export async function handleEnter(
|
||||
激活状态: shouldSwitch ? "🎯 已设为当前激活工作企业" : "可随时运行 hose-use corps switch 进行切换",
|
||||
};
|
||||
|
||||
const { profilePairs, warningText } = formatIdentityLines(sessionResult.identity);
|
||||
Object.assign(successPairs, profilePairs);
|
||||
|
||||
return {
|
||||
stdout: `[SUCCESS] 协助企业凭证获取并落盘成功!\n${printKeyValue(successPairs)}\n`,
|
||||
stdout: `[SUCCESS] 协助企业凭证获取并落盘成功!\n${printKeyValue(successPairs)}\n${warningText}`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user