@serfab/cadre-host 1.13.0 → 1.14.0
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 +332 -423
- package/dist/bin/host.d.ts +6 -3
- package/dist/bin/host.js +301 -505
- package/dist/bin/host.js.map +1 -1
- package/dist/bin/join-output.d.ts +56 -0
- package/dist/bin/join-output.js +92 -0
- package/dist/bin/join-output.js.map +1 -0
- package/dist/bin/nat-output.d.ts +49 -0
- package/dist/bin/nat-output.js +127 -0
- package/dist/bin/nat-output.js.map +1 -0
- package/dist/hosted/claim-details.d.ts +44 -0
- package/dist/hosted/claim-details.js +66 -0
- package/dist/hosted/claim-details.js.map +1 -0
- package/dist/hosted/hosted-node-service.d.ts +318 -0
- package/dist/hosted/hosted-node-service.js +666 -0
- package/dist/hosted/hosted-node-service.js.map +1 -0
- package/dist/hosted/hosted-node-store.d.ts +40 -0
- package/dist/hosted/hosted-node-store.js +126 -0
- package/dist/hosted/hosted-node-store.js.map +1 -0
- package/dist/{donation/donation-supervisor.d.ts → hosted/hosted-node-supervisor.d.ts} +70 -53
- package/dist/hosted/hosted-node-supervisor.js +396 -0
- package/dist/hosted/hosted-node-supervisor.js.map +1 -0
- package/dist/hosted/hosted-node-watcher.d.ts +83 -0
- package/dist/hosted/hosted-node-watcher.js +224 -0
- package/dist/hosted/hosted-node-watcher.js.map +1 -0
- package/dist/hosted/index.d.ts +16 -0
- package/dist/hosted/index.js +13 -0
- package/dist/hosted/index.js.map +1 -0
- package/dist/hosted/node-status.d.ts +35 -0
- package/dist/hosted/node-status.js +61 -0
- package/dist/hosted/node-status.js.map +1 -0
- package/dist/hosted/types.d.ts +134 -0
- package/dist/hosted/types.js +22 -0
- package/dist/hosted/types.js.map +1 -0
- package/dist/index.d.ts +12 -24
- package/dist/index.js +9 -19
- package/dist/index.js.map +1 -1
- package/dist/installer/config.d.ts +4 -34
- package/dist/installer/config.js +3 -18
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/index.d.ts +7 -19
- package/dist/installer/index.js +14 -69
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/paths.d.ts +0 -2
- package/dist/installer/paths.js +0 -4
- package/dist/installer/paths.js.map +1 -1
- package/dist/installer/wizard.d.ts +0 -7
- package/dist/installer/wizard.js +1 -8
- package/dist/installer/wizard.js.map +1 -1
- package/dist/nat/address-resolver.d.ts +18 -17
- package/dist/nat/address-resolver.js +79 -25
- package/dist/nat/address-resolver.js.map +1 -1
- package/dist/nat/address-watch.d.ts +37 -0
- package/dist/nat/address-watch.js +84 -0
- package/dist/nat/address-watch.js.map +1 -0
- package/dist/nat/ddns/duckdns.d.ts +2 -1
- package/dist/nat/ddns/duckdns.js +5 -1
- package/dist/nat/ddns/duckdns.js.map +1 -1
- package/dist/nat/ddns/index.d.ts +6 -0
- package/dist/nat/ddns/index.js.map +1 -1
- package/dist/nat/index.d.ts +12 -9
- package/dist/nat/index.js +6 -5
- package/dist/nat/index.js.map +1 -1
- package/dist/nat/nat-service.d.ts +203 -77
- package/dist/nat/nat-service.js +602 -237
- package/dist/nat/nat-service.js.map +1 -1
- package/dist/nat/nat-store.d.ts +12 -5
- package/dist/nat/nat-store.js +114 -30
- package/dist/nat/nat-store.js.map +1 -1
- package/dist/nat/port-mapper.d.ts +83 -79
- package/dist/nat/port-mapper.js +148 -189
- package/dist/nat/port-mapper.js.map +1 -1
- package/dist/nat/reachability.d.ts +31 -15
- package/dist/nat/reachability.js +97 -22
- package/dist/nat/reachability.js.map +1 -1
- package/dist/nat/types.d.ts +78 -27
- package/dist/nat/types.js +8 -5
- package/dist/nat/types.js.map +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +29 -71
- package/dist/orchestrator/host-process-orchestrator.js +78 -218
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/{installer/identity.d.ts → orchestrator/identity-file.d.ts} +5 -5
- package/dist/{installer/identity.js → orchestrator/identity-file.js} +6 -6
- package/dist/orchestrator/identity-file.js.map +1 -0
- package/dist/orchestrator/index.d.ts +2 -3
- package/dist/orchestrator/index.js +1 -1
- package/dist/orchestrator/index.js.map +1 -1
- package/dist/orchestrator/node-identity.d.ts +6 -6
- package/dist/orchestrator/node-identity.js +7 -7
- package/dist/orchestrator/node-identity.js.map +1 -1
- package/dist/orchestrator/port-allocator.d.ts +5 -6
- package/dist/orchestrator/port-allocator.js +9 -11
- package/dist/orchestrator/port-allocator.js.map +1 -1
- package/dist/orchestrator/state-store.d.ts +3 -5
- package/dist/orchestrator/state-store.js +2 -10
- package/dist/orchestrator/state-store.js.map +1 -1
- package/dist/orchestrator/types.d.ts +33 -22
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/server/error-handler.d.ts +5 -25
- package/dist/server/error-handler.js +11 -74
- package/dist/server/error-handler.js.map +1 -1
- package/dist/server/events/types.d.ts +7 -11
- package/dist/server/events/types.js +2 -1
- package/dist/server/events/types.js.map +1 -1
- package/dist/server/index.d.ts +11 -37
- package/dist/server/index.js +30 -48
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes/hosted-nodes.d.ts +28 -0
- package/dist/server/routes/hosted-nodes.js +68 -0
- package/dist/server/routes/hosted-nodes.js.map +1 -0
- package/dist/server/routes/nat.d.ts +4 -1
- package/dist/server/routes/nat.js +13 -2
- package/dist/server/routes/nat.js.map +1 -1
- package/dist/server/routes/nodes.d.ts +6 -20
- package/dist/server/routes/nodes.js +7 -86
- package/dist/server/routes/nodes.js.map +1 -1
- package/dist/server/routes/settings.d.ts +2 -7
- package/dist/server/routes/settings.js +3 -7
- package/dist/server/routes/settings.js.map +1 -1
- package/dist/server/routes/status.d.ts +2 -25
- package/dist/server/routes/status.js +1 -11
- package/dist/server/routes/status.js.map +1 -1
- package/dist/server/server.js +8 -8
- package/dist/server/settings-store.d.ts +2 -2
- package/dist/server/settings-store.js +2 -2
- package/dist/server/static.js +1 -2
- package/dist/server/static.js.map +1 -1
- package/dist/ui/assets/index-4FWuU8ye.js +19 -0
- package/dist/ui/assets/index-4FWuU8ye.js.map +1 -0
- package/dist/ui/assets/index-Di9Q4d01.css +1 -0
- package/dist/ui/index.html +2 -2
- package/dist/update/index.d.ts +2 -2
- package/dist/update/index.js +2 -2
- package/dist/update/store.d.ts +1 -1
- package/dist/update/store.js +1 -1
- package/dist/update/types.d.ts +1 -1
- package/dist/update/types.js +1 -1
- package/package.json +5 -6
- package/src/__tests__/cli-nat.smoke.test.ts +219 -212
- package/src/__tests__/cli.smoke.test.ts +1 -1
- package/src/__tests__/global-setup.ts +2 -3
- package/src/__tests__/orchestrator-claim-secret.test.ts +112 -0
- package/src/__tests__/orchestrator-handle-contract.ts +134 -134
- package/src/__tests__/orchestrator-node-identity.test.ts +182 -203
- package/src/__tests__/orchestrator-ports.test.ts +124 -143
- package/src/__tests__/orchestrator-push.test.ts +138 -146
- package/src/__tests__/orchestrator.test.ts +1019 -1063
- package/src/bin/host.ts +368 -553
- package/src/bin/join-output.ts +120 -0
- package/src/bin/nat-output.ts +177 -0
- package/src/{donation → hosted}/__tests__/fake-orchestrator.test.ts +173 -173
- package/src/{donation → hosted}/__tests__/fake-orchestrator.ts +265 -243
- package/src/hosted/__tests__/hosted-node-service.test.ts +609 -0
- package/src/hosted/__tests__/hosted-node-supervisor.test.ts +474 -0
- package/src/hosted/__tests__/test-invitation.ts +33 -0
- package/src/hosted/claim-details.ts +96 -0
- package/src/hosted/hosted-node-service.ts +795 -0
- package/src/hosted/hosted-node-store.ts +144 -0
- package/src/hosted/hosted-node-supervisor.ts +439 -0
- package/src/hosted/hosted-node-watcher.ts +250 -0
- package/src/hosted/index.ts +53 -0
- package/src/hosted/node-status.ts +71 -0
- package/src/hosted/types.ts +153 -0
- package/src/index.ts +72 -91
- package/src/installer/__tests__/config.test.ts +15 -40
- package/src/installer/__tests__/installer.smoke.test.ts +5 -86
- package/src/installer/__tests__/wizard.test.ts +56 -64
- package/src/installer/config.ts +135 -175
- package/src/installer/index.ts +15 -83
- package/src/installer/paths.ts +104 -109
- package/src/installer/wizard.ts +87 -103
- package/src/nat/__tests__/address-resolver.test.ts +107 -82
- package/src/nat/__tests__/nat-service.test.ts +433 -408
- package/src/nat/__tests__/nat-store.test.ts +127 -93
- package/src/nat/__tests__/port-mapper.test.ts +30 -191
- package/src/nat/__tests__/reachability.test.ts +96 -13
- package/src/nat/address-resolver.ts +94 -52
- package/src/nat/address-watch.ts +92 -0
- package/src/nat/ddns/duckdns.ts +5 -1
- package/src/nat/ddns/index.ts +6 -0
- package/src/nat/index.ts +87 -71
- package/src/nat/nat-service.ts +889 -501
- package/src/nat/nat-store.ts +237 -154
- package/src/nat/port-mapper.ts +241 -329
- package/src/nat/reachability.ts +134 -25
- package/src/nat/types.ts +209 -159
- package/src/{installer/__tests__/identity.test.ts → orchestrator/__tests__/identity-file.test.ts} +34 -34
- package/src/orchestrator/__tests__/node-identity.test.ts +62 -62
- package/src/orchestrator/host-process-orchestrator.ts +81 -243
- package/src/{installer/identity.ts → orchestrator/identity-file.ts} +56 -56
- package/src/orchestrator/index.ts +9 -10
- package/src/orchestrator/node-identity.ts +41 -41
- package/src/orchestrator/port-allocator.ts +71 -73
- package/src/orchestrator/state-store.ts +76 -90
- package/src/orchestrator/types.ts +34 -23
- package/src/server/__tests__/bus.test.ts +38 -38
- package/src/server/__tests__/error-handler.test.ts +81 -118
- package/src/server/__tests__/fakes.ts +40 -44
- package/src/server/__tests__/hosted-nodes-route.test.ts +160 -0
- package/src/server/__tests__/nodes-route.test.ts +114 -283
- package/src/server/__tests__/publishers.test.ts +193 -180
- package/src/server/__tests__/server.smoke.test.ts +134 -223
- package/src/server/__tests__/settings-route.test.ts +179 -195
- package/src/server/__tests__/sse-route.test.ts +119 -119
- package/src/server/__tests__/status-route.test.ts +82 -121
- package/src/server/error-handler.ts +112 -178
- package/src/server/events/types.ts +20 -24
- package/src/server/index.ts +223 -267
- package/src/server/routes/hosted-nodes.ts +83 -0
- package/src/server/routes/nat.ts +75 -63
- package/src/server/routes/nodes.ts +96 -188
- package/src/server/routes/settings.ts +115 -123
- package/src/server/routes/status.ts +102 -134
- package/src/server/server.ts +8 -8
- package/src/server/settings-store.ts +2 -2
- package/src/server/static.ts +1 -2
- package/src/update/index.ts +2 -2
- package/src/update/store.ts +1 -1
- package/src/update/types.ts +1 -1
- package/dist/auth/duration.d.ts +0 -1
- package/dist/auth/duration.js +0 -32
- package/dist/auth/duration.js.map +0 -1
- package/dist/auth/index.d.ts +0 -11
- package/dist/auth/index.js +0 -9
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/self-label.d.ts +0 -36
- package/dist/auth/self-label.js +0 -57
- package/dist/auth/self-label.js.map +0 -1
- package/dist/auth/trust-circle-store.d.ts +0 -26
- package/dist/auth/trust-circle-store.js +0 -129
- package/dist/auth/trust-circle-store.js.map +0 -1
- package/dist/auth/trust-circle.d.ts +0 -156
- package/dist/auth/trust-circle.js +0 -307
- package/dist/auth/trust-circle.js.map +0 -1
- package/dist/auth/types.d.ts +0 -84
- package/dist/auth/types.js +0 -24
- package/dist/auth/types.js.map +0 -1
- package/dist/donation/donation-service.d.ts +0 -389
- package/dist/donation/donation-service.js +0 -828
- package/dist/donation/donation-service.js.map +0 -1
- package/dist/donation/donation-store.d.ts +0 -51
- package/dist/donation/donation-store.js +0 -152
- package/dist/donation/donation-store.js.map +0 -1
- package/dist/donation/donation-supervisor.js +0 -364
- package/dist/donation/donation-supervisor.js.map +0 -1
- package/dist/donation/grant-service.d.ts +0 -80
- package/dist/donation/grant-service.js +0 -210
- package/dist/donation/grant-service.js.map +0 -1
- package/dist/donation/grant-store.d.ts +0 -38
- package/dist/donation/grant-store.js +0 -135
- package/dist/donation/grant-store.js.map +0 -1
- package/dist/donation/index.d.ts +0 -20
- package/dist/donation/index.js +0 -17
- package/dist/donation/index.js.map +0 -1
- package/dist/donation/types.d.ts +0 -224
- package/dist/donation/types.js +0 -40
- package/dist/donation/types.js.map +0 -1
- package/dist/installer/identity.js.map +0 -1
- package/dist/owner/index.d.ts +0 -11
- package/dist/owner/index.js +0 -11
- package/dist/owner/index.js.map +0 -1
- package/dist/owner/owner-node-client.d.ts +0 -110
- package/dist/owner/owner-node-client.js +0 -184
- package/dist/owner/owner-node-client.js.map +0 -1
- package/dist/server/routes/bootstrap-node-validation.d.ts +0 -115
- package/dist/server/routes/bootstrap-node-validation.js +0 -197
- package/dist/server/routes/bootstrap-node-validation.js.map +0 -1
- package/dist/server/routes/grants-admin.d.ts +0 -29
- package/dist/server/routes/grants-admin.js +0 -58
- package/dist/server/routes/grants-admin.js.map +0 -1
- package/dist/server/routes/grants.d.ts +0 -28
- package/dist/server/routes/grants.js +0 -165
- package/dist/server/routes/grants.js.map +0 -1
- package/dist/server/routes/provision-request-validation.d.ts +0 -45
- package/dist/server/routes/provision-request-validation.js +0 -97
- package/dist/server/routes/provision-request-validation.js.map +0 -1
- package/dist/server/routes/strands.d.ts +0 -20
- package/dist/server/routes/strands.js +0 -38
- package/dist/server/routes/strands.js.map +0 -1
- package/dist/server/routes/trust-circle.d.ts +0 -17
- package/dist/server/routes/trust-circle.js +0 -35
- package/dist/server/routes/trust-circle.js.map +0 -1
- package/dist/strands/index.d.ts +0 -7
- package/dist/strands/index.js +0 -6
- package/dist/strands/index.js.map +0 -1
- package/dist/strands/strand-service.d.ts +0 -50
- package/dist/strands/strand-service.js +0 -103
- package/dist/strands/strand-service.js.map +0 -1
- package/dist/strands/types.d.ts +0 -93
- package/dist/strands/types.js +0 -23
- package/dist/strands/types.js.map +0 -1
- package/dist/ui/assets/index-C6nELNfC.js +0 -23
- package/dist/ui/assets/index-C6nELNfC.js.map +0 -1
- package/dist/ui/assets/index-TtIYSeZO.css +0 -1
- package/src/__tests__/cli-invite.smoke.test.ts +0 -192
- package/src/__tests__/host-owner.smoke.test.ts +0 -123
- package/src/__tests__/orchestrator-owner.test.ts +0 -234
- package/src/__tests__/orchestrator-pin-keys.test.ts +0 -152
- package/src/auth/__tests__/duration.test.ts +0 -28
- package/src/auth/__tests__/self-label.test.ts +0 -85
- package/src/auth/__tests__/trust-circle-integration.test.ts +0 -152
- package/src/auth/__tests__/trust-circle-store.test.ts +0 -115
- package/src/auth/__tests__/trust-circle.test.ts +0 -445
- package/src/auth/duration.ts +0 -33
- package/src/auth/index.ts +0 -21
- package/src/auth/self-label.ts +0 -74
- package/src/auth/trust-circle-store.ts +0 -155
- package/src/auth/trust-circle.ts +0 -395
- package/src/auth/types.ts +0 -99
- package/src/donation/__tests__/donation-service.test.ts +0 -1193
- package/src/donation/__tests__/donation-supervisor.test.ts +0 -548
- package/src/donation/__tests__/grant-service.test.ts +0 -213
- package/src/donation/__tests__/grant-store.test.ts +0 -113
- package/src/donation/donation-service.ts +0 -1033
- package/src/donation/donation-store.ts +0 -176
- package/src/donation/donation-supervisor.ts +0 -411
- package/src/donation/grant-service.ts +0 -252
- package/src/donation/grant-store.ts +0 -152
- package/src/donation/index.ts +0 -65
- package/src/donation/types.ts +0 -260
- package/src/owner/__tests__/owner-node-client.test.ts +0 -194
- package/src/owner/index.ts +0 -12
- package/src/owner/owner-node-client.ts +0 -259
- package/src/server/__tests__/bootstrap-node-validation.test.ts +0 -138
- package/src/server/__tests__/grants-admin-route.test.ts +0 -171
- package/src/server/__tests__/grants-route.test.ts +0 -394
- package/src/server/__tests__/strands-route.test.ts +0 -234
- package/src/server/routes/bootstrap-node-validation.ts +0 -206
- package/src/server/routes/grants-admin.ts +0 -74
- package/src/server/routes/grants.ts +0 -193
- package/src/server/routes/provision-request-validation.ts +0 -105
- package/src/server/routes/strands.ts +0 -54
- package/src/server/routes/trust-circle.ts +0 -49
- package/src/strands/__tests__/strand-service.test.ts +0 -165
- package/src/strands/index.ts +0 -14
- package/src/strands/strand-service.ts +0 -135
- package/src/strands/types.ts +0 -102
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP client for the owner node's loopback admin channel (the 6.6
|
|
3
|
-
* `cadre-node-admin-channel` contract).
|
|
4
|
-
*
|
|
5
|
-
* cadre-host's manager process holds no in-process `CadreNode`; it spawns the
|
|
6
|
-
* admin's owner node as a managed child (see `HostProcessOrchestrator`)
|
|
7
|
-
* and delegates all owner/membership/identity operations to it over this
|
|
8
|
-
* client. The client implements **all three** trimmed `CadreNodeLike`
|
|
9
|
-
* interfaces — the trust-circle one (`auth/trust-circle.ts`), the NAT one
|
|
10
|
-
* (`nat/nat-service.ts`), and the strand one (`strands/strand-service.ts`) —
|
|
11
|
-
* plus `pushInviteAddresses` and `addDrone` (the node-donation requester side).
|
|
12
|
-
*
|
|
13
|
-
* Transport: `Authorization: Bearer <token>` against
|
|
14
|
-
* `http://127.0.0.1:<adminPort>`. Every response uses the cadre-provider
|
|
15
|
-
* envelope `{ ok: true, data }` / `{ ok: false, error: { code, message } }`.
|
|
16
|
-
* A refused connection, a transport error, or any non-2xx response surfaces
|
|
17
|
-
* as {@link OwnerNodeUnavailableError}; the trust-circle / NAT services
|
|
18
|
-
* translate that into a `node_unavailable` domain error so the management API
|
|
19
|
-
* returns a clear 503 rather than a raw 500.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import debug from 'debug';
|
|
23
|
-
import type { CadreInvite, DroneInitResult } from '@serfab/cadre-core';
|
|
24
|
-
|
|
25
|
-
import type { OwnerAdminEndpoint } from '../orchestrator/index.js';
|
|
26
|
-
import type { CadreNodeLike as TrustCircleCadreNodeLike } from '../auth/trust-circle.js';
|
|
27
|
-
import type { CadreNodeLike as NatCadreNodeLike } from '../nat/nat-service.js';
|
|
28
|
-
import type { CadreNodeLike as StrandCadreNodeLike } from '../strands/strand-service.js';
|
|
29
|
-
import type { StrandListSnapshot, StrandRemovalResult } from '../strands/types.js';
|
|
30
|
-
|
|
31
|
-
const log = debug('cadre:host:owner-client');
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Raised when the owner node's admin channel can't be reached or returns
|
|
35
|
-
* a non-success response. Carries the node's stable error `code` when one was
|
|
36
|
-
* present in the envelope (e.g. `not_ready`, `not_authorized`).
|
|
37
|
-
*/
|
|
38
|
-
export class OwnerNodeUnavailableError extends Error {
|
|
39
|
-
/** The admin-channel error code, when the node answered with an envelope. */
|
|
40
|
-
readonly nodeCode?: string;
|
|
41
|
-
|
|
42
|
-
constructor(message: string, nodeCode?: string) {
|
|
43
|
-
super(message);
|
|
44
|
-
this.name = 'OwnerNodeUnavailableError';
|
|
45
|
-
if (nodeCode !== undefined) this.nodeCode = nodeCode;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Endpoint provided directly or via a getter (so it tracks re-spawns). */
|
|
50
|
-
type EndpointSource =
|
|
51
|
-
| OwnerAdminEndpoint
|
|
52
|
-
| (() => OwnerAdminEndpoint | undefined)
|
|
53
|
-
| undefined;
|
|
54
|
-
|
|
55
|
-
export interface OwnerNodeClientOptions {
|
|
56
|
-
/** Fetch override for tests. Defaults to the global `fetch`. */
|
|
57
|
-
fetch?: typeof fetch;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export class OwnerNodeClient
|
|
61
|
-
implements TrustCircleCadreNodeLike, NatCadreNodeLike, StrandCadreNodeLike {
|
|
62
|
-
private readonly endpointSource: EndpointSource;
|
|
63
|
-
private readonly fetchImpl: typeof fetch;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param endpoint Either a fixed `{ baseUrl, token }` or a getter returning
|
|
67
|
-
* the current endpoint (pass `orchestrator.getOwnerAdminEndpoint`
|
|
68
|
-
* bound, so a restart's new bearer token is picked up automatically).
|
|
69
|
-
*/
|
|
70
|
-
constructor(endpoint: EndpointSource, opts: OwnerNodeClientOptions = {}) {
|
|
71
|
-
this.endpointSource = endpoint;
|
|
72
|
-
this.fetchImpl = opts.fetch ?? fetch;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// --- trust-circle CadreNodeLike ---
|
|
76
|
-
|
|
77
|
-
async createInvite(
|
|
78
|
-
token?: string,
|
|
79
|
-
expiresInMs?: number,
|
|
80
|
-
): Promise<{ invite: CadreInvite; encodedInvite: string }> {
|
|
81
|
-
const body: Record<string, unknown> = {};
|
|
82
|
-
if (token !== undefined) body.token = token;
|
|
83
|
-
if (expiresInMs !== undefined) body.expiresInMs = expiresInMs;
|
|
84
|
-
return await this.request<{ invite: CadreInvite; encodedInvite: string }>(
|
|
85
|
-
'POST',
|
|
86
|
-
'/admin/invites',
|
|
87
|
-
body,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async acceptPhone(
|
|
92
|
-
options: { phonePeerId: string; token?: string },
|
|
93
|
-
issuedInvite?: CadreInvite,
|
|
94
|
-
): Promise<void> {
|
|
95
|
-
const body: Record<string, unknown> = { phonePeerId: options.phonePeerId };
|
|
96
|
-
if (options.token !== undefined) body.token = options.token;
|
|
97
|
-
if (issuedInvite !== undefined) body.issuedInvite = issuedInvite;
|
|
98
|
-
await this.request('POST', '/admin/accept-phone', body);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async removePeer(peerId: string): Promise<void> {
|
|
102
|
-
await this.request('DELETE', `/admin/members/${encodeURIComponent(peerId)}`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Encode an invite for out-of-band delivery. The admin contract has no
|
|
107
|
-
* encode route (the mint route already returns `encodedInvite`), so this
|
|
108
|
-
* mirrors cadre-core's encoding (`base64url(JSON.stringify(invite))`).
|
|
109
|
-
*/
|
|
110
|
-
encodeInvite(invite: CadreInvite): string {
|
|
111
|
-
return Buffer.from(JSON.stringify(invite), 'utf8').toString('base64url');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async listMembers(): Promise<Array<{ peerId: string; multiaddr: string | null }>> {
|
|
115
|
-
const data = await this.request<{ members: Array<{ peerId: string; multiaddr: string | null }> }>(
|
|
116
|
-
'GET',
|
|
117
|
-
'/admin/members',
|
|
118
|
-
);
|
|
119
|
-
return data.members;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async isMember(peerId: string): Promise<boolean> {
|
|
123
|
-
const data = await this.request<{ member: boolean }>(
|
|
124
|
-
'GET',
|
|
125
|
-
`/admin/members/${encodeURIComponent(peerId)}`,
|
|
126
|
-
);
|
|
127
|
-
return data.member;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** Authorized-membership surface (excludes self) — see {@link listMembers} for the addressable one. */
|
|
131
|
-
async listAuthorizedMembers(): Promise<Array<{ peerId: string; multiaddr: string | null }>> {
|
|
132
|
-
const data = await this.request<{ members: Array<{ peerId: string; multiaddr: string | null }> }>(
|
|
133
|
-
'GET',
|
|
134
|
-
'/admin/authorized-members',
|
|
135
|
-
);
|
|
136
|
-
return data.members;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async isAuthorizedMember(peerId: string): Promise<boolean> {
|
|
140
|
-
const data = await this.request<{ member: boolean }>(
|
|
141
|
-
'GET',
|
|
142
|
-
`/admin/authorized-members/${encodeURIComponent(peerId)}`,
|
|
143
|
-
);
|
|
144
|
-
return data.member;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// --- NAT CadreNodeLike ---
|
|
148
|
-
|
|
149
|
-
async getPeerId(): Promise<string> {
|
|
150
|
-
const data = await this.request<{ peerId: string | null; partyId: string }>('GET', '/admin/identity');
|
|
151
|
-
return data.peerId ?? '';
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async getMultiaddrs(): Promise<string[]> {
|
|
155
|
-
const data = await this.request<{ multiaddrs: string[] }>('GET', '/admin/multiaddrs');
|
|
156
|
-
return data.multiaddrs;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// --- strand CadreNodeLike ---
|
|
160
|
-
|
|
161
|
-
/** This party's strands plus the node's current control-connection count. */
|
|
162
|
-
async listStrands(): Promise<StrandListSnapshot> {
|
|
163
|
-
return await this.request<StrandListSnapshot>('GET', '/admin/strands');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Remove this party's participation in one strand.
|
|
168
|
-
*
|
|
169
|
-
* `?confirm=1` is appended **only** when the caller asked for it. The node
|
|
170
|
-
* refuses an unconfirmed closed-strand removal with `confirmation_required`;
|
|
171
|
-
* that refusal is surfaced, never retried with the flag added — the row holds
|
|
172
|
-
* this party's membership key for the strand and nothing else does.
|
|
173
|
-
*/
|
|
174
|
-
async removeStrand(strandId: string, opts: { confirm: boolean }): Promise<StrandRemovalResult> {
|
|
175
|
-
const query = opts.confirm ? '?confirm=1' : '';
|
|
176
|
-
return await this.request<StrandRemovalResult>(
|
|
177
|
-
'DELETE',
|
|
178
|
-
`/admin/strands/${encodeURIComponent(strandId)}${query}`,
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// --- drone seeding (node-donation requester side) ---
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Mint a seed authorizing a drone — a provider-hosted / donated node — to join
|
|
186
|
-
* this node's cadre. The node signs the seed with its own authority key; only
|
|
187
|
-
* the signed, public `encodedSeed` is returned (the private key never leaves
|
|
188
|
-
* the node). This is the requester ("phone") side of the node-donation flow:
|
|
189
|
-
* the donor host presents the returned seed to the donated node's `POST /seed`.
|
|
190
|
-
*/
|
|
191
|
-
async addDrone(options: { dronePeerId: string; droneMultiaddrs: string[] }): Promise<DroneInitResult> {
|
|
192
|
-
return await this.request<DroneInitResult>('POST', '/admin/add-drone', {
|
|
193
|
-
dronePeerId: options.dronePeerId,
|
|
194
|
-
droneMultiaddrs: options.droneMultiaddrs,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// --- push-model invite addresses ---
|
|
199
|
-
|
|
200
|
-
/** Push the NAT-resolved addresses the node should embed in future invites. */
|
|
201
|
-
async pushInviteAddresses(addresses: string[]): Promise<void> {
|
|
202
|
-
await this.request('PUT', '/admin/invite-addresses', { addresses });
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// --- internals ---
|
|
206
|
-
|
|
207
|
-
private resolveEndpoint(): OwnerAdminEndpoint {
|
|
208
|
-
const ep = typeof this.endpointSource === 'function' ? this.endpointSource() : this.endpointSource;
|
|
209
|
-
if (!ep) {
|
|
210
|
-
throw new OwnerNodeUnavailableError('Owner node admin endpoint is not available');
|
|
211
|
-
}
|
|
212
|
-
return ep;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private async request<T>(method: string, path: string, body?: unknown): Promise<T> {
|
|
216
|
-
const ep = this.resolveEndpoint();
|
|
217
|
-
const headers: Record<string, string> = { authorization: `Bearer ${ep.token}` };
|
|
218
|
-
const init: RequestInit = { method, headers };
|
|
219
|
-
if (body !== undefined) {
|
|
220
|
-
headers['content-type'] = 'application/json';
|
|
221
|
-
init.body = JSON.stringify(body);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
let res: Response;
|
|
225
|
-
try {
|
|
226
|
-
res = await this.fetchImpl(`${ep.baseUrl}${path}`, init);
|
|
227
|
-
} catch (err) {
|
|
228
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
229
|
-
log('admin %s %s transport error: %s', method, path, message);
|
|
230
|
-
throw new OwnerNodeUnavailableError(`Owner node unreachable: ${message}`);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const envelope = await this.parseEnvelope(res);
|
|
234
|
-
if (!res.ok || !envelope.ok) {
|
|
235
|
-
const code = envelope.error?.code;
|
|
236
|
-
const message = envelope.error?.message ?? `admin ${method} ${path} → HTTP ${res.status}`;
|
|
237
|
-
log('admin %s %s failed: [%s] %s', method, path, code ?? res.status, message);
|
|
238
|
-
throw new OwnerNodeUnavailableError(message, code);
|
|
239
|
-
}
|
|
240
|
-
return envelope.data as T;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
private async parseEnvelope(res: Response): Promise<{
|
|
244
|
-
ok?: boolean;
|
|
245
|
-
data?: unknown;
|
|
246
|
-
error?: { code?: string; message?: string };
|
|
247
|
-
}> {
|
|
248
|
-
try {
|
|
249
|
-
const parsed = await res.json();
|
|
250
|
-
if (parsed && typeof parsed === 'object') {
|
|
251
|
-
return parsed as { ok?: boolean; data?: unknown; error?: { code?: string; message?: string } };
|
|
252
|
-
}
|
|
253
|
-
} catch {
|
|
254
|
-
// Non-JSON body — fall through to an empty envelope; status drives the
|
|
255
|
-
// ok/non-ok decision in the caller.
|
|
256
|
-
}
|
|
257
|
-
return {};
|
|
258
|
-
}
|
|
259
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The host's `bootstrapNodes` rule — the requester addresses a donated node is
|
|
3
|
-
* started with — exercised directly.
|
|
4
|
-
*
|
|
5
|
-
* This is one half of a **manual tripwire**: cadre-provider carries an identical
|
|
6
|
-
* copy of this rule's per-entry half
|
|
7
|
-
* (`packages/cadre-provider/src/server/bootstrap-node-validation.ts`) and the
|
|
8
|
-
* per-entry rows below are the same rows
|
|
9
|
-
* `packages/cadre-provider/src/server/__tests__/bootstrap-node-validation.test.ts`
|
|
10
|
-
* pins that copy to. The empty-list row differs on purpose: this host accepts an
|
|
11
|
-
* empty list (a phone requester dials its lent node instead), the provider still
|
|
12
|
-
* requires one. Neither suite can observe the other package — nothing here
|
|
13
|
-
* imports cadre-provider's server module — so this does not detect a change made
|
|
14
|
-
* over there; what it does is fail if *this* copy is changed, which is how an
|
|
15
|
-
* editor is landed on the comment pointing at the other one.
|
|
16
|
-
*
|
|
17
|
-
* The route contract (`POST /grants` → 400, nothing provisioned) lives in
|
|
18
|
-
* `grants-route.test.ts`, next to the rest of that route's HTTP behaviour.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { describe, it, expect } from 'vitest';
|
|
22
|
-
|
|
23
|
-
import { validateBootstrapNodes } from '../routes/bootstrap-node-validation.js';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A real, decodable peer id. Placeholder strings like `12D3KooReq` look right and
|
|
27
|
-
* are not: `peerIdFromString` throws `Incorrect length` on them, which is exactly
|
|
28
|
-
* the typo this rule exists to catch.
|
|
29
|
-
*/
|
|
30
|
-
const PEER = '12D3KooWA9hbnKrRnPRSPTRkzXqTHzGE8YpJ3JHZmQ5tGwLRTMmp';
|
|
31
|
-
const GOOD = `/ip4/127.0.0.1/tcp/4001/p2p/${PEER}`;
|
|
32
|
-
/** A second, distinct dialable address, for "which entry was bad" assertions. */
|
|
33
|
-
const GOOD_2 = `/dns4/bootstrap.example/tcp/443/wss/p2p/${PEER}`;
|
|
34
|
-
|
|
35
|
-
describe('validateBootstrapNodes (the host copy of the address rule)', () => {
|
|
36
|
-
function errorOf(value: unknown): string {
|
|
37
|
-
const result = validateBootstrapNodes(value);
|
|
38
|
-
if (!('error' in result)) throw new Error(`expected a rejection, got ${JSON.stringify(result)}`);
|
|
39
|
-
return result.error;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
it('accepts a dialable address and returns it trimmed', () => {
|
|
43
|
-
expect(validateBootstrapNodes([` ${GOOD}\n`])).toEqual({ nodes: [GOOD] });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('accepts several dialable addresses across transports', () => {
|
|
47
|
-
expect(validateBootstrapNodes([GOOD, GOOD_2])).toEqual({ nodes: [GOOD, GOOD_2] });
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('accepts a relayed address whose relay and target peer ids both decode', () => {
|
|
51
|
-
const relayed = `/ip4/1.2.3.4/tcp/4001/p2p/${PEER}/p2p-circuit/p2p/${PEER}`;
|
|
52
|
-
expect(validateBootstrapNodes([relayed])).toEqual({ nodes: [relayed] });
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// The one row that differs from cadre-provider's table: a requester with no address
|
|
56
|
-
// of its own (a phone) sends none and dials the lent node itself.
|
|
57
|
-
it('treats an absent field and an empty list alike: no addresses, nothing rejected', () => {
|
|
58
|
-
expect(validateBootstrapNodes(undefined)).toEqual({ nodes: [] });
|
|
59
|
-
expect(validateBootstrapNodes([])).toEqual({ nodes: [] });
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('rejects a non-array, and an array with a non-string element', () => {
|
|
63
|
-
expect(errorOf(GOOD)).toBe('bootstrapNodes must be an array of strings');
|
|
64
|
-
expect(errorOf(null)).toBe('bootstrapNodes must be an array of strings');
|
|
65
|
-
expect(errorOf([42])).toBe('bootstrapNodes must be an array of strings');
|
|
66
|
-
expect(errorOf([GOOD, { addr: GOOD }])).toBe('bootstrapNodes must be an array of strings');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('rejects an empty or whitespace-only entry with the blank-value message', () => {
|
|
70
|
-
for (const blank of ['', ' ', '\t\n']) {
|
|
71
|
-
expect(errorOf([blank])).toMatch(/must not be empty or whitespace-only/);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Case 1: `@libp2p/bootstrap` maps `multiaddr()` over the list before filtering,
|
|
76
|
-
// so this one throws during libp2p construction and the child never starts.
|
|
77
|
-
it('rejects a string that is not a multiaddr, naming it', () => {
|
|
78
|
-
for (const bad of ['not-an-address', '42', 'bootstrap.example:4001']) {
|
|
79
|
-
const message = errorOf([bad]);
|
|
80
|
-
expect(message).toMatch(/must be multiaddrs/);
|
|
81
|
-
expect(message).toContain(bad);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// Case 2: the quiet one — parses, then gets filtered out inside the child and
|
|
86
|
-
// the node comes up healthy-looking with zero bootstrap peers.
|
|
87
|
-
it('rejects a valid multiaddr with no /p2p/ component, naming it', () => {
|
|
88
|
-
const message = errorOf(['/ip4/127.0.0.1/tcp/4001']);
|
|
89
|
-
expect(message).toMatch(/must include a \/p2p\/<peerId> component/);
|
|
90
|
-
expect(message).toContain('/ip4/127.0.0.1/tcp/4001');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Case 3: `multiaddr()` does not validate the /p2p/ value; `peerIdFromString`
|
|
94
|
-
// does, and throws inside the child's libp2p construction.
|
|
95
|
-
it('rejects a /p2p/ component whose peer id does not decode, naming the entry and the id', () => {
|
|
96
|
-
const bad = '/ip4/127.0.0.1/tcp/4001/p2p/12D3KooReq';
|
|
97
|
-
const message = errorOf([bad]);
|
|
98
|
-
expect(message).toMatch(/must carry a decodable peer id/);
|
|
99
|
-
expect(message).toContain(bad);
|
|
100
|
-
expect(message).toContain('12D3KooReq');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('rejects a relayed address whose relay peer id does not decode', () => {
|
|
104
|
-
expect(errorOf([`/ip4/1.2.3.4/tcp/4001/p2p/12D3KooReq/p2p-circuit/p2p/${PEER}`]))
|
|
105
|
-
.toMatch(/must carry a decodable peer id/);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Case 4: parses, names a decodable peer, and survives `@libp2p/bootstrap`'s
|
|
109
|
-
// filter — but names no place, so libp2p finds no transport and the dial fails
|
|
110
|
-
// with no valid addresses. Same visible outcome as case 2.
|
|
111
|
-
it('rejects an address that names only peer ids, with no location to dial', () => {
|
|
112
|
-
for (const bad of [`/p2p/${PEER}`, `/p2p/${PEER}/p2p-circuit/p2p/${PEER}`]) {
|
|
113
|
-
const message = errorOf([bad]);
|
|
114
|
-
expect(message).toMatch(/must name where to reach the peer/);
|
|
115
|
-
expect(message).toContain(bad);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// A partial address is deliberately still accepted: which transports the child
|
|
120
|
-
// can dial is the embedder's choice, so only the total absence of a location is
|
|
121
|
-
// a boundary error.
|
|
122
|
-
it('accepts an address with a location but no transport, leaving that to the child', () => {
|
|
123
|
-
const partial = `/ip4/1.2.3.4/p2p/${PEER}`;
|
|
124
|
-
expect(validateBootstrapNodes([partial])).toEqual({ nodes: [partial] });
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('names the offending entry when only one address in a batch is bad', () => {
|
|
128
|
-
const message = errorOf([GOOD, '/ip4/10.0.0.9/tcp/4001', GOOD_2]);
|
|
129
|
-
expect(message).toContain('/ip4/10.0.0.9/tcp/4001');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// A requester must not be able to turn one junk string into a megabyte of log line.
|
|
133
|
-
it('caps the echoed value for an over-long rejected address', () => {
|
|
134
|
-
const message = errorOf([`/ip4/1.2.3.4/tcp/${'9'.repeat(5000)}`]);
|
|
135
|
-
expect(message).toContain('chars)');
|
|
136
|
-
expect(message.length).toBeLessThan(400);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import Fastify from 'fastify';
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
|
|
7
|
-
import { registerErrorHandler } from '../error-handler.js';
|
|
8
|
-
import { EventBus } from '../events/bus.js';
|
|
9
|
-
import { registerGrantsAdminRoutes } from '../routes/grants-admin.js';
|
|
10
|
-
import {
|
|
11
|
-
DonationService,
|
|
12
|
-
DonationStore,
|
|
13
|
-
GrantService,
|
|
14
|
-
GrantStore,
|
|
15
|
-
createGrantAdminHandlers,
|
|
16
|
-
} from '../../donation/index.js';
|
|
17
|
-
import type { DonationView, Grant, GrantListing } from '../../donation/index.js';
|
|
18
|
-
import { FakeOrchestrator } from '../../donation/__tests__/fake-orchestrator.js';
|
|
19
|
-
|
|
20
|
-
/** A well-formed 32-byte base64url owner key, which `provision` requires. */
|
|
21
|
-
const OWNER_KEY = Buffer.alloc(32, 7).toString('base64url');
|
|
22
|
-
|
|
23
|
-
let tmpRoot: string;
|
|
24
|
-
let app: ReturnType<typeof Fastify>;
|
|
25
|
-
let grants: GrantService;
|
|
26
|
-
let donations: DonationService;
|
|
27
|
-
let donationStore: DonationStore;
|
|
28
|
-
let orch: FakeOrchestrator;
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
tmpRoot = mkdtempSync(join(tmpdir(), 'cadre-host-grants-route-'));
|
|
32
|
-
grants = new GrantService({ store: new GrantStore(tmpRoot) });
|
|
33
|
-
orch = new FakeOrchestrator();
|
|
34
|
-
donationStore = new DonationStore(tmpRoot);
|
|
35
|
-
donations = new DonationService({ orchestrator: orch, grants, store: donationStore });
|
|
36
|
-
app = Fastify();
|
|
37
|
-
registerErrorHandler(app);
|
|
38
|
-
registerGrantsAdminRoutes(app, { handlers: createGrantAdminHandlers(grants, donations), events: new EventBus() });
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
afterEach(async () => {
|
|
42
|
-
await app.close();
|
|
43
|
-
try { rmSync(tmpRoot, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('/grants-admin routes', () => {
|
|
47
|
-
it('POST issues a grant, GET lists it, DELETE revokes it', async () => {
|
|
48
|
-
const post = await app.inject({
|
|
49
|
-
method: 'POST',
|
|
50
|
-
url: '/grants-admin',
|
|
51
|
-
payload: { label: "Alice's cadre", maxNodes: 2 },
|
|
52
|
-
});
|
|
53
|
-
expect(post.statusCode).toBe(200);
|
|
54
|
-
const created = (post.json() as { grant: Grant }).grant;
|
|
55
|
-
expect(created.token).toBeTruthy();
|
|
56
|
-
expect(created.maxNodes).toBe(2);
|
|
57
|
-
|
|
58
|
-
const list = await app.inject({ method: 'GET', url: '/grants-admin' });
|
|
59
|
-
expect(list.statusCode).toBe(200);
|
|
60
|
-
expect((list.json() as { grants: Grant[] }).grants.map(g => g.token)).toContain(created.token);
|
|
61
|
-
|
|
62
|
-
const del = await app.inject({
|
|
63
|
-
method: 'DELETE',
|
|
64
|
-
url: `/grants-admin/${encodeURIComponent(created.token)}`,
|
|
65
|
-
});
|
|
66
|
-
expect(del.statusCode).toBe(200);
|
|
67
|
-
|
|
68
|
-
// Revoked → still listed, now carries revokedAt.
|
|
69
|
-
const after = await app.inject({ method: 'GET', url: '/grants-admin' });
|
|
70
|
-
const row = (after.json() as { grants: Grant[] }).grants.find(g => g.token === created.token);
|
|
71
|
-
expect(row?.revokedAt).toBeTruthy();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('POST with an empty label → 400 invalid_label', async () => {
|
|
75
|
-
const res = await app.inject({ method: 'POST', url: '/grants-admin', payload: { label: ' ' } });
|
|
76
|
-
expect(res.statusCode).toBe(400);
|
|
77
|
-
expect((res.json() as { error: { code: string } }).error.code).toBe('invalid_label');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('POST with a bad maxNodes → 400 invalid_max_nodes', async () => {
|
|
81
|
-
const res = await app.inject({ method: 'POST', url: '/grants-admin', payload: { label: 'X', maxNodes: 0 } });
|
|
82
|
-
expect(res.statusCode).toBe(400);
|
|
83
|
-
expect((res.json() as { error: { code: string } }).error.code).toBe('invalid_max_nodes');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('DELETE of an unknown token → 404 not_found', async () => {
|
|
87
|
-
const res = await app.inject({ method: 'DELETE', url: '/grants-admin/nope' });
|
|
88
|
-
expect(res.statusCode).toBe(404);
|
|
89
|
-
expect((res.json() as { error: { code: string } }).error.code).toBe('not_found');
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
function provisionUnder(token: string): Promise<DonationView> {
|
|
94
|
-
return donations.provision({ grantToken: token, partyId: 'party-P', bootstrapNodes: [], ownerKeys: [OWNER_KEY] });
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
describe('/grants-admin listing', () => {
|
|
98
|
-
it("GET reports each grant's live nodes and the donations a revoke would end", async () => {
|
|
99
|
-
const a = grants.issue({ label: 'A', maxNodes: 3 });
|
|
100
|
-
const b = grants.issue({ label: 'B' });
|
|
101
|
-
const seeded = await provisionUnder(a.token);
|
|
102
|
-
const failed = await provisionUnder(a.token);
|
|
103
|
-
const ended = await provisionUnder(a.token);
|
|
104
|
-
const other = await provisionUnder(b.token);
|
|
105
|
-
donationStore.put({ ...donationStore.get(seeded.id)!, status: 'seeded' });
|
|
106
|
-
donationStore.put({ ...donationStore.get(failed.id)!, status: 'error', error: 'respawn gave up' });
|
|
107
|
-
await donations.terminate(ended.id);
|
|
108
|
-
|
|
109
|
-
const res = await app.inject({ method: 'GET', url: '/grants-admin' });
|
|
110
|
-
|
|
111
|
-
const listed = (res.json() as { grants: GrantListing[] }).grants;
|
|
112
|
-
const rowA = listed.find(g => g.token === a.token);
|
|
113
|
-
const rowB = listed.find(g => g.token === b.token);
|
|
114
|
-
// `error` is not live, but a revoke still tears it down; `terminated` is neither.
|
|
115
|
-
expect(rowA?.liveNodes).toBe(1);
|
|
116
|
-
expect(rowA?.donations).toEqual(expect.arrayContaining([
|
|
117
|
-
{ id: seeded.id, status: 'seeded' },
|
|
118
|
-
{ id: failed.id, status: 'error' },
|
|
119
|
-
]));
|
|
120
|
-
expect(rowA?.donations).toHaveLength(2);
|
|
121
|
-
expect(rowB?.liveNodes).toBe(1);
|
|
122
|
-
expect(rowB?.donations).toEqual([{ id: other.id, status: 'awaiting_seed' }]);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
describe('/grants-admin donated-node teardown', () => {
|
|
127
|
-
it('DELETE /grants-admin/:token terminates the nodes donated under the grant', async () => {
|
|
128
|
-
const { token } = grants.issue({ label: 'Alice' });
|
|
129
|
-
const donation = await provisionUnder(token);
|
|
130
|
-
|
|
131
|
-
const res = await app.inject({ method: 'DELETE', url: `/grants-admin/${encodeURIComponent(token)}` });
|
|
132
|
-
|
|
133
|
-
expect(res.statusCode).toBe(200);
|
|
134
|
-
expect(res.json()).toEqual({ ok: true, terminated: [donation.id] });
|
|
135
|
-
expect(donations.get(donation.id)?.status).toBe('terminated');
|
|
136
|
-
expect(orch.removed).toEqual(['dock_1']);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('?keepNodes=true revokes the grant but leaves its nodes running', async () => {
|
|
140
|
-
const { token } = grants.issue({ label: 'Alice' });
|
|
141
|
-
const donation = await provisionUnder(token);
|
|
142
|
-
|
|
143
|
-
const res = await app.inject({
|
|
144
|
-
method: 'DELETE',
|
|
145
|
-
url: `/grants-admin/${encodeURIComponent(token)}?keepNodes=true`,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
expect(res.statusCode).toBe(200);
|
|
149
|
-
expect(res.json()).toEqual({ ok: true, terminated: [] });
|
|
150
|
-
expect(grants.validate(token).reason).toBe('revoked');
|
|
151
|
-
expect(donations.get(donation.id)?.status).toBe('awaiting_seed');
|
|
152
|
-
expect(orch.stopped).toEqual([]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('DELETE /grants-admin/donations/:id ends one node under a revoked grant; an unknown id 404s', async () => {
|
|
156
|
-
const { token } = grants.issue({ label: 'Alice', maxNodes: 2 });
|
|
157
|
-
const kept = await provisionUnder(token);
|
|
158
|
-
const ended = await provisionUnder(token);
|
|
159
|
-
grants.revoke(token);
|
|
160
|
-
|
|
161
|
-
const res = await app.inject({ method: 'DELETE', url: `/grants-admin/donations/${ended.id}` });
|
|
162
|
-
|
|
163
|
-
expect(res.statusCode).toBe(200);
|
|
164
|
-
expect(donations.get(ended.id)?.status).toBe('terminated');
|
|
165
|
-
expect(donations.get(kept.id)?.status).toBe('awaiting_seed');
|
|
166
|
-
|
|
167
|
-
const unknown = await app.inject({ method: 'DELETE', url: '/grants-admin/donations/grn_nope' });
|
|
168
|
-
expect(unknown.statusCode).toBe(404);
|
|
169
|
-
expect((unknown.json() as { error: { code: string } }).error.code).toBe('not_found');
|
|
170
|
-
});
|
|
171
|
-
});
|