|
| 1 | +// Doctor node-hosting precondition tests cover browser-only auth and unreachable onboarding. |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import type { OpenClawConfig } from "../config/types.openclaw.js"; |
| 4 | +import { collectNodeHostingPreconditionFindings } from "./doctor-node-hosting-preconditions.js"; |
| 5 | + |
| 6 | +function findingsFor(cfg: OpenClawConfig) { |
| 7 | + return collectNodeHostingPreconditionFindings(cfg); |
| 8 | +} |
| 9 | + |
| 10 | +describe("node-hosting preconditions", () => { |
| 11 | + it.each([ |
| 12 | + { |
| 13 | + name: "identity-header auth alone", |
| 14 | + cfg: { |
| 15 | + gateway: { |
| 16 | + bind: "lan", |
| 17 | + auth: { mode: "trusted-proxy" }, |
| 18 | + }, |
| 19 | + }, |
| 20 | + requirements: ["machine-client-auth"], |
| 21 | + }, |
| 22 | + { |
| 23 | + name: "loopback onboarding alone", |
| 24 | + cfg: { |
| 25 | + gateway: { |
| 26 | + bind: "loopback", |
| 27 | + auth: { mode: "token", token: "configured-token" }, |
| 28 | + }, |
| 29 | + }, |
| 30 | + requirements: ["node-onboarding-url"], |
| 31 | + }, |
| 32 | + { |
| 33 | + name: "both unavailable", |
| 34 | + cfg: { |
| 35 | + gateway: { |
| 36 | + bind: "loopback", |
| 37 | + auth: { mode: "trusted-proxy" }, |
| 38 | + }, |
| 39 | + }, |
| 40 | + requirements: ["machine-client-auth", "node-onboarding-url"], |
| 41 | + }, |
| 42 | + { |
| 43 | + name: "Tailscale identity without a shared secret", |
| 44 | + cfg: { |
| 45 | + gateway: { |
| 46 | + bind: "loopback", |
| 47 | + tailscale: { mode: "serve" }, |
| 48 | + auth: { mode: "token", allowTailscale: true }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + requirements: ["machine-client-auth"], |
| 52 | + }, |
| 53 | + ] satisfies Array<{ |
| 54 | + name: string; |
| 55 | + cfg: OpenClawConfig; |
| 56 | + requirements: string[]; |
| 57 | + }>)("warns when $name", ({ cfg, requirements }) => { |
| 58 | + expect(findingsFor(cfg).map((finding) => finding.requirement)).toEqual(requirements); |
| 59 | + }); |
| 60 | + |
| 61 | + it("does not warn for token auth with a reachable bind", () => { |
| 62 | + expect( |
| 63 | + findingsFor({ |
| 64 | + gateway: { |
| 65 | + bind: "lan", |
| 66 | + auth: { |
| 67 | + mode: "token", |
| 68 | + token: { source: "env", provider: "default", id: "GATEWAY_TOKEN" }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }), |
| 72 | + ).toEqual([]); |
| 73 | + }); |
| 74 | + |
| 75 | + it("gives accurate machine-auth and edge-routing remediation", () => { |
| 76 | + const findings = findingsFor({ |
| 77 | + gateway: { |
| 78 | + bind: "loopback", |
| 79 | + auth: { mode: "trusted-proxy" }, |
| 80 | + }, |
| 81 | + }); |
| 82 | + |
| 83 | + expect(findings.find((finding) => finding.requirement === "machine-client-auth")?.fixHint).toBe( |
| 84 | + "Switch gateway.auth.mode to token and configure gateway.auth.token as a SecretRef so machine clients can authenticate as devices. Keep trusted-proxy only if machine clients use a clean loopback/direct gateway.auth.password path. Cloudflare Access service tokens are the alternative for Access-fronted gateways, but node-host support for CF-Access-Client-Id / CF-Access-Client-Secret is not implemented yet.", |
| 85 | + ); |
| 86 | + expect(findings.find((finding) => finding.requirement === "node-onboarding-url")).toMatchObject( |
| 87 | + { |
| 88 | + message: |
| 89 | + "Gateway is only bound to loopback. Set gateway.bind=lan, enable tailscale serve, or configure plugins.entries.device-pair.config.publicUrl.", |
| 90 | + fixHint: |
| 91 | + "If an edge proxy fronts node onboarding, allow /j/* and /__openclaw__/worker without edge identity auth, and preserve WebSocket upgrade on /__openclaw__/worker. Both routes enforce their own credentials.", |
| 92 | + }, |
| 93 | + ); |
| 94 | + }); |
| 95 | + |
| 96 | + it("accepts a configured public URL for loopback onboarding", () => { |
| 97 | + expect( |
| 98 | + findingsFor({ |
| 99 | + gateway: { |
| 100 | + bind: "loopback", |
| 101 | + auth: { mode: "token", token: "configured-token" }, |
| 102 | + }, |
| 103 | + plugins: { |
| 104 | + entries: { |
| 105 | + "device-pair": { config: { publicUrl: "wss://gateway.example" } }, |
| 106 | + }, |
| 107 | + }, |
| 108 | + }), |
| 109 | + ).toEqual([]); |
| 110 | + }); |
| 111 | +}); |
0 commit comments