@serfab/cadre-host 0.11.0 → 0.13.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 +406 -296
- package/dist/bin/host.d.ts +11 -7
- package/dist/bin/host.js +40 -12
- package/dist/bin/host.js.map +1 -1
- package/dist/installer/config.d.ts +4 -4
- package/dist/installer/config.js +5 -39
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/identity.d.ts +8 -1
- package/dist/installer/identity.js +8 -1
- package/dist/installer/identity.js.map +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +2 -2
- package/dist/orchestrator/host-process-orchestrator.js +14 -4
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/server/routes/bootstrap-node-validation.d.ts +96 -0
- package/dist/server/routes/bootstrap-node-validation.js +178 -0
- package/dist/server/routes/bootstrap-node-validation.js.map +1 -0
- package/dist/server/routes/grants.js +8 -25
- package/dist/server/routes/grants.js.map +1 -1
- package/dist/server/routes/provision-request-validation.d.ts +45 -0
- package/dist/server/routes/provision-request-validation.js +97 -0
- package/dist/server/routes/provision-request-validation.js.map +1 -0
- package/dist/server/settings-store.d.ts +1 -1
- package/dist/server/settings-store.js +5 -1
- package/dist/server/settings-store.js.map +1 -1
- package/package.json +5 -4
- package/src/__tests__/cli.smoke.test.ts +8 -3
- package/src/__tests__/global-setup.ts +9 -4
- package/src/__tests__/orchestrator-node-identity.test.ts +204 -204
- package/src/__tests__/orchestrator.test.ts +951 -951
- package/src/bin/__tests__/cli-reference.test.ts +167 -0
- package/src/bin/host.ts +1326 -1299
- package/src/donation/__tests__/donation-service.test.ts +1068 -1068
- package/src/donation/__tests__/donation-supervisor.test.ts +510 -510
- package/src/donation/__tests__/fake-orchestrator.test.ts +168 -168
- package/src/installer/__tests__/config.test.ts +134 -112
- package/src/installer/config.ts +5 -43
- package/src/installer/identity.ts +8 -1
- package/src/nat/__tests__/nat-service.test.ts +515 -497
- package/src/orchestrator/host-process-orchestrator.ts +1143 -1133
- package/src/server/__tests__/bootstrap-node-validation.test.ts +134 -0
- package/src/server/__tests__/grants-route.test.ts +326 -263
- package/src/server/__tests__/settings-route.test.ts +8 -7
- package/src/server/routes/bootstrap-node-validation.ts +187 -0
- package/src/server/routes/grants.ts +9 -26
- package/src/server/routes/provision-request-validation.ts +105 -0
- package/src/server/settings-store.ts +41 -37
|
@@ -0,0 +1,134 @@
|
|
|
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 a
|
|
6
|
+
* byte-identical copy of this rule
|
|
7
|
+
* (`packages/cadre-provider/src/server/bootstrap-node-validation.ts`) and the table
|
|
8
|
+
* below is the same table
|
|
9
|
+
* `packages/cadre-provider/src/server/__tests__/bootstrap-node-validation.test.ts`
|
|
10
|
+
* pins that copy to. Neither suite can observe the other package — nothing here
|
|
11
|
+
* imports cadre-provider's server module — so this does not detect a change made
|
|
12
|
+
* over there; what it does is fail if *this* copy is changed, which is how an
|
|
13
|
+
* editor is landed on the comment pointing at the other one.
|
|
14
|
+
*
|
|
15
|
+
* The route contract (`POST /grants` → 400, nothing provisioned) lives in
|
|
16
|
+
* `grants-route.test.ts`, next to the rest of that route's HTTP behaviour.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { describe, it, expect } from 'vitest';
|
|
20
|
+
|
|
21
|
+
import { validateBootstrapNodes } from '../routes/bootstrap-node-validation.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A real, decodable peer id. Placeholder strings like `12D3KooReq` look right and
|
|
25
|
+
* are not: `peerIdFromString` throws `Incorrect length` on them, which is exactly
|
|
26
|
+
* the typo this rule exists to catch.
|
|
27
|
+
*/
|
|
28
|
+
const PEER = '12D3KooWA9hbnKrRnPRSPTRkzXqTHzGE8YpJ3JHZmQ5tGwLRTMmp';
|
|
29
|
+
const GOOD = `/ip4/127.0.0.1/tcp/4001/p2p/${PEER}`;
|
|
30
|
+
/** A second, distinct dialable address, for "which entry was bad" assertions. */
|
|
31
|
+
const GOOD_2 = `/dns4/bootstrap.example/tcp/443/wss/p2p/${PEER}`;
|
|
32
|
+
|
|
33
|
+
describe('validateBootstrapNodes (the host copy of the address rule)', () => {
|
|
34
|
+
function errorOf(value: unknown): string {
|
|
35
|
+
const result = validateBootstrapNodes(value);
|
|
36
|
+
if (!('error' in result)) throw new Error(`expected a rejection, got ${JSON.stringify(result)}`);
|
|
37
|
+
return result.error;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
it('accepts a dialable address and returns it trimmed', () => {
|
|
41
|
+
expect(validateBootstrapNodes([` ${GOOD}\n`])).toEqual({ nodes: [GOOD] });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('accepts several dialable addresses across transports', () => {
|
|
45
|
+
expect(validateBootstrapNodes([GOOD, GOOD_2])).toEqual({ nodes: [GOOD, GOOD_2] });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('accepts a relayed address whose relay and target peer ids both decode', () => {
|
|
49
|
+
const relayed = `/ip4/1.2.3.4/tcp/4001/p2p/${PEER}/p2p-circuit/p2p/${PEER}`;
|
|
50
|
+
expect(validateBootstrapNodes([relayed])).toEqual({ nodes: [relayed] });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('treats an absent field and an empty list alike: the field is required', () => {
|
|
54
|
+
expect(errorOf(undefined)).toBe('bootstrapNodes is required');
|
|
55
|
+
expect(errorOf([])).toBe('bootstrapNodes is required');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('rejects a non-array, and an array with a non-string element', () => {
|
|
59
|
+
expect(errorOf(GOOD)).toBe('bootstrapNodes must be an array of strings');
|
|
60
|
+
expect(errorOf(null)).toBe('bootstrapNodes must be an array of strings');
|
|
61
|
+
expect(errorOf([42])).toBe('bootstrapNodes must be an array of strings');
|
|
62
|
+
expect(errorOf([GOOD, { addr: GOOD }])).toBe('bootstrapNodes must be an array of strings');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('rejects an empty or whitespace-only entry with the blank-value message', () => {
|
|
66
|
+
for (const blank of ['', ' ', '\t\n']) {
|
|
67
|
+
expect(errorOf([blank])).toMatch(/must not be empty or whitespace-only/);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Case 1: `@libp2p/bootstrap` maps `multiaddr()` over the list before filtering,
|
|
72
|
+
// so this one throws during libp2p construction and the child never starts.
|
|
73
|
+
it('rejects a string that is not a multiaddr, naming it', () => {
|
|
74
|
+
for (const bad of ['not-an-address', '42', 'bootstrap.example:4001']) {
|
|
75
|
+
const message = errorOf([bad]);
|
|
76
|
+
expect(message).toMatch(/must be multiaddrs/);
|
|
77
|
+
expect(message).toContain(bad);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Case 2: the quiet one — parses, then gets filtered out inside the child and
|
|
82
|
+
// the node comes up healthy-looking with zero bootstrap peers.
|
|
83
|
+
it('rejects a valid multiaddr with no /p2p/ component, naming it', () => {
|
|
84
|
+
const message = errorOf(['/ip4/127.0.0.1/tcp/4001']);
|
|
85
|
+
expect(message).toMatch(/must include a \/p2p\/<peerId> component/);
|
|
86
|
+
expect(message).toContain('/ip4/127.0.0.1/tcp/4001');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Case 3: `multiaddr()` does not validate the /p2p/ value; `peerIdFromString`
|
|
90
|
+
// does, and throws inside the child's libp2p construction.
|
|
91
|
+
it('rejects a /p2p/ component whose peer id does not decode, naming the entry and the id', () => {
|
|
92
|
+
const bad = '/ip4/127.0.0.1/tcp/4001/p2p/12D3KooReq';
|
|
93
|
+
const message = errorOf([bad]);
|
|
94
|
+
expect(message).toMatch(/must carry a decodable peer id/);
|
|
95
|
+
expect(message).toContain(bad);
|
|
96
|
+
expect(message).toContain('12D3KooReq');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('rejects a relayed address whose relay peer id does not decode', () => {
|
|
100
|
+
expect(errorOf([`/ip4/1.2.3.4/tcp/4001/p2p/12D3KooReq/p2p-circuit/p2p/${PEER}`]))
|
|
101
|
+
.toMatch(/must carry a decodable peer id/);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Case 4: parses, names a decodable peer, and survives `@libp2p/bootstrap`'s
|
|
105
|
+
// filter — but names no place, so libp2p finds no transport and the dial fails
|
|
106
|
+
// with no valid addresses. Same visible outcome as case 2.
|
|
107
|
+
it('rejects an address that names only peer ids, with no location to dial', () => {
|
|
108
|
+
for (const bad of [`/p2p/${PEER}`, `/p2p/${PEER}/p2p-circuit/p2p/${PEER}`]) {
|
|
109
|
+
const message = errorOf([bad]);
|
|
110
|
+
expect(message).toMatch(/must name where to reach the peer/);
|
|
111
|
+
expect(message).toContain(bad);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// A partial address is deliberately still accepted: which transports the child
|
|
116
|
+
// can dial is the embedder's choice, so only the total absence of a location is
|
|
117
|
+
// a boundary error.
|
|
118
|
+
it('accepts an address with a location but no transport, leaving that to the child', () => {
|
|
119
|
+
const partial = `/ip4/1.2.3.4/p2p/${PEER}`;
|
|
120
|
+
expect(validateBootstrapNodes([partial])).toEqual({ nodes: [partial] });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('names the offending entry when only one address in a batch is bad', () => {
|
|
124
|
+
const message = errorOf([GOOD, '/ip4/10.0.0.9/tcp/4001', GOOD_2]);
|
|
125
|
+
expect(message).toContain('/ip4/10.0.0.9/tcp/4001');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// A requester must not be able to turn one junk string into a megabyte of log line.
|
|
129
|
+
it('caps the echoed value for an over-long rejected address', () => {
|
|
130
|
+
const message = errorOf([`/ip4/1.2.3.4/tcp/${'9'.repeat(5000)}`]);
|
|
131
|
+
expect(message).toContain('chars)');
|
|
132
|
+
expect(message.length).toBeLessThan(400);
|
|
133
|
+
});
|
|
134
|
+
});
|