Fix outbound confirmation and verification safety
This commit is contained in:
1 parent
b17bd09194
commit
67a461452c
20 files changed
+313
-74
No files matched your search
@@ -126,7 +126,8 @@ export async function handleCorpSync(
|
||||
snSuffix: stringOption(args.options.snSuffix) ?? stringOption(args.options["sn-suffix"]),
|
||||
docIdPrefix: stringOption(args.options.docIdPrefix) ?? stringOption(args.options["doc-id-prefix"]),
|
||||
docIdSuffix: stringOption(args.options.docIdSuffix) ?? stringOption(args.options["doc-id-suffix"]),
|
||||
dryRun
|
||||
dryRun,
|
||||
confirm: confirmed
|
||||
});
|
||||
if (dryRun) {
|
||||
console.error(`[corps-replay-test] 预览模式:已成功从 ${prodCorp.name} 提取单据并转换为 Webhook Payload(未实际推送)。`);
|
||||
|
||||
@@ -189,7 +189,8 @@ export async function handleDeployCommand(
|
||||
nodeId,
|
||||
rejectionNum,
|
||||
corporationId,
|
||||
dryRun
|
||||
dryRun,
|
||||
confirm: booleanOption(args.options.yes) === true || booleanOption(args.options.confirm) === true
|
||||
},
|
||||
outputOptions(args.options)
|
||||
);
|
||||
|
||||
@@ -288,7 +288,7 @@ describe("seal-use webhook replay CLI", () => {
|
||||
return new Response("Not found", { status: 404 });
|
||||
}) as any;
|
||||
|
||||
const result = await runCli(["webhook", "replay", "run-001"]);
|
||||
const result = await runCli(["webhook", "replay", "run-001", "--yes"]);
|
||||
|
||||
expect(result.isError).toBe(false);
|
||||
expect(result.exitCode).toBe(0);
|
||||
@@ -569,5 +569,66 @@ describe("seal-use webhook replay CLI", () => {
|
||||
expect(parsed.safetyGuards.targetModeAssisted).toBe(true);
|
||||
expect(parsed.safetyGuards.nodeId412Blocked).toBe(true);
|
||||
});
|
||||
|
||||
test("webhook replay requires confirmation before provisioning or pushing", async () => {
|
||||
setupMockEnv();
|
||||
let mutations = 0;
|
||||
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const method = init?.method ?? (input instanceof Request ? input.method : "GET");
|
||||
if (method !== "GET") mutations++;
|
||||
return new Response(JSON.stringify({ data: mockApprovalRun }), {
|
||||
status: 200, headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}) as typeof fetch;
|
||||
const result = await runCli(["approval-runs", "replay", "run-001"]);
|
||||
expect(result.exitCode).toBe(10);
|
||||
expect(result.stderr).toContain("--yes or --confirm");
|
||||
expect(mutations).toBe(0);
|
||||
});
|
||||
|
||||
test("outbound CLI gates both entry points and passes either confirmation flag", async () => {
|
||||
setupMockEnv();
|
||||
let pushes = 0;
|
||||
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
||||
const requestUrl = input instanceof Request ? input.url : input.toString();
|
||||
if (requestUrl.includes("/api/hosecloud/outbound")) {
|
||||
pushes++;
|
||||
return new Response(JSON.stringify({ data: { success: true } }), {
|
||||
status: 200, headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
return new Response(JSON.stringify({ data: { integrations: [{
|
||||
type: "hosecloud", signKey: "key", mode: "assisted", corporationId: "corp"
|
||||
}] } }), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
}) as typeof fetch;
|
||||
for (const command of [
|
||||
["approval-runs", "replay", "--sn", "SN", "--channel", "hose-outbound"],
|
||||
["deploy", "hosecloud", "test-outbound"]
|
||||
]) {
|
||||
const args = [...command, "--flow-id", "flow", "--message-id", "message"];
|
||||
for (const flags of [[], ["--yes=false"], ["--force"]]) {
|
||||
const before = pushes;
|
||||
const result = await runCli([...args, ...flags]);
|
||||
expect(result.exitCode).toBe(10);
|
||||
expect(pushes).toBe(before);
|
||||
}
|
||||
for (const flag of ["--yes", "--confirm"]) {
|
||||
const before = pushes;
|
||||
const result = await runCli([...args, flag]);
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(pushes).toBe(before + 1);
|
||||
const parsed = JSON.parse(result.stdout);
|
||||
expect(parsed.consumptionVerified).toBe(false);
|
||||
expect(parsed.recordId).toBeUndefined();
|
||||
}
|
||||
|
||||
const before = pushes;
|
||||
const preview = await runCli([...args, "--node-id", "FLOW:real-node", "--dry-run"]);
|
||||
expect(preview.exitCode).toBe(0);
|
||||
expect(pushes).toBe(before);
|
||||
const parsed = JSON.parse(preview.stdout);
|
||||
expect((parsed.safetyGuards ?? parsed.safetyCheck).nodeId412Blocked).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -148,6 +148,7 @@ export async function handleWebhookCommand(
|
||||
const docIdSuffix = stringOption(args.options.docIdSuffix) ?? stringOption(args.options["doc-id-suffix"]);
|
||||
const docIdPrefix = stringOption(args.options.docIdPrefix) ?? stringOption(args.options["doc-id-prefix"]);
|
||||
const dryRun = booleanOption(args.options.dryRun) ?? booleanOption(args.options["dry-run"]);
|
||||
const confirm = booleanOption(args.options.yes) === true || booleanOption(args.options.confirm) === true;
|
||||
|
||||
const channel =
|
||||
stringOption(args.options.channel) ??
|
||||
@@ -178,6 +179,7 @@ export async function handleWebhookCommand(
|
||||
rejectionNum,
|
||||
targetSignKey,
|
||||
dryRun,
|
||||
confirm,
|
||||
force
|
||||
});
|
||||
|
||||
@@ -207,7 +209,8 @@ export async function handleWebhookCommand(
|
||||
snSuffix,
|
||||
docIdPrefix,
|
||||
docIdSuffix,
|
||||
dryRun
|
||||
dryRun,
|
||||
confirm
|
||||
});
|
||||
|
||||
if (dryRun) {
|
||||
|
||||
+17
-11
@@ -435,9 +435,9 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
{
|
||||
name: "replay",
|
||||
usage: [
|
||||
"seal-use webhook replay <recordId> [--webhook <idOrName>] [--sn-suffix <str>] [--dry-run] [--corp <corpId>]",
|
||||
"seal-use webhook replay --sn <documentSN> [--webhook <idOrName>] [--source-corp <corpId>] [--target-corp <corpId>]",
|
||||
"seal-use webhook replay --limit <n> [--status <status>] [--source-corp <corpId>] [--target-corp <corpId>]"
|
||||
"seal-use webhook replay <recordId> [--webhook <idOrName>] [--sn-suffix <str>] [--dry-run] [--yes|--confirm] [--corp <corpId>]",
|
||||
"seal-use webhook replay --sn <documentSN> [--webhook <idOrName>] [--source-corp <corpId>] [--target-corp <corpId>] [--yes|--confirm]",
|
||||
"seal-use webhook replay --limit <n> [--status <status>] [--source-corp <corpId>] [--target-corp <corpId>] [--yes|--confirm]"
|
||||
],
|
||||
options: [
|
||||
{ flag: "<recordId>", description: "Approval run record ID to replay" },
|
||||
@@ -450,6 +450,7 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
{ flag: "--sn-suffix <str>", description: "Optional suffix appended to documentSN and documentId" },
|
||||
{ flag: "--sn-prefix <str>", description: "Optional prefix prepended to documentSN and documentId" },
|
||||
{ flag: "--dry-run", description: "Generate and output Webhook payload JSON without sending HTTP request" },
|
||||
{ flag: "--yes, --confirm", description: "Required for live replay; --force only overrides the environment guard" },
|
||||
{ flag: "--force", description: "Allow replaying to a production enterprise" }
|
||||
],
|
||||
description: "Extracts structured form fields from historical approval records (Webhook or Hose source), sanitizes field types, and pushes documents to the target Webhook channel. Automatically infers 1-to-1 bound test/production enterprise pairs."
|
||||
@@ -582,11 +583,11 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
name: "replay",
|
||||
summary: "Replay approval run record into a Webhook integration",
|
||||
usage: [
|
||||
"seal-use approval-runs replay <recordId> [--webhook <idOrName>] [--sn-suffix <str>] [--dry-run] [--corp <corpId>]",
|
||||
"seal-use approval-runs replay --sn <documentSN> [--webhook <idOrName>] [--source-corp <corpId>] [--target-corp <corpId>]",
|
||||
"seal-use approval-runs replay --sn <documentSN> --channel hose-outbound [--sign-key <key>] [--target-corp <corpId>] [--dry-run]",
|
||||
"seal-use approval-runs replay <recordId> --channel hose-outbound [--sign-key <key>] [--target-corp <corpId>] [--dry-run]",
|
||||
"seal-use approval-runs replay --limit <n> [--status <status>] [--source-corp <corpId>] [--target-corp <corpId>]"
|
||||
"seal-use approval-runs replay <recordId> [--webhook <idOrName>] [--sn-suffix <str>] [--dry-run] [--yes|--confirm] [--corp <corpId>]",
|
||||
"seal-use approval-runs replay --sn <documentSN> [--webhook <idOrName>] [--source-corp <corpId>] [--target-corp <corpId>] [--yes|--confirm]",
|
||||
"seal-use approval-runs replay --sn <documentSN> --channel hose-outbound [--sign-key <key>] [--target-corp <corpId>] [--dry-run] [--yes|--confirm]",
|
||||
"seal-use approval-runs replay <recordId> --channel hose-outbound [--sign-key <key>] [--target-corp <corpId>] [--dry-run] [--yes|--confirm]",
|
||||
"seal-use approval-runs replay --limit <n> [--status <status>] [--source-corp <corpId>] [--target-corp <corpId>] [--yes|--confirm]"
|
||||
],
|
||||
options: [
|
||||
{ flag: "<recordId>", description: "Approval run record ID" },
|
||||
@@ -601,7 +602,8 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
{ flag: "--source-corp <corpId>", description: "Source enterprise where records reside" },
|
||||
{ flag: "--target-corp <corpId>", description: "Target enterprise where records are pushed" },
|
||||
{ flag: "--sn-suffix <str>", description: "Optional suffix appended to documentSN" },
|
||||
{ flag: "--dry-run", description: "Preview payload without sending" }
|
||||
{ flag: "--dry-run", description: "Preview payload without sending" },
|
||||
{ flag: "--yes, --confirm", description: "Required for live replay; --force only overrides environment and pairing guards" }
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -758,8 +760,12 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
name: "hosecloud test-outbound",
|
||||
summary: "向合思出站 (outbound) 接口推送测试/重放消息以模拟工作流触发(要求 assisted 模式)",
|
||||
usage: [
|
||||
"seal-use deploy hosecloud test-outbound [--sign-key <key>] --flow-id <id> --message-id <msgId> [--dry-run] [--corp <corpId>]",
|
||||
"seal-use deploy hosecloud test-outbound [--sign-key <key>] --sn <SN> --message-id <msgId> [--dry-run] [--corp <corpId>]"
|
||||
"seal-use deploy hosecloud test-outbound [--sign-key <key>] --flow-id <id> --message-id <msgId> [--dry-run] [--yes|--confirm] [--corp <corpId>]",
|
||||
"seal-use deploy hosecloud test-outbound [--sign-key <key>] --sn <SN> --message-id <msgId> [--dry-run] [--yes|--confirm] [--corp <corpId>]"
|
||||
],
|
||||
options: [
|
||||
{ flag: "--dry-run", description: "Preview the outbound payload without sending" },
|
||||
{ flag: "--yes, --confirm", description: "Required for live outbound push" }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -158,6 +158,19 @@ describe("option helpers", () => {
|
||||
expect(() => parseHoseExpireSeconds("invalid")).toThrow("必须为有效时长");
|
||||
});
|
||||
|
||||
test("overflowing --expire literals are usage errors before reaching auth", () => {
|
||||
for (const parse of [parseDelegationExpireHours, parseHoseExpireSeconds]) {
|
||||
for (const literal of ["9".repeat(309), "9".repeat(309) + "s", "9".repeat(308) + "d"]) {
|
||||
expect(() => parse(literal)).toThrow();
|
||||
try {
|
||||
parse(literal);
|
||||
} catch (error) {
|
||||
expect((error as { exitCode: number }).exitCode).toBe(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("both --expire flags read a unitless literal the same way", () => {
|
||||
// Regression: the two parsers used to each carry their own copy of the
|
||||
// unitless heuristic, so `--expire 300` meant 5 minutes on one path and
|
||||
|
||||
+1
-1
@@ -533,7 +533,7 @@ export function parseHoseExpireSeconds(
|
||||
}
|
||||
|
||||
const seconds = Math.round(expireSeconds(token));
|
||||
if (seconds <= 0) {
|
||||
if (!Number.isFinite(seconds) || seconds <= 0) {
|
||||
throw usageError(`Invalid --expire: 计算得 ${seconds} 秒。必须为大于 0 的有效时长。`);
|
||||
}
|
||||
return seconds;
|
||||
|
||||
Reference in new issue
Block a user