@bongos/core 1.21.69 → 1.21.70
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/.bongos-core.json +24 -24
- package/.claude/skills/bongos-feedback/SKILL.md +10 -46
- package/clients/bongos-client/README.md +1 -1
- package/clients/bongos-client/bongos-client.global.js +6 -2
- package/clients/bongos-client/index.cjs +6 -2
- package/clients/bongos-client/index.d.ts +10 -3
- package/clients/bongos-client/index.mjs +6 -2
- package/docs/api/openapi.json +151 -15
- package/docs/api-reference.md +6 -4
- package/docs/module-api-changelog.md +2 -0
- package/modules/platform-identity/instance-feedback.js +108 -7
- package/modules/platform-identity/routes/sso.js +71 -0
- package/package-lock.json +2 -2
- package/package.json +1 -1
- package/release-notes.json +5 -0
- package/scripts/gds/feedback-send.js +144 -71
- package/src/bongos/platform-visibility-gate.js +3 -0
- package/src/bongos/routes/feedback.js +91 -77
- package/src/module-api.js +1 -1
- package/tests/instance_feedback.mjs +267 -68
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// tests/instance_feedback.mjs — `bongos feedback`: a builder
|
|
2
|
-
//
|
|
3
|
-
// the hub files it (
|
|
1
|
+
// tests/instance_feedback.mjs — `bongos feedback`: a builder reports something
|
|
2
|
+
// about Bongos itself straight to the hub, their project vouches for who sent it
|
|
3
|
+
// with a one-time receipt, and the hub files it (tasks 1004462, 1004591). DB-free: the hub half is driven through its
|
|
4
4
|
// pure module with a fake `ideas.capture`, the project half through its real
|
|
5
5
|
// router with a fake hub.
|
|
6
6
|
|
|
@@ -8,6 +8,7 @@ import assert from 'node:assert/strict';
|
|
|
8
8
|
import { test } from 'node:test';
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import path from 'node:path';
|
|
11
|
+
import os from 'node:os';
|
|
11
12
|
import { createRequire } from 'node:module';
|
|
12
13
|
import { fileURLToPath } from 'node:url';
|
|
13
14
|
|
|
@@ -118,9 +119,12 @@ test('the hub route authenticates the project and the sender BEFORE spending or
|
|
|
118
119
|
'the route passes neither a rank nor a vector — both are fixed in instance-feedback.js');
|
|
119
120
|
});
|
|
120
121
|
|
|
121
|
-
// ── the project: the
|
|
122
|
+
// ── the project: the receipt (task 1004591) ──────────────────────────────────
|
|
123
|
+
// The project no longer relays anything. It vouches: a signed-in builder asks
|
|
124
|
+
// for a one-time receipt naming them and the hash of the text, and the hub
|
|
125
|
+
// redeems it once at the project's public URL.
|
|
122
126
|
|
|
123
|
-
async function withRoute(
|
|
127
|
+
async function withRoute(opts, fn) {
|
|
124
128
|
const r2 = createRequire(import.meta.url);
|
|
125
129
|
const authPath = r2.resolve(path.join(ROOT, 'src/bongos/auth.js'));
|
|
126
130
|
const routePath = r2.resolve(path.join(ROOT, 'src/bongos/routes/feedback.js'));
|
|
@@ -129,24 +133,21 @@ async function withRoute({ idp, hub }, fn) {
|
|
|
129
133
|
const saved = realAuth.requireBuilder;
|
|
130
134
|
realAuth.requireBuilder = (req, _res, next) => { req.builder = { id: 5, github_id: '42', github_login: 'someone' }; next(); };
|
|
131
135
|
delete r2.cache[routePath];
|
|
132
|
-
const
|
|
133
|
-
const fetchImpl = async (url, opts) => {
|
|
134
|
-
sent.push({ url, body: JSON.parse(opts.body) });
|
|
135
|
-
const { status, body } = hub;
|
|
136
|
-
return { status, json: async () => body };
|
|
137
|
-
};
|
|
136
|
+
const build = r2(routePath);
|
|
138
137
|
const express = r2('express');
|
|
139
138
|
const app = express();
|
|
140
139
|
app.use(express.json());
|
|
141
140
|
app.use(r2(envPath).attachFail);
|
|
142
|
-
app.use(
|
|
141
|
+
app.use(build({ hub: () => 'https://hub.example.com', ...opts }));
|
|
143
142
|
const server = app.listen(0);
|
|
144
143
|
await new Promise((res) => server.once('listening', res));
|
|
145
|
-
const
|
|
144
|
+
const url = (p) => `http://127.0.0.1:${server.address().port}${p}`;
|
|
145
|
+
const post = (body) => fetch(url('/feedback/receipt'), {
|
|
146
146
|
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
|
147
147
|
}).then(async (r) => ({ status: r.status, body: await r.json() }));
|
|
148
|
+
const redeem = (id) => fetch(url(`/feedback/receipt/${id}`)).then(async (r) => ({ status: r.status, body: await r.json() }));
|
|
148
149
|
try {
|
|
149
|
-
await fn({ post,
|
|
150
|
+
await fn({ post, redeem, build });
|
|
150
151
|
} finally {
|
|
151
152
|
server.close();
|
|
152
153
|
realAuth.requireBuilder = saved;
|
|
@@ -154,75 +155,232 @@ async function withRoute({ idp, hub }, fn) {
|
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
test('
|
|
160
|
-
await withRoute({
|
|
161
|
-
|
|
162
|
-
assert.equal(
|
|
163
|
-
|
|
164
|
-
assert.
|
|
165
|
-
|
|
166
|
-
assert.equal(
|
|
167
|
-
assert.equal(
|
|
168
|
-
assert.equal(
|
|
169
|
-
assert.equal(
|
|
170
|
-
assert.equal(
|
|
171
|
-
assert.equal(
|
|
172
|
-
assert.
|
|
173
|
-
assert.equal(sent[0].body.client_secret, 's3cret');
|
|
158
|
+
const HASH = IF.sha256Hex('it broke');
|
|
159
|
+
|
|
160
|
+
test('a receipt names the SESSION\'s builder and the text hash, and redeems exactly once', async () => {
|
|
161
|
+
await withRoute({}, async ({ post, redeem }) => {
|
|
162
|
+
const r = await post({ sha256: HASH, kind: 'idea' });
|
|
163
|
+
assert.equal(r.status, 201, JSON.stringify(r.body));
|
|
164
|
+
assert.equal(r.body.hub, 'https://hub.example.com');
|
|
165
|
+
assert.match(r.body.receipt, /^[A-Za-z0-9_-]{24}$/);
|
|
166
|
+
const first = await redeem(r.body.receipt);
|
|
167
|
+
assert.equal(first.status, 200);
|
|
168
|
+
assert.equal(first.body.github_id, '42', 'from the session, never the body');
|
|
169
|
+
assert.equal(first.body.github_login, 'someone');
|
|
170
|
+
assert.equal(first.body.sha256, HASH);
|
|
171
|
+
assert.equal(first.body.kind, 'idea');
|
|
172
|
+
assert.equal((await redeem(r.body.receipt)).status, 404, 'single use');
|
|
173
|
+
assert.equal((await redeem('not-a-real-receipt-id')).status, 404);
|
|
174
174
|
});
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
test('a
|
|
178
|
-
await withRoute({
|
|
179
|
-
|
|
180
|
-
assert.equal(
|
|
181
|
-
assert.equal(
|
|
182
|
-
assert.equal(sent.length, 0);
|
|
177
|
+
test('a receipt request with a body naming a sender, or no hash, is refused', async () => {
|
|
178
|
+
await withRoute({}, async ({ post }) => {
|
|
179
|
+
assert.equal((await post({ sha256: HASH, github_id: '1' })).status, 400, 'no sender rides the body');
|
|
180
|
+
assert.equal((await post({ sha256: 'abc' })).status, 400);
|
|
181
|
+
assert.equal((await post({ sha256: HASH, kind: 'task' })).status, 400);
|
|
183
182
|
});
|
|
184
183
|
});
|
|
185
184
|
|
|
186
|
-
test('
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
185
|
+
test('receipts expire and the store is capped', () => {
|
|
186
|
+
const { makeReceiptStore } = require_(path.join(ROOT, 'src/bongos/routes/feedback.js'));
|
|
187
|
+
let now = 0;
|
|
188
|
+
const store = makeReceiptStore({ now: () => now, ttlMs: 1000, max: 3 });
|
|
189
|
+
const id = store.issue({ github_id: '1' });
|
|
190
|
+
now = 1001;
|
|
191
|
+
assert.equal(store.redeem(id), null, 'expired');
|
|
192
|
+
const live = [0, 1, 2].map((i) => store.issue({ github_id: String(i) }));
|
|
193
|
+
assert.equal(store.issue({ github_id: 'noisy' }), null, 'a full store refuses the new one');
|
|
194
|
+
assert.equal(store._rows.size, 3);
|
|
195
|
+
assert.equal(store.redeem(live[0]).github_id, '0', 'and never evicts a pending receipt');
|
|
194
196
|
});
|
|
195
197
|
|
|
196
|
-
test('a
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
});
|
|
198
|
+
test('a members-only project still lets the hub redeem a receipt — and nothing else', () => {
|
|
199
|
+
const { isExempt } = require_(path.join(ROOT, 'src/bongos/platform-visibility-gate.js'));
|
|
200
|
+
assert.equal(isExempt('/api/bongos/feedback/receipt/AbC_d-123456789012', 'GET'), true);
|
|
201
|
+
assert.equal(isExempt('/api/bongos/feedback/receipt', 'POST'), false, 'issuing one needs a member');
|
|
202
|
+
assert.equal(isExempt('/api/bongos/feedback/receipt/AbC/x', 'GET'), false);
|
|
203
|
+
assert.equal(isExempt('/api/bongos/feedback/receipt/AbC', 'DELETE'), false);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('reports go to the Cloud Bongos hub unless overridden; the hub itself answers null', () => {
|
|
207
|
+
const { feedbackHub, DEFAULT_FEEDBACK_HUB } = require_(path.join(ROOT, 'src/bongos/routes/feedback.js'));
|
|
208
|
+
assert.equal(feedbackHub({ env: {}, isHub: false }), DEFAULT_FEEDBACK_HUB);
|
|
209
|
+
assert.equal(feedbackHub({ env: {}, isHub: true }), null);
|
|
210
|
+
assert.equal(feedbackHub({ env: { CLOUDBONGOS_FEEDBACK_HUB: 'https://test-hub.example.com/' }, isHub: false }), 'https://test-hub.example.com');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// ── the hub: the direct door (task 1004591) ──────────────────────────────────
|
|
214
|
+
|
|
215
|
+
function receiptFetch(receipt, status = 200) {
|
|
216
|
+
const calls = [];
|
|
217
|
+
const fetchImpl = async (url, opts) => { calls.push({ url, opts }); return { status, json: async () => receipt }; };
|
|
218
|
+
return { fetchImpl, calls };
|
|
219
|
+
}
|
|
220
|
+
const DEPS = (extra = {}) => ({
|
|
221
|
+
assertPublicHost: async () => {},
|
|
222
|
+
capture: async (c) => { DEPS.last = c; return { id: 3, routing: { routed: true, task_id: 77, goal_id: 9, status: 'backlog' } }; },
|
|
223
|
+
getAccount: async () => ({ github_login: 'hub-login' }),
|
|
224
|
+
hubBuilderId: async () => 99,
|
|
225
|
+
...extra,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('direct: a hosted project\'s matching receipt files the report as verified', async () => {
|
|
229
|
+
const { fetchImpl, calls } = receiptFetch({ github_id: '42', github_login: 'will', sha256: HASH, kind: 'bug', core_version: '1.21.70' });
|
|
230
|
+
const landing = await IF.fileDirectReport({
|
|
231
|
+
origin: 'https://mercury.cloudbongos.com', receipt: 'r'.repeat(24), message: 'it broke', kind: 'bug',
|
|
232
|
+
context: { cli_version: '1.21.70', os: 'darwin' }, hubHost: 'cloudbongos.com',
|
|
233
|
+
}, DEPS({ fetchImpl }));
|
|
234
|
+
assert.equal(calls[0].url, `https://mercury.cloudbongos.com/api/bongos/feedback/receipt/${'r'.repeat(24)}`);
|
|
235
|
+
assert.equal(calls[0].opts.redirect, 'error', 'a redirect is never followed');
|
|
236
|
+
assert.equal(landing.landed, 'task');
|
|
237
|
+
assert.equal(DEPS.last.filerRank, null, 'still waits for a nod');
|
|
238
|
+
assert.equal(DEPS.last.vector, 'instance-feedback');
|
|
239
|
+
assert.equal(DEPS.last.capturedBy, 99);
|
|
240
|
+
assert.match(DEPS.last.bodyMd, /Sent by: @hub-login/);
|
|
241
|
+
assert.match(DEPS.last.bodyMd, /verified \(a project Cloud Bongos hosts\)/);
|
|
242
|
+
assert.match(DEPS.last.bodyMd, /Core 1\.21\.70/);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test('direct: a self-hosted project\'s word is labelled and never borrows a hub account', async () => {
|
|
246
|
+
const { fetchImpl } = receiptFetch({ github_id: '42', github_login: 'will', sha256: HASH, kind: 'bug' });
|
|
247
|
+
const lookups = [];
|
|
248
|
+
await IF.fileDirectReport({
|
|
249
|
+
origin: 'https://bongos.acme.example', receipt: 'r'.repeat(24), message: 'it broke', kind: 'bug', hubHost: 'cloudbongos.com',
|
|
250
|
+
}, DEPS({
|
|
251
|
+
fetchImpl,
|
|
252
|
+
getAccount: async (id) => { lookups.push(['account', id]); return { github_login: 'hub-login' }; },
|
|
253
|
+
hubBuilderId: async (id) => { lookups.push(['builder', id]); return 99; },
|
|
254
|
+
}));
|
|
255
|
+
assert.deepEqual(lookups, [], 'neither hub row is even read for an unverified sender');
|
|
256
|
+
assert.equal(DEPS.last.capturedBy, null);
|
|
257
|
+
assert.doesNotMatch(DEPS.last.bodyMd, /hub-login/);
|
|
258
|
+
assert.match(DEPS.last.bodyMd, /Sent by: @will \(GitHub user 42\)/);
|
|
259
|
+
assert.match(DEPS.last.bodyMd, /confirmed by bongos\.acme\.example \(self-hosted, not verified by us\)/);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test('direct: a report the project does not vouch for is dropped, never filed', async () => {
|
|
263
|
+
const filed = [];
|
|
264
|
+
const deps = (receipt, status, extra) => DEPS({ ...receiptFetch(receipt, status), capture: async (c) => { filed.push(c); return {}; }, ...extra });
|
|
265
|
+
const base = { origin: 'https://p.example.com', receipt: 'r'.repeat(24), message: 'it broke', kind: 'bug', hubHost: 'cloudbongos.com' };
|
|
266
|
+
const good = { github_id: '42', sha256: HASH, kind: 'bug' };
|
|
267
|
+
assert.deepEqual(await IF.fileDirectReport(base, deps({ ...good, sha256: IF.sha256Hex('something else') })), { dropped: 'text_mismatch' });
|
|
268
|
+
assert.deepEqual(await IF.fileDirectReport(base, deps({ ...good, kind: 'idea' })), { dropped: 'kind_mismatch' });
|
|
269
|
+
assert.deepEqual(await IF.fileDirectReport(base, deps(good, 404)), { dropped: 'receipt_http_404' });
|
|
270
|
+
assert.deepEqual(await IF.fileDirectReport(base, deps({ ...good, github_id: 'x' })), { dropped: 'receipt_malformed' });
|
|
271
|
+
assert.deepEqual(await IF.fileDirectReport(base, deps(good, 200, { assertPublicHost: async () => { throw new Error('private'); } })), { dropped: 'private_host' });
|
|
272
|
+
assert.deepEqual(await IF.fileDirectReport({ ...base, receipt: '../../x' }, deps(good)), { dropped: 'bad_receipt' });
|
|
273
|
+
assert.equal(filed.length, 0);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('direct: only a bare https origin on a public DNS name is ever called', () => {
|
|
277
|
+
for (const bad of ['http://p.example.com', 'https://127.0.0.1', 'https://[::1]', 'https://localhost', 'https://p.example.com:8443',
|
|
278
|
+
'https://p.example.com/path', 'https://u:p@p.example.com', 'https://box.internal', 'https://intranet', 'ftp://p.example.com']) {
|
|
279
|
+
assert.equal(IF.projectOrigin(bad), null, bad);
|
|
280
|
+
}
|
|
281
|
+
assert.deepEqual(IF.projectOrigin('https://Mercury.CloudBongos.com/'), { origin: 'https://mercury.cloudbongos.com', host: 'mercury.cloudbongos.com' });
|
|
282
|
+
assert.equal(IF.isHostedBy('mercury.cloudbongos.com', 'cloudbongos.com'), true);
|
|
283
|
+
assert.equal(IF.isHostedBy('evilcloudbongos.com', 'cloudbongos.com'), false);
|
|
284
|
+
assert.equal(IF.isHostedBy('x.example.com', ''), false);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('direct route: answers 202 before verifying, and caps BEFORE anything is fetched', () => {
|
|
288
|
+
const src = fs.readFileSync(path.join(ROOT, 'modules/platform-identity/routes/sso.js'), 'utf8');
|
|
289
|
+
const route = src.slice(src.indexOf("router.post('/sso/feedback/direct'"));
|
|
290
|
+
const at = (s) => { const i = route.indexOf(s); assert.ok(i > 0, `route has ${s}`); return i; };
|
|
291
|
+
assert.ok(at('projectOrigin') < at('directIpLimiter.take'));
|
|
292
|
+
assert.ok(at("directIpLimiter.take(ip, 'direct')") < at('directFeedbackLimiter.take'), 'a per-address cap no named host can dodge');
|
|
293
|
+
assert.ok(at('directFeedbackLimiter.take') < at('res.status(202)'));
|
|
294
|
+
assert.ok(at('res.status(202)') < at('fileDirectReport'));
|
|
295
|
+
assert.match(route, /assertPublicHost/);
|
|
209
296
|
});
|
|
210
297
|
|
|
211
298
|
// ── the CLI ───────────────────────────────────────────────────────────────────
|
|
212
299
|
|
|
213
|
-
test('`bongos feedback` is a registered verb, and every refusal
|
|
300
|
+
test('`bongos feedback` is a registered verb, and every refusal has a plain line', () => {
|
|
214
301
|
const { VERBS } = require_(path.join(ROOT, 'bin/bongos.js'));
|
|
215
302
|
assert.equal(VERBS.feedback.script, 'feedback-send.js');
|
|
216
303
|
const { REFUSALS, readMessage } = require_(path.join(ROOT, 'scripts/gds/feedback-send.js'));
|
|
217
|
-
for (const code of ['message_required', '
|
|
218
|
-
assert.ok(REFUSALS[code], code);
|
|
219
|
-
}
|
|
220
|
-
for (const code of ['validation_failed']) {
|
|
221
|
-
assert.ok(REFUSALS[code], code);
|
|
222
|
-
}
|
|
304
|
+
for (const code of ['message_required', 'too_long', 'local_only', 'no_scrubber']) assert.ok(REFUSALS[code], code);
|
|
223
305
|
assert.equal(readMessage(['--idea', 'filter', 'by', 'goal']), 'filter by goal');
|
|
224
306
|
});
|
|
225
307
|
|
|
308
|
+
// The skill tells the agent to use --message-file; it used to send the literal
|
|
309
|
+
// "[object Object]" because argText's result object was used as the text.
|
|
310
|
+
test('--message-file and stdin give the TEXT, never an object', () => {
|
|
311
|
+
const { readMessage } = require_(path.join(ROOT, 'scripts/gds/feedback-send.js'));
|
|
312
|
+
assert.equal(readMessage(['--message-file', '-'], { readStdin: () => 'from stdin' }), 'from stdin');
|
|
313
|
+
assert.equal(readMessage(['--message-file', 'x.md'], { readFile: () => 'from file' }), 'from file');
|
|
314
|
+
assert.equal(readMessage([], { stdinIsPiped: true, readStdin: () => 'piped' }), 'piped');
|
|
315
|
+
assert.equal(readMessage([], { stdinIsPiped: false }), '');
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
async function runCli(argv, extra = {}) {
|
|
319
|
+
const { main } = require_(path.join(ROOT, 'scripts/gds/feedback-send.js'));
|
|
320
|
+
const out = []; const err = [];
|
|
321
|
+
const log = console.log; const error = console.error;
|
|
322
|
+
console.log = (...a) => out.push(a.join(' ')); console.error = (...a) => err.push(a.join(' '));
|
|
323
|
+
const spawned = [];
|
|
324
|
+
try {
|
|
325
|
+
const code = await main(argv, {
|
|
326
|
+
requireSession: async () => ({ token: 't' }),
|
|
327
|
+
base: 'https://mercury.cloudbongos.com',
|
|
328
|
+
checkRepeat: () => false,
|
|
329
|
+
spawnDelivery: (job) => spawned.push(job),
|
|
330
|
+
...extra,
|
|
331
|
+
});
|
|
332
|
+
return { code, out, err, spawned };
|
|
333
|
+
} finally { console.log = log; console.error = error; }
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
test('the CLI prints one line and hands the network to the background', async () => {
|
|
337
|
+
const r = await runCli(['claim', 'hung']);
|
|
338
|
+
assert.equal(r.code, 0);
|
|
339
|
+
assert.deepEqual(r.out, ['Sent to the Bongos team.']);
|
|
340
|
+
assert.deepEqual(r.spawned, [{ message: 'claim hung', kind: 'bug' }]);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test('the CLI refuses a project only this computer can reach, and sends nothing', async () => {
|
|
344
|
+
for (const base of ['http://localhost:3000', 'http://127.0.0.1:3006', 'https://dev.test']) {
|
|
345
|
+
const r = await runCli(['x'], { base });
|
|
346
|
+
assert.equal(r.code, 1, base);
|
|
347
|
+
assert.equal(r.spawned.length, 0);
|
|
348
|
+
assert.match(r.err.join('\n'), /only on your computer/);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test('the same report twice inside the window is sent once', async () => {
|
|
353
|
+
const { checkAndRecordRepeat } = require_(path.join(ROOT, 'scripts/gds/feedback-send.js'));
|
|
354
|
+
const file = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'fb-')), 'sent.json');
|
|
355
|
+
assert.equal(checkAndRecordRepeat('Claim hung\nfirst time', { file, now: 0 }), false);
|
|
356
|
+
assert.equal(checkAndRecordRepeat('claim hung \nsecond rant', { file, now: 1000 }), true);
|
|
357
|
+
assert.equal(checkAndRecordRepeat('a different problem', { file, now: 2000 }), false);
|
|
358
|
+
assert.equal(checkAndRecordRepeat('claim hung', { file, now: 7 * 60 * 60 * 1000 }), false, 'the window expires');
|
|
359
|
+
const r = await runCli(['x'], { checkRepeat: () => true });
|
|
360
|
+
assert.equal(r.spawned.length, 0);
|
|
361
|
+
assert.match(r.out[0], /Already sent/);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test('deliver: receipt for the exact text from the project, then the report straight to the hub', async () => {
|
|
365
|
+
const { deliver } = require_(path.join(ROOT, 'scripts/gds/feedback-send.js'));
|
|
366
|
+
const reqs = [];
|
|
367
|
+
const api = { request: async (m, p, o) => { reqs.push({ m, p, body: o.body }); return { ok: true, data: { receipt: 'R'.repeat(24), hub: 'https://hub.example.com' } }; } };
|
|
368
|
+
const sent = [];
|
|
369
|
+
const fetchImpl = async (url, opts) => { sent.push({ url, body: JSON.parse(opts.body) }); return { status: 202, json: async () => ({ ok: true }) }; };
|
|
370
|
+
const out = await deliver({ message: 'it broke', kind: 'bug' }, { api, base: 'https://mercury.cloudbongos.com', fetchImpl });
|
|
371
|
+
assert.deepEqual(out, { ok: true, hub: 'https://hub.example.com' });
|
|
372
|
+
assert.deepEqual(reqs[0], { m: 'POST', p: '/feedback/receipt', body: { sha256: IF.sha256Hex('it broke'), kind: 'bug' } });
|
|
373
|
+
assert.equal(sent[0].url, 'https://hub.example.com/api/bongos/sso/feedback/direct');
|
|
374
|
+
assert.equal(sent[0].body.origin, 'https://mercury.cloudbongos.com');
|
|
375
|
+
assert.equal(sent[0].body.receipt, 'R'.repeat(24));
|
|
376
|
+
assert.equal(sent[0].body.message, 'it broke');
|
|
377
|
+
const hubSelf = await deliver({ message: 'x', kind: 'bug' }, {
|
|
378
|
+
api: { request: async () => ({ ok: true, data: { receipt: 'R'.repeat(24), hub: null } }) },
|
|
379
|
+
base: 'https://cloudbongos.com', fetchImpl,
|
|
380
|
+
});
|
|
381
|
+
assert.equal(hubSelf.hub, 'https://cloudbongos.com', 'on the hub itself, the report goes to the project it talks to');
|
|
382
|
+
});
|
|
383
|
+
|
|
226
384
|
// ── the hub route, driven for real ────────────────────────────────────────────
|
|
227
385
|
// The assembled /sso router with its DB edges stubbed: the client lookup, the
|
|
228
386
|
// membership read and the account read on the platform-identity domain, the
|
|
@@ -230,6 +388,11 @@ test('`bongos feedback` is a registered verb, and every refusal code has a plain
|
|
|
230
388
|
|
|
231
389
|
async function withHub(overrides, fn) {
|
|
232
390
|
const r2 = createRequire(import.meta.url);
|
|
391
|
+
// No real DNS from a unit test: the direct door's background redeem resolves
|
|
392
|
+
// the named host through project-stats, so refuse every host here.
|
|
393
|
+
const ps = r2(path.join(ROOT, 'modules/platform-identity/project-stats.js'));
|
|
394
|
+
const savedAssert = ps.assertPublicHost;
|
|
395
|
+
ps.assertPublicHost = async () => { throw new Error('no network in tests'); };
|
|
233
396
|
const api = r2(path.join(ROOT, 'src/module-api.js'));
|
|
234
397
|
const seams = r2(path.join(ROOT, 'src/module-seams.js'));
|
|
235
398
|
const pi = r2(path.join(ROOT, 'modules/platform-identity/platform-identity.js'));
|
|
@@ -250,6 +413,7 @@ async function withHub(overrides, fn) {
|
|
|
250
413
|
delete r2.cache[routerPath];
|
|
251
414
|
const express = r2('express');
|
|
252
415
|
const app = express();
|
|
416
|
+
app.set('trust proxy', 1); // as src/platform-server.js does
|
|
253
417
|
app.use(express.json());
|
|
254
418
|
app.use(r2(path.join(ROOT, 'src/bongos/middleware/error-envelope.js')).attachFail);
|
|
255
419
|
app.use(r2(routerPath)());
|
|
@@ -258,10 +422,14 @@ async function withHub(overrides, fn) {
|
|
|
258
422
|
const post = (body) => fetch(`http://127.0.0.1:${server.address().port}/sso/feedback`, {
|
|
259
423
|
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
|
260
424
|
}).then(async (res) => ({ status: res.status, body: await res.json() }));
|
|
261
|
-
|
|
425
|
+
const postTo = (p, body, headers = {}) => fetch(`http://127.0.0.1:${server.address().port}${p}`, {
|
|
426
|
+
method: 'POST', headers: { 'Content-Type': 'application/json', ...headers }, body: JSON.stringify(body),
|
|
427
|
+
}).then(async (res) => ({ status: res.status, body: await res.json() }));
|
|
428
|
+
try { await fn({ post, postTo, captured }); } finally {
|
|
262
429
|
server.close();
|
|
263
430
|
Object.assign(pi, saved);
|
|
264
431
|
api.pool.query = savedQuery;
|
|
432
|
+
ps.assertPublicHost = savedAssert;
|
|
265
433
|
delete r2.cache[routerPath];
|
|
266
434
|
}
|
|
267
435
|
}
|
|
@@ -295,6 +463,36 @@ test('hub: a wrong secret, an unwitnessed sender and a forged field are all refu
|
|
|
295
463
|
});
|
|
296
464
|
});
|
|
297
465
|
|
|
466
|
+
// The router's limiters live for the life of the module, so each case below
|
|
467
|
+
// uses its own made-up caller addresses (sent as X-Forwarded-For; the harness
|
|
468
|
+
// trusts the proxy as the platform server does) and its own project hosts.
|
|
469
|
+
const direct = (postTo, ip, host) => postTo('/sso/feedback/direct',
|
|
470
|
+
{ origin: `https://${host}`, receipt: 'r'.repeat(24), message: 'x' }, { 'X-Forwarded-For': ip });
|
|
471
|
+
|
|
472
|
+
test('direct route: one address naming a fresh host each time is still capped', async () => {
|
|
473
|
+
await withHub({}, async ({ postTo }) => {
|
|
474
|
+
const codes = [];
|
|
475
|
+
for (let i = 0; i < IF.PER_SENDER_LIMIT + 2; i++) codes.push((await direct(postTo, '203.0.113.1', `fresh${i}.example.com`)).status);
|
|
476
|
+
assert.deepEqual(codes.slice(0, IF.PER_SENDER_LIMIT), Array(IF.PER_SENDER_LIMIT).fill(202));
|
|
477
|
+
assert.equal(codes.at(-1), 429);
|
|
478
|
+
assert.equal((await postTo('/sso/feedback/direct', { origin: 'https://127.0.0.1', receipt: 'r'.repeat(24), message: 'x' })).status, 400);
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
test('direct route: callers never share a bucket, and a capped caller costs a project nothing', async () => {
|
|
483
|
+
await withHub({}, async ({ postTo }) => {
|
|
484
|
+
// Many different addresses, one report each: nobody is refused (no global bucket).
|
|
485
|
+
for (let i = 0; i < IF.PER_PROJECT_LIMIT + 5; i++) {
|
|
486
|
+
assert.equal((await direct(postTo, `198.51.100.${i + 1}`, `spread${i}.example.com`)).status, 202, `address ${i}`);
|
|
487
|
+
}
|
|
488
|
+
// An address past its own cap keeps naming a victim project: always 429...
|
|
489
|
+
for (let i = 0; i < IF.PER_SENDER_LIMIT; i++) await direct(postTo, '203.0.113.9', `burn${i}.example.com`);
|
|
490
|
+
for (let i = 0; i < IF.PER_PROJECT_LIMIT + 5; i++) assert.equal((await direct(postTo, '203.0.113.9', 'victim.example.com')).status, 429);
|
|
491
|
+
// ...and the victim's own builders still get through.
|
|
492
|
+
assert.equal((await direct(postTo, '192.0.2.50', 'victim.example.com')).status, 202);
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
|
|
298
496
|
// ── proactive filing (task 1004467) ───────────────────────────────────────────
|
|
299
497
|
// The owner's rule: a builder venting that Bongos is broken gets it filed without
|
|
300
498
|
// asking. That lives in two places, and both must keep saying it.
|
|
@@ -334,6 +532,7 @@ test('every report is secret-scrubbed before it leaves the machine, and never se
|
|
|
334
532
|
assert.ok(r.removed >= 2);
|
|
335
533
|
assert.equal(scrubReport('bongos claim hung for two minutes', {}).text, 'bongos claim hung for two minutes', 'plain prose is untouched');
|
|
336
534
|
const src = fs.readFileSync(path.join(ROOT, 'scripts/gds/feedback-send.js'), 'utf8');
|
|
337
|
-
|
|
338
|
-
assert.
|
|
535
|
+
const main = src.slice(src.indexOf('async function main('));
|
|
536
|
+
assert.ok(main.indexOf('scrubReport(message)') < main.indexOf('spawnDelivery'), 'scrubbed before anything is handed off');
|
|
537
|
+
assert.match(main, /message: scrubbed\.text/, 'only the scrubbed text is sent');
|
|
339
538
|
});
|