@fedify/fedify 2.1.30 → 2.1.32
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/dist/attachment-arrays-DZ4JHJD8.mjs +111 -0
- package/dist/{builder-CTpfuuVp.mjs → builder--sc-rozj.mjs} +3 -3
- package/dist/callback-BARPujV7.d.mts +2388 -0
- package/dist/{client-CAM_bQXx.d.cts → client-9DPcy_Yx.d.ts} +16 -1
- package/dist/{client-CSddvgWN.d.ts → client-B3ruDgWg.d.cts} +16 -1
- package/dist/{client-CjDMsn4a.mjs → client-cpPaW7Ww.mjs} +189 -65
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +254 -0
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-DLLaDau8.d.ts → context-DE2YrQwM.d.ts} +56 -13
- package/dist/{context-BNwv9Q1v.d.cts → context-y6ZUQCMf.d.cts} +56 -13
- package/dist/{deno-BATJ1hq6.mjs → deno-L23b3Hba.mjs} +1 -1
- package/dist/docloader-DUXr9k_O.mjs +124 -0
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +280 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1559 -26
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +723 -68
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-CK3efjgM.js → http-BtbMAgTA.js} +176 -105
- package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
- package/dist/{http-BoR1M3W7.cjs → http-D5woFKA_.cjs} +177 -106
- package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
- package/dist/{http-Bjd6I92u.mjs → http-HX6wVyJh.mjs} +198 -98
- package/dist/{inbox-9MlBGgs9.mjs → inbox-CL7A0HXT.mjs} +1 -1
- package/dist/{key-ClQh9Qqh.mjs → key-Dai3f5yI.mjs} +3 -2
- package/dist/{kv-cache-BxSx_Iyp.cjs → kv-cache-B0V_e231.cjs} +59 -17
- package/dist/{kv-cache-ImApO425.js → kv-cache-BsDg-cT8.js} +60 -18
- package/dist/{ld-Crg0Xmwr.mjs → ld-DN6x1iZ8.mjs} +153 -21
- package/dist/ld-signature-DoZcbsZR.mjs +23 -0
- package/dist/{middleware-jL9p9V9G.cjs → middleware-Cl6k5Hrm.cjs} +1 -1
- package/dist/{middleware-CmD3lpy4.cjs → middleware-CrfRuKCf.cjs} +728 -143
- package/dist/{middleware-CE0b69gj.mjs → middleware-DiquMgtt.mjs} +444 -115
- package/dist/{middleware-C2AJFk8W.js → middleware-DunNtbo9.js} +727 -143
- package/dist/{middleware-Bi5D6DBT.mjs → middleware-SnQS8eIb.mjs} +1 -1
- package/dist/{mod-DiuFTYUt.d.cts → mod-CehHJOV4.d.cts} +30 -13
- package/dist/{mod-CWJNbyju.d.ts → mod-DLJpnqdw.d.ts} +1 -1
- package/dist/{mod-BLDHhuW0.d.ts → mod-Mh3oIuRK.d.ts} +30 -13
- package/dist/{mod-DNEgTI8M.d.ts → mod-REfljt0T.d.ts} +4 -9
- package/dist/{mod-Cn9GJ5ex.d.cts → mod-UvIGUHqW.d.cts} +4 -9
- package/dist/{mod-BmlfRBmU.d.cts → mod-sTa1Zzxk.d.cts} +1 -1
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +764 -19
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +292 -30
- package/dist/otel/mod.cjs +36 -30
- package/dist/otel/mod.d.cts +13 -0
- package/dist/otel/mod.d.ts +13 -0
- package/dist/otel/mod.js +36 -30
- package/dist/{owner-BRoKojK1.mjs → owner-DwyDorZI.mjs} +2 -2
- package/dist/{proof-CHXVlsH_.cjs → proof-Be-4K4jn.cjs} +193 -46
- package/dist/{proof-DMIAezxz.mjs → proof-DYjmyrHh.mjs} +38 -13
- package/dist/{proof-7R4s10TJ.js → proof-Du4-5SHY.js} +187 -46
- package/dist/send-BGSfQkIK.mjs +416 -0
- package/dist/sig/http.test.mjs +506 -2
- package/dist/sig/key-types.test.d.mts +218 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +573 -8
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +95 -3
- package/dist/{temporal-DR0JahMu.mjs → temporal-CNCchWly.mjs} +3 -5
- package/dist/testing/mod.d.mts +1 -2177
- package/dist/{types-DRPjmHVV.cjs → types-B5wRhemi.cjs} +187 -63
- package/dist/{types-miAYfiGO.js → types-CXy2lRVU.js} +188 -64
- package/dist/utils/docloader.test.mjs +316 -32
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +7 -7
- package/dist/docloader-OLWc7P2D.mjs +0 -82
- package/dist/send-BHIt_8ia.mjs +0 -260
- /package/dist/{collection-BD6-SZ6O.mjs → collection-DnoYNwBC.mjs} +0 -0
- /package/dist/{negotiation-BehA2uul.mjs → negotiation-xb0QR3u_.mjs} +0 -0
- /package/dist/{retry-B_E3V_Dx.mjs → retry-CI1flGDD.mjs} +0 -0
- /package/dist/{types-DCP0WLdt.mjs → types-s4mCTGkT.mjs} +0 -0
|
@@ -9,18 +9,21 @@ import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.m
|
|
|
9
9
|
import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
|
|
10
10
|
import { t as assertNotEquals } from "../assert_not_equals-BkxW5QJI.mjs";
|
|
11
11
|
import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
|
|
12
|
-
import {
|
|
12
|
+
import { c as signRequest, u as verifyRequest } from "../http-HX6wVyJh.mjs";
|
|
13
13
|
import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CtZLJq76.mjs";
|
|
14
|
-
import {
|
|
14
|
+
import { n as getAuthenticatedDocumentLoader } from "../docloader-DUXr9k_O.mjs";
|
|
15
15
|
import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
|
|
16
|
-
import { a as compactJsonLd,
|
|
17
|
-
import { t as
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
16
|
+
import { a as compactJsonLd, c as detachSignature, g as verifyJsonLd, i as attachSignature, m as signJsonLd } from "../ld-DN6x1iZ8.mjs";
|
|
17
|
+
import { t as ldSignatureWithoutCreated } from "../ld-signature-DoZcbsZR.mjs";
|
|
18
|
+
import { t as doesActorOwnKey } from "../owner-DwyDorZI.mjs";
|
|
19
|
+
import { n as signObject, r as verifyObject } from "../proof-DYjmyrHh.mjs";
|
|
20
|
+
import { a as createFederation, i as KvSpecDeterminer, n as FederationImpl, r as InboxContextImpl, t as ContextImpl } from "../middleware-DiquMgtt.mjs";
|
|
21
|
+
import { t as SendActivityError } from "../send-BGSfQkIK.mjs";
|
|
22
|
+
import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
21
23
|
import * as vocab from "@fedify/vocab";
|
|
22
24
|
import { Create, Offer, Person, getTypeId, lookupObject } from "@fedify/vocab";
|
|
23
25
|
import { FetchError, UrlError, getDocumentLoader } from "@fedify/vocab-runtime";
|
|
26
|
+
import { configure, reset } from "@logtape/logtape";
|
|
24
27
|
import dns from "node:dns/promises";
|
|
25
28
|
//#region ../fixture/src/fixtures/example.com/create.json
|
|
26
29
|
var id$2 = "https://example.com/create";
|
|
@@ -86,7 +89,7 @@ var person2_default = {
|
|
|
86
89
|
};
|
|
87
90
|
//#endregion
|
|
88
91
|
//#region src/federation/middleware.test.ts
|
|
89
|
-
const documentLoader = getDocumentLoader();
|
|
92
|
+
const documentLoader = getDocumentLoader({ allowPrivateAddress: true });
|
|
90
93
|
test("createFederation()", async (t) => {
|
|
91
94
|
const kv = new MemoryKvStore();
|
|
92
95
|
await t.step("allowPrivateAddress", () => {
|
|
@@ -194,6 +197,104 @@ test("createFederation()", async (t) => {
|
|
|
194
197
|
}), TypeError);
|
|
195
198
|
});
|
|
196
199
|
});
|
|
200
|
+
test("FederationImpl.startQueue()", async (t) => {
|
|
201
|
+
function createCountingQueue() {
|
|
202
|
+
const messages = [];
|
|
203
|
+
let listenCount = 0;
|
|
204
|
+
return {
|
|
205
|
+
messages,
|
|
206
|
+
get listenCount() {
|
|
207
|
+
return listenCount;
|
|
208
|
+
},
|
|
209
|
+
enqueue(message) {
|
|
210
|
+
messages.push(message);
|
|
211
|
+
return Promise.resolve();
|
|
212
|
+
},
|
|
213
|
+
listen() {
|
|
214
|
+
listenCount++;
|
|
215
|
+
return Promise.resolve();
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
await t.step("starts a fanout-only queue with an explicit selector", async () => {
|
|
220
|
+
const queue = createCountingQueue();
|
|
221
|
+
const federation = new FederationImpl({
|
|
222
|
+
kv: new MemoryKvStore(),
|
|
223
|
+
queue: { fanout: queue },
|
|
224
|
+
manuallyStartQueue: true
|
|
225
|
+
});
|
|
226
|
+
await federation.startQueue(void 0, { queue: "fanout" });
|
|
227
|
+
assertEquals(queue.listenCount, 1);
|
|
228
|
+
await federation.startQueue(void 0, { queue: "fanout" });
|
|
229
|
+
assertEquals(queue.listenCount, 1);
|
|
230
|
+
});
|
|
231
|
+
await t.step("starts a fanout-only queue without a selector", async () => {
|
|
232
|
+
const queue = createCountingQueue();
|
|
233
|
+
await new FederationImpl({
|
|
234
|
+
kv: new MemoryKvStore(),
|
|
235
|
+
queue: { fanout: queue },
|
|
236
|
+
manuallyStartQueue: true
|
|
237
|
+
}).startQueue(void 0);
|
|
238
|
+
assertEquals(queue.listenCount, 1);
|
|
239
|
+
});
|
|
240
|
+
await t.step("starts a fanout-only queue after a fanout enqueue", async () => {
|
|
241
|
+
const queue = createCountingQueue();
|
|
242
|
+
const ctx = new ContextImpl({
|
|
243
|
+
data: void 0,
|
|
244
|
+
federation: new FederationImpl({
|
|
245
|
+
kv: new MemoryKvStore(),
|
|
246
|
+
contextLoaderFactory: () => mockDocumentLoader,
|
|
247
|
+
queue: { fanout: queue }
|
|
248
|
+
}),
|
|
249
|
+
url: new URL("https://example.com/"),
|
|
250
|
+
documentLoader: mockDocumentLoader,
|
|
251
|
+
contextLoader: mockDocumentLoader
|
|
252
|
+
});
|
|
253
|
+
const activity = new vocab.Create({
|
|
254
|
+
id: new URL("https://example.com/activity/1"),
|
|
255
|
+
actor: new URL("https://example.com/person")
|
|
256
|
+
});
|
|
257
|
+
await ctx.sendActivity([{
|
|
258
|
+
privateKey: rsaPrivateKey2,
|
|
259
|
+
keyId: rsaPublicKey2.id
|
|
260
|
+
}], {
|
|
261
|
+
id: new URL("https://example.com/recipient"),
|
|
262
|
+
inboxId: new URL("https://example.com/inbox")
|
|
263
|
+
}, activity, { fanout: "force" });
|
|
264
|
+
assertEquals(queue.listenCount, 1);
|
|
265
|
+
assertEquals(queue.messages.length, 1);
|
|
266
|
+
assertEquals(queue.messages[0].type, "fanout");
|
|
267
|
+
});
|
|
268
|
+
await t.step("does not start a fanout-only queue automatically when manually started", async () => {
|
|
269
|
+
const queue = createCountingQueue();
|
|
270
|
+
const ctx = new ContextImpl({
|
|
271
|
+
data: void 0,
|
|
272
|
+
federation: new FederationImpl({
|
|
273
|
+
kv: new MemoryKvStore(),
|
|
274
|
+
contextLoaderFactory: () => mockDocumentLoader,
|
|
275
|
+
queue: { fanout: queue },
|
|
276
|
+
manuallyStartQueue: true
|
|
277
|
+
}),
|
|
278
|
+
url: new URL("https://example.com/"),
|
|
279
|
+
documentLoader: mockDocumentLoader,
|
|
280
|
+
contextLoader: mockDocumentLoader
|
|
281
|
+
});
|
|
282
|
+
const activity = new vocab.Create({
|
|
283
|
+
id: new URL("https://example.com/activity/1"),
|
|
284
|
+
actor: new URL("https://example.com/person")
|
|
285
|
+
});
|
|
286
|
+
await ctx.sendActivity([{
|
|
287
|
+
privateKey: rsaPrivateKey2,
|
|
288
|
+
keyId: rsaPublicKey2.id
|
|
289
|
+
}], {
|
|
290
|
+
id: new URL("https://example.com/recipient"),
|
|
291
|
+
inboxId: new URL("https://example.com/inbox")
|
|
292
|
+
}, activity, { fanout: "force" });
|
|
293
|
+
assertEquals(queue.listenCount, 0);
|
|
294
|
+
assertEquals(queue.messages.length, 1);
|
|
295
|
+
assertEquals(queue.messages[0].type, "fanout");
|
|
296
|
+
});
|
|
297
|
+
});
|
|
197
298
|
test({
|
|
198
299
|
name: "Federation.createContext()",
|
|
199
300
|
permissions: {
|
|
@@ -216,7 +317,8 @@ test({
|
|
|
216
317
|
const federation = createFederation({
|
|
217
318
|
kv,
|
|
218
319
|
documentLoaderFactory: () => rejectingLoader,
|
|
219
|
-
contextLoaderFactory: () => mockDocumentLoader
|
|
320
|
+
contextLoaderFactory: () => mockDocumentLoader,
|
|
321
|
+
authenticatedDocumentLoaderFactory: (identity) => getAuthenticatedDocumentLoader(identity, { allowPrivateAddress: true })
|
|
220
322
|
});
|
|
221
323
|
let ctx = federation.createContext(new URL("https://example.com:1234/"), 123);
|
|
222
324
|
assertEquals(ctx.data, 123);
|
|
@@ -321,7 +423,7 @@ test({
|
|
|
321
423
|
documentUrl: "https://example.com/auth-check",
|
|
322
424
|
document: true
|
|
323
425
|
});
|
|
324
|
-
assertEquals(await ctx.lookupObject("https://example.com/object"), null);
|
|
426
|
+
assertEquals(await withDnsLookup(() => Promise.reject(/* @__PURE__ */ new Error("Resolver unavailable")), () => ctx.lookupObject("https://example.com/object")), null);
|
|
325
427
|
await assertRejects(() => ctx.sendActivity({ identifier: "handle" }, [], new vocab.Create({})), TypeError, "The activity to send must have at least one actor property.");
|
|
326
428
|
await ctx.sendActivity({ identifier: "handle" }, [], new vocab.Create({ actor: new URL("https://example.com/users/handle") }));
|
|
327
429
|
esm_default.get("https://example.com/object", () => new Response(JSON.stringify({
|
|
@@ -570,7 +672,7 @@ test({
|
|
|
570
672
|
assertStrictEquals(clone.contextLoader, ctx.contextLoader);
|
|
571
673
|
assertStrictEquals(clone.federation, ctx.federation);
|
|
572
674
|
});
|
|
573
|
-
esm_default.get("
|
|
675
|
+
esm_default.get("path:/.well-known/nodeinfo", (cl) => {
|
|
574
676
|
const headers = cl.options.headers ?? {};
|
|
575
677
|
assertEquals(new Headers(headers).get("User-Agent"), "CustomUserAgent/1.2.3");
|
|
576
678
|
return new Response(JSON.stringify({ links: [{
|
|
@@ -578,7 +680,7 @@ test({
|
|
|
578
680
|
href: "https://example.com/nodeinfo/2.1"
|
|
579
681
|
}] }));
|
|
580
682
|
});
|
|
581
|
-
esm_default.get("
|
|
683
|
+
esm_default.get("path:/nodeinfo/2.1", (cl) => {
|
|
582
684
|
const headers = cl.options.headers ?? {};
|
|
583
685
|
assertEquals(new Headers(headers).get("User-Agent"), "CustomUserAgent/1.2.3");
|
|
584
686
|
return new Response(JSON.stringify({
|
|
@@ -599,7 +701,11 @@ test({
|
|
|
599
701
|
kv,
|
|
600
702
|
userAgent: "CustomUserAgent/1.2.3"
|
|
601
703
|
}).createContext(new URL("https://example.com/"), 123);
|
|
602
|
-
|
|
704
|
+
const lookupExample = () => Promise.resolve([{
|
|
705
|
+
address: "93.184.215.14",
|
|
706
|
+
family: 4
|
|
707
|
+
}]);
|
|
708
|
+
assertEquals(await withDnsLookup(lookupExample, () => ctx.lookupNodeInfo("https://example.com/")), {
|
|
603
709
|
software: {
|
|
604
710
|
name: "foo",
|
|
605
711
|
version: "1.2.3"
|
|
@@ -611,7 +717,7 @@ test({
|
|
|
611
717
|
localComments: 456
|
|
612
718
|
}
|
|
613
719
|
});
|
|
614
|
-
assertEquals(await ctx.lookupNodeInfo("https://example.com/", { parse: "none" }), {
|
|
720
|
+
assertEquals(await withDnsLookup(lookupExample, () => ctx.lookupNodeInfo("https://example.com/", { parse: "none" })), {
|
|
615
721
|
software: {
|
|
616
722
|
name: "foo",
|
|
617
723
|
version: "1.2.3"
|
|
@@ -623,6 +729,22 @@ test({
|
|
|
623
729
|
localComments: 456
|
|
624
730
|
}
|
|
625
731
|
});
|
|
732
|
+
await assertRejects(() => ctx.lookupNodeInfo("https://example.com/", { timeout: 0 }), RangeError);
|
|
733
|
+
const caller = new AbortController();
|
|
734
|
+
caller.abort();
|
|
735
|
+
assertEquals(await ctx.lookupNodeInfo("https://example.com/", {
|
|
736
|
+
signal: caller.signal,
|
|
737
|
+
timeout: null
|
|
738
|
+
}), void 0);
|
|
739
|
+
assertEquals(await ctx.lookupNodeInfo("https://example.com/", {
|
|
740
|
+
parse: "none",
|
|
741
|
+
signal: caller.signal,
|
|
742
|
+
timeout: null
|
|
743
|
+
}), void 0);
|
|
744
|
+
await assertRejects(() => ctx.lookupNodeInfo("https://example.com/", {
|
|
745
|
+
parse: "none",
|
|
746
|
+
timeout: 0
|
|
747
|
+
}), RangeError);
|
|
626
748
|
});
|
|
627
749
|
await t.step("RequestContext", async () => {
|
|
628
750
|
const federation = createFederation({
|
|
@@ -718,6 +840,343 @@ test({
|
|
|
718
840
|
esm_default.hardReset();
|
|
719
841
|
}
|
|
720
842
|
});
|
|
843
|
+
test("RequestContext signature checks", async (t) => {
|
|
844
|
+
const [tracerProvider, exporter] = createTestTracerProvider();
|
|
845
|
+
const keyId = rsaPublicKey3.id.href;
|
|
846
|
+
const ownerId = rsaPublicKey3.ownerId.href;
|
|
847
|
+
const request = await signRequest(new Request("https://example.com/"), rsaPrivateKey3, rsaPublicKey3.id);
|
|
848
|
+
function setup(options = {}) {
|
|
849
|
+
const loads = {
|
|
850
|
+
key: 0,
|
|
851
|
+
owner: 0
|
|
852
|
+
};
|
|
853
|
+
const loader = async (url, loaderOptions) => {
|
|
854
|
+
if (url === keyId) loads.key++;
|
|
855
|
+
else if (url === ownerId) loads.owner++;
|
|
856
|
+
await options.gate;
|
|
857
|
+
return await (options.load ?? mockDocumentLoader)(url, loaderOptions);
|
|
858
|
+
};
|
|
859
|
+
const federation = createFederation({
|
|
860
|
+
kv: new MemoryKvStore(),
|
|
861
|
+
documentLoaderFactory: () => loader,
|
|
862
|
+
contextLoaderFactory: () => mockDocumentLoader,
|
|
863
|
+
tracerProvider: options.tracerProvider ?? tracerProvider
|
|
864
|
+
});
|
|
865
|
+
return {
|
|
866
|
+
ctx: federation.createContext(options.request ?? new Request(request), void 0),
|
|
867
|
+
loads,
|
|
868
|
+
loader,
|
|
869
|
+
federation
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
try {
|
|
873
|
+
for (const mode of [
|
|
874
|
+
"keys",
|
|
875
|
+
"owners",
|
|
876
|
+
"warm owners",
|
|
877
|
+
"mixed"
|
|
878
|
+
]) await t.step(`coalesces ${mode}`, async () => {
|
|
879
|
+
exporter.clear();
|
|
880
|
+
let release;
|
|
881
|
+
const { ctx, loads, loader } = setup({ gate: new Promise((resolve) => release = resolve) });
|
|
882
|
+
if (mode === "warm owners") {
|
|
883
|
+
release();
|
|
884
|
+
assert(await ctx.getSignedKey());
|
|
885
|
+
}
|
|
886
|
+
const results = Promise.all(Array.from({ length: 8 }, (_, i) => {
|
|
887
|
+
const options = i % 2 === 0 ? {} : {
|
|
888
|
+
documentLoader: loader,
|
|
889
|
+
contextLoader: ctx.contextLoader,
|
|
890
|
+
tracerProvider
|
|
891
|
+
};
|
|
892
|
+
return mode === "keys" || mode === "mixed" && i % 2 === 0 ? ctx.getSignedKey(options) : ctx.getSignedKeyOwner(options);
|
|
893
|
+
}));
|
|
894
|
+
release();
|
|
895
|
+
for (const result of await results) assert(result != null);
|
|
896
|
+
assertEquals(loads, {
|
|
897
|
+
key: 1,
|
|
898
|
+
owner: mode === "keys" ? 0 : 1
|
|
899
|
+
});
|
|
900
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 1);
|
|
901
|
+
assert(await ctx.getSignedKey());
|
|
902
|
+
if (mode !== "keys") assert(await ctx.getSignedKeyOwner());
|
|
903
|
+
assertEquals(loads, {
|
|
904
|
+
key: 1,
|
|
905
|
+
owner: mode === "keys" ? 0 : 1
|
|
906
|
+
});
|
|
907
|
+
});
|
|
908
|
+
await t.step("memoizes null keys", async () => {
|
|
909
|
+
exporter.clear();
|
|
910
|
+
const { ctx, loads } = setup({ load: () => Promise.reject(/* @__PURE__ */ new Error("unavailable")) });
|
|
911
|
+
for (let i = 0; i < 3; i++) {
|
|
912
|
+
assertEquals(await ctx.getSignedKey(), null);
|
|
913
|
+
assertEquals(await ctx.getSignedKeyOwner(), null);
|
|
914
|
+
}
|
|
915
|
+
assertEquals(loads, {
|
|
916
|
+
key: 1,
|
|
917
|
+
owner: 0
|
|
918
|
+
});
|
|
919
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 1);
|
|
920
|
+
assert(await ctx.getSignedKey({ documentLoader: mockDocumentLoader }));
|
|
921
|
+
assert(await ctx.getSignedKeyOwner({ documentLoader: mockDocumentLoader }));
|
|
922
|
+
});
|
|
923
|
+
await t.step("coalesces key-owner FetchError results", async () => {
|
|
924
|
+
const { ctx, loads } = setup({ load: async (url, options) => {
|
|
925
|
+
if (url === ownerId) throw new FetchError(new URL(url), "HTTP 401: Unauthorized");
|
|
926
|
+
return await mockDocumentLoader(url, options);
|
|
927
|
+
} });
|
|
928
|
+
assert(await ctx.getSignedKey());
|
|
929
|
+
assertEquals(await Promise.all(Array.from({ length: 8 }, () => ctx.getSignedKeyOwner())), Array(8).fill(null));
|
|
930
|
+
assertEquals(await ctx.getSignedKeyOwner(), null);
|
|
931
|
+
assertEquals(loads, {
|
|
932
|
+
key: 1,
|
|
933
|
+
owner: 1
|
|
934
|
+
});
|
|
935
|
+
assert(await ctx.getSignedKeyOwner({ documentLoader: mockDocumentLoader }));
|
|
936
|
+
});
|
|
937
|
+
await t.step("memoizes unsigned requests", async () => {
|
|
938
|
+
exporter.clear();
|
|
939
|
+
const { ctx, loads } = setup({ request: new Request("https://example.com/") });
|
|
940
|
+
for (let i = 0; i < 3; i++) {
|
|
941
|
+
assertEquals(await ctx.getSignedKey(), null);
|
|
942
|
+
assertEquals(await ctx.getSignedKeyOwner(), null);
|
|
943
|
+
}
|
|
944
|
+
assertEquals(loads, {
|
|
945
|
+
key: 0,
|
|
946
|
+
owner: 0
|
|
947
|
+
});
|
|
948
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 1);
|
|
949
|
+
});
|
|
950
|
+
await t.step("memoizes null owners without trusting a key's owner claim", async () => {
|
|
951
|
+
const { ctx, loads } = setup({ load: async (url, options) => url === ownerId ? {
|
|
952
|
+
documentUrl: url,
|
|
953
|
+
contextUrl: null,
|
|
954
|
+
document: {
|
|
955
|
+
...person2_default,
|
|
956
|
+
publicKey: []
|
|
957
|
+
}
|
|
958
|
+
} : await mockDocumentLoader(url, options) });
|
|
959
|
+
assert(await ctx.getSignedKey());
|
|
960
|
+
assertEquals(await Promise.all(Array.from({ length: 8 }, () => ctx.getSignedKeyOwner())), Array(8).fill(null));
|
|
961
|
+
for (let i = 0; i < 3; i++) assertEquals(await ctx.getSignedKeyOwner(), null);
|
|
962
|
+
assertEquals(loads, {
|
|
963
|
+
key: 1,
|
|
964
|
+
owner: 1
|
|
965
|
+
});
|
|
966
|
+
assert(await ctx.getSignedKeyOwner({ documentLoader: mockDocumentLoader }));
|
|
967
|
+
assert(await ctx.getSignedKeyOwner());
|
|
968
|
+
});
|
|
969
|
+
await t.step("isolates concurrent document loaders before success", async () => {
|
|
970
|
+
const { ctx, loads } = setup();
|
|
971
|
+
let otherLoads = 0;
|
|
972
|
+
const otherLoader = async (url, options) => {
|
|
973
|
+
otherLoads++;
|
|
974
|
+
if (url === ownerId) return {
|
|
975
|
+
documentUrl: url,
|
|
976
|
+
contextUrl: null,
|
|
977
|
+
document: {
|
|
978
|
+
...person2_default,
|
|
979
|
+
name: "Other view"
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
return await mockDocumentLoader(url, options);
|
|
983
|
+
};
|
|
984
|
+
const [first, second] = await Promise.all([ctx.getSignedKeyOwner(), ctx.getSignedKeyOwner({ documentLoader: otherLoader })]);
|
|
985
|
+
assertEquals(first?.name, "Jane Doe");
|
|
986
|
+
assertEquals(second?.name, "Other view");
|
|
987
|
+
const cached = await ctx.getSignedKeyOwner();
|
|
988
|
+
assert(cached === first || cached === second);
|
|
989
|
+
assertStrictEquals(await ctx.getSignedKeyOwner({ documentLoader: otherLoader }), cached);
|
|
990
|
+
assertEquals(loads, {
|
|
991
|
+
key: 1,
|
|
992
|
+
owner: 1
|
|
993
|
+
});
|
|
994
|
+
assertEquals(otherLoads, 2);
|
|
995
|
+
});
|
|
996
|
+
await t.step("preserves in-flight null while another loader succeeds", async () => {
|
|
997
|
+
exporter.clear();
|
|
998
|
+
let release;
|
|
999
|
+
const gate = new Promise((resolve) => release = resolve);
|
|
1000
|
+
const { ctx, loads } = setup({ load: async () => {
|
|
1001
|
+
await gate;
|
|
1002
|
+
throw new TypeError("fetch failed");
|
|
1003
|
+
} });
|
|
1004
|
+
const failed = Promise.all([ctx.getSignedKey(), ctx.getSignedKeyOwner()]);
|
|
1005
|
+
const owner = await ctx.getSignedKeyOwner({ documentLoader: mockDocumentLoader });
|
|
1006
|
+
assert(owner);
|
|
1007
|
+
release();
|
|
1008
|
+
assertEquals(await failed, [null, null]);
|
|
1009
|
+
assertStrictEquals(await ctx.getSignedKeyOwner(), owner);
|
|
1010
|
+
assert(await ctx.getSignedKey());
|
|
1011
|
+
assertEquals(loads, {
|
|
1012
|
+
key: 1,
|
|
1013
|
+
owner: 0
|
|
1014
|
+
});
|
|
1015
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 2);
|
|
1016
|
+
});
|
|
1017
|
+
await t.step("isolates context loaders", async () => {
|
|
1018
|
+
exporter.clear();
|
|
1019
|
+
const { ctx, loads } = setup();
|
|
1020
|
+
const otherContextLoader = (url, options) => mockDocumentLoader(url, options);
|
|
1021
|
+
await Promise.all([ctx.getSignedKeyOwner(), ctx.getSignedKeyOwner({ contextLoader: otherContextLoader })]);
|
|
1022
|
+
assertEquals(loads, {
|
|
1023
|
+
key: 2,
|
|
1024
|
+
owner: 2
|
|
1025
|
+
});
|
|
1026
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 2);
|
|
1027
|
+
});
|
|
1028
|
+
await t.step("shares work across tracer providers", async () => {
|
|
1029
|
+
exporter.clear();
|
|
1030
|
+
const [otherProvider, otherExporter] = createTestTracerProvider();
|
|
1031
|
+
try {
|
|
1032
|
+
const { ctx, loads } = setup();
|
|
1033
|
+
await Promise.all([
|
|
1034
|
+
ctx.getSignedKeyOwner(),
|
|
1035
|
+
ctx.getSignedKeyOwner({ tracerProvider: otherProvider }),
|
|
1036
|
+
ctx.getSignedKey(),
|
|
1037
|
+
ctx.getSignedKey({ tracerProvider: otherProvider })
|
|
1038
|
+
]);
|
|
1039
|
+
assert(await ctx.getSignedKeyOwner({ tracerProvider: otherProvider }));
|
|
1040
|
+
assertEquals(loads, {
|
|
1041
|
+
key: 1,
|
|
1042
|
+
owner: 1
|
|
1043
|
+
});
|
|
1044
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 1);
|
|
1045
|
+
assertEquals(otherExporter.getSpans("http_signatures.verify").length, 0);
|
|
1046
|
+
} finally {
|
|
1047
|
+
await otherProvider.shutdown();
|
|
1048
|
+
}
|
|
1049
|
+
});
|
|
1050
|
+
await t.step("reuses success with a fresh authorization loader", async () => {
|
|
1051
|
+
exporter.clear();
|
|
1052
|
+
const { ctx, loads } = setup();
|
|
1053
|
+
let freshLoads = 0;
|
|
1054
|
+
const freshLoader = (url, options) => {
|
|
1055
|
+
freshLoads++;
|
|
1056
|
+
return mockDocumentLoader(url, options);
|
|
1057
|
+
};
|
|
1058
|
+
const key = await ctx.getSignedKey({ documentLoader: freshLoader });
|
|
1059
|
+
assert(key);
|
|
1060
|
+
assertStrictEquals(await ctx.getSignedKey(), key);
|
|
1061
|
+
const owner = await ctx.getSignedKeyOwner();
|
|
1062
|
+
assert(owner);
|
|
1063
|
+
assertStrictEquals(await ctx.getSignedKeyOwner({ documentLoader: freshLoader }), owner);
|
|
1064
|
+
assertEquals(loads, {
|
|
1065
|
+
key: 0,
|
|
1066
|
+
owner: 1
|
|
1067
|
+
});
|
|
1068
|
+
assertEquals(freshLoads, 1);
|
|
1069
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 1);
|
|
1070
|
+
});
|
|
1071
|
+
await t.step("retains a transient owner lookup failure as null", async () => {
|
|
1072
|
+
let fail = true;
|
|
1073
|
+
const { ctx, loads } = setup({ load: async (url, options) => {
|
|
1074
|
+
if (url === ownerId && fail) throw new TypeError("fetch failed");
|
|
1075
|
+
return await mockDocumentLoader(url, options);
|
|
1076
|
+
} });
|
|
1077
|
+
assert(await ctx.getSignedKey());
|
|
1078
|
+
assertEquals(await ctx.getSignedKeyOwner(), null);
|
|
1079
|
+
fail = false;
|
|
1080
|
+
assertEquals(await ctx.getSignedKeyOwner(), null);
|
|
1081
|
+
assertEquals(loads, {
|
|
1082
|
+
key: 1,
|
|
1083
|
+
owner: 1
|
|
1084
|
+
});
|
|
1085
|
+
assert(await ctx.getSignedKeyOwner({ documentLoader: mockDocumentLoader }));
|
|
1086
|
+
});
|
|
1087
|
+
await t.step("rechecks an owner after another loader verifies the key", async () => {
|
|
1088
|
+
let fail = true;
|
|
1089
|
+
const { ctx, loads } = setup({ load: async (url, options) => {
|
|
1090
|
+
if (url === keyId && fail) throw new TypeError("fetch failed");
|
|
1091
|
+
return await mockDocumentLoader(url, options);
|
|
1092
|
+
} });
|
|
1093
|
+
assertEquals(await ctx.getSignedKeyOwner(), null);
|
|
1094
|
+
fail = false;
|
|
1095
|
+
assertEquals(await ctx.getSignedKeyOwner(), null);
|
|
1096
|
+
assertEquals(loads, {
|
|
1097
|
+
key: 1,
|
|
1098
|
+
owner: 0
|
|
1099
|
+
});
|
|
1100
|
+
assert(await ctx.getSignedKey({ documentLoader: mockDocumentLoader }));
|
|
1101
|
+
assertEquals((await ctx.getSignedKeyOwner())?.id?.href, ownerId);
|
|
1102
|
+
assertEquals(loads, {
|
|
1103
|
+
key: 1,
|
|
1104
|
+
owner: 1
|
|
1105
|
+
});
|
|
1106
|
+
});
|
|
1107
|
+
await t.step("retries unexpected key rejections from a rejection handler", async () => {
|
|
1108
|
+
exporter.clear();
|
|
1109
|
+
const failure = /* @__PURE__ */ new Error("transient context loader failure");
|
|
1110
|
+
let rejectContext = true;
|
|
1111
|
+
const contextLoader = async (url, options) => {
|
|
1112
|
+
if (rejectContext) throw failure;
|
|
1113
|
+
return await mockDocumentLoader(url, options);
|
|
1114
|
+
};
|
|
1115
|
+
const { ctx, loads } = setup();
|
|
1116
|
+
const options = { contextLoader };
|
|
1117
|
+
const failedKeys = Promise.allSettled([
|
|
1118
|
+
ctx.getSignedKey(options),
|
|
1119
|
+
ctx.getSignedKeyOwner(options),
|
|
1120
|
+
ctx.getSignedKey(options)
|
|
1121
|
+
]);
|
|
1122
|
+
const recovery = ctx.getSignedKey(options).catch(() => {
|
|
1123
|
+
rejectContext = false;
|
|
1124
|
+
return ctx.getSignedKey(options);
|
|
1125
|
+
});
|
|
1126
|
+
for (const result of await failedKeys) assertEquals(result.status, "rejected");
|
|
1127
|
+
assert(await recovery);
|
|
1128
|
+
assertEquals(loads, {
|
|
1129
|
+
key: 2,
|
|
1130
|
+
owner: 0
|
|
1131
|
+
});
|
|
1132
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 2);
|
|
1133
|
+
});
|
|
1134
|
+
await t.step("retries owner rejections while retaining the verified key", async () => {
|
|
1135
|
+
exporter.clear();
|
|
1136
|
+
let rejectContext = false;
|
|
1137
|
+
const contextLoader = async (url, options) => {
|
|
1138
|
+
if (rejectContext) throw new Error("transient owner context failure");
|
|
1139
|
+
return await mockDocumentLoader(url, options);
|
|
1140
|
+
};
|
|
1141
|
+
const { ctx, loads } = setup();
|
|
1142
|
+
const options = { contextLoader };
|
|
1143
|
+
assert(await ctx.getSignedKey(options));
|
|
1144
|
+
assertEquals(loads, {
|
|
1145
|
+
key: 1,
|
|
1146
|
+
owner: 0
|
|
1147
|
+
});
|
|
1148
|
+
rejectContext = true;
|
|
1149
|
+
const failures = await Promise.allSettled([ctx.getSignedKeyOwner(options), ctx.getSignedKeyOwner(options)]);
|
|
1150
|
+
for (const result of failures) assertEquals(result.status, "rejected");
|
|
1151
|
+
assertEquals(loads, {
|
|
1152
|
+
key: 1,
|
|
1153
|
+
owner: 1
|
|
1154
|
+
});
|
|
1155
|
+
rejectContext = false;
|
|
1156
|
+
assert(await ctx.getSignedKeyOwner(options));
|
|
1157
|
+
assertEquals(loads, {
|
|
1158
|
+
key: 1,
|
|
1159
|
+
owner: 2
|
|
1160
|
+
});
|
|
1161
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 1);
|
|
1162
|
+
});
|
|
1163
|
+
await t.step("keeps clones and separate requests independent", async () => {
|
|
1164
|
+
exporter.clear();
|
|
1165
|
+
const { ctx, loads, federation } = setup();
|
|
1166
|
+
assert(await ctx.getSignedKeyOwner());
|
|
1167
|
+
const clone = ctx.clone(void 0);
|
|
1168
|
+
const separate = federation.createContext(new Request(request), void 0);
|
|
1169
|
+
await Promise.all([clone.getSignedKeyOwner(), separate.getSignedKeyOwner()]);
|
|
1170
|
+
assertEquals(loads, {
|
|
1171
|
+
key: 3,
|
|
1172
|
+
owner: 3
|
|
1173
|
+
});
|
|
1174
|
+
assertEquals(exporter.getSpans("http_signatures.verify").length, 3);
|
|
1175
|
+
});
|
|
1176
|
+
} finally {
|
|
1177
|
+
await tracerProvider.shutdown();
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
721
1180
|
test("Federation.fetch() [rfc9421] multiple POST signatures", async (t) => {
|
|
722
1181
|
for (const validSecond of [true, false]) await t.step(validSecond ? "valid second signature" : "both signatures invalid", async () => {
|
|
723
1182
|
const inbox = [];
|
|
@@ -761,7 +1220,7 @@ test("Federation.fetch()", async (t) => {
|
|
|
761
1220
|
kv,
|
|
762
1221
|
documentLoaderFactory: () => mockDocumentLoader,
|
|
763
1222
|
authenticatedDocumentLoaderFactory(identity) {
|
|
764
|
-
const docLoader = getAuthenticatedDocumentLoader(identity);
|
|
1223
|
+
const docLoader = getAuthenticatedDocumentLoader(identity, { allowPrivateAddress: true });
|
|
765
1224
|
return (url) => {
|
|
766
1225
|
if (new URL(url).host === "example.com") return docLoader(url);
|
|
767
1226
|
return mockDocumentLoader(url);
|
|
@@ -928,7 +1387,7 @@ test("Federation.setInboxListeners()", async (t) => {
|
|
|
928
1387
|
kv,
|
|
929
1388
|
documentLoaderFactory: () => mockDocumentLoader,
|
|
930
1389
|
authenticatedDocumentLoaderFactory(identity) {
|
|
931
|
-
const docLoader = getAuthenticatedDocumentLoader(identity);
|
|
1390
|
+
const docLoader = getAuthenticatedDocumentLoader(identity, { allowPrivateAddress: true });
|
|
932
1391
|
return (url) => {
|
|
933
1392
|
const urlObj = new URL(url);
|
|
934
1393
|
authenticatedRequests.push([url, identity.keyId.href]);
|
|
@@ -1251,7 +1710,7 @@ test("Federation.setInboxListeners()", async (t) => {
|
|
|
1251
1710
|
kv,
|
|
1252
1711
|
documentLoaderFactory: () => mockDocumentLoader,
|
|
1253
1712
|
authenticatedDocumentLoaderFactory(identity) {
|
|
1254
|
-
const docLoader = getAuthenticatedDocumentLoader(identity);
|
|
1713
|
+
const docLoader = getAuthenticatedDocumentLoader(identity, { allowPrivateAddress: true });
|
|
1255
1714
|
return (url) => {
|
|
1256
1715
|
if (new URL(url).host === "example.com") return docLoader(url);
|
|
1257
1716
|
return mockDocumentLoader(url);
|
|
@@ -1386,7 +1845,7 @@ test("FederationImpl.sendActivity()", async (t) => {
|
|
|
1386
1845
|
});
|
|
1387
1846
|
const federation = new FederationImpl({
|
|
1388
1847
|
kv: new MemoryKvStore(),
|
|
1389
|
-
|
|
1848
|
+
allowPrivateAddress: true
|
|
1390
1849
|
});
|
|
1391
1850
|
const context = federation.createContext(new URL("https://example.com/"));
|
|
1392
1851
|
await t.step("success", async () => {
|
|
@@ -1447,6 +1906,356 @@ test("FederationImpl.sendActivity()", async (t) => {
|
|
|
1447
1906
|
});
|
|
1448
1907
|
esm_default.hardReset();
|
|
1449
1908
|
});
|
|
1909
|
+
const QUEUE_STARTUP_WARNING = "Failed to start queue workers automatically: {error}";
|
|
1910
|
+
/**
|
|
1911
|
+
* Captures unhandled promise rejections for the duration of a test step.
|
|
1912
|
+
*
|
|
1913
|
+
* Deno dispatches `unhandledrejection` on `globalThis`, while Node.js and Bun
|
|
1914
|
+
* dispatch `unhandledRejection` on `process`. Bun's test runner currently
|
|
1915
|
+
* fires neither, so there the native runner's own unhandled-rejection failure
|
|
1916
|
+
* remains the signal; the assertion is harmless otherwise.
|
|
1917
|
+
*/
|
|
1918
|
+
function captureUnhandledRejections() {
|
|
1919
|
+
const reasons = [];
|
|
1920
|
+
const isDeno = "Deno" in globalThis;
|
|
1921
|
+
const onRejectionEvent = (event) => {
|
|
1922
|
+
event.preventDefault();
|
|
1923
|
+
reasons.push(event.reason);
|
|
1924
|
+
};
|
|
1925
|
+
const onProcessRejection = (reason) => {
|
|
1926
|
+
reasons.push(reason);
|
|
1927
|
+
};
|
|
1928
|
+
const globalTarget = globalThis;
|
|
1929
|
+
const proc = globalThis.process;
|
|
1930
|
+
if (isDeno) globalTarget.addEventListener?.("unhandledrejection", onRejectionEvent);
|
|
1931
|
+
else proc?.on?.("unhandledRejection", onProcessRejection);
|
|
1932
|
+
async function settle() {
|
|
1933
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1934
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1935
|
+
}
|
|
1936
|
+
return {
|
|
1937
|
+
reasons,
|
|
1938
|
+
settle,
|
|
1939
|
+
stop() {
|
|
1940
|
+
if (isDeno) globalTarget.removeEventListener?.("unhandledrejection", onRejectionEvent);
|
|
1941
|
+
else proc?.off?.("unhandledRejection", onProcessRejection);
|
|
1942
|
+
}
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
async function configureQueueStartupWarningCapture(records) {
|
|
1946
|
+
await configure({
|
|
1947
|
+
sinks: { buffer(record) {
|
|
1948
|
+
records.push(record);
|
|
1949
|
+
} },
|
|
1950
|
+
loggers: [{
|
|
1951
|
+
category: "fedify",
|
|
1952
|
+
sinks: ["buffer"],
|
|
1953
|
+
lowestLevel: "warning"
|
|
1954
|
+
}, {
|
|
1955
|
+
category: ["logtape", "meta"],
|
|
1956
|
+
sinks: []
|
|
1957
|
+
}],
|
|
1958
|
+
reset: true
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
function queueStartupWarnings(records, error) {
|
|
1962
|
+
return records.filter((record) => record.level === "warning" && record.category.length === 3 && record.category[0] === "fedify" && record.category[1] === "federation" && record.category[2] === "queue" && record.rawMessage === QUEUE_STARTUP_WARNING && record.properties.error === error);
|
|
1963
|
+
}
|
|
1964
|
+
test("Federation.fetch() reports automatic queue startup failures", async (t) => {
|
|
1965
|
+
const listenError = /* @__PURE__ */ new TypeError("simulated listen() failure");
|
|
1966
|
+
const queue = {
|
|
1967
|
+
enqueue() {
|
|
1968
|
+
return Promise.resolve();
|
|
1969
|
+
},
|
|
1970
|
+
listen() {
|
|
1971
|
+
throw listenError;
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
const capture = captureUnhandledRejections();
|
|
1975
|
+
const records = [];
|
|
1976
|
+
await configureQueueStartupWarningCapture(records);
|
|
1977
|
+
try {
|
|
1978
|
+
const federation = createFederation({
|
|
1979
|
+
kv: new MemoryKvStore(),
|
|
1980
|
+
queue,
|
|
1981
|
+
skipSignatureVerification: true,
|
|
1982
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
1983
|
+
contextLoaderFactory: () => mockDocumentLoader
|
|
1984
|
+
});
|
|
1985
|
+
federation.setActorDispatcher("/actors/{identifier}", () => new Person({ id: new URL("https://example.com/actor") }));
|
|
1986
|
+
federation.setInboxListeners("/actors/{identifier}/inbox", "/inbox").on(Create, () => {});
|
|
1987
|
+
const post = (id) => federation.fetch(new Request("https://example.com/inbox", {
|
|
1988
|
+
method: "POST",
|
|
1989
|
+
headers: { "Content-Type": "application/activity+json" },
|
|
1990
|
+
body: JSON.stringify({
|
|
1991
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
1992
|
+
id,
|
|
1993
|
+
type: "Create",
|
|
1994
|
+
actor: "https://example.com/actor"
|
|
1995
|
+
})
|
|
1996
|
+
}), { contextData: void 0 });
|
|
1997
|
+
await t.step("synchronous failure", async () => {
|
|
1998
|
+
assertEquals((await post("https://example.com/activities/queued-1")).status, 202);
|
|
1999
|
+
await capture.settle();
|
|
2000
|
+
assertEquals(queueStartupWarnings(records, listenError).length, 1);
|
|
2001
|
+
assertEquals(capture.reasons, []);
|
|
2002
|
+
assertEquals((await post("https://example.com/activities/queued-2")).status, 202);
|
|
2003
|
+
await capture.settle();
|
|
2004
|
+
assertEquals(queueStartupWarnings(records, listenError).length, 1, "the warning must be logged only once per federation instance");
|
|
2005
|
+
assertEquals(capture.reasons, []);
|
|
2006
|
+
});
|
|
2007
|
+
await t.step("asynchronous failure", async () => {
|
|
2008
|
+
const asyncError = /* @__PURE__ */ new TypeError("simulated async listen() failure");
|
|
2009
|
+
let rejectListen;
|
|
2010
|
+
const asyncFederation = createFederation({
|
|
2011
|
+
kv: new MemoryKvStore(),
|
|
2012
|
+
queue: {
|
|
2013
|
+
enqueue() {
|
|
2014
|
+
return Promise.resolve();
|
|
2015
|
+
},
|
|
2016
|
+
listen() {
|
|
2017
|
+
return new Promise((_resolve, reject) => {
|
|
2018
|
+
rejectListen = reject;
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
},
|
|
2022
|
+
skipSignatureVerification: true,
|
|
2023
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
2024
|
+
contextLoaderFactory: () => mockDocumentLoader
|
|
2025
|
+
});
|
|
2026
|
+
asyncFederation.setActorDispatcher("/actors/{identifier}", () => new Person({ id: new URL("https://example.com/actor") }));
|
|
2027
|
+
asyncFederation.setInboxListeners("/actors/{identifier}/inbox", "/inbox").on(Create, () => {});
|
|
2028
|
+
assertEquals((await asyncFederation.fetch(new Request("https://example.com/inbox", {
|
|
2029
|
+
method: "POST",
|
|
2030
|
+
headers: { "Content-Type": "application/activity+json" },
|
|
2031
|
+
body: JSON.stringify({
|
|
2032
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
2033
|
+
id: "https://example.com/activities/queued-async",
|
|
2034
|
+
type: "Create",
|
|
2035
|
+
actor: "https://example.com/actor"
|
|
2036
|
+
})
|
|
2037
|
+
}), { contextData: void 0 })).status, 202);
|
|
2038
|
+
await capture.settle();
|
|
2039
|
+
assertEquals(queueStartupWarnings(records, asyncError).length, 0);
|
|
2040
|
+
assert(rejectListen != null);
|
|
2041
|
+
rejectListen(asyncError);
|
|
2042
|
+
await capture.settle();
|
|
2043
|
+
assertEquals(queueStartupWarnings(records, asyncError).length, 1, "a listener that rejects after startup must still be reported");
|
|
2044
|
+
assertEquals(capture.reasons, []);
|
|
2045
|
+
});
|
|
2046
|
+
} finally {
|
|
2047
|
+
await capture.settle();
|
|
2048
|
+
capture.stop();
|
|
2049
|
+
await reset();
|
|
2050
|
+
}
|
|
2051
|
+
});
|
|
2052
|
+
test("Federation.startQueue() rejects when a queue cannot listen", async () => {
|
|
2053
|
+
const listenError = /* @__PURE__ */ new TypeError("simulated listen() failure");
|
|
2054
|
+
const federation = createFederation({
|
|
2055
|
+
kv: new MemoryKvStore(),
|
|
2056
|
+
queue: {
|
|
2057
|
+
enqueue() {
|
|
2058
|
+
return Promise.resolve();
|
|
2059
|
+
},
|
|
2060
|
+
listen() {
|
|
2061
|
+
throw listenError;
|
|
2062
|
+
}
|
|
2063
|
+
},
|
|
2064
|
+
manuallyStartQueue: true
|
|
2065
|
+
});
|
|
2066
|
+
assertStrictEquals(await assertRejects(() => federation.startQueue(void 0)), listenError);
|
|
2067
|
+
});
|
|
2068
|
+
test("Federation.startQueue() keeps other queue workers running", async () => {
|
|
2069
|
+
const outboxError = /* @__PURE__ */ new TypeError("simulated outbox listen() failure");
|
|
2070
|
+
const lateInboxError = /* @__PURE__ */ new TypeError("simulated late inbox failure");
|
|
2071
|
+
let rejectInbox;
|
|
2072
|
+
let fanoutStarted = false;
|
|
2073
|
+
const inbox = {
|
|
2074
|
+
enqueue() {
|
|
2075
|
+
return Promise.resolve();
|
|
2076
|
+
},
|
|
2077
|
+
listen() {
|
|
2078
|
+
return new Promise((_resolve, reject) => {
|
|
2079
|
+
rejectInbox = reject;
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
};
|
|
2083
|
+
const outbox = {
|
|
2084
|
+
enqueue() {
|
|
2085
|
+
return Promise.resolve();
|
|
2086
|
+
},
|
|
2087
|
+
listen() {
|
|
2088
|
+
throw outboxError;
|
|
2089
|
+
}
|
|
2090
|
+
};
|
|
2091
|
+
const fanout = {
|
|
2092
|
+
enqueue() {
|
|
2093
|
+
return Promise.resolve();
|
|
2094
|
+
},
|
|
2095
|
+
listen() {
|
|
2096
|
+
fanoutStarted = true;
|
|
2097
|
+
return new Promise(() => {});
|
|
2098
|
+
}
|
|
2099
|
+
};
|
|
2100
|
+
const capture = captureUnhandledRejections();
|
|
2101
|
+
try {
|
|
2102
|
+
const federation = createFederation({
|
|
2103
|
+
kv: new MemoryKvStore(),
|
|
2104
|
+
queue: {
|
|
2105
|
+
inbox,
|
|
2106
|
+
outbox,
|
|
2107
|
+
fanout
|
|
2108
|
+
},
|
|
2109
|
+
manuallyStartQueue: true
|
|
2110
|
+
});
|
|
2111
|
+
assertStrictEquals(await assertRejects(() => federation.startQueue(void 0)), outboxError);
|
|
2112
|
+
assert(fanoutStarted, "a synchronous throw from one queue must not prevent later queues from starting");
|
|
2113
|
+
assert(rejectInbox != null);
|
|
2114
|
+
rejectInbox(lateInboxError);
|
|
2115
|
+
await capture.settle();
|
|
2116
|
+
assertEquals(capture.reasons, [], "an earlier listener rejection must remain handled after startup fails");
|
|
2117
|
+
} finally {
|
|
2118
|
+
await capture.settle();
|
|
2119
|
+
capture.stop();
|
|
2120
|
+
}
|
|
2121
|
+
});
|
|
2122
|
+
test("ContextImpl.sendActivity() reports automatic queue startup failures", async (t) => {
|
|
2123
|
+
const sender = [{
|
|
2124
|
+
privateKey: ed25519PrivateKey,
|
|
2125
|
+
keyId: ed25519Multikey.id
|
|
2126
|
+
}];
|
|
2127
|
+
const recipient = {
|
|
2128
|
+
id: new URL("https://example.com/recipient"),
|
|
2129
|
+
inboxId: new URL("https://example.com/inbox")
|
|
2130
|
+
};
|
|
2131
|
+
const createActivity = () => new Create({
|
|
2132
|
+
id: new URL("https://example.com/activities/queue-startup-send"),
|
|
2133
|
+
actor: new URL("https://example.com/actor")
|
|
2134
|
+
});
|
|
2135
|
+
await t.step("outbox", async () => {
|
|
2136
|
+
const listenError = /* @__PURE__ */ new TypeError("simulated outbox listen() failure");
|
|
2137
|
+
const messages = [];
|
|
2138
|
+
const queue = {
|
|
2139
|
+
enqueue(message) {
|
|
2140
|
+
messages.push(message);
|
|
2141
|
+
return Promise.resolve();
|
|
2142
|
+
},
|
|
2143
|
+
listen() {
|
|
2144
|
+
throw listenError;
|
|
2145
|
+
}
|
|
2146
|
+
};
|
|
2147
|
+
const capture = captureUnhandledRejections();
|
|
2148
|
+
const records = [];
|
|
2149
|
+
await configureQueueStartupWarningCapture(records);
|
|
2150
|
+
try {
|
|
2151
|
+
await new ContextImpl({
|
|
2152
|
+
data: void 0,
|
|
2153
|
+
federation: new FederationImpl({
|
|
2154
|
+
kv: new MemoryKvStore(),
|
|
2155
|
+
queue: { outbox: queue },
|
|
2156
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
2157
|
+
contextLoaderFactory: () => mockDocumentLoader
|
|
2158
|
+
}),
|
|
2159
|
+
url: new URL("https://example.com/"),
|
|
2160
|
+
documentLoader: mockDocumentLoader,
|
|
2161
|
+
contextLoader: mockDocumentLoader
|
|
2162
|
+
}).sendActivity(sender, recipient, createActivity());
|
|
2163
|
+
assertEquals(messages.map((message) => message.type), ["outbox"]);
|
|
2164
|
+
await capture.settle();
|
|
2165
|
+
assertEquals(queueStartupWarnings(records, listenError).length, 1);
|
|
2166
|
+
assertEquals(capture.reasons, []);
|
|
2167
|
+
} finally {
|
|
2168
|
+
await capture.settle();
|
|
2169
|
+
capture.stop();
|
|
2170
|
+
await reset();
|
|
2171
|
+
}
|
|
2172
|
+
});
|
|
2173
|
+
await t.step("fanout", async () => {
|
|
2174
|
+
const listenError = /* @__PURE__ */ new TypeError("simulated fanout listen() failure");
|
|
2175
|
+
const messages = [];
|
|
2176
|
+
const outbox = {
|
|
2177
|
+
enqueue() {
|
|
2178
|
+
return Promise.resolve();
|
|
2179
|
+
},
|
|
2180
|
+
listen() {
|
|
2181
|
+
return Promise.resolve();
|
|
2182
|
+
}
|
|
2183
|
+
};
|
|
2184
|
+
const fanout = {
|
|
2185
|
+
enqueue(message) {
|
|
2186
|
+
messages.push(message);
|
|
2187
|
+
return Promise.resolve();
|
|
2188
|
+
},
|
|
2189
|
+
listen() {
|
|
2190
|
+
throw listenError;
|
|
2191
|
+
}
|
|
2192
|
+
};
|
|
2193
|
+
const capture = captureUnhandledRejections();
|
|
2194
|
+
const records = [];
|
|
2195
|
+
await configureQueueStartupWarningCapture(records);
|
|
2196
|
+
try {
|
|
2197
|
+
await new ContextImpl({
|
|
2198
|
+
data: void 0,
|
|
2199
|
+
federation: new FederationImpl({
|
|
2200
|
+
kv: new MemoryKvStore(),
|
|
2201
|
+
queue: {
|
|
2202
|
+
outbox,
|
|
2203
|
+
fanout
|
|
2204
|
+
},
|
|
2205
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
2206
|
+
contextLoaderFactory: () => mockDocumentLoader
|
|
2207
|
+
}),
|
|
2208
|
+
url: new URL("https://example.com/"),
|
|
2209
|
+
documentLoader: mockDocumentLoader,
|
|
2210
|
+
contextLoader: mockDocumentLoader
|
|
2211
|
+
}).sendActivity(sender, recipient, createActivity(), { fanout: "force" });
|
|
2212
|
+
assertEquals(messages.map((message) => message.type), ["fanout"]);
|
|
2213
|
+
await capture.settle();
|
|
2214
|
+
assertEquals(queueStartupWarnings(records, listenError).length, 1);
|
|
2215
|
+
assertEquals(capture.reasons, []);
|
|
2216
|
+
} finally {
|
|
2217
|
+
await capture.settle();
|
|
2218
|
+
capture.stop();
|
|
2219
|
+
await reset();
|
|
2220
|
+
}
|
|
2221
|
+
});
|
|
2222
|
+
});
|
|
2223
|
+
test("queued Linked Data signatures without created use normalization contexts", async (t) => {
|
|
2224
|
+
for (const legacy of [false, true]) await t.step(legacy ? "legacy compacted payload" : "verified normalized cache", async () => {
|
|
2225
|
+
const normalized = await compactJsonLd(ldSignatureWithoutCreated, mockDocumentLoader);
|
|
2226
|
+
const raw = legacy ? normalized : structuredClone(ldSignatureWithoutCreated);
|
|
2227
|
+
const federation = new FederationImpl({
|
|
2228
|
+
kv: new MemoryKvStore(),
|
|
2229
|
+
contextLoaderFactory: () => async (url) => {
|
|
2230
|
+
if (url === "https://www.w3.org/ns/activitystreams" || url === "https://w3id.org/identity/v1") return await mockDocumentLoader(url);
|
|
2231
|
+
throw new Error(`Unexpected context: ${url}`);
|
|
2232
|
+
}
|
|
2233
|
+
});
|
|
2234
|
+
let deliveries = 0;
|
|
2235
|
+
let receivedRaw;
|
|
2236
|
+
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, (ctx, activity) => {
|
|
2237
|
+
deliveries++;
|
|
2238
|
+
receivedRaw = ctx.activity;
|
|
2239
|
+
assertEquals(activity.id?.href, ldSignatureWithoutCreated.id);
|
|
2240
|
+
});
|
|
2241
|
+
await federation.processQueuedTask(void 0, {
|
|
2242
|
+
type: "inbox",
|
|
2243
|
+
id: crypto.randomUUID(),
|
|
2244
|
+
baseUrl: "https://example.com",
|
|
2245
|
+
activity: raw,
|
|
2246
|
+
...legacy ? {} : {
|
|
2247
|
+
normalizedActivity: normalized,
|
|
2248
|
+
ldSignatureVerified: true
|
|
2249
|
+
},
|
|
2250
|
+
started: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2251
|
+
attempt: 0,
|
|
2252
|
+
identifier: null,
|
|
2253
|
+
traceContext: {}
|
|
2254
|
+
});
|
|
2255
|
+
assertEquals(deliveries, 1);
|
|
2256
|
+
assertEquals(receivedRaw, raw);
|
|
2257
|
+
});
|
|
2258
|
+
});
|
|
1450
2259
|
test("FederationImpl.processQueuedTask()", async (t) => {
|
|
1451
2260
|
await t.step("with MessageQueue having nativeRetrial", async () => {
|
|
1452
2261
|
const kv = new MemoryKvStore();
|
|
@@ -3353,7 +4162,7 @@ test("ContextImpl.sendActivity()", async (t) => {
|
|
|
3353
4162
|
const kv = new MemoryKvStore();
|
|
3354
4163
|
const federation = new FederationImpl({
|
|
3355
4164
|
kv,
|
|
3356
|
-
|
|
4165
|
+
allowPrivateAddress: true
|
|
3357
4166
|
});
|
|
3358
4167
|
federation.setActorDispatcher("/{identifier}", async (ctx, identifier) => {
|
|
3359
4168
|
if (identifier !== "1") return null;
|
|
@@ -3462,19 +4271,23 @@ test("ContextImpl.sendActivity()", async (t) => {
|
|
|
3462
4271
|
};
|
|
3463
4272
|
const federation2 = new FederationImpl({
|
|
3464
4273
|
kv,
|
|
3465
|
-
|
|
4274
|
+
allowPrivateAddress: true,
|
|
3466
4275
|
queue
|
|
3467
4276
|
});
|
|
3468
4277
|
federation2.setActorDispatcher("/{identifier}", async (ctx, identifier) => {
|
|
3469
|
-
if (identifier !== "john") return null;
|
|
4278
|
+
if (identifier !== "john" && identifier !== "rsa-only") return null;
|
|
3470
4279
|
const keys = await ctx.getActorKeyPairs(identifier);
|
|
3471
4280
|
return new vocab.Person({
|
|
3472
4281
|
id: ctx.getActorUri(identifier),
|
|
3473
|
-
preferredUsername:
|
|
4282
|
+
preferredUsername: identifier,
|
|
3474
4283
|
publicKey: keys[0].cryptographicKey,
|
|
3475
4284
|
assertionMethods: keys.map((k) => k.multikey)
|
|
3476
4285
|
});
|
|
3477
4286
|
}).setKeyPairsDispatcher((_ctx, identifier) => {
|
|
4287
|
+
if (identifier === "rsa-only") return [{
|
|
4288
|
+
privateKey: rsaPrivateKey2,
|
|
4289
|
+
publicKey: rsaPublicKey2.publicKey
|
|
4290
|
+
}];
|
|
3478
4291
|
if (identifier !== "john") return [];
|
|
3479
4292
|
return [{
|
|
3480
4293
|
privateKey: rsaPrivateKey2,
|
|
@@ -3523,6 +4336,375 @@ test("ContextImpl.sendActivity()", async (t) => {
|
|
|
3523
4336
|
proofCount++;
|
|
3524
4337
|
}
|
|
3525
4338
|
assertEquals(proofCount, 1);
|
|
4339
|
+
const oldContext = [
|
|
4340
|
+
"https://w3id.org/identity/v1",
|
|
4341
|
+
"https://www.w3.org/ns/activitystreams",
|
|
4342
|
+
"https://w3id.org/security/data-integrity/v1"
|
|
4343
|
+
];
|
|
4344
|
+
const oldJson = await (await signObject(new vocab.Create({
|
|
4345
|
+
id: new URL("https://example.com/activity/1"),
|
|
4346
|
+
actor: new URL("https://example.com/john")
|
|
4347
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
4348
|
+
contextLoader: documentLoader,
|
|
4349
|
+
context: oldContext
|
|
4350
|
+
})).toJsonLd({
|
|
4351
|
+
format: "compact",
|
|
4352
|
+
contextLoader: documentLoader,
|
|
4353
|
+
context: oldContext
|
|
4354
|
+
});
|
|
4355
|
+
queue.clear();
|
|
4356
|
+
await federation2.processQueuedTask(void 0, {
|
|
4357
|
+
...fanoutMsg,
|
|
4358
|
+
id: crypto.randomUUID(),
|
|
4359
|
+
activity: oldJson
|
|
4360
|
+
});
|
|
4361
|
+
const replayed = queue.messages.at(-1);
|
|
4362
|
+
assert(replayed != null && replayed.type === "outbox");
|
|
4363
|
+
assertEquals(detachSignature(replayed.activity), oldJson);
|
|
4364
|
+
const proofless = { ...oldJson };
|
|
4365
|
+
delete proofless.proof;
|
|
4366
|
+
queue.clear();
|
|
4367
|
+
await federation2.processQueuedTask(void 0, {
|
|
4368
|
+
...fanoutMsg,
|
|
4369
|
+
id: crypto.randomUUID(),
|
|
4370
|
+
activity: proofless
|
|
4371
|
+
});
|
|
4372
|
+
const signedReplay = queue.messages.at(-1);
|
|
4373
|
+
assert(signedReplay != null && signedReplay.type === "outbox");
|
|
4374
|
+
assert(typeof signedReplay.activity === "object" && signedReplay.activity != null && "proof" in signedReplay.activity);
|
|
4375
|
+
const edKey = (await ctx2.getActorKeyPairs("john")).find((key) => key.privateKey.algorithm.name === "Ed25519");
|
|
4376
|
+
assert(edKey != null && edKey.multikey.id != null);
|
|
4377
|
+
const restoredJson = await (await signObject(new vocab.Create({
|
|
4378
|
+
id: new URL("https://example.com/activity/old"),
|
|
4379
|
+
actor: ctx2.getActorUri("john")
|
|
4380
|
+
}), edKey.privateKey, edKey.multikey.id, {
|
|
4381
|
+
contextLoader: documentLoader,
|
|
4382
|
+
context: oldContext
|
|
4383
|
+
})).toJsonLd({
|
|
4384
|
+
format: "compact",
|
|
4385
|
+
contextLoader: documentLoader,
|
|
4386
|
+
context: oldContext
|
|
4387
|
+
});
|
|
4388
|
+
const restored = await vocab.Create.fromJsonLd(restoredJson, {
|
|
4389
|
+
contextLoader: documentLoader,
|
|
4390
|
+
documentLoader
|
|
4391
|
+
});
|
|
4392
|
+
queue.clear();
|
|
4393
|
+
await ctx2.sendActivity([{
|
|
4394
|
+
privateKey: rsaPrivateKey2,
|
|
4395
|
+
keyId: rsaPublicKey2.id
|
|
4396
|
+
}], {
|
|
4397
|
+
id: new URL("https://example.com/recipient"),
|
|
4398
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4399
|
+
}, restored);
|
|
4400
|
+
const resent = queue.messages.at(-1);
|
|
4401
|
+
assert(resent != null && resent.type === "outbox");
|
|
4402
|
+
assertEquals(detachSignature(resent.activity), restoredJson);
|
|
4403
|
+
queue.clear();
|
|
4404
|
+
await ctx2.sendActivity([{
|
|
4405
|
+
privateKey: rsaPrivateKey2,
|
|
4406
|
+
keyId: rsaPublicKey2.id
|
|
4407
|
+
}], {
|
|
4408
|
+
id: new URL("https://example.com/recipient"),
|
|
4409
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4410
|
+
}, restored, { fanout: "force" });
|
|
4411
|
+
const queuedFanout = queue.messages.at(-1);
|
|
4412
|
+
assert(queuedFanout != null && queuedFanout.type === "fanout");
|
|
4413
|
+
assertEquals(queuedFanout.activity, restoredJson);
|
|
4414
|
+
const restoredWithSignature = await vocab.Create.fromJsonLd(attachSignature(restoredJson, {
|
|
4415
|
+
"@context": "https://w3id.org/identity/v1",
|
|
4416
|
+
type: "RsaSignature2017",
|
|
4417
|
+
creator: "https://example.com/person2#key4",
|
|
4418
|
+
created: "2026-01-01T00:00:00Z",
|
|
4419
|
+
signatureValue: "abc"
|
|
4420
|
+
}), {
|
|
4421
|
+
contextLoader: documentLoader,
|
|
4422
|
+
documentLoader
|
|
4423
|
+
});
|
|
4424
|
+
queue.clear();
|
|
4425
|
+
await ctx2.sendActivity([{
|
|
4426
|
+
privateKey: rsaPrivateKey2,
|
|
4427
|
+
keyId: rsaPublicKey2.id
|
|
4428
|
+
}], {
|
|
4429
|
+
id: new URL("https://example.com/recipient"),
|
|
4430
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4431
|
+
}, restoredWithSignature);
|
|
4432
|
+
const resigned = queue.messages.at(-1);
|
|
4433
|
+
assert(resigned != null && resigned.type === "outbox");
|
|
4434
|
+
assertEquals(detachSignature(resigned.activity), restoredJson);
|
|
4435
|
+
const rsaOnlyJson = await (await signObject(new vocab.Create({
|
|
4436
|
+
id: new URL("https://example.com/activity/rsa-only"),
|
|
4437
|
+
actor: new URL("https://example.com/rsa-only")
|
|
4438
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
4439
|
+
contextLoader: documentLoader,
|
|
4440
|
+
context: oldContext
|
|
4441
|
+
})).toJsonLd({
|
|
4442
|
+
format: "compact",
|
|
4443
|
+
contextLoader: documentLoader,
|
|
4444
|
+
context: oldContext
|
|
4445
|
+
});
|
|
4446
|
+
const rsaOnlyRestored = await vocab.Create.fromJsonLd(rsaOnlyJson, {
|
|
4447
|
+
contextLoader: documentLoader,
|
|
4448
|
+
documentLoader
|
|
4449
|
+
});
|
|
4450
|
+
queue.clear();
|
|
4451
|
+
await ctx2.sendActivity({ identifier: "rsa-only" }, {
|
|
4452
|
+
id: new URL("https://example.com/recipient"),
|
|
4453
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4454
|
+
}, rsaOnlyRestored, { fanout: "force" });
|
|
4455
|
+
const rsaOnlyMessage = queue.messages.at(-1);
|
|
4456
|
+
assert(rsaOnlyMessage != null && rsaOnlyMessage.type === "fanout");
|
|
4457
|
+
assertEquals(rsaOnlyMessage.activity, rsaOnlyJson);
|
|
4458
|
+
queue.clear();
|
|
4459
|
+
await ctx2.sendActivity({ username: "john" }, {
|
|
4460
|
+
id: new URL("https://example.com/recipient"),
|
|
4461
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4462
|
+
}, restored, { fanout: "force" });
|
|
4463
|
+
const namedFanout = queue.messages.at(-1);
|
|
4464
|
+
assert(namedFanout != null && namedFanout.type === "fanout");
|
|
4465
|
+
const namedJson = detachSignature(namedFanout.activity);
|
|
4466
|
+
assertEquals((Array.isArray(namedJson.proof) ? namedJson.proof : [namedJson.proof]).length, 1);
|
|
4467
|
+
assert(namedJson["@context"].includes("https://w3id.org/security/v1"));
|
|
4468
|
+
const noIdJson = await (await signObject(new vocab.Create({ actor: ctx2.getActorUri("john") }), edKey.privateKey, edKey.multikey.id, {
|
|
4469
|
+
contextLoader: documentLoader,
|
|
4470
|
+
context: oldContext
|
|
4471
|
+
})).toJsonLd({
|
|
4472
|
+
format: "compact",
|
|
4473
|
+
contextLoader: documentLoader,
|
|
4474
|
+
context: oldContext
|
|
4475
|
+
});
|
|
4476
|
+
const noIdRestored = await vocab.Create.fromJsonLd(noIdJson, {
|
|
4477
|
+
contextLoader: documentLoader,
|
|
4478
|
+
documentLoader
|
|
4479
|
+
});
|
|
4480
|
+
queue.clear();
|
|
4481
|
+
await ctx2.sendActivity([{
|
|
4482
|
+
privateKey: rsaPrivateKey2,
|
|
4483
|
+
keyId: rsaPublicKey2.id
|
|
4484
|
+
}], {
|
|
4485
|
+
id: new URL("https://example.com/recipient"),
|
|
4486
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4487
|
+
}, noIdRestored);
|
|
4488
|
+
const noIdQueued = queue.messages.at(-1);
|
|
4489
|
+
assert(noIdQueued != null && noIdQueued.type === "outbox");
|
|
4490
|
+
assert(typeof detachSignature(noIdQueued.activity).id === "string");
|
|
4491
|
+
const currentJson = await (await signObject(new vocab.Create({
|
|
4492
|
+
id: new URL("https://example.com/activity/current"),
|
|
4493
|
+
actor: ctx2.getActorUri("john")
|
|
4494
|
+
}), edKey.privateKey, edKey.multikey.id, { contextLoader: documentLoader })).toJsonLd({
|
|
4495
|
+
format: "compact",
|
|
4496
|
+
contextLoader: documentLoader
|
|
4497
|
+
});
|
|
4498
|
+
const currentRestored = await vocab.Create.fromJsonLd(currentJson, {
|
|
4499
|
+
contextLoader: documentLoader,
|
|
4500
|
+
documentLoader
|
|
4501
|
+
});
|
|
4502
|
+
queue.clear();
|
|
4503
|
+
await ctx2.sendActivity({ username: "john" }, {
|
|
4504
|
+
id: new URL("https://example.com/recipient"),
|
|
4505
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4506
|
+
}, currentRestored, { fanout: "force" });
|
|
4507
|
+
const currentFanout = queue.messages.at(-1);
|
|
4508
|
+
assert(currentFanout != null && currentFanout.type === "fanout");
|
|
4509
|
+
const currentQueued = detachSignature(currentFanout.activity);
|
|
4510
|
+
assertEquals((Array.isArray(currentQueued.proof) ? currentQueued.proof : [currentQueued.proof]).length, 2);
|
|
4511
|
+
});
|
|
4512
|
+
queue.clear();
|
|
4513
|
+
await t.step("activity transformers preserve proofs", async () => {
|
|
4514
|
+
const originalProof = new vocab.DataIntegrityProof({
|
|
4515
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
4516
|
+
verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
|
|
4517
|
+
proofPurpose: "assertionMethod",
|
|
4518
|
+
proofValue: new Uint8Array([
|
|
4519
|
+
1,
|
|
4520
|
+
2,
|
|
4521
|
+
3,
|
|
4522
|
+
4
|
|
4523
|
+
]),
|
|
4524
|
+
created: Temporal.Instant.from("2026-01-01T00:00:00Z")
|
|
4525
|
+
});
|
|
4526
|
+
const addedProof = new vocab.DataIntegrityProof({
|
|
4527
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
4528
|
+
verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
|
|
4529
|
+
proofPurpose: "assertionMethod",
|
|
4530
|
+
proofValue: new Uint8Array([
|
|
4531
|
+
5,
|
|
4532
|
+
6,
|
|
4533
|
+
7,
|
|
4534
|
+
8
|
|
4535
|
+
]),
|
|
4536
|
+
created: Temporal.Instant.from("2026-01-02T00:00:00Z")
|
|
4537
|
+
});
|
|
4538
|
+
const replacementProof = new vocab.DataIntegrityProof({
|
|
4539
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
4540
|
+
verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
|
|
4541
|
+
proofPurpose: "assertionMethod",
|
|
4542
|
+
proofValue: new Uint8Array([
|
|
4543
|
+
9,
|
|
4544
|
+
10,
|
|
4545
|
+
11,
|
|
4546
|
+
12
|
|
4547
|
+
]),
|
|
4548
|
+
created: Temporal.Instant.from("2026-01-03T00:00:00Z")
|
|
4549
|
+
});
|
|
4550
|
+
const restoredProof = new vocab.DataIntegrityProof({
|
|
4551
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
4552
|
+
verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
|
|
4553
|
+
proofPurpose: "assertionMethod",
|
|
4554
|
+
proofValue: new Uint8Array([
|
|
4555
|
+
13,
|
|
4556
|
+
14,
|
|
4557
|
+
15,
|
|
4558
|
+
16
|
|
4559
|
+
]),
|
|
4560
|
+
created: Temporal.Instant.from("2026-01-04T00:00:00Z")
|
|
4561
|
+
});
|
|
4562
|
+
const restoredProofHolder = {};
|
|
4563
|
+
const federation3 = new FederationImpl({
|
|
4564
|
+
kv,
|
|
4565
|
+
allowPrivateAddress: true,
|
|
4566
|
+
queue,
|
|
4567
|
+
activityTransformers: [(activity) => {
|
|
4568
|
+
if (activity.id?.href === "https://example.com/activity/transformed-proof") return activity.clone({ proofs: [originalProof, addedProof] });
|
|
4569
|
+
if (activity.id?.href === "https://example.com/activity/replaced-proof") return new vocab.Create({
|
|
4570
|
+
id: activity.id,
|
|
4571
|
+
actor: new URL("https://example.com/rsa-only"),
|
|
4572
|
+
object: new URL("https://example.com/note/replaced"),
|
|
4573
|
+
proofs: [replacementProof]
|
|
4574
|
+
});
|
|
4575
|
+
if (activity.id?.href === "https://example.com/activity/restored-proof") return activity.clone({ proofs: [restoredProofHolder.old, restoredProof] });
|
|
4576
|
+
return activity;
|
|
4577
|
+
}]
|
|
4578
|
+
});
|
|
4579
|
+
federation3.setActorDispatcher("/{identifier}", async (ctx, identifier) => {
|
|
4580
|
+
if (identifier !== "rsa-only") return null;
|
|
4581
|
+
const keys = await ctx.getActorKeyPairs(identifier);
|
|
4582
|
+
return new vocab.Person({
|
|
4583
|
+
id: ctx.getActorUri(identifier),
|
|
4584
|
+
preferredUsername: identifier,
|
|
4585
|
+
publicKey: keys[0].cryptographicKey,
|
|
4586
|
+
assertionMethods: keys.map((k) => k.multikey)
|
|
4587
|
+
});
|
|
4588
|
+
}).setKeyPairsDispatcher((_ctx, identifier) => identifier === "rsa-only" ? [{
|
|
4589
|
+
privateKey: rsaPrivateKey2,
|
|
4590
|
+
publicKey: rsaPublicKey2.publicKey
|
|
4591
|
+
}] : []);
|
|
4592
|
+
const ctx3 = new ContextImpl({
|
|
4593
|
+
data: void 0,
|
|
4594
|
+
federation: federation3,
|
|
4595
|
+
url: new URL("https://example.com/"),
|
|
4596
|
+
documentLoader,
|
|
4597
|
+
contextLoader: documentLoader
|
|
4598
|
+
});
|
|
4599
|
+
const activity = new vocab.Create({
|
|
4600
|
+
id: new URL("https://example.com/activity/transformed-proof"),
|
|
4601
|
+
actor: ctx3.getActorUri("rsa-only"),
|
|
4602
|
+
proofs: [originalProof]
|
|
4603
|
+
});
|
|
4604
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
4605
|
+
id: new URL("https://example.com/recipient"),
|
|
4606
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4607
|
+
}, activity, { fanout: "force" });
|
|
4608
|
+
const fanout = queue.messages.at(-1);
|
|
4609
|
+
assert(fanout != null && fanout.type === "fanout");
|
|
4610
|
+
const fanoutJson = detachSignature(fanout.activity);
|
|
4611
|
+
assertEquals((Array.isArray(fanoutJson.proof) ? fanoutJson.proof : [fanoutJson.proof]).length, 2);
|
|
4612
|
+
const replacedActivity = new vocab.Create({
|
|
4613
|
+
id: new URL("https://example.com/activity/replaced-proof"),
|
|
4614
|
+
actor: ctx3.getActorUri("rsa-only"),
|
|
4615
|
+
proofs: [originalProof]
|
|
4616
|
+
});
|
|
4617
|
+
queue.clear();
|
|
4618
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
4619
|
+
id: new URL("https://example.com/recipient"),
|
|
4620
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4621
|
+
}, replacedActivity, { fanout: "force" });
|
|
4622
|
+
const replacedFanout = queue.messages.at(-1);
|
|
4623
|
+
assert(replacedFanout != null && replacedFanout.type === "fanout");
|
|
4624
|
+
const replacedJson = detachSignature(replacedFanout.activity);
|
|
4625
|
+
assertEquals(replacedJson.object, "https://example.com/note/replaced");
|
|
4626
|
+
const replacedProofs = Array.isArray(replacedJson.proof) ? replacedJson.proof : [replacedJson.proof];
|
|
4627
|
+
assertEquals(replacedProofs.length, 1);
|
|
4628
|
+
const [keptProof] = replacedProofs;
|
|
4629
|
+
assertEquals(keptProof.created, "2026-01-03T00:00:00Z");
|
|
4630
|
+
const oldContext = [
|
|
4631
|
+
"https://w3id.org/identity/v1",
|
|
4632
|
+
"https://www.w3.org/ns/activitystreams",
|
|
4633
|
+
"https://w3id.org/security/data-integrity/v1"
|
|
4634
|
+
];
|
|
4635
|
+
const restoredJson = await (await signObject(new vocab.Create({
|
|
4636
|
+
id: new URL("https://example.com/activity/restored-proof"),
|
|
4637
|
+
actor: ctx3.getActorUri("rsa-only")
|
|
4638
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
4639
|
+
contextLoader: documentLoader,
|
|
4640
|
+
context: oldContext
|
|
4641
|
+
})).toJsonLd({
|
|
4642
|
+
format: "compact",
|
|
4643
|
+
contextLoader: documentLoader,
|
|
4644
|
+
context: oldContext
|
|
4645
|
+
});
|
|
4646
|
+
const restored = await vocab.Create.fromJsonLd(restoredJson, {
|
|
4647
|
+
contextLoader: documentLoader,
|
|
4648
|
+
documentLoader
|
|
4649
|
+
});
|
|
4650
|
+
for await (const proof of restored.getProofs({ contextLoader: documentLoader })) {
|
|
4651
|
+
restoredProofHolder.old = proof;
|
|
4652
|
+
break;
|
|
4653
|
+
}
|
|
4654
|
+
queue.clear();
|
|
4655
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
4656
|
+
id: new URL("https://example.com/recipient"),
|
|
4657
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4658
|
+
}, restored, { fanout: "force" });
|
|
4659
|
+
const restoredFanout = queue.messages.at(-1);
|
|
4660
|
+
assert(restoredFanout != null && restoredFanout.type === "fanout");
|
|
4661
|
+
const restoredFanoutJson = detachSignature(restoredFanout.activity);
|
|
4662
|
+
const restoredProofs = Array.isArray(restoredFanoutJson.proof) ? restoredFanoutJson.proof : [restoredFanoutJson.proof];
|
|
4663
|
+
assertEquals(restoredProofs.length, 1);
|
|
4664
|
+
const [transformedProof] = restoredProofs;
|
|
4665
|
+
assertEquals(transformedProof.created, "2026-01-04T00:00:00Z");
|
|
4666
|
+
assert(Array.isArray(restoredFanoutJson["@context"]) && restoredFanoutJson["@context"].includes("https://w3id.org/security/v1"));
|
|
4667
|
+
const staleTimestampJson = await (await signObject(new vocab.Create({
|
|
4668
|
+
id: new URL("https://example.com/activity/stale-timestamp"),
|
|
4669
|
+
actor: ctx3.getActorUri("rsa-only")
|
|
4670
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
4671
|
+
contextLoader: documentLoader,
|
|
4672
|
+
context: oldContext
|
|
4673
|
+
})).toJsonLd({
|
|
4674
|
+
format: "compact",
|
|
4675
|
+
contextLoader: documentLoader,
|
|
4676
|
+
context: oldContext
|
|
4677
|
+
});
|
|
4678
|
+
const staleTimestampProof = Array.isArray(staleTimestampJson.proof) ? staleTimestampJson.proof[0] : staleTimestampJson.proof;
|
|
4679
|
+
staleTimestampProof.created = "2026-01-01T00:00:00+00:00";
|
|
4680
|
+
const staleTimestamp = await vocab.Create.fromJsonLd(staleTimestampJson, {
|
|
4681
|
+
contextLoader: documentLoader,
|
|
4682
|
+
documentLoader
|
|
4683
|
+
});
|
|
4684
|
+
queue.clear();
|
|
4685
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
4686
|
+
id: new URL("https://example.com/recipient"),
|
|
4687
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4688
|
+
}, staleTimestamp, { fanout: "force" });
|
|
4689
|
+
const staleTimestampFanout = queue.messages.at(-1);
|
|
4690
|
+
assert(staleTimestampFanout != null && staleTimestampFanout.type === "fanout");
|
|
4691
|
+
assertEquals(detachSignature(staleTimestampFanout.activity), staleTimestampJson);
|
|
4692
|
+
const proofless = new vocab.Create({
|
|
4693
|
+
id: new URL("https://example.com/activity/proofless"),
|
|
4694
|
+
actor: ctx3.getActorUri("rsa-only")
|
|
4695
|
+
});
|
|
4696
|
+
let unformattedSerializations = 0;
|
|
4697
|
+
const originalToJsonLd = proofless.toJsonLd.bind(proofless);
|
|
4698
|
+
Object.defineProperty(proofless, "toJsonLd", { value: async (options) => {
|
|
4699
|
+
if (options?.format == null) unformattedSerializations++;
|
|
4700
|
+
return await originalToJsonLd(options);
|
|
4701
|
+
} });
|
|
4702
|
+
queue.clear();
|
|
4703
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
4704
|
+
id: new URL("https://example.com/recipient"),
|
|
4705
|
+
inboxId: new URL("https://example.com/inbox")
|
|
4706
|
+
}, proofless, { fanout: "skip" });
|
|
4707
|
+
assertEquals(unformattedSerializations, 0);
|
|
3526
4708
|
});
|
|
3527
4709
|
queue.clear();
|
|
3528
4710
|
await t.step("fanout: \"skip\"", async () => {
|
|
@@ -3585,7 +4767,7 @@ test("ContextImpl.sendActivity()", async (t) => {
|
|
|
3585
4767
|
const asyncEnqueued = [];
|
|
3586
4768
|
const fed = new FederationImpl({
|
|
3587
4769
|
kv,
|
|
3588
|
-
|
|
4770
|
+
allowPrivateAddress: true,
|
|
3589
4771
|
queue: {
|
|
3590
4772
|
enqueue(message) {
|
|
3591
4773
|
return new Promise((resolve) => {
|
|
@@ -3752,10 +4934,10 @@ test({
|
|
|
3752
4934
|
const signedInvite = await signObject(new vocab.Invite({ actor: new URL("https://example.com/person2") }), ed25519PrivateKey, ed25519Multikey.id);
|
|
3753
4935
|
assert(await ctx.routeActivity("id", signedInvite));
|
|
3754
4936
|
assertEquals(activities, [[null, signedOffer], ["id", signedInvite]]);
|
|
3755
|
-
assertFalse(await ctx.routeActivity(null, new vocab.Create({
|
|
4937
|
+
assertFalse(await withDnsLookup(() => Promise.reject(/* @__PURE__ */ new Error("Resolver unavailable")), () => ctx.routeActivity(null, new vocab.Create({
|
|
3756
4938
|
id: new URL("https://example.com/not-found"),
|
|
3757
4939
|
actor: new URL("https://example.com/person")
|
|
3758
|
-
})));
|
|
4940
|
+
}))));
|
|
3759
4941
|
assertEquals(activities, [[null, signedOffer], ["id", signedInvite]]);
|
|
3760
4942
|
assertFalse(await ctx.routeActivity(null, new vocab.Create({
|
|
3761
4943
|
id: new URL("https://example.com/person"),
|
|
@@ -4113,7 +5295,7 @@ test("InboxContextImpl.forwardActivity()", async (t) => {
|
|
|
4113
5295
|
});
|
|
4114
5296
|
const federation = new FederationImpl({
|
|
4115
5297
|
kv: new MemoryKvStore(),
|
|
4116
|
-
|
|
5298
|
+
allowPrivateAddress: true
|
|
4117
5299
|
});
|
|
4118
5300
|
await t.step("skip", async () => {
|
|
4119
5301
|
await new InboxContextImpl(null, {
|
|
@@ -4204,6 +5386,63 @@ test("InboxContextImpl.forwardActivity()", async (t) => {
|
|
|
4204
5386
|
});
|
|
4205
5387
|
esm_default.hardReset();
|
|
4206
5388
|
});
|
|
5389
|
+
test("InboxContextImpl.forwardActivity() without created", async (t) => {
|
|
5390
|
+
for (const immediate of [true, false]) await t.step(immediate ? "immediate delivery" : "queued delivery", async () => {
|
|
5391
|
+
const delivered = [];
|
|
5392
|
+
const queued = [];
|
|
5393
|
+
esm_default.spyGlobal();
|
|
5394
|
+
esm_default.post("https://example.com/inbox", async (call) => {
|
|
5395
|
+
delivered.push(await call.request.json());
|
|
5396
|
+
return new Response(null, { status: 202 });
|
|
5397
|
+
});
|
|
5398
|
+
try {
|
|
5399
|
+
const federation = new FederationImpl({
|
|
5400
|
+
kv: new MemoryKvStore(),
|
|
5401
|
+
allowPrivateAddress: true,
|
|
5402
|
+
manuallyStartQueue: true,
|
|
5403
|
+
queue: { outbox: {
|
|
5404
|
+
enqueue(message) {
|
|
5405
|
+
queued.push(message);
|
|
5406
|
+
return Promise.resolve();
|
|
5407
|
+
},
|
|
5408
|
+
async listen() {}
|
|
5409
|
+
} }
|
|
5410
|
+
});
|
|
5411
|
+
const activity = structuredClone(ldSignatureWithoutCreated);
|
|
5412
|
+
assert(await verifyJsonLd(activity, {
|
|
5413
|
+
documentLoader: mockDocumentLoader,
|
|
5414
|
+
contextLoader: mockDocumentLoader
|
|
5415
|
+
}));
|
|
5416
|
+
await new InboxContextImpl(null, activity, activity.id, "https://www.w3.org/ns/activitystreams#Create", {
|
|
5417
|
+
data: void 0,
|
|
5418
|
+
federation,
|
|
5419
|
+
url: new URL("https://example.com/"),
|
|
5420
|
+
documentLoader: mockDocumentLoader,
|
|
5421
|
+
contextLoader: mockDocumentLoader
|
|
5422
|
+
}).forwardActivity([{
|
|
5423
|
+
privateKey: rsaPrivateKey2,
|
|
5424
|
+
keyId: rsaPublicKey2.id
|
|
5425
|
+
}], {
|
|
5426
|
+
id: new URL("https://example.com/recipient"),
|
|
5427
|
+
inboxId: new URL("https://example.com/inbox")
|
|
5428
|
+
}, {
|
|
5429
|
+
skipIfUnsigned: true,
|
|
5430
|
+
immediate
|
|
5431
|
+
});
|
|
5432
|
+
if (immediate) {
|
|
5433
|
+
assertEquals(delivered, [activity]);
|
|
5434
|
+
assertEquals(queued, []);
|
|
5435
|
+
} else {
|
|
5436
|
+
assertEquals(delivered, []);
|
|
5437
|
+
assertEquals(queued.length, 1);
|
|
5438
|
+
assertEquals(queued[0].type, "outbox");
|
|
5439
|
+
assertEquals(queued[0].activity, activity);
|
|
5440
|
+
}
|
|
5441
|
+
} finally {
|
|
5442
|
+
esm_default.hardReset();
|
|
5443
|
+
}
|
|
5444
|
+
});
|
|
5445
|
+
});
|
|
4207
5446
|
test("KvSpecDeterminer", async (t) => {
|
|
4208
5447
|
await t.step("should use default spec when not found in KV", async () => {
|
|
4209
5448
|
assertEquals(await new KvSpecDeterminer(new MemoryKvStore(), ["test", "spec"]).determineSpec("example.com"), "rfc9421");
|
|
@@ -4258,6 +5497,286 @@ test("ContextImpl.sendActivity() honors the private-address policy", async (t) =
|
|
|
4258
5497
|
}
|
|
4259
5498
|
});
|
|
4260
5499
|
});
|
|
5500
|
+
function deferredSignal() {
|
|
5501
|
+
let resolve;
|
|
5502
|
+
return {
|
|
5503
|
+
promise: new Promise((r) => resolve = r),
|
|
5504
|
+
resolve
|
|
5505
|
+
};
|
|
5506
|
+
}
|
|
5507
|
+
test("ContextImpl.sendActivity() waits for sibling deliveries on failure", async () => {
|
|
5508
|
+
const failingInbox = "http://127.0.0.1:3001/inbox/fail";
|
|
5509
|
+
const slowInbox = "http://127.0.0.1:3002/inbox/slow";
|
|
5510
|
+
const failingEntered = deferredSignal();
|
|
5511
|
+
const slowEntered = deferredSignal();
|
|
5512
|
+
const slowCompleted = deferredSignal();
|
|
5513
|
+
let releaseSlow;
|
|
5514
|
+
const slowGate = new Promise((resolve) => releaseSlow = resolve);
|
|
5515
|
+
let slowStarted = false;
|
|
5516
|
+
let slowSettled = false;
|
|
5517
|
+
esm_default.spyGlobal();
|
|
5518
|
+
esm_default.post(failingInbox, () => {
|
|
5519
|
+
failingEntered.resolve();
|
|
5520
|
+
return new Response(null, { status: 500 });
|
|
5521
|
+
});
|
|
5522
|
+
esm_default.post(slowInbox, async () => {
|
|
5523
|
+
slowStarted = true;
|
|
5524
|
+
slowEntered.resolve();
|
|
5525
|
+
await slowGate;
|
|
5526
|
+
slowSettled = true;
|
|
5527
|
+
slowCompleted.resolve();
|
|
5528
|
+
return new Response(null, { status: 202 });
|
|
5529
|
+
});
|
|
5530
|
+
let observed;
|
|
5531
|
+
let released = false;
|
|
5532
|
+
try {
|
|
5533
|
+
const ctx = createFederation({
|
|
5534
|
+
kv: new MemoryKvStore(),
|
|
5535
|
+
allowPrivateAddress: true
|
|
5536
|
+
}).createContext(new URL("https://example.com/"));
|
|
5537
|
+
const activity = new Create({
|
|
5538
|
+
id: new URL("https://example.com/activity/fanout"),
|
|
5539
|
+
actor: new URL("https://example.com/person")
|
|
5540
|
+
});
|
|
5541
|
+
let outerSettled = false;
|
|
5542
|
+
let outerError;
|
|
5543
|
+
observed = ctx.sendActivity([{
|
|
5544
|
+
privateKey: ed25519PrivateKey,
|
|
5545
|
+
keyId: ed25519Multikey.id
|
|
5546
|
+
}], [new Person({
|
|
5547
|
+
id: new URL("https://example.com/recipients/failing"),
|
|
5548
|
+
inbox: new URL(failingInbox)
|
|
5549
|
+
}), new Person({
|
|
5550
|
+
id: new URL("https://example.com/recipients/slow"),
|
|
5551
|
+
inbox: new URL(slowInbox)
|
|
5552
|
+
})], activity, { immediate: true }).then(() => {
|
|
5553
|
+
outerSettled = true;
|
|
5554
|
+
}, (error) => {
|
|
5555
|
+
outerSettled = true;
|
|
5556
|
+
outerError = error;
|
|
5557
|
+
});
|
|
5558
|
+
await Promise.all([failingEntered.promise, slowEntered.promise]);
|
|
5559
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
5560
|
+
assertFalse(outerSettled, "sendActivity() must wait for sibling deliveries before rejecting");
|
|
5561
|
+
releaseSlow();
|
|
5562
|
+
released = true;
|
|
5563
|
+
await observed;
|
|
5564
|
+
assert(slowSettled, "the delayed delivery should have settled");
|
|
5565
|
+
assertInstanceOf(outerError, SendActivityError);
|
|
5566
|
+
} finally {
|
|
5567
|
+
if (!released) releaseSlow();
|
|
5568
|
+
if (slowStarted) await slowCompleted.promise;
|
|
5569
|
+
await observed;
|
|
5570
|
+
esm_default.hardReset();
|
|
5571
|
+
}
|
|
5572
|
+
});
|
|
5573
|
+
test("InboxContextImpl.forwardActivity() waits for sibling deliveries on failure", async () => {
|
|
5574
|
+
const failingInbox = "http://127.0.0.1:3003/inbox/fail";
|
|
5575
|
+
const slowInbox = "http://127.0.0.1:3004/inbox/slow";
|
|
5576
|
+
const failingEntered = deferredSignal();
|
|
5577
|
+
const slowEntered = deferredSignal();
|
|
5578
|
+
const slowCompleted = deferredSignal();
|
|
5579
|
+
let releaseSlow;
|
|
5580
|
+
const slowGate = new Promise((resolve) => releaseSlow = resolve);
|
|
5581
|
+
let slowStarted = false;
|
|
5582
|
+
let slowSettled = false;
|
|
5583
|
+
esm_default.spyGlobal();
|
|
5584
|
+
esm_default.post(failingInbox, () => {
|
|
5585
|
+
failingEntered.resolve();
|
|
5586
|
+
return new Response(null, { status: 500 });
|
|
5587
|
+
});
|
|
5588
|
+
esm_default.post(slowInbox, async () => {
|
|
5589
|
+
slowStarted = true;
|
|
5590
|
+
slowEntered.resolve();
|
|
5591
|
+
await slowGate;
|
|
5592
|
+
slowSettled = true;
|
|
5593
|
+
slowCompleted.resolve();
|
|
5594
|
+
return new Response(null, { status: 202 });
|
|
5595
|
+
});
|
|
5596
|
+
let observed;
|
|
5597
|
+
let released = false;
|
|
5598
|
+
try {
|
|
5599
|
+
const federation = new FederationImpl({
|
|
5600
|
+
kv: new MemoryKvStore(),
|
|
5601
|
+
allowPrivateAddress: true
|
|
5602
|
+
});
|
|
5603
|
+
const activity = await signObject(new vocab.Create({
|
|
5604
|
+
id: new URL("https://example.com/activity/forward"),
|
|
5605
|
+
actor: new URL("https://example.com/person2")
|
|
5606
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
5607
|
+
contextLoader: mockDocumentLoader,
|
|
5608
|
+
documentLoader: mockDocumentLoader
|
|
5609
|
+
});
|
|
5610
|
+
const ctx = new InboxContextImpl(null, await activity.toJsonLd({ contextLoader: mockDocumentLoader }), activity.id?.href, getTypeId(activity).href, {
|
|
5611
|
+
data: void 0,
|
|
5612
|
+
federation,
|
|
5613
|
+
url: new URL("https://example.com/"),
|
|
5614
|
+
documentLoader: mockDocumentLoader,
|
|
5615
|
+
contextLoader: mockDocumentLoader
|
|
5616
|
+
});
|
|
5617
|
+
let outerSettled = false;
|
|
5618
|
+
let outerError;
|
|
5619
|
+
observed = ctx.forwardActivity([{
|
|
5620
|
+
privateKey: ed25519PrivateKey,
|
|
5621
|
+
keyId: ed25519Multikey.id
|
|
5622
|
+
}], [{
|
|
5623
|
+
id: new URL("https://example.com/recipients/failing"),
|
|
5624
|
+
inboxId: new URL(failingInbox)
|
|
5625
|
+
}, {
|
|
5626
|
+
id: new URL("https://example.com/recipients/slow"),
|
|
5627
|
+
inboxId: new URL(slowInbox)
|
|
5628
|
+
}], {
|
|
5629
|
+
immediate: true,
|
|
5630
|
+
skipIfUnsigned: true
|
|
5631
|
+
}).then(() => {
|
|
5632
|
+
outerSettled = true;
|
|
5633
|
+
}, (error) => {
|
|
5634
|
+
outerSettled = true;
|
|
5635
|
+
outerError = error;
|
|
5636
|
+
});
|
|
5637
|
+
await Promise.all([failingEntered.promise, slowEntered.promise]);
|
|
5638
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
5639
|
+
assertFalse(outerSettled, "forwardActivity() must wait for sibling deliveries before rejecting");
|
|
5640
|
+
releaseSlow();
|
|
5641
|
+
released = true;
|
|
5642
|
+
await observed;
|
|
5643
|
+
assert(slowSettled, "the delayed delivery should have settled");
|
|
5644
|
+
assertInstanceOf(outerError, SendActivityError);
|
|
5645
|
+
} finally {
|
|
5646
|
+
if (!released) releaseSlow();
|
|
5647
|
+
if (slowStarted) await slowCompleted.promise;
|
|
5648
|
+
await observed;
|
|
5649
|
+
esm_default.hardReset();
|
|
5650
|
+
}
|
|
5651
|
+
});
|
|
5652
|
+
test("FederationImpl.sendActivity() drains deliveries when fan-out setup fails", async () => {
|
|
5653
|
+
const slowInbox = "http://127.0.0.1:3005/inbox/slow";
|
|
5654
|
+
const slowEntered = deferredSignal();
|
|
5655
|
+
const slowCompleted = deferredSignal();
|
|
5656
|
+
let releaseSlow;
|
|
5657
|
+
const slowGate = new Promise((resolve) => releaseSlow = resolve);
|
|
5658
|
+
let slowStarted = false;
|
|
5659
|
+
let slowSettled = false;
|
|
5660
|
+
esm_default.spyGlobal();
|
|
5661
|
+
esm_default.post(slowInbox, async () => {
|
|
5662
|
+
slowStarted = true;
|
|
5663
|
+
slowEntered.resolve();
|
|
5664
|
+
await slowGate;
|
|
5665
|
+
slowSettled = true;
|
|
5666
|
+
slowCompleted.resolve();
|
|
5667
|
+
return new Response(null, { status: 202 });
|
|
5668
|
+
});
|
|
5669
|
+
let observed;
|
|
5670
|
+
let released = false;
|
|
5671
|
+
try {
|
|
5672
|
+
const federation = new FederationImpl({
|
|
5673
|
+
kv: new MemoryKvStore(),
|
|
5674
|
+
allowPrivateAddress: true
|
|
5675
|
+
});
|
|
5676
|
+
const context = federation.createContext(new URL("https://example.com/"));
|
|
5677
|
+
const activity = new Create({
|
|
5678
|
+
id: new URL("https://example.com/activity/setup-failure"),
|
|
5679
|
+
actor: new URL("https://example.com/person")
|
|
5680
|
+
});
|
|
5681
|
+
let outerSettled = false;
|
|
5682
|
+
let outerError;
|
|
5683
|
+
observed = federation.sendActivity([{
|
|
5684
|
+
privateKey: ed25519PrivateKey,
|
|
5685
|
+
keyId: ed25519Multikey.id
|
|
5686
|
+
}], {
|
|
5687
|
+
[slowInbox]: {
|
|
5688
|
+
actorIds: ["https://example.com/recipients/slow"],
|
|
5689
|
+
sharedInbox: false
|
|
5690
|
+
},
|
|
5691
|
+
"not a url": {
|
|
5692
|
+
actorIds: ["https://example.com/recipients/invalid"],
|
|
5693
|
+
sharedInbox: false
|
|
5694
|
+
}
|
|
5695
|
+
}, activity, {
|
|
5696
|
+
context,
|
|
5697
|
+
immediate: true
|
|
5698
|
+
}).then(() => {
|
|
5699
|
+
outerSettled = true;
|
|
5700
|
+
}, (error) => {
|
|
5701
|
+
outerSettled = true;
|
|
5702
|
+
outerError = error;
|
|
5703
|
+
});
|
|
5704
|
+
await slowEntered.promise;
|
|
5705
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
5706
|
+
assertFalse(outerSettled, "sendActivity() must drain started deliveries when fan-out setup fails");
|
|
5707
|
+
releaseSlow();
|
|
5708
|
+
released = true;
|
|
5709
|
+
await observed;
|
|
5710
|
+
assert(slowSettled, "the started delivery should have settled");
|
|
5711
|
+
assertInstanceOf(outerError, TypeError);
|
|
5712
|
+
} finally {
|
|
5713
|
+
if (!released) releaseSlow();
|
|
5714
|
+
if (slowStarted) await slowCompleted.promise;
|
|
5715
|
+
await observed;
|
|
5716
|
+
esm_default.hardReset();
|
|
5717
|
+
}
|
|
5718
|
+
});
|
|
5719
|
+
test("FederationImpl.sendActivity() handles rejections while building headers", async () => {
|
|
5720
|
+
const federation = new FederationImpl({ kv: new MemoryKvStore() });
|
|
5721
|
+
const context = federation.createContext(new URL("https://example.com/"));
|
|
5722
|
+
const activity = await signObject(new Create({
|
|
5723
|
+
id: new URL("https://example.com/activity/header-failure"),
|
|
5724
|
+
actor: new URL("https://example.com/person")
|
|
5725
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
5726
|
+
contextLoader: mockDocumentLoader,
|
|
5727
|
+
documentLoader: mockDocumentLoader
|
|
5728
|
+
});
|
|
5729
|
+
const subtle = crypto.subtle;
|
|
5730
|
+
const originalDigest = subtle.digest;
|
|
5731
|
+
let digestCalls = 0;
|
|
5732
|
+
let releaseSecondDigest;
|
|
5733
|
+
const secondDigestGate = new Promise((resolve) => {
|
|
5734
|
+
releaseSecondDigest = resolve;
|
|
5735
|
+
});
|
|
5736
|
+
let secondDigestStarted;
|
|
5737
|
+
const secondDigestEntered = new Promise((resolve) => {
|
|
5738
|
+
secondDigestStarted = resolve;
|
|
5739
|
+
});
|
|
5740
|
+
subtle.digest = async (algorithm, data) => {
|
|
5741
|
+
digestCalls++;
|
|
5742
|
+
if (digestCalls === 2) {
|
|
5743
|
+
secondDigestStarted();
|
|
5744
|
+
await secondDigestGate;
|
|
5745
|
+
}
|
|
5746
|
+
return await originalDigest.call(subtle, algorithm, data);
|
|
5747
|
+
};
|
|
5748
|
+
const capture = captureUnhandledRejections();
|
|
5749
|
+
let released = false;
|
|
5750
|
+
try {
|
|
5751
|
+
const observed = federation.sendActivity([{
|
|
5752
|
+
privateKey: ed25519PrivateKey,
|
|
5753
|
+
keyId: ed25519Multikey.id
|
|
5754
|
+
}], {
|
|
5755
|
+
"ftp://example.com/fail": {
|
|
5756
|
+
actorIds: ["https://example.com/recipients/failing"],
|
|
5757
|
+
sharedInbox: false
|
|
5758
|
+
},
|
|
5759
|
+
"http://127.0.0.1:3006/inbox": {
|
|
5760
|
+
actorIds: ["https://example.com/recipients/slow"],
|
|
5761
|
+
sharedInbox: false
|
|
5762
|
+
}
|
|
5763
|
+
}, activity, {
|
|
5764
|
+
context,
|
|
5765
|
+
immediate: true,
|
|
5766
|
+
collectionSync: "https://example.com/followers"
|
|
5767
|
+
}).catch((error) => error);
|
|
5768
|
+
await secondDigestEntered;
|
|
5769
|
+
await capture.settle();
|
|
5770
|
+
assertEquals(capture.reasons, [], "an early rejection must not surface as an unhandled rejection");
|
|
5771
|
+
releaseSecondDigest();
|
|
5772
|
+
released = true;
|
|
5773
|
+
await observed;
|
|
5774
|
+
} finally {
|
|
5775
|
+
if (!released) releaseSecondDigest();
|
|
5776
|
+
subtle.digest = originalDigest;
|
|
5777
|
+
capture.stop();
|
|
5778
|
+
}
|
|
5779
|
+
});
|
|
4261
5780
|
test("Federation.fetch() bounds inbox bodies before dispatch", async () => {
|
|
4262
5781
|
let dispatched = false;
|
|
4263
5782
|
const json = JSON.stringify({
|
|
@@ -4315,5 +5834,19 @@ test("Federation.fetch() bounds inbox bodies before dispatch", async () => {
|
|
|
4315
5834
|
}), { contextData: void 0 })).status, 202);
|
|
4316
5835
|
assert(dispatched);
|
|
4317
5836
|
});
|
|
5837
|
+
/**
|
|
5838
|
+
* Runs the given function while `node:dns/promises`' `lookup()`, which the
|
|
5839
|
+
* default public fetch resolves hostnames with, is replaced, so that no test
|
|
5840
|
+
* depends on the real DNS.
|
|
5841
|
+
*/
|
|
5842
|
+
async function withDnsLookup(lookup, fn) {
|
|
5843
|
+
const originalLookup = dns.lookup;
|
|
5844
|
+
dns.lookup = lookup;
|
|
5845
|
+
try {
|
|
5846
|
+
return await fn();
|
|
5847
|
+
} finally {
|
|
5848
|
+
dns.lookup = originalLookup;
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
4318
5851
|
//#endregion
|
|
4319
5852
|
export {};
|