























@@ -609,6 +609,72 @@ describe("device-pair /pair default setup code", () => {
609609text: "⚠️ This command requires operator.pairing for internal gateway callers.",
610610});
611611});
612+613+it("normalizes bare publicUrl host ports before issuing setup codes", async () => {
614+const command = registerPairCommand({
615+pluginConfig: {
616+publicUrl: "gateway.example.test:18789/setup",
617+},
618+});
619+const result = await command.handler(
620+createCommandContext({
621+channel: "webchat",
622+args: "",
623+commandBody: "/pair",
624+gatewayClientScopes: ["operator.write", "operator.pairing"],
625+}),
626+);
627+const text = requireText(result);
628+629+expect(pluginApiMocks.issueDeviceBootstrapToken).toHaveBeenCalledTimes(1);
630+expect(text).toContain("Gateway: ws://gateway.example.test:18789");
631+});
632+633+it("rejects invalid bare publicUrl host ports", async () => {
634+const command = registerPairCommand({
635+pluginConfig: {
636+publicUrl: "localhost:notaport",
637+},
638+});
639+const result = await command.handler(
640+createCommandContext({
641+channel: "webchat",
642+args: "",
643+commandBody: "/pair",
644+gatewayClientScopes: ["operator.write", "operator.pairing"],
645+}),
646+);
647+648+expect(pluginApiMocks.issueDeviceBootstrapToken).not.toHaveBeenCalled();
649+expect(result).toEqual({ text: "Error: Configured publicUrl is invalid." });
650+});
651+652+it.each([
653+"http://localhost:notaport",
654+"http:gateway.example.test",
655+"ws:gateway.example.test",
656+"http:/localhost:notaport",
657+"ftp:/gateway.example.test",
658+"mailto:foo@example.com",
659+"ws://user:pass@gateway.example.test:18789",
660+])("rejects invalid publicUrl %s before issuing setup codes", async (publicUrl) => {
661+const command = registerPairCommand({
662+pluginConfig: {
663+ publicUrl,
664+},
665+});
666+const result = await command.handler(
667+createCommandContext({
668+channel: "webchat",
669+args: "",
670+commandBody: "/pair",
671+gatewayClientScopes: ["operator.write", "operator.pairing"],
672+}),
673+);
674+675+expect(pluginApiMocks.issueDeviceBootstrapToken).not.toHaveBeenCalled();
676+expect(result).toEqual({ text: "Error: Configured publicUrl is invalid." });
677+});
612678});
613679614680describe("device-pair notify pending formatting", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。