@serfab/cadre-host 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/dist/auth/duration.d.ts +1 -0
- package/dist/auth/duration.js +32 -0
- package/dist/auth/duration.js.map +1 -0
- package/dist/auth/index.d.ts +9 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/trust-circle-store.d.ts +26 -0
- package/dist/auth/trust-circle-store.js +129 -0
- package/dist/auth/trust-circle-store.js.map +1 -0
- package/dist/auth/trust-circle.d.ts +91 -0
- package/dist/auth/trust-circle.js +230 -0
- package/dist/auth/trust-circle.js.map +1 -0
- package/dist/auth/types.d.ts +81 -0
- package/dist/auth/types.js +24 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/bin/host.d.ts +13 -0
- package/dist/bin/host.js +826 -0
- package/dist/bin/host.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/installer/browser.d.ts +14 -0
- package/dist/installer/browser.js +35 -0
- package/dist/installer/browser.js.map +1 -0
- package/dist/installer/config.d.ts +43 -0
- package/dist/installer/config.js +113 -0
- package/dist/installer/config.js.map +1 -0
- package/dist/installer/identity.d.ts +23 -0
- package/dist/installer/identity.js +36 -0
- package/dist/installer/identity.js.map +1 -0
- package/dist/installer/index.d.ts +83 -0
- package/dist/installer/index.js +204 -0
- package/dist/installer/index.js.map +1 -0
- package/dist/installer/paths.d.ts +33 -0
- package/dist/installer/paths.js +84 -0
- package/dist/installer/paths.js.map +1 -0
- package/dist/installer/platform.d.ts +9 -0
- package/dist/installer/platform.js +21 -0
- package/dist/installer/platform.js.map +1 -0
- package/dist/installer/service-host/index.d.ts +11 -0
- package/dist/installer/service-host/index.js +16 -0
- package/dist/installer/service-host/index.js.map +1 -0
- package/dist/installer/service-host/launchd.d.ts +16 -0
- package/dist/installer/service-host/launchd.js +79 -0
- package/dist/installer/service-host/launchd.js.map +1 -0
- package/dist/installer/service-host/nssm.d.ts +20 -0
- package/dist/installer/service-host/nssm.js +88 -0
- package/dist/installer/service-host/nssm.js.map +1 -0
- package/dist/installer/service-host/systemd.d.ts +16 -0
- package/dist/installer/service-host/systemd.js +78 -0
- package/dist/installer/service-host/systemd.js.map +1 -0
- package/dist/installer/service-host/template.d.ts +6 -0
- package/dist/installer/service-host/template.js +20 -0
- package/dist/installer/service-host/template.js.map +1 -0
- package/dist/installer/service-host/types.d.ts +40 -0
- package/dist/installer/service-host/types.js +6 -0
- package/dist/installer/service-host/types.js.map +1 -0
- package/dist/installer/wizard.d.ts +31 -0
- package/dist/installer/wizard.js +67 -0
- package/dist/installer/wizard.js.map +1 -0
- package/dist/nat/address-resolver.d.ts +22 -0
- package/dist/nat/address-resolver.js +31 -0
- package/dist/nat/address-resolver.js.map +1 -0
- package/dist/nat/ddns/duckdns.d.ts +12 -0
- package/dist/nat/ddns/duckdns.js +57 -0
- package/dist/nat/ddns/duckdns.js.map +1 -0
- package/dist/nat/ddns/index.d.ts +30 -0
- package/dist/nat/ddns/index.js +21 -0
- package/dist/nat/ddns/index.js.map +1 -0
- package/dist/nat/ddns/updater.d.ts +68 -0
- package/dist/nat/ddns/updater.js +194 -0
- package/dist/nat/ddns/updater.js.map +1 -0
- package/dist/nat/external-ip.d.ts +62 -0
- package/dist/nat/external-ip.js +114 -0
- package/dist/nat/external-ip.js.map +1 -0
- package/dist/nat/index.d.ts +22 -0
- package/dist/nat/index.js +16 -0
- package/dist/nat/index.js.map +1 -0
- package/dist/nat/nat-service.d.ts +101 -0
- package/dist/nat/nat-service.js +284 -0
- package/dist/nat/nat-service.js.map +1 -0
- package/dist/nat/nat-store.d.ts +19 -0
- package/dist/nat/nat-store.js +136 -0
- package/dist/nat/nat-store.js.map +1 -0
- package/dist/nat/port-mapper.d.ts +98 -0
- package/dist/nat/port-mapper.js +226 -0
- package/dist/nat/port-mapper.js.map +1 -0
- package/dist/nat/reachability.d.ts +19 -0
- package/dist/nat/reachability.js +29 -0
- package/dist/nat/reachability.js.map +1 -0
- package/dist/nat/secrets/file-store.d.ts +23 -0
- package/dist/nat/secrets/file-store.js +102 -0
- package/dist/nat/secrets/file-store.js.map +1 -0
- package/dist/nat/secrets/index.d.ts +36 -0
- package/dist/nat/secrets/index.js +56 -0
- package/dist/nat/secrets/index.js.map +1 -0
- package/dist/nat/secrets/keytar-store.d.ts +18 -0
- package/dist/nat/secrets/keytar-store.js +52 -0
- package/dist/nat/secrets/keytar-store.js.map +1 -0
- package/dist/nat/types.d.ts +120 -0
- package/dist/nat/types.js +24 -0
- package/dist/nat/types.js.map +1 -0
- package/dist/orchestrator/host-process-orchestrator.d.ts +87 -0
- package/dist/orchestrator/host-process-orchestrator.js +557 -0
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -0
- package/dist/orchestrator/index.d.ts +3 -0
- package/dist/orchestrator/index.js +2 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/log-rotator.d.ts +25 -0
- package/dist/orchestrator/log-rotator.js +56 -0
- package/dist/orchestrator/log-rotator.js.map +1 -0
- package/dist/orchestrator/pid-liveness.d.ts +11 -0
- package/dist/orchestrator/pid-liveness.js +26 -0
- package/dist/orchestrator/pid-liveness.js.map +1 -0
- package/dist/orchestrator/port-allocator.d.ts +16 -0
- package/dist/orchestrator/port-allocator.js +38 -0
- package/dist/orchestrator/port-allocator.js.map +1 -0
- package/dist/orchestrator/state-store.d.ts +32 -0
- package/dist/orchestrator/state-store.js +44 -0
- package/dist/orchestrator/state-store.js.map +1 -0
- package/dist/orchestrator/types.d.ts +85 -0
- package/dist/orchestrator/types.js +31 -0
- package/dist/orchestrator/types.js.map +1 -0
- package/dist/server/error-handler.d.ts +26 -0
- package/dist/server/error-handler.js +95 -0
- package/dist/server/error-handler.js.map +1 -0
- package/dist/server/events/bus.d.ts +17 -0
- package/dist/server/events/bus.js +36 -0
- package/dist/server/events/bus.js.map +1 -0
- package/dist/server/events/sse-route.d.ts +22 -0
- package/dist/server/events/sse-route.js +65 -0
- package/dist/server/events/sse-route.js.map +1 -0
- package/dist/server/events/types.d.ts +25 -0
- package/dist/server/events/types.js +8 -0
- package/dist/server/events/types.js.map +1 -0
- package/dist/server/index.d.ts +67 -0
- package/dist/server/index.js +149 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/origin-guard.d.ts +24 -0
- package/dist/server/origin-guard.js +72 -0
- package/dist/server/origin-guard.js.map +1 -0
- package/dist/server/routes/nat.d.ts +16 -0
- package/dist/server/routes/nat.js +42 -0
- package/dist/server/routes/nat.js.map +1 -0
- package/dist/server/routes/nodes.d.ts +23 -0
- package/dist/server/routes/nodes.js +128 -0
- package/dist/server/routes/nodes.js.map +1 -0
- package/dist/server/routes/settings.d.ts +26 -0
- package/dist/server/routes/settings.js +97 -0
- package/dist/server/routes/settings.js.map +1 -0
- package/dist/server/routes/status.d.ts +42 -0
- package/dist/server/routes/status.js +76 -0
- package/dist/server/routes/status.js.map +1 -0
- package/dist/server/routes/trust-circle.d.ts +17 -0
- package/dist/server/routes/trust-circle.js +35 -0
- package/dist/server/routes/trust-circle.js.map +1 -0
- package/dist/server/routes/update.d.ts +16 -0
- package/dist/server/routes/update.js +29 -0
- package/dist/server/routes/update.js.map +1 -0
- package/dist/server/server.d.ts +40 -0
- package/dist/server/server.js +90 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/settings-store.d.ts +24 -0
- package/dist/server/settings-store.js +27 -0
- package/dist/server/settings-store.js.map +1 -0
- package/dist/server/static.d.ts +25 -0
- package/dist/server/static.js +177 -0
- package/dist/server/static.js.map +1 -0
- package/dist/ui/assets/index-BwU5mJGF.css +1 -0
- package/dist/ui/assets/index-C9uChk2P.js +14 -0
- package/dist/ui/assets/index-C9uChk2P.js.map +1 -0
- package/dist/ui/index.html +14 -0
- package/dist/update/apply.d.ts +37 -0
- package/dist/update/apply.js +102 -0
- package/dist/update/apply.js.map +1 -0
- package/dist/update/index.d.ts +101 -0
- package/dist/update/index.js +228 -0
- package/dist/update/index.js.map +1 -0
- package/dist/update/manifest.d.ts +48 -0
- package/dist/update/manifest.js +152 -0
- package/dist/update/manifest.js.map +1 -0
- package/dist/update/release-key.d.ts +24 -0
- package/dist/update/release-key.js +52 -0
- package/dist/update/release-key.js.map +1 -0
- package/dist/update/store.d.ts +22 -0
- package/dist/update/store.js +81 -0
- package/dist/update/store.js.map +1 -0
- package/dist/update/types.d.ts +90 -0
- package/dist/update/types.js +22 -0
- package/dist/update/types.js.map +1 -0
- package/dist/update/version.d.ts +18 -0
- package/dist/update/version.js +76 -0
- package/dist/update/version.js.map +1 -0
- package/package.json +80 -0
- package/service/README.md +86 -0
- package/service/cadre-host.service.tmpl +16 -0
- package/service/com.serfab.cadre-host.plist.tmpl +35 -0
- package/service/install-service.ps1 +98 -0
- package/service/uninstall-service.ps1 +19 -0
- package/src/__tests__/cli-invite.smoke.test.ts +187 -0
- package/src/__tests__/cli-nat.smoke.test.ts +207 -0
- package/src/__tests__/cli.smoke.test.ts +41 -0
- package/src/__tests__/orchestrator.test.ts +570 -0
- package/src/auth/__tests__/duration.test.ts +28 -0
- package/src/auth/__tests__/trust-circle-integration.test.ts +128 -0
- package/src/auth/__tests__/trust-circle-store.test.ts +115 -0
- package/src/auth/__tests__/trust-circle.test.ts +334 -0
- package/src/auth/duration.ts +33 -0
- package/src/auth/index.ts +19 -0
- package/src/auth/trust-circle-store.ts +155 -0
- package/src/auth/trust-circle.ts +304 -0
- package/src/auth/types.ts +96 -0
- package/src/bin/host.ts +905 -0
- package/src/index.ts +167 -0
- package/src/installer/__tests__/config.test.ts +86 -0
- package/src/installer/__tests__/identity.test.ts +34 -0
- package/src/installer/__tests__/installer.smoke.test.ts +124 -0
- package/src/installer/__tests__/paths.test.ts +47 -0
- package/src/installer/__tests__/service-host.test.ts +62 -0
- package/src/installer/__tests__/wizard.test.ts +60 -0
- package/src/installer/browser.ts +42 -0
- package/src/installer/config.ts +153 -0
- package/src/installer/identity.ts +49 -0
- package/src/installer/index.ts +303 -0
- package/src/installer/paths.ts +109 -0
- package/src/installer/platform.ts +27 -0
- package/src/installer/service-host/index.ts +21 -0
- package/src/installer/service-host/launchd.ts +90 -0
- package/src/installer/service-host/nssm.ts +100 -0
- package/src/installer/service-host/systemd.ts +88 -0
- package/src/installer/service-host/template.ts +21 -0
- package/src/installer/service-host/types.ts +48 -0
- package/src/installer/wizard.ts +92 -0
- package/src/nat/__tests__/address-resolver.test.ts +82 -0
- package/src/nat/__tests__/ddns-duckdns.test.ts +83 -0
- package/src/nat/__tests__/ddns-updater.test.ts +253 -0
- package/src/nat/__tests__/external-ip.test.ts +124 -0
- package/src/nat/__tests__/nat-service.test.ts +305 -0
- package/src/nat/__tests__/nat-store.test.ts +93 -0
- package/src/nat/__tests__/port-mapper.test.ts +191 -0
- package/src/nat/__tests__/reachability.test.ts +24 -0
- package/src/nat/__tests__/secrets.test.ts +156 -0
- package/src/nat/address-resolver.ts +51 -0
- package/src/nat/ddns/duckdns.ts +76 -0
- package/src/nat/ddns/index.ts +55 -0
- package/src/nat/ddns/updater.ts +243 -0
- package/src/nat/external-ip.ts +154 -0
- package/src/nat/index.ts +71 -0
- package/src/nat/nat-service.ts +375 -0
- package/src/nat/nat-store.ts +154 -0
- package/src/nat/port-mapper.ts +329 -0
- package/src/nat/reachability.ts +34 -0
- package/src/nat/secrets/file-store.ts +130 -0
- package/src/nat/secrets/index.ts +82 -0
- package/src/nat/secrets/keytar-store.ts +67 -0
- package/src/nat/types.ts +157 -0
- package/src/orchestrator/host-process-orchestrator.ts +626 -0
- package/src/orchestrator/index.ts +3 -0
- package/src/orchestrator/log-rotator.ts +53 -0
- package/src/orchestrator/pid-liveness.ts +24 -0
- package/src/orchestrator/port-allocator.ts +43 -0
- package/src/orchestrator/state-store.ts +72 -0
- package/src/orchestrator/types.ts +95 -0
- package/src/server/__tests__/bus.test.ts +38 -0
- package/src/server/__tests__/error-handler.test.ts +96 -0
- package/src/server/__tests__/nodes-route.test.ts +179 -0
- package/src/server/__tests__/origin-guard.test.ts +72 -0
- package/src/server/__tests__/publishers.test.ts +216 -0
- package/src/server/__tests__/server.smoke.test.ts +178 -0
- package/src/server/__tests__/settings-route.test.ts +177 -0
- package/src/server/__tests__/sse-route.test.ts +119 -0
- package/src/server/__tests__/status-route.test.ts +113 -0
- package/src/server/error-handler.ts +108 -0
- package/src/server/events/bus.ts +42 -0
- package/src/server/events/sse-route.ts +81 -0
- package/src/server/events/types.ts +22 -0
- package/src/server/index.ts +209 -0
- package/src/server/origin-guard.ts +84 -0
- package/src/server/routes/nat.ts +63 -0
- package/src/server/routes/nodes.ts +147 -0
- package/src/server/routes/settings.ts +115 -0
- package/src/server/routes/status.ts +108 -0
- package/src/server/routes/trust-circle.ts +49 -0
- package/src/server/routes/update.ts +43 -0
- package/src/server/server.ts +122 -0
- package/src/server/settings-store.ts +37 -0
- package/src/server/static.ts +191 -0
- package/src/update/__tests__/apply.test.ts +101 -0
- package/src/update/__tests__/manifest.test.ts +93 -0
- package/src/update/__tests__/store.test.ts +81 -0
- package/src/update/__tests__/update-service.integration.test.ts +221 -0
- package/src/update/__tests__/version.test.ts +31 -0
- package/src/update/apply.ts +148 -0
- package/src/update/index.ts +303 -0
- package/src/update/manifest.ts +172 -0
- package/src/update/release-key.ts +55 -0
- package/src/update/store.ts +101 -0
- package/src/update/types.ts +109 -0
- package/src/update/version.ts +80 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Cadre Host Service Units
|
|
2
|
+
|
|
3
|
+
Host cadre-host as a per-user system service. All three units are configured
|
|
4
|
+
so that **a clean exit (code 0) is final** — `cadre-host uninstall` (or any
|
|
5
|
+
explicit `systemctl stop` / `nssm stop`) leaves the service stopped. Crashes
|
|
6
|
+
still trigger a restart.
|
|
7
|
+
|
|
8
|
+
| Platform | File | Service host |
|
|
9
|
+
| -------- | ---- | ------------ |
|
|
10
|
+
| Linux | [`cadre-host.service.tmpl`](./cadre-host.service.tmpl) | systemd (user) |
|
|
11
|
+
| macOS | [`com.serfab.cadre-host.plist.tmpl`](./com.serfab.cadre-host.plist.tmpl) | launchd (LaunchAgent) |
|
|
12
|
+
| Windows | [`install-service.ps1`](./install-service.ps1) / [`uninstall-service.ps1`](./uninstall-service.ps1) | NSSM |
|
|
13
|
+
|
|
14
|
+
The `.tmpl` files contain `@TOKEN@` placeholders that the installer
|
|
15
|
+
substitutes at install time (`@NODE_PATH@`, `@HOST_JS@`, `@DATA_DIR@`).
|
|
16
|
+
Inspect the rendered files under `~/.config/systemd/user/cadre-host.service`
|
|
17
|
+
or `~/Library/LaunchAgents/com.serfab.cadre-host.plist` after running
|
|
18
|
+
`cadre-host install`.
|
|
19
|
+
|
|
20
|
+
## Scope (v1)
|
|
21
|
+
|
|
22
|
+
**Per-user install only.** The systemd unit is installed under the user's
|
|
23
|
+
control (`systemctl --user`), the launchd unit is a `LaunchAgent` (not a
|
|
24
|
+
`LaunchDaemon`), and NSSM runs as the current user.
|
|
25
|
+
|
|
26
|
+
A `--system` flag is accepted by `cadre-host install` but currently errors
|
|
27
|
+
out — running cadre-host as a dedicated system user requires more work
|
|
28
|
+
around data-dir ownership and capability dropping. Tracked separately.
|
|
29
|
+
|
|
30
|
+
## Linux (systemd) — manual smoke
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Render + install + enable + start in one go:
|
|
34
|
+
cadre-host install --non-interactive --data-dir ~/.local/share/cadre-host
|
|
35
|
+
|
|
36
|
+
# After install, the unit lives at:
|
|
37
|
+
# ~/.config/systemd/user/cadre-host.service
|
|
38
|
+
# Inspect status:
|
|
39
|
+
systemctl --user status cadre-host
|
|
40
|
+
journalctl --user -u cadre-host -f
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`Restart=on-failure` + `RestartPreventExitStatus=0` make exit 0 final.
|
|
44
|
+
|
|
45
|
+
The installer also runs `loginctl enable-linger <user>` so the unit survives
|
|
46
|
+
logout / reboot.
|
|
47
|
+
|
|
48
|
+
## macOS (launchd) — manual smoke
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
cadre-host install --non-interactive --data-dir "$HOME/Library/Application Support/CadreHost"
|
|
52
|
+
|
|
53
|
+
# After install, the plist lives at:
|
|
54
|
+
# ~/Library/LaunchAgents/com.serfab.cadre-host.plist
|
|
55
|
+
launchctl print gui/$(id -u)/com.serfab.cadre-host
|
|
56
|
+
tail -f "$HOME/Library/Application Support/CadreHost/logs/out.log"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`KeepAlive.SuccessfulExit = false` plus `KeepAlive.Crashed = true` mean a
|
|
60
|
+
clean exit stays down while a crash is relaunched.
|
|
61
|
+
|
|
62
|
+
## Windows (NSSM) — manual smoke
|
|
63
|
+
|
|
64
|
+
Install [NSSM](https://nssm.cc/download) and put `nssm.exe` on PATH first.
|
|
65
|
+
|
|
66
|
+
```powershell
|
|
67
|
+
cadre-host install --non-interactive --data-dir $env:LocalAppData\CadreHost
|
|
68
|
+
|
|
69
|
+
# After install, inspect the service:
|
|
70
|
+
nssm.exe status CadreHost
|
|
71
|
+
Get-Service CadreHost
|
|
72
|
+
Get-Content $env:LocalAppData\CadreHost\logs\out.log -Tail 30 -Wait
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`AppExit 0 Exit` tells NSSM not to restart on clean exit; other exit codes
|
|
76
|
+
are handled by `AppExit Default Restart` with a 5-second delay and a
|
|
77
|
+
10-second throttle. NSSM is **not** bundled with the npm package; the
|
|
78
|
+
standalone-binary distribution (see `tickets/backlog/cadre-host-standalone-binary.md`)
|
|
79
|
+
will ship it.
|
|
80
|
+
|
|
81
|
+
## CI gap
|
|
82
|
+
|
|
83
|
+
Cross-platform CI does **not** invoke `systemctl --user enable`,
|
|
84
|
+
`launchctl bootstrap`, or `nssm install`. The installer's unit-rendering
|
|
85
|
+
logic is covered by unit tests; the actual service-host registration must
|
|
86
|
+
be smoke-tested manually on each platform before tagging a release.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=Sereus Cadre Host
|
|
3
|
+
After=network-online.target
|
|
4
|
+
Wants=network-online.target
|
|
5
|
+
|
|
6
|
+
[Service]
|
|
7
|
+
Type=simple
|
|
8
|
+
ExecStart=@NODE_PATH@ @HOST_JS@ start --no-tui --data-dir @DATA_DIR@
|
|
9
|
+
Restart=on-failure
|
|
10
|
+
RestartPreventExitStatus=0
|
|
11
|
+
RestartSec=5s
|
|
12
|
+
Environment=NODE_ENV=production
|
|
13
|
+
NoNewPrivileges=true
|
|
14
|
+
|
|
15
|
+
[Install]
|
|
16
|
+
WantedBy=default.target
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>Label</key>
|
|
6
|
+
<string>com.serfab.cadre-host</string>
|
|
7
|
+
<key>ProgramArguments</key>
|
|
8
|
+
<array>
|
|
9
|
+
<string>@NODE_PATH@</string>
|
|
10
|
+
<string>@HOST_JS@</string>
|
|
11
|
+
<string>start</string>
|
|
12
|
+
<string>--no-tui</string>
|
|
13
|
+
<string>--data-dir</string>
|
|
14
|
+
<string>@DATA_DIR@</string>
|
|
15
|
+
</array>
|
|
16
|
+
<key>RunAtLoad</key>
|
|
17
|
+
<true/>
|
|
18
|
+
<key>KeepAlive</key>
|
|
19
|
+
<dict>
|
|
20
|
+
<key>SuccessfulExit</key>
|
|
21
|
+
<false/>
|
|
22
|
+
<key>Crashed</key>
|
|
23
|
+
<true/>
|
|
24
|
+
</dict>
|
|
25
|
+
<key>StandardOutPath</key>
|
|
26
|
+
<string>@DATA_DIR@/logs/out.log</string>
|
|
27
|
+
<key>StandardErrorPath</key>
|
|
28
|
+
<string>@DATA_DIR@/logs/err.log</string>
|
|
29
|
+
<key>EnvironmentVariables</key>
|
|
30
|
+
<dict>
|
|
31
|
+
<key>NODE_ENV</key>
|
|
32
|
+
<string>production</string>
|
|
33
|
+
</dict>
|
|
34
|
+
</dict>
|
|
35
|
+
</plist>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<#
|
|
2
|
+
.SYNOPSIS
|
|
3
|
+
Install the Cadre Host as a Windows service using NSSM.
|
|
4
|
+
|
|
5
|
+
.DESCRIPTION
|
|
6
|
+
Registers a Windows service named "CadreHost" that runs cadre-host via
|
|
7
|
+
NSSM. The service is configured so that exit code 0 is final (no
|
|
8
|
+
restart); non-zero exits trigger a 5-second-delayed restart, throttled
|
|
9
|
+
to 10 seconds.
|
|
10
|
+
|
|
11
|
+
NSSM (the Non-Sucking Service Manager) must be on PATH. Get it from
|
|
12
|
+
https://nssm.cc/download.
|
|
13
|
+
|
|
14
|
+
.PARAMETER NodePath
|
|
15
|
+
Path to node.exe. Defaults to (Get-Command node).Source.
|
|
16
|
+
|
|
17
|
+
.PARAMETER HostJs
|
|
18
|
+
Path to the cadre-host CLI entrypoint (dist/bin/host.js). Defaults to
|
|
19
|
+
the script's parent dir + dist\bin\host.js.
|
|
20
|
+
|
|
21
|
+
.PARAMETER DataDir
|
|
22
|
+
Cadre host data directory (host.config.json + identity + state). Defaults
|
|
23
|
+
to $env:LocalAppData\CadreHost.
|
|
24
|
+
#>
|
|
25
|
+
|
|
26
|
+
[CmdletBinding()]
|
|
27
|
+
param(
|
|
28
|
+
[string]$NodePath,
|
|
29
|
+
[string]$HostJs,
|
|
30
|
+
[string]$DataDir
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
$ErrorActionPreference = 'Stop'
|
|
34
|
+
$ServiceName = 'CadreHost'
|
|
35
|
+
|
|
36
|
+
$nssm = Get-Command nssm.exe -ErrorAction SilentlyContinue
|
|
37
|
+
if (-not $nssm) {
|
|
38
|
+
Write-Error @"
|
|
39
|
+
nssm.exe not found on PATH.
|
|
40
|
+
Install NSSM from https://nssm.cc/download and either add it to PATH or
|
|
41
|
+
copy nssm.exe to a directory on PATH. NSSM is required to host the
|
|
42
|
+
Cadre Host as a Windows service.
|
|
43
|
+
"@
|
|
44
|
+
exit 1
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (-not $NodePath) {
|
|
48
|
+
$node = Get-Command node.exe -ErrorAction SilentlyContinue
|
|
49
|
+
if (-not $node) {
|
|
50
|
+
Write-Error 'node.exe not found on PATH. Pass -NodePath explicitly.'
|
|
51
|
+
exit 1
|
|
52
|
+
}
|
|
53
|
+
$NodePath = $node.Source
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (-not $HostJs) {
|
|
57
|
+
$HostJs = (Resolve-Path (Join-Path $PSScriptRoot '..\dist\bin\host.js')).Path
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (-not (Test-Path $HostJs)) {
|
|
61
|
+
Write-Error "Cadre-host entry not found at $HostJs. Run 'yarn build' or set -HostJs."
|
|
62
|
+
exit 1
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (-not $DataDir) {
|
|
66
|
+
$DataDir = Join-Path $env:LocalAppData 'CadreHost'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
$LogDir = Join-Path $DataDir 'logs'
|
|
70
|
+
if (-not (Test-Path $LogDir)) {
|
|
71
|
+
New-Item -ItemType Directory -Path $LogDir -Force | Out-Null
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Remove any existing service so this script is idempotent.
|
|
75
|
+
$existing = & nssm.exe status $ServiceName 2>$null
|
|
76
|
+
if ($LASTEXITCODE -eq 0) {
|
|
77
|
+
Write-Host "Removing existing $ServiceName service..."
|
|
78
|
+
& nssm.exe stop $ServiceName confirm | Out-Null
|
|
79
|
+
& nssm.exe remove $ServiceName confirm | Out-Null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Write-Host "Installing $ServiceName service..."
|
|
83
|
+
|
|
84
|
+
# Use array-passed args so paths with spaces (e.g. "C:\Program Files\nodejs\node.exe")
|
|
85
|
+
# are quoted correctly.
|
|
86
|
+
$installArgs = @('install', $ServiceName, $NodePath, $HostJs, 'start', '--no-tui', '--data-dir', $DataDir)
|
|
87
|
+
& nssm.exe @installArgs
|
|
88
|
+
|
|
89
|
+
& nssm.exe set $ServiceName AppExit Default Restart
|
|
90
|
+
& nssm.exe set $ServiceName AppExit 0 Exit
|
|
91
|
+
& nssm.exe set $ServiceName AppRestartDelay 5000
|
|
92
|
+
& nssm.exe set $ServiceName AppThrottle 10000
|
|
93
|
+
& nssm.exe set $ServiceName AppStdout (Join-Path $LogDir 'out.log')
|
|
94
|
+
& nssm.exe set $ServiceName AppStderr (Join-Path $LogDir 'err.log')
|
|
95
|
+
& nssm.exe set $ServiceName AppRotateFiles 1
|
|
96
|
+
& nssm.exe set $ServiceName Start SERVICE_AUTO_START
|
|
97
|
+
|
|
98
|
+
Write-Host "Service installed. Start it with: nssm start $ServiceName"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<#
|
|
2
|
+
.SYNOPSIS
|
|
3
|
+
Uninstall the Cadre Host Windows service.
|
|
4
|
+
#>
|
|
5
|
+
|
|
6
|
+
[CmdletBinding()]
|
|
7
|
+
param()
|
|
8
|
+
|
|
9
|
+
$ErrorActionPreference = 'Stop'
|
|
10
|
+
$ServiceName = 'CadreHost'
|
|
11
|
+
|
|
12
|
+
$nssm = Get-Command nssm.exe -ErrorAction SilentlyContinue
|
|
13
|
+
if (-not $nssm) {
|
|
14
|
+
Write-Error 'nssm.exe not found on PATH. Install NSSM from https://nssm.cc/download.'
|
|
15
|
+
exit 1
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
& nssm.exe stop $ServiceName confirm 2>$null | Out-Null
|
|
19
|
+
& nssm.exe remove $ServiceName confirm
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI smoke test for the `invite` subcommand. Spawns a stub HTTP server
|
|
3
|
+
* playing the role of cadre-host's management API and asserts the CLI:
|
|
4
|
+
* - POSTs the expected body to /auth/invites
|
|
5
|
+
* - Prints the encodedInvite on stdout
|
|
6
|
+
* - Exits 0 on success / non-zero on connect failure
|
|
7
|
+
*
|
|
8
|
+
* Relies on `yarn build` having produced dist/bin/host.js.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { spawn } from 'node:child_process';
|
|
12
|
+
import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http';
|
|
13
|
+
import { existsSync } from 'node:fs';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { dirname, resolve } from 'node:path';
|
|
16
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
17
|
+
|
|
18
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const binPath = resolve(here, '../../dist/bin/host.js');
|
|
20
|
+
|
|
21
|
+
interface StubServer {
|
|
22
|
+
server: Server;
|
|
23
|
+
port: number;
|
|
24
|
+
requests: Array<{ method: string; url: string; body: string }>;
|
|
25
|
+
setResponse(handler: (req: IncomingMessage, res: ServerResponse) => void): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function startStub(): Promise<StubServer> {
|
|
29
|
+
const requests: StubServer['requests'] = [];
|
|
30
|
+
let handler: (req: IncomingMessage, res: ServerResponse) => void = (_req, res) => {
|
|
31
|
+
res.statusCode = 200;
|
|
32
|
+
res.setHeader('content-type', 'application/json');
|
|
33
|
+
res.end(JSON.stringify({
|
|
34
|
+
encodedInvite: 'fake-encoded-invite',
|
|
35
|
+
token: 'fake-token',
|
|
36
|
+
expiresAt: new Date(Date.now() + 60_000).toISOString(),
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const server = createServer((req, res) => {
|
|
41
|
+
const chunks: Buffer[] = [];
|
|
42
|
+
req.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
43
|
+
req.on('end', () => {
|
|
44
|
+
requests.push({ method: req.method ?? '', url: req.url ?? '', body: Buffer.concat(chunks).toString('utf8') });
|
|
45
|
+
handler(req, res);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await new Promise<void>((resolveStart) => server.listen(0, '127.0.0.1', () => resolveStart()));
|
|
50
|
+
const addr = server.address();
|
|
51
|
+
const port = typeof addr === 'object' && addr ? addr.port : 0;
|
|
52
|
+
return {
|
|
53
|
+
server,
|
|
54
|
+
port,
|
|
55
|
+
requests,
|
|
56
|
+
setResponse: (h) => { handler = h; },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function runCli(args: string[]): Promise<{ code: number; stdout: string; stderr: string }> {
|
|
61
|
+
return new Promise((resolveRun) => {
|
|
62
|
+
const child = spawn(process.execPath, [binPath, ...args], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
63
|
+
let stdout = '';
|
|
64
|
+
let stderr = '';
|
|
65
|
+
child.stdout.on('data', (chunk: Buffer) => { stdout += chunk.toString('utf8'); });
|
|
66
|
+
child.stderr.on('data', (chunk: Buffer) => { stderr += chunk.toString('utf8'); });
|
|
67
|
+
child.on('close', (code) => resolveRun({ code: code ?? -1, stdout, stderr }));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let stub: StubServer;
|
|
72
|
+
|
|
73
|
+
beforeEach(async () => {
|
|
74
|
+
if (!existsSync(binPath)) {
|
|
75
|
+
throw new Error(`cadre-host bin not built at ${binPath}; run \`yarn build\` first`);
|
|
76
|
+
}
|
|
77
|
+
stub = await startStub();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(async () => {
|
|
81
|
+
await new Promise<void>((resolveClose) => stub.server.close(() => resolveClose()));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('cadre-host invite CLI', () => {
|
|
85
|
+
it('POSTs to /auth/invites with label + ttlMs and prints encoded invite', async () => {
|
|
86
|
+
const result = await runCli(['invite', "Mom's phone", '--ttl', '12h', '--port', String(stub.port)]);
|
|
87
|
+
|
|
88
|
+
expect(result.code).toBe(0);
|
|
89
|
+
expect(result.stdout.trim()).toBe('fake-encoded-invite');
|
|
90
|
+
expect(stub.requests).toHaveLength(1);
|
|
91
|
+
expect(stub.requests[0]!.method).toBe('POST');
|
|
92
|
+
expect(stub.requests[0]!.url).toBe('/auth/invites');
|
|
93
|
+
const body = JSON.parse(stub.requests[0]!.body);
|
|
94
|
+
expect(body.label).toBe("Mom's phone");
|
|
95
|
+
expect(body.ttlMs).toBe(12 * 60 * 60 * 1000);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('exits non-zero when cadre-host returns an error', async () => {
|
|
99
|
+
stub.setResponse((_req, res) => {
|
|
100
|
+
res.statusCode = 500;
|
|
101
|
+
res.end('boom');
|
|
102
|
+
});
|
|
103
|
+
const result = await runCli(['invite', 'Test', '--port', String(stub.port)]);
|
|
104
|
+
expect(result.code).not.toBe(0);
|
|
105
|
+
expect(result.stderr).toContain('500');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('exits 2 (no service) when cadre-host is not reachable', async () => {
|
|
109
|
+
// Use a port the stub server occupied; close it first so connections fail.
|
|
110
|
+
const port = stub.port;
|
|
111
|
+
await new Promise<void>((resolveClose) => stub.server.close(() => resolveClose()));
|
|
112
|
+
const result = await runCli(['invite', 'Test', '--port', String(port)]);
|
|
113
|
+
expect(result.code).toBe(2);
|
|
114
|
+
expect(result.stderr).toMatch(/cadre-host start|Failed to reach/);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('rejects invalid --ttl', async () => {
|
|
118
|
+
const result = await runCli(['invite', 'Test', '--ttl', 'eternity', '--port', String(stub.port)]);
|
|
119
|
+
expect(result.code).toBe(1);
|
|
120
|
+
expect(result.stderr).toMatch(/Invalid --ttl/);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('cadre-host trust list CLI', () => {
|
|
125
|
+
it('renders members and pending invites', async () => {
|
|
126
|
+
stub.setResponse((_req, res) => {
|
|
127
|
+
res.statusCode = 200;
|
|
128
|
+
res.setHeader('content-type', 'application/json');
|
|
129
|
+
res.end(JSON.stringify({
|
|
130
|
+
members: [
|
|
131
|
+
{ peerId: '12D3KooWAlice', label: 'Alice', addedAt: 't1' },
|
|
132
|
+
{ peerId: '12D3KooWHost', label: 'Host', addedAt: 't2', self: true },
|
|
133
|
+
],
|
|
134
|
+
pending: [
|
|
135
|
+
{ token: 'tok1', label: 'Mom', createdAt: 't3', expiresAt: 't4' },
|
|
136
|
+
],
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const result = await runCli(['trust', 'list', '--port', String(stub.port)]);
|
|
141
|
+
expect(result.code).toBe(0);
|
|
142
|
+
expect(result.stdout).toContain('12D3KooWAlice');
|
|
143
|
+
expect(result.stdout).toContain('Alice');
|
|
144
|
+
expect(result.stdout).toContain('[self]');
|
|
145
|
+
expect(result.stdout).toContain('tok1');
|
|
146
|
+
expect(result.stdout).toContain('Mom');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('cadre-host trust revoke CLI', () => {
|
|
151
|
+
it('DELETEs /auth/invites/<token> by default', async () => {
|
|
152
|
+
stub.setResponse((_req, res) => {
|
|
153
|
+
res.statusCode = 204;
|
|
154
|
+
res.end();
|
|
155
|
+
});
|
|
156
|
+
const result = await runCli(['trust', 'revoke', 'some-token', '--port', String(stub.port)]);
|
|
157
|
+
expect(result.code).toBe(0);
|
|
158
|
+
expect(stub.requests[0]!.method).toBe('DELETE');
|
|
159
|
+
expect(stub.requests[0]!.url).toBe('/auth/invites/some-token');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('DELETEs /auth/members/<peerId> when id looks like a peerId', async () => {
|
|
163
|
+
stub.setResponse((_req, res) => {
|
|
164
|
+
res.statusCode = 204;
|
|
165
|
+
res.end();
|
|
166
|
+
});
|
|
167
|
+
const result = await runCli(['trust', 'revoke', '12D3KooWAlice', '--port', String(stub.port)]);
|
|
168
|
+
expect(result.code).toBe(0);
|
|
169
|
+
expect(stub.requests[0]!.url).toBe('/auth/members/12D3KooWAlice');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('treats secp256k1 peer IDs (16Uiu2HAm…) as members', async () => {
|
|
173
|
+
stub.setResponse((_req, res) => {
|
|
174
|
+
res.statusCode = 204;
|
|
175
|
+
res.end();
|
|
176
|
+
});
|
|
177
|
+
const result = await runCli(['trust', 'revoke', '16Uiu2HAmExample', '--port', String(stub.port)]);
|
|
178
|
+
expect(result.code).toBe(0);
|
|
179
|
+
expect(stub.requests[0]!.url).toBe('/auth/members/16Uiu2HAmExample');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('rejects invalid --port', async () => {
|
|
183
|
+
const result = await runCli(['trust', 'revoke', 'some-token', '--port', 'garbage']);
|
|
184
|
+
expect(result.code).toBe(1);
|
|
185
|
+
expect(result.stderr).toMatch(/Invalid --port/);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI smoke test for the `nat` subcommand. Spawns a stub HTTP server playing
|
|
3
|
+
* the role of cadre-host's management API and asserts the CLI:
|
|
4
|
+
* - GETs /nat/status
|
|
5
|
+
* - POSTs /nat/test
|
|
6
|
+
* - PUTs /nat/ddns with the expected body
|
|
7
|
+
* - PUTs /nat/settings
|
|
8
|
+
* - Exits non-zero when the host is not reachable
|
|
9
|
+
*
|
|
10
|
+
* Relies on `yarn build` having produced dist/bin/host.js.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { spawn } from 'node:child_process';
|
|
14
|
+
import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http';
|
|
15
|
+
import { existsSync } from 'node:fs';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { dirname, resolve } from 'node:path';
|
|
18
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
19
|
+
|
|
20
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const binPath = resolve(here, '../../dist/bin/host.js');
|
|
22
|
+
|
|
23
|
+
interface StubServer {
|
|
24
|
+
server: Server;
|
|
25
|
+
port: number;
|
|
26
|
+
requests: Array<{ method: string; url: string; body: string }>;
|
|
27
|
+
setResponse(handler: (req: IncomingMessage, res: ServerResponse) => void): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DEFAULT_STATUS = {
|
|
31
|
+
portMode: 'auto-upnp',
|
|
32
|
+
externalPort: 4001,
|
|
33
|
+
internalPort: 4001,
|
|
34
|
+
routerExternalIp: '203.0.113.5',
|
|
35
|
+
mappingLeaseExpiresAt: null,
|
|
36
|
+
externalIp: '203.0.113.5',
|
|
37
|
+
externalIpDetectedAt: new Date().toISOString(),
|
|
38
|
+
cgnatDetected: false,
|
|
39
|
+
directReachability: 'reachable',
|
|
40
|
+
lastTestedAt: null,
|
|
41
|
+
ddns: {
|
|
42
|
+
providerId: 'duckdns',
|
|
43
|
+
hostname: 'foo.duckdns.org',
|
|
44
|
+
externallyManaged: false,
|
|
45
|
+
lastUpdateAt: null,
|
|
46
|
+
lastUpdateOk: null,
|
|
47
|
+
lastError: null,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
async function startStub(): Promise<StubServer> {
|
|
52
|
+
const requests: StubServer['requests'] = [];
|
|
53
|
+
let handler: (req: IncomingMessage, res: ServerResponse) => void = (_req, res) => {
|
|
54
|
+
res.statusCode = 200;
|
|
55
|
+
res.setHeader('content-type', 'application/json');
|
|
56
|
+
res.end(JSON.stringify(DEFAULT_STATUS));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const server = createServer((req, res) => {
|
|
60
|
+
const chunks: Buffer[] = [];
|
|
61
|
+
req.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
62
|
+
req.on('end', () => {
|
|
63
|
+
requests.push({ method: req.method ?? '', url: req.url ?? '', body: Buffer.concat(chunks).toString('utf8') });
|
|
64
|
+
handler(req, res);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await new Promise<void>((resolveStart) => server.listen(0, '127.0.0.1', () => resolveStart()));
|
|
69
|
+
const addr = server.address();
|
|
70
|
+
const port = typeof addr === 'object' && addr ? addr.port : 0;
|
|
71
|
+
return {
|
|
72
|
+
server,
|
|
73
|
+
port,
|
|
74
|
+
requests,
|
|
75
|
+
setResponse: (h) => { handler = h; },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function runCli(args: string[]): Promise<{ code: number; stdout: string; stderr: string }> {
|
|
80
|
+
return new Promise((resolveRun) => {
|
|
81
|
+
const child = spawn(process.execPath, [binPath, ...args], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
82
|
+
let stdout = '';
|
|
83
|
+
let stderr = '';
|
|
84
|
+
child.stdout.on('data', (chunk: Buffer) => { stdout += chunk.toString('utf8'); });
|
|
85
|
+
child.stderr.on('data', (chunk: Buffer) => { stderr += chunk.toString('utf8'); });
|
|
86
|
+
child.on('close', (code) => resolveRun({ code: code ?? -1, stdout, stderr }));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let stub: StubServer;
|
|
91
|
+
|
|
92
|
+
beforeEach(async () => {
|
|
93
|
+
if (!existsSync(binPath)) {
|
|
94
|
+
throw new Error(`cadre-host bin not built at ${binPath}; run \`yarn build\` first`);
|
|
95
|
+
}
|
|
96
|
+
stub = await startStub();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
afterEach(async () => {
|
|
100
|
+
await new Promise<void>((resolveClose) => stub.server.close(() => resolveClose()));
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('cadre-host nat status', () => {
|
|
104
|
+
it('GETs /nat/status and renders the snapshot', async () => {
|
|
105
|
+
const result = await runCli(['nat', 'status', '--port', String(stub.port)]);
|
|
106
|
+
expect(result.code).toBe(0);
|
|
107
|
+
expect(stub.requests).toHaveLength(1);
|
|
108
|
+
expect(stub.requests[0]!.method).toBe('GET');
|
|
109
|
+
expect(stub.requests[0]!.url).toBe('/nat/status');
|
|
110
|
+
expect(result.stdout).toContain('auto-upnp');
|
|
111
|
+
expect(result.stdout).toContain('203.0.113.5');
|
|
112
|
+
expect(result.stdout).toContain('foo.duckdns.org');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('--json prints raw JSON', async () => {
|
|
116
|
+
const result = await runCli(['nat', 'status', '--port', String(stub.port), '--json']);
|
|
117
|
+
expect(result.code).toBe(0);
|
|
118
|
+
const parsed = JSON.parse(result.stdout);
|
|
119
|
+
expect(parsed.portMode).toBe('auto-upnp');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('exits 2 when cadre-host is unreachable', async () => {
|
|
123
|
+
const port = stub.port;
|
|
124
|
+
await new Promise<void>((resolveClose) => stub.server.close(() => resolveClose()));
|
|
125
|
+
const result = await runCli(['nat', 'status', '--port', String(port)]);
|
|
126
|
+
expect(result.code).toBe(2);
|
|
127
|
+
expect(result.stderr).toMatch(/cadre-host start|Failed to reach/);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('cadre-host nat test', () => {
|
|
132
|
+
it('POSTs /nat/test', async () => {
|
|
133
|
+
const result = await runCli(['nat', 'test', '--port', String(stub.port)]);
|
|
134
|
+
expect(result.code).toBe(0);
|
|
135
|
+
expect(stub.requests[0]!.method).toBe('POST');
|
|
136
|
+
expect(stub.requests[0]!.url).toBe('/nat/test');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('cadre-host nat ddns set', () => {
|
|
141
|
+
it('PUTs /nat/ddns with provider + hostname + token', async () => {
|
|
142
|
+
const result = await runCli([
|
|
143
|
+
'nat', 'ddns', 'set', 'duckdns',
|
|
144
|
+
'--hostname', 'foo.duckdns.org',
|
|
145
|
+
'--token', 'TOK',
|
|
146
|
+
'--port', String(stub.port),
|
|
147
|
+
]);
|
|
148
|
+
expect(result.code).toBe(0);
|
|
149
|
+
expect(stub.requests[0]!.method).toBe('PUT');
|
|
150
|
+
expect(stub.requests[0]!.url).toBe('/nat/ddns');
|
|
151
|
+
const body = JSON.parse(stub.requests[0]!.body);
|
|
152
|
+
expect(body.providerId).toBe('duckdns');
|
|
153
|
+
expect(body.hostname).toBe('foo.duckdns.org');
|
|
154
|
+
expect(body.config).toEqual({ token: 'TOK' });
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('exits 1 when --hostname is missing', async () => {
|
|
158
|
+
const result = await runCli([
|
|
159
|
+
'nat', 'ddns', 'set', 'duckdns',
|
|
160
|
+
'--token', 'TOK',
|
|
161
|
+
'--port', String(stub.port),
|
|
162
|
+
]);
|
|
163
|
+
expect(result.code).toBe(1);
|
|
164
|
+
expect(result.stderr).toMatch(/--hostname/);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('exits 1 when --token is missing on a non-TTY stdin', async () => {
|
|
168
|
+
const result = await runCli([
|
|
169
|
+
'nat', 'ddns', 'set', 'duckdns',
|
|
170
|
+
'--hostname', 'foo.duckdns.org',
|
|
171
|
+
'--port', String(stub.port),
|
|
172
|
+
]);
|
|
173
|
+
expect(result.code).toBe(1);
|
|
174
|
+
expect(result.stderr).toMatch(/--token/);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('cadre-host nat ddns external', () => {
|
|
179
|
+
it('PUTs /nat/settings with externallyManaged=true', async () => {
|
|
180
|
+
const result = await runCli([
|
|
181
|
+
'nat', 'ddns', 'external',
|
|
182
|
+
'--hostname', 'mydomain.example.com',
|
|
183
|
+
'--port', String(stub.port),
|
|
184
|
+
]);
|
|
185
|
+
expect(result.code).toBe(0);
|
|
186
|
+
expect(stub.requests[0]!.method).toBe('PUT');
|
|
187
|
+
expect(stub.requests[0]!.url).toBe('/nat/settings');
|
|
188
|
+
const body = JSON.parse(stub.requests[0]!.body);
|
|
189
|
+
expect(body.ddns.hostname).toBe('mydomain.example.com');
|
|
190
|
+
expect(body.ddns.externallyManaged).toBe(true);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('cadre-host nat settings', () => {
|
|
195
|
+
it('PUTs /nat/settings with --external-port and --no-upnp', async () => {
|
|
196
|
+
const result = await runCli([
|
|
197
|
+
'nat', 'settings',
|
|
198
|
+
'--external-port', '4002',
|
|
199
|
+
'--no-upnp',
|
|
200
|
+
'--port', String(stub.port),
|
|
201
|
+
]);
|
|
202
|
+
expect(result.code).toBe(0);
|
|
203
|
+
const body = JSON.parse(stub.requests[0]!.body);
|
|
204
|
+
expect(body.externalPort).toBe(4002);
|
|
205
|
+
expect(body.upnpEnabled).toBe(false);
|
|
206
|
+
});
|
|
207
|
+
});
|