@fedify/fedify 2.4.6-dev.2628 → 2.4.6
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-5yDbmjEb.mjs +16 -0
- package/dist/{builder-kj5boG2l.mjs → builder-CadJYxhX.mjs} +2 -2
- package/dist/callback-DPDs_dxC.d.mts +5280 -0
- package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
- package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
- package/dist/{client-5SIFzW3q.mjs → client-DU3owZBD.mjs} +86 -11
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- package/dist/compat/mod.cjs +1 -1
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/mod.js +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{compound-proof-BoNAYSHt.mjs → compound-proof-CbWKyg2H.mjs} +2 -2
- package/dist/{context-D0gFIgev.d.cts → context-DUwicVx-.d.cts} +31 -14
- package/dist/{context-CVOOd9pD.d.ts → context-iGMHITvS.d.ts} +31 -14
- package/dist/{deno-ksnVeCA7.mjs → deno-BKSRi6w3.mjs} +1 -1
- package/dist/{docloader-BhVNi06k.mjs → docloader-BcDiJfFl.mjs} +2 -2
- 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/compound-fanout.test.mjs +4 -4
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler-compound-proof.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +206 -14
- package/dist/federation/hashlink-media.test.mjs +2 -2
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox-report.test.mjs +5 -5
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1188 -13
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +3 -3
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +1 -1
- package/dist/federation/outgoing-proof.test.mjs +4 -4
- package/dist/federation/portable-actor.test.mjs +3 -3
- package/dist/federation/portable-chain.test.mjs +3 -3
- package/dist/federation/portable-collection.test.mjs +4 -4
- package/dist/federation/portable-delivery.test.mjs +2 -2
- package/dist/federation/portable-gateway-keys.test.mjs +5 -5
- package/dist/federation/portable-inbox.test.mjs +4 -4
- package/dist/federation/portable-parse-uri.test.mjs +1 -1
- package/dist/federation/portable-route-activity.test.mjs +2 -2
- package/dist/federation/portable.test.mjs +3 -3
- package/dist/federation/send.test.mjs +293 -3
- package/dist/federation/tasks/enqueue.test.mjs +1 -1
- package/dist/federation/tasks/tasks.test.mjs +2 -2
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{federation-BtPz9sr3.cjs → federation-CM4nzbhO.cjs} +501 -145
- package/dist/{http-BSARoDPh.mjs → http-B6sfb5xN.mjs} +8 -6
- package/dist/{http-rH230xCD.js → http-BwgldAIk.js} +2803 -2633
- package/dist/{http-CeVcKQMZ.cjs → http-Tj9eQ_rd.cjs} +2640 -2458
- package/dist/{inbox-BdZenpZQ.mjs → inbox-B7NVkb8j.mjs} +2 -2
- package/dist/{key-VEL1QqHF.d.cts → key-CIdQA7Pc.d.cts} +5 -5
- package/dist/{key-CyCcut3h.d.ts → key-CjtBFzaE.d.ts} +5 -5
- package/dist/{kv-cache-CNfNI_95.js → kv-cache-C-5yfTw-.js} +1 -1
- package/dist/{kv-cache-Cxn7pNMx.mjs → kv-cache-CvWuigft.mjs} +1 -1
- package/dist/{kv-cache-BpGIONmd.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
- package/dist/{ld-DJZrjNuN.mjs → ld-BGnZDnia.mjs} +176 -24
- package/dist/ld-signature-D1tFSFK8.mjs +23 -0
- package/dist/{metrics-DtxsYIkN.mjs → metrics-DHUP4F1-.mjs} +1 -1
- package/dist/{middleware-DyEjt33n.mjs → middleware-CUb31OGG.mjs} +1 -1
- package/dist/{middleware-DDvck2q9.js → middleware-DX8wADUa.js} +452 -98
- package/dist/{middleware-DblGj642.mjs → middleware-mRXKHq68.mjs} +445 -176
- package/dist/{mod-B1Qt5cQQ.d.ts → mod-B6s6hA4y.d.ts} +3 -3
- package/dist/{mod-ss0wBUH1.d.cts → mod-CJf5GcVD.d.cts} +3 -3
- package/dist/{mod-makPMVMg.d.cts → mod-CSlxqNto.d.cts} +1 -1
- package/dist/{mod-CpyjFA9s.d.ts → mod-D2DiA8u5.d.cts} +29 -7
- package/dist/{mod-BTxJG7ZH.d.cts → mod-DKRf1FLm.d.ts} +29 -7
- package/dist/{mod-B5COx5Wd.d.ts → mod-Dqu6Dl1k.d.ts} +1 -1
- package/dist/mod.cjs +6 -6
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +6 -6
- package/dist/nodeinfo/client.test.mjs +432 -4
- 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/{outgoing-jsonld-4IJqPYos.mjs → outgoing-jsonld-Dsca6G_Y.mjs} +35 -4
- package/dist/{owner-2vfqhUJw.mjs → owner-DEiBiiqR.mjs} +4 -4
- package/dist/{portable-collection-Cs--KD5A.cjs → portable-collection--h11WDIi.cjs} +3 -2
- package/dist/{portable-collection-DKJwGO8S.mjs → portable-collection-D0-tInp2.mjs} +2 -2
- package/dist/{portable-collection-B7AQ_dW7.js → portable-collection-M6d5I5JQ.js} +3 -2
- package/dist/{portable-key-DXGepvtD.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
- package/dist/portable-verifier-CPA86vIP.js +22 -0
- package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
- package/dist/{proof-DW0FK6Cp.mjs → proof-C4pwAF2k.mjs} +31 -11
- package/dist/{send-CqsocpvF.mjs → send-ivzJCtb-.mjs} +100 -22
- package/dist/sig/compound-proof-discovery.test.mjs +1 -1
- package/dist/sig/compound-proof-producer.test.mjs +1 -1
- package/dist/sig/compound-proof-verification.test.mjs +2 -2
- package/dist/sig/compound-proof.test.mjs +3 -3
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key-types.test.d.mts +162 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +572 -7
- package/dist/sig/mitra-receive-interop.test.mjs +4 -4
- package/dist/sig/mitra-send-interop.test.mjs +3 -3
- 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/portable-collection.test.mjs +1 -1
- package/dist/sig/portable-interop.test.mjs +3 -3
- package/dist/sig/portable-key.test.mjs +5 -5
- package/dist/sig/proof.test.mjs +100 -6
- package/dist/sig/tootik-request-interop.test.mjs +4 -4
- package/dist/sig/tootik-send-interop.test.mjs +3 -3
- package/dist/sig/verification.test.mjs +3 -3
- package/dist/{temporal-Dm2E1-vs.mjs → temporal-B6OlxwK_.mjs} +3 -5
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +3 -5045
- package/dist/{transformers-DAtXl_Kc.js → transformers-BlJ53iKs.js} +3 -2
- package/dist/{transformers-BalCrSsr.cjs → transformers-aIK89ibB.cjs} +3 -2
- package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
- package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/kv-cache.test.mjs +1 -1
- 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/dist/utils/portable-verifier.test.d.mts +2 -0
- package/dist/utils/portable-verifier.test.mjs +126 -0
- package/package.json +6 -6
|
@@ -16,16 +16,18 @@ import "../std__assert-DvMDRPes.mjs";
|
|
|
16
16
|
import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
|
|
17
17
|
import { t as assertStrictEquals } from "../assert_strict_equals-CYvBmkpC.mjs";
|
|
18
18
|
import { t as assert } from "../assert-D1Eafmd_.mjs";
|
|
19
|
-
import { g as recordInboxActivity } from "../metrics-
|
|
20
|
-
import { a as compactJsonLd,
|
|
21
|
-
import { a as signObject, s as verifyObject } from "../proof-
|
|
22
|
-
import { p as verifyRequest, u as signRequest } from "../http-
|
|
19
|
+
import { g as recordInboxActivity } from "../metrics-DHUP4F1-.mjs";
|
|
20
|
+
import { _ as verifyJsonLd, a as compactJsonLd, c as detachSignature, h as signJsonLd, i as attachSignature } from "../ld-BGnZDnia.mjs";
|
|
21
|
+
import { a as signObject, s as verifyObject } from "../proof-C4pwAF2k.mjs";
|
|
22
|
+
import { p as verifyRequest, u as signRequest } from "../http-B6sfb5xN.mjs";
|
|
23
23
|
import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
|
|
24
|
-
import { n as getAuthenticatedDocumentLoader } from "../docloader-
|
|
25
|
-
import {
|
|
26
|
-
import { t as doesActorOwnKey } from "../owner-
|
|
24
|
+
import { n as getAuthenticatedDocumentLoader } from "../docloader-BcDiJfFl.mjs";
|
|
25
|
+
import { E as handleBenchmarkTrigger, i as KvSpecDeterminer, n as FederationImpl, o as createFederation, r as InboxContextImpl, t as ContextImpl } from "../middleware-mRXKHq68.mjs";
|
|
26
|
+
import { t as doesActorOwnKey } from "../owner-DEiBiiqR.mjs";
|
|
27
|
+
import { t as SendActivityError } from "../send-ivzJCtb-.mjs";
|
|
27
28
|
import { t as CircuitBreaker } from "../circuit-breaker-XJ53md4S.mjs";
|
|
28
29
|
import { t as TaskCodec } from "../codec-C6rTrpIp.mjs";
|
|
30
|
+
import { t as ldSignatureWithoutCreated } from "../ld-signature-D1tFSFK8.mjs";
|
|
29
31
|
import { t as markCircuitBreakerLegacySweepDone } from "../circuit-breaker-test-utils-DW6YC_Pe.mjs";
|
|
30
32
|
import { configure, reset } from "@logtape/logtape";
|
|
31
33
|
import { RouterError } from "@fedify/uri-template";
|
|
@@ -634,6 +636,104 @@ test("benchmarkMode trigger endpoint", async (t) => {
|
|
|
634
636
|
assertEquals(messages[0].inbox, "https://sink.example/inbox");
|
|
635
637
|
});
|
|
636
638
|
});
|
|
639
|
+
test("FederationImpl.startQueue()", async (t) => {
|
|
640
|
+
function createCountingQueue() {
|
|
641
|
+
const messages = [];
|
|
642
|
+
let listenCount = 0;
|
|
643
|
+
return {
|
|
644
|
+
messages,
|
|
645
|
+
get listenCount() {
|
|
646
|
+
return listenCount;
|
|
647
|
+
},
|
|
648
|
+
enqueue(message) {
|
|
649
|
+
messages.push(message);
|
|
650
|
+
return Promise.resolve();
|
|
651
|
+
},
|
|
652
|
+
listen() {
|
|
653
|
+
listenCount++;
|
|
654
|
+
return Promise.resolve();
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
await t.step("starts a fanout-only queue with an explicit selector", async () => {
|
|
659
|
+
const queue = createCountingQueue();
|
|
660
|
+
const federation = new FederationImpl({
|
|
661
|
+
kv: new MemoryKvStore(),
|
|
662
|
+
queue: { fanout: queue },
|
|
663
|
+
manuallyStartQueue: true
|
|
664
|
+
});
|
|
665
|
+
await federation.startQueue(void 0, { queue: "fanout" });
|
|
666
|
+
assertEquals(queue.listenCount, 1);
|
|
667
|
+
await federation.startQueue(void 0, { queue: "fanout" });
|
|
668
|
+
assertEquals(queue.listenCount, 1);
|
|
669
|
+
});
|
|
670
|
+
await t.step("starts a fanout-only queue without a selector", async () => {
|
|
671
|
+
const queue = createCountingQueue();
|
|
672
|
+
await new FederationImpl({
|
|
673
|
+
kv: new MemoryKvStore(),
|
|
674
|
+
queue: { fanout: queue },
|
|
675
|
+
manuallyStartQueue: true
|
|
676
|
+
}).startQueue(void 0);
|
|
677
|
+
assertEquals(queue.listenCount, 1);
|
|
678
|
+
});
|
|
679
|
+
await t.step("starts a fanout-only queue after a fanout enqueue", async () => {
|
|
680
|
+
const queue = createCountingQueue();
|
|
681
|
+
const ctx = new ContextImpl({
|
|
682
|
+
data: void 0,
|
|
683
|
+
federation: new FederationImpl({
|
|
684
|
+
kv: new MemoryKvStore(),
|
|
685
|
+
contextLoaderFactory: () => mockDocumentLoader,
|
|
686
|
+
queue: { fanout: queue }
|
|
687
|
+
}),
|
|
688
|
+
url: new URL("https://example.com/"),
|
|
689
|
+
documentLoader: mockDocumentLoader,
|
|
690
|
+
contextLoader: mockDocumentLoader
|
|
691
|
+
});
|
|
692
|
+
const activity = new vocab.Create({
|
|
693
|
+
id: new URL("https://example.com/activity/1"),
|
|
694
|
+
actor: new URL("https://example.com/person")
|
|
695
|
+
});
|
|
696
|
+
await ctx.sendActivity([{
|
|
697
|
+
privateKey: rsaPrivateKey2,
|
|
698
|
+
keyId: rsaPublicKey2.id
|
|
699
|
+
}], {
|
|
700
|
+
id: new URL("https://example.com/recipient"),
|
|
701
|
+
inboxId: new URL("https://example.com/inbox")
|
|
702
|
+
}, activity, { fanout: "force" });
|
|
703
|
+
assertEquals(queue.listenCount, 1);
|
|
704
|
+
assertEquals(queue.messages.length, 1);
|
|
705
|
+
assertEquals(queue.messages[0].type, "fanout");
|
|
706
|
+
});
|
|
707
|
+
await t.step("does not start a fanout-only queue automatically when manually started", async () => {
|
|
708
|
+
const queue = createCountingQueue();
|
|
709
|
+
const ctx = new ContextImpl({
|
|
710
|
+
data: void 0,
|
|
711
|
+
federation: new FederationImpl({
|
|
712
|
+
kv: new MemoryKvStore(),
|
|
713
|
+
contextLoaderFactory: () => mockDocumentLoader,
|
|
714
|
+
queue: { fanout: queue },
|
|
715
|
+
manuallyStartQueue: true
|
|
716
|
+
}),
|
|
717
|
+
url: new URL("https://example.com/"),
|
|
718
|
+
documentLoader: mockDocumentLoader,
|
|
719
|
+
contextLoader: mockDocumentLoader
|
|
720
|
+
});
|
|
721
|
+
const activity = new vocab.Create({
|
|
722
|
+
id: new URL("https://example.com/activity/1"),
|
|
723
|
+
actor: new URL("https://example.com/person")
|
|
724
|
+
});
|
|
725
|
+
await ctx.sendActivity([{
|
|
726
|
+
privateKey: rsaPrivateKey2,
|
|
727
|
+
keyId: rsaPublicKey2.id
|
|
728
|
+
}], {
|
|
729
|
+
id: new URL("https://example.com/recipient"),
|
|
730
|
+
inboxId: new URL("https://example.com/inbox")
|
|
731
|
+
}, activity, { fanout: "force" });
|
|
732
|
+
assertEquals(queue.listenCount, 0);
|
|
733
|
+
assertEquals(queue.messages.length, 1);
|
|
734
|
+
assertEquals(queue.messages[0].type, "fanout");
|
|
735
|
+
});
|
|
736
|
+
});
|
|
637
737
|
test({
|
|
638
738
|
name: "Federation.createContext()",
|
|
639
739
|
permissions: {
|
|
@@ -1074,6 +1174,22 @@ test({
|
|
|
1074
1174
|
localComments: 456
|
|
1075
1175
|
}
|
|
1076
1176
|
});
|
|
1177
|
+
await assertRejects(() => ctx.lookupNodeInfo("https://example.com/", { timeout: 0 }), RangeError);
|
|
1178
|
+
const caller = new AbortController();
|
|
1179
|
+
caller.abort();
|
|
1180
|
+
assertEquals(await ctx.lookupNodeInfo("https://example.com/", {
|
|
1181
|
+
signal: caller.signal,
|
|
1182
|
+
timeout: null
|
|
1183
|
+
}), void 0);
|
|
1184
|
+
assertEquals(await ctx.lookupNodeInfo("https://example.com/", {
|
|
1185
|
+
parse: "none",
|
|
1186
|
+
signal: caller.signal,
|
|
1187
|
+
timeout: null
|
|
1188
|
+
}), void 0);
|
|
1189
|
+
await assertRejects(() => ctx.lookupNodeInfo("https://example.com/", {
|
|
1190
|
+
parse: "none",
|
|
1191
|
+
timeout: 0
|
|
1192
|
+
}), RangeError);
|
|
1077
1193
|
});
|
|
1078
1194
|
await t.step("RequestContext", async () => {
|
|
1079
1195
|
const federation = createFederation({
|
|
@@ -2077,10 +2193,9 @@ test("Federation.fetch() records HTTP server request metrics", async (t) => {
|
|
|
2077
2193
|
});
|
|
2078
2194
|
await t.step("preserves QUERY as a known HTTP method", async () => {
|
|
2079
2195
|
const { federation, recorder } = createTestContext();
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
}), { contextData: void 0 })).status >= 100);
|
|
2196
|
+
const request = new Request("https://example.com/users/alice", { headers: { "Accept": "application/activity+json" } });
|
|
2197
|
+
Object.defineProperty(request, "method", { value: "QUERY" });
|
|
2198
|
+
assert((await federation.fetch(request, { contextData: void 0 })).status >= 100);
|
|
2084
2199
|
const counts = recorder.getMeasurements("fedify.http.server.request.count");
|
|
2085
2200
|
assertEquals(counts.length, 1);
|
|
2086
2201
|
assertEquals(counts[0].attributes["http.request.method"], "QUERY");
|
|
@@ -3599,6 +3714,356 @@ test("FederationImpl.sendActivity()", async (t) => {
|
|
|
3599
3714
|
});
|
|
3600
3715
|
esm_default.hardReset();
|
|
3601
3716
|
});
|
|
3717
|
+
const QUEUE_STARTUP_WARNING = "Failed to start queue workers automatically: {error}";
|
|
3718
|
+
/**
|
|
3719
|
+
* Captures unhandled promise rejections for the duration of a test step.
|
|
3720
|
+
*
|
|
3721
|
+
* Deno dispatches `unhandledrejection` on `globalThis`, while Node.js and Bun
|
|
3722
|
+
* dispatch `unhandledRejection` on `process`. Bun's test runner currently
|
|
3723
|
+
* fires neither, so there the native runner's own unhandled-rejection failure
|
|
3724
|
+
* remains the signal; the assertion is harmless otherwise.
|
|
3725
|
+
*/
|
|
3726
|
+
function captureUnhandledRejections() {
|
|
3727
|
+
const reasons = [];
|
|
3728
|
+
const isDeno = "Deno" in globalThis;
|
|
3729
|
+
const onRejectionEvent = (event) => {
|
|
3730
|
+
event.preventDefault();
|
|
3731
|
+
reasons.push(event.reason);
|
|
3732
|
+
};
|
|
3733
|
+
const onProcessRejection = (reason) => {
|
|
3734
|
+
reasons.push(reason);
|
|
3735
|
+
};
|
|
3736
|
+
const globalTarget = globalThis;
|
|
3737
|
+
const proc = globalThis.process;
|
|
3738
|
+
if (isDeno) globalTarget.addEventListener?.("unhandledrejection", onRejectionEvent);
|
|
3739
|
+
else proc?.on?.("unhandledRejection", onProcessRejection);
|
|
3740
|
+
async function settle() {
|
|
3741
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
3742
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
3743
|
+
}
|
|
3744
|
+
return {
|
|
3745
|
+
reasons,
|
|
3746
|
+
settle,
|
|
3747
|
+
stop() {
|
|
3748
|
+
if (isDeno) globalTarget.removeEventListener?.("unhandledrejection", onRejectionEvent);
|
|
3749
|
+
else proc?.off?.("unhandledRejection", onProcessRejection);
|
|
3750
|
+
}
|
|
3751
|
+
};
|
|
3752
|
+
}
|
|
3753
|
+
async function configureQueueStartupWarningCapture(records) {
|
|
3754
|
+
await configure({
|
|
3755
|
+
sinks: { buffer(record) {
|
|
3756
|
+
records.push(record);
|
|
3757
|
+
} },
|
|
3758
|
+
loggers: [{
|
|
3759
|
+
category: "fedify",
|
|
3760
|
+
sinks: ["buffer"],
|
|
3761
|
+
lowestLevel: "warning"
|
|
3762
|
+
}, {
|
|
3763
|
+
category: ["logtape", "meta"],
|
|
3764
|
+
sinks: []
|
|
3765
|
+
}],
|
|
3766
|
+
reset: true
|
|
3767
|
+
});
|
|
3768
|
+
}
|
|
3769
|
+
function queueStartupWarnings(records, error) {
|
|
3770
|
+
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);
|
|
3771
|
+
}
|
|
3772
|
+
test("Federation.fetch() reports automatic queue startup failures", async (t) => {
|
|
3773
|
+
const listenError = /* @__PURE__ */ new TypeError("simulated listen() failure");
|
|
3774
|
+
const queue = {
|
|
3775
|
+
enqueue() {
|
|
3776
|
+
return Promise.resolve();
|
|
3777
|
+
},
|
|
3778
|
+
listen() {
|
|
3779
|
+
throw listenError;
|
|
3780
|
+
}
|
|
3781
|
+
};
|
|
3782
|
+
const capture = captureUnhandledRejections();
|
|
3783
|
+
const records = [];
|
|
3784
|
+
await configureQueueStartupWarningCapture(records);
|
|
3785
|
+
try {
|
|
3786
|
+
const federation = createFederation({
|
|
3787
|
+
kv: new MemoryKvStore(),
|
|
3788
|
+
queue,
|
|
3789
|
+
skipSignatureVerification: true,
|
|
3790
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
3791
|
+
contextLoaderFactory: () => mockDocumentLoader
|
|
3792
|
+
});
|
|
3793
|
+
federation.setActorDispatcher("/actors/{identifier}", () => new Person({ id: new URL("https://example.com/actor") }));
|
|
3794
|
+
federation.setInboxListeners("/actors/{identifier}/inbox", "/inbox").on(Create, () => {});
|
|
3795
|
+
const post = (id) => federation.fetch(new Request("https://example.com/inbox", {
|
|
3796
|
+
method: "POST",
|
|
3797
|
+
headers: { "Content-Type": "application/activity+json" },
|
|
3798
|
+
body: JSON.stringify({
|
|
3799
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
3800
|
+
id,
|
|
3801
|
+
type: "Create",
|
|
3802
|
+
actor: "https://example.com/actor"
|
|
3803
|
+
})
|
|
3804
|
+
}), { contextData: void 0 });
|
|
3805
|
+
await t.step("synchronous failure", async () => {
|
|
3806
|
+
assertEquals((await post("https://example.com/activities/queued-1")).status, 202);
|
|
3807
|
+
await capture.settle();
|
|
3808
|
+
assertEquals(queueStartupWarnings(records, listenError).length, 1);
|
|
3809
|
+
assertEquals(capture.reasons, []);
|
|
3810
|
+
assertEquals((await post("https://example.com/activities/queued-2")).status, 202);
|
|
3811
|
+
await capture.settle();
|
|
3812
|
+
assertEquals(queueStartupWarnings(records, listenError).length, 1, "the warning must be logged only once per federation instance");
|
|
3813
|
+
assertEquals(capture.reasons, []);
|
|
3814
|
+
});
|
|
3815
|
+
await t.step("asynchronous failure", async () => {
|
|
3816
|
+
const asyncError = /* @__PURE__ */ new TypeError("simulated async listen() failure");
|
|
3817
|
+
let rejectListen;
|
|
3818
|
+
const asyncFederation = createFederation({
|
|
3819
|
+
kv: new MemoryKvStore(),
|
|
3820
|
+
queue: {
|
|
3821
|
+
enqueue() {
|
|
3822
|
+
return Promise.resolve();
|
|
3823
|
+
},
|
|
3824
|
+
listen() {
|
|
3825
|
+
return new Promise((_resolve, reject) => {
|
|
3826
|
+
rejectListen = reject;
|
|
3827
|
+
});
|
|
3828
|
+
}
|
|
3829
|
+
},
|
|
3830
|
+
skipSignatureVerification: true,
|
|
3831
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
3832
|
+
contextLoaderFactory: () => mockDocumentLoader
|
|
3833
|
+
});
|
|
3834
|
+
asyncFederation.setActorDispatcher("/actors/{identifier}", () => new Person({ id: new URL("https://example.com/actor") }));
|
|
3835
|
+
asyncFederation.setInboxListeners("/actors/{identifier}/inbox", "/inbox").on(Create, () => {});
|
|
3836
|
+
assertEquals((await asyncFederation.fetch(new Request("https://example.com/inbox", {
|
|
3837
|
+
method: "POST",
|
|
3838
|
+
headers: { "Content-Type": "application/activity+json" },
|
|
3839
|
+
body: JSON.stringify({
|
|
3840
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
3841
|
+
id: "https://example.com/activities/queued-async",
|
|
3842
|
+
type: "Create",
|
|
3843
|
+
actor: "https://example.com/actor"
|
|
3844
|
+
})
|
|
3845
|
+
}), { contextData: void 0 })).status, 202);
|
|
3846
|
+
await capture.settle();
|
|
3847
|
+
assertEquals(queueStartupWarnings(records, asyncError).length, 0);
|
|
3848
|
+
assert(rejectListen != null);
|
|
3849
|
+
rejectListen(asyncError);
|
|
3850
|
+
await capture.settle();
|
|
3851
|
+
assertEquals(queueStartupWarnings(records, asyncError).length, 1, "a listener that rejects after startup must still be reported");
|
|
3852
|
+
assertEquals(capture.reasons, []);
|
|
3853
|
+
});
|
|
3854
|
+
} finally {
|
|
3855
|
+
await capture.settle();
|
|
3856
|
+
capture.stop();
|
|
3857
|
+
await reset();
|
|
3858
|
+
}
|
|
3859
|
+
});
|
|
3860
|
+
test("Federation.startQueue() rejects when a queue cannot listen", async () => {
|
|
3861
|
+
const listenError = /* @__PURE__ */ new TypeError("simulated listen() failure");
|
|
3862
|
+
const federation = createFederation({
|
|
3863
|
+
kv: new MemoryKvStore(),
|
|
3864
|
+
queue: {
|
|
3865
|
+
enqueue() {
|
|
3866
|
+
return Promise.resolve();
|
|
3867
|
+
},
|
|
3868
|
+
listen() {
|
|
3869
|
+
throw listenError;
|
|
3870
|
+
}
|
|
3871
|
+
},
|
|
3872
|
+
manuallyStartQueue: true
|
|
3873
|
+
});
|
|
3874
|
+
assertStrictEquals(await assertRejects(() => federation.startQueue(void 0)), listenError);
|
|
3875
|
+
});
|
|
3876
|
+
test("Federation.startQueue() keeps other queue workers running", async () => {
|
|
3877
|
+
const outboxError = /* @__PURE__ */ new TypeError("simulated outbox listen() failure");
|
|
3878
|
+
const lateInboxError = /* @__PURE__ */ new TypeError("simulated late inbox failure");
|
|
3879
|
+
let rejectInbox;
|
|
3880
|
+
let fanoutStarted = false;
|
|
3881
|
+
const inbox = {
|
|
3882
|
+
enqueue() {
|
|
3883
|
+
return Promise.resolve();
|
|
3884
|
+
},
|
|
3885
|
+
listen() {
|
|
3886
|
+
return new Promise((_resolve, reject) => {
|
|
3887
|
+
rejectInbox = reject;
|
|
3888
|
+
});
|
|
3889
|
+
}
|
|
3890
|
+
};
|
|
3891
|
+
const outbox = {
|
|
3892
|
+
enqueue() {
|
|
3893
|
+
return Promise.resolve();
|
|
3894
|
+
},
|
|
3895
|
+
listen() {
|
|
3896
|
+
throw outboxError;
|
|
3897
|
+
}
|
|
3898
|
+
};
|
|
3899
|
+
const fanout = {
|
|
3900
|
+
enqueue() {
|
|
3901
|
+
return Promise.resolve();
|
|
3902
|
+
},
|
|
3903
|
+
listen() {
|
|
3904
|
+
fanoutStarted = true;
|
|
3905
|
+
return new Promise(() => {});
|
|
3906
|
+
}
|
|
3907
|
+
};
|
|
3908
|
+
const capture = captureUnhandledRejections();
|
|
3909
|
+
try {
|
|
3910
|
+
const federation = createFederation({
|
|
3911
|
+
kv: new MemoryKvStore(),
|
|
3912
|
+
queue: {
|
|
3913
|
+
inbox,
|
|
3914
|
+
outbox,
|
|
3915
|
+
fanout
|
|
3916
|
+
},
|
|
3917
|
+
manuallyStartQueue: true
|
|
3918
|
+
});
|
|
3919
|
+
assertStrictEquals(await assertRejects(() => federation.startQueue(void 0)), outboxError);
|
|
3920
|
+
assert(fanoutStarted, "a synchronous throw from one queue must not prevent later queues from starting");
|
|
3921
|
+
assert(rejectInbox != null);
|
|
3922
|
+
rejectInbox(lateInboxError);
|
|
3923
|
+
await capture.settle();
|
|
3924
|
+
assertEquals(capture.reasons, [], "an earlier listener rejection must remain handled after startup fails");
|
|
3925
|
+
} finally {
|
|
3926
|
+
await capture.settle();
|
|
3927
|
+
capture.stop();
|
|
3928
|
+
}
|
|
3929
|
+
});
|
|
3930
|
+
test("ContextImpl.sendActivity() reports automatic queue startup failures", async (t) => {
|
|
3931
|
+
const sender = [{
|
|
3932
|
+
privateKey: ed25519PrivateKey,
|
|
3933
|
+
keyId: ed25519Multikey.id
|
|
3934
|
+
}];
|
|
3935
|
+
const recipient = {
|
|
3936
|
+
id: new URL("https://example.com/recipient"),
|
|
3937
|
+
inboxId: new URL("https://example.com/inbox")
|
|
3938
|
+
};
|
|
3939
|
+
const createActivity = () => new Create({
|
|
3940
|
+
id: new URL("https://example.com/activities/queue-startup-send"),
|
|
3941
|
+
actor: new URL("https://example.com/actor")
|
|
3942
|
+
});
|
|
3943
|
+
await t.step("outbox", async () => {
|
|
3944
|
+
const listenError = /* @__PURE__ */ new TypeError("simulated outbox listen() failure");
|
|
3945
|
+
const messages = [];
|
|
3946
|
+
const queue = {
|
|
3947
|
+
enqueue(message) {
|
|
3948
|
+
messages.push(message);
|
|
3949
|
+
return Promise.resolve();
|
|
3950
|
+
},
|
|
3951
|
+
listen() {
|
|
3952
|
+
throw listenError;
|
|
3953
|
+
}
|
|
3954
|
+
};
|
|
3955
|
+
const capture = captureUnhandledRejections();
|
|
3956
|
+
const records = [];
|
|
3957
|
+
await configureQueueStartupWarningCapture(records);
|
|
3958
|
+
try {
|
|
3959
|
+
await new ContextImpl({
|
|
3960
|
+
data: void 0,
|
|
3961
|
+
federation: new FederationImpl({
|
|
3962
|
+
kv: new MemoryKvStore(),
|
|
3963
|
+
queue: { outbox: queue },
|
|
3964
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
3965
|
+
contextLoaderFactory: () => mockDocumentLoader
|
|
3966
|
+
}),
|
|
3967
|
+
url: new URL("https://example.com/"),
|
|
3968
|
+
documentLoader: mockDocumentLoader,
|
|
3969
|
+
contextLoader: mockDocumentLoader
|
|
3970
|
+
}).sendActivity(sender, recipient, createActivity());
|
|
3971
|
+
assertEquals(messages.map((message) => message.type), ["outbox"]);
|
|
3972
|
+
await capture.settle();
|
|
3973
|
+
assertEquals(queueStartupWarnings(records, listenError).length, 1);
|
|
3974
|
+
assertEquals(capture.reasons, []);
|
|
3975
|
+
} finally {
|
|
3976
|
+
await capture.settle();
|
|
3977
|
+
capture.stop();
|
|
3978
|
+
await reset();
|
|
3979
|
+
}
|
|
3980
|
+
});
|
|
3981
|
+
await t.step("fanout", async () => {
|
|
3982
|
+
const listenError = /* @__PURE__ */ new TypeError("simulated fanout listen() failure");
|
|
3983
|
+
const messages = [];
|
|
3984
|
+
const outbox = {
|
|
3985
|
+
enqueue() {
|
|
3986
|
+
return Promise.resolve();
|
|
3987
|
+
},
|
|
3988
|
+
listen() {
|
|
3989
|
+
return Promise.resolve();
|
|
3990
|
+
}
|
|
3991
|
+
};
|
|
3992
|
+
const fanout = {
|
|
3993
|
+
enqueue(message) {
|
|
3994
|
+
messages.push(message);
|
|
3995
|
+
return Promise.resolve();
|
|
3996
|
+
},
|
|
3997
|
+
listen() {
|
|
3998
|
+
throw listenError;
|
|
3999
|
+
}
|
|
4000
|
+
};
|
|
4001
|
+
const capture = captureUnhandledRejections();
|
|
4002
|
+
const records = [];
|
|
4003
|
+
await configureQueueStartupWarningCapture(records);
|
|
4004
|
+
try {
|
|
4005
|
+
await new ContextImpl({
|
|
4006
|
+
data: void 0,
|
|
4007
|
+
federation: new FederationImpl({
|
|
4008
|
+
kv: new MemoryKvStore(),
|
|
4009
|
+
queue: {
|
|
4010
|
+
outbox,
|
|
4011
|
+
fanout
|
|
4012
|
+
},
|
|
4013
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
4014
|
+
contextLoaderFactory: () => mockDocumentLoader
|
|
4015
|
+
}),
|
|
4016
|
+
url: new URL("https://example.com/"),
|
|
4017
|
+
documentLoader: mockDocumentLoader,
|
|
4018
|
+
contextLoader: mockDocumentLoader
|
|
4019
|
+
}).sendActivity(sender, recipient, createActivity(), { fanout: "force" });
|
|
4020
|
+
assertEquals(messages.map((message) => message.type), ["fanout"]);
|
|
4021
|
+
await capture.settle();
|
|
4022
|
+
assertEquals(queueStartupWarnings(records, listenError).length, 1);
|
|
4023
|
+
assertEquals(capture.reasons, []);
|
|
4024
|
+
} finally {
|
|
4025
|
+
await capture.settle();
|
|
4026
|
+
capture.stop();
|
|
4027
|
+
await reset();
|
|
4028
|
+
}
|
|
4029
|
+
});
|
|
4030
|
+
});
|
|
4031
|
+
test("queued Linked Data signatures without created use normalization contexts", async (t) => {
|
|
4032
|
+
for (const legacy of [false, true]) await t.step(legacy ? "legacy compacted payload" : "verified normalized cache", async () => {
|
|
4033
|
+
const normalized = await compactJsonLd(ldSignatureWithoutCreated, mockDocumentLoader);
|
|
4034
|
+
const raw = legacy ? normalized : structuredClone(ldSignatureWithoutCreated);
|
|
4035
|
+
const federation = new FederationImpl({
|
|
4036
|
+
kv: new MemoryKvStore(),
|
|
4037
|
+
contextLoaderFactory: () => async (url) => {
|
|
4038
|
+
if (url === "https://www.w3.org/ns/activitystreams" || url === "https://w3id.org/identity/v1") return await mockDocumentLoader(url);
|
|
4039
|
+
throw new Error(`Unexpected context: ${url}`);
|
|
4040
|
+
}
|
|
4041
|
+
});
|
|
4042
|
+
let deliveries = 0;
|
|
4043
|
+
let receivedRaw;
|
|
4044
|
+
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, (ctx, activity) => {
|
|
4045
|
+
deliveries++;
|
|
4046
|
+
receivedRaw = ctx.activity;
|
|
4047
|
+
assertEquals(activity.id?.href, ldSignatureWithoutCreated.id);
|
|
4048
|
+
});
|
|
4049
|
+
await federation.processQueuedTask(void 0, {
|
|
4050
|
+
type: "inbox",
|
|
4051
|
+
id: crypto.randomUUID(),
|
|
4052
|
+
baseUrl: "https://example.com",
|
|
4053
|
+
activity: raw,
|
|
4054
|
+
...legacy ? {} : {
|
|
4055
|
+
normalizedActivity: normalized,
|
|
4056
|
+
ldSignatureVerified: true
|
|
4057
|
+
},
|
|
4058
|
+
started: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4059
|
+
attempt: 0,
|
|
4060
|
+
identifier: null,
|
|
4061
|
+
traceContext: {}
|
|
4062
|
+
});
|
|
4063
|
+
assertEquals(deliveries, 1);
|
|
4064
|
+
assertEquals(receivedRaw, raw);
|
|
4065
|
+
});
|
|
4066
|
+
});
|
|
3602
4067
|
test("FederationImpl.processQueuedTask()", async (t) => {
|
|
3603
4068
|
await t.step("with MessageQueue having nativeRetrial", async () => {
|
|
3604
4069
|
const kv = new MemoryKvStore();
|
|
@@ -7265,15 +7730,19 @@ test("ContextImpl.sendActivity()", async (t) => {
|
|
|
7265
7730
|
queue
|
|
7266
7731
|
});
|
|
7267
7732
|
federation2.setActorDispatcher("/{identifier}", async (ctx, identifier) => {
|
|
7268
|
-
if (identifier !== "john") return null;
|
|
7733
|
+
if (identifier !== "john" && identifier !== "rsa-only") return null;
|
|
7269
7734
|
const keys = await ctx.getActorKeyPairs(identifier);
|
|
7270
7735
|
return new vocab.Person({
|
|
7271
7736
|
id: ctx.getActorUri(identifier),
|
|
7272
|
-
preferredUsername:
|
|
7737
|
+
preferredUsername: identifier,
|
|
7273
7738
|
publicKey: keys[0].cryptographicKey,
|
|
7274
7739
|
assertionMethods: keys.map((k) => k.multikey)
|
|
7275
7740
|
});
|
|
7276
7741
|
}).setKeyPairsDispatcher((_ctx, identifier) => {
|
|
7742
|
+
if (identifier === "rsa-only") return [{
|
|
7743
|
+
privateKey: rsaPrivateKey2,
|
|
7744
|
+
publicKey: rsaPublicKey2.publicKey
|
|
7745
|
+
}];
|
|
7277
7746
|
if (identifier !== "john") return [];
|
|
7278
7747
|
return [{
|
|
7279
7748
|
privateKey: rsaPrivateKey2,
|
|
@@ -7322,6 +7791,375 @@ test("ContextImpl.sendActivity()", async (t) => {
|
|
|
7322
7791
|
proofCount++;
|
|
7323
7792
|
}
|
|
7324
7793
|
assertEquals(proofCount, 1);
|
|
7794
|
+
const oldContext = [
|
|
7795
|
+
"https://w3id.org/identity/v1",
|
|
7796
|
+
"https://www.w3.org/ns/activitystreams",
|
|
7797
|
+
"https://w3id.org/security/data-integrity/v1"
|
|
7798
|
+
];
|
|
7799
|
+
const oldJson = await (await signObject(new vocab.Create({
|
|
7800
|
+
id: new URL("https://example.com/activity/1"),
|
|
7801
|
+
actor: new URL("https://example.com/john")
|
|
7802
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
7803
|
+
contextLoader: documentLoader,
|
|
7804
|
+
context: oldContext
|
|
7805
|
+
})).toJsonLd({
|
|
7806
|
+
format: "compact",
|
|
7807
|
+
contextLoader: documentLoader,
|
|
7808
|
+
context: oldContext
|
|
7809
|
+
});
|
|
7810
|
+
queue.clear();
|
|
7811
|
+
await federation2.processQueuedTask(void 0, {
|
|
7812
|
+
...fanoutMsg,
|
|
7813
|
+
id: crypto.randomUUID(),
|
|
7814
|
+
activity: oldJson
|
|
7815
|
+
});
|
|
7816
|
+
const replayed = queue.messages.at(-1);
|
|
7817
|
+
assert(replayed != null && replayed.type === "outbox");
|
|
7818
|
+
assertEquals(detachSignature(replayed.activity), oldJson);
|
|
7819
|
+
const proofless = { ...oldJson };
|
|
7820
|
+
delete proofless.proof;
|
|
7821
|
+
queue.clear();
|
|
7822
|
+
await federation2.processQueuedTask(void 0, {
|
|
7823
|
+
...fanoutMsg,
|
|
7824
|
+
id: crypto.randomUUID(),
|
|
7825
|
+
activity: proofless
|
|
7826
|
+
});
|
|
7827
|
+
const signedReplay = queue.messages.at(-1);
|
|
7828
|
+
assert(signedReplay != null && signedReplay.type === "outbox");
|
|
7829
|
+
assert(typeof signedReplay.activity === "object" && signedReplay.activity != null && "proof" in signedReplay.activity);
|
|
7830
|
+
const edKey = (await ctx2.getActorKeyPairs("john")).find((key) => key.privateKey.algorithm.name === "Ed25519");
|
|
7831
|
+
assert(edKey != null && edKey.multikey.id != null);
|
|
7832
|
+
const restoredJson = await (await signObject(new vocab.Create({
|
|
7833
|
+
id: new URL("https://example.com/activity/old"),
|
|
7834
|
+
actor: ctx2.getActorUri("john")
|
|
7835
|
+
}), edKey.privateKey, edKey.multikey.id, {
|
|
7836
|
+
contextLoader: documentLoader,
|
|
7837
|
+
context: oldContext
|
|
7838
|
+
})).toJsonLd({
|
|
7839
|
+
format: "compact",
|
|
7840
|
+
contextLoader: documentLoader,
|
|
7841
|
+
context: oldContext
|
|
7842
|
+
});
|
|
7843
|
+
const restored = await vocab.Create.fromJsonLd(restoredJson, {
|
|
7844
|
+
contextLoader: documentLoader,
|
|
7845
|
+
documentLoader
|
|
7846
|
+
});
|
|
7847
|
+
queue.clear();
|
|
7848
|
+
await ctx2.sendActivity([{
|
|
7849
|
+
privateKey: rsaPrivateKey2,
|
|
7850
|
+
keyId: rsaPublicKey2.id
|
|
7851
|
+
}], {
|
|
7852
|
+
id: new URL("https://example.com/recipient"),
|
|
7853
|
+
inboxId: new URL("https://example.com/inbox")
|
|
7854
|
+
}, restored);
|
|
7855
|
+
const resent = queue.messages.at(-1);
|
|
7856
|
+
assert(resent != null && resent.type === "outbox");
|
|
7857
|
+
assertEquals(detachSignature(resent.activity), restoredJson);
|
|
7858
|
+
queue.clear();
|
|
7859
|
+
await ctx2.sendActivity([{
|
|
7860
|
+
privateKey: rsaPrivateKey2,
|
|
7861
|
+
keyId: rsaPublicKey2.id
|
|
7862
|
+
}], {
|
|
7863
|
+
id: new URL("https://example.com/recipient"),
|
|
7864
|
+
inboxId: new URL("https://example.com/inbox")
|
|
7865
|
+
}, restored, { fanout: "force" });
|
|
7866
|
+
const queuedFanout = queue.messages.at(-1);
|
|
7867
|
+
assert(queuedFanout != null && queuedFanout.type === "fanout");
|
|
7868
|
+
assertEquals(queuedFanout.activity, restoredJson);
|
|
7869
|
+
const restoredWithSignature = await vocab.Create.fromJsonLd(attachSignature(restoredJson, {
|
|
7870
|
+
"@context": "https://w3id.org/identity/v1",
|
|
7871
|
+
type: "RsaSignature2017",
|
|
7872
|
+
creator: "https://example.com/person2#key4",
|
|
7873
|
+
created: "2026-01-01T00:00:00Z",
|
|
7874
|
+
signatureValue: "abc"
|
|
7875
|
+
}), {
|
|
7876
|
+
contextLoader: documentLoader,
|
|
7877
|
+
documentLoader
|
|
7878
|
+
});
|
|
7879
|
+
queue.clear();
|
|
7880
|
+
await ctx2.sendActivity([{
|
|
7881
|
+
privateKey: rsaPrivateKey2,
|
|
7882
|
+
keyId: rsaPublicKey2.id
|
|
7883
|
+
}], {
|
|
7884
|
+
id: new URL("https://example.com/recipient"),
|
|
7885
|
+
inboxId: new URL("https://example.com/inbox")
|
|
7886
|
+
}, restoredWithSignature);
|
|
7887
|
+
const resigned = queue.messages.at(-1);
|
|
7888
|
+
assert(resigned != null && resigned.type === "outbox");
|
|
7889
|
+
assertEquals(detachSignature(resigned.activity), restoredJson);
|
|
7890
|
+
const rsaOnlyJson = await (await signObject(new vocab.Create({
|
|
7891
|
+
id: new URL("https://example.com/activity/rsa-only"),
|
|
7892
|
+
actor: new URL("https://example.com/rsa-only")
|
|
7893
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
7894
|
+
contextLoader: documentLoader,
|
|
7895
|
+
context: oldContext
|
|
7896
|
+
})).toJsonLd({
|
|
7897
|
+
format: "compact",
|
|
7898
|
+
contextLoader: documentLoader,
|
|
7899
|
+
context: oldContext
|
|
7900
|
+
});
|
|
7901
|
+
const rsaOnlyRestored = await vocab.Create.fromJsonLd(rsaOnlyJson, {
|
|
7902
|
+
contextLoader: documentLoader,
|
|
7903
|
+
documentLoader
|
|
7904
|
+
});
|
|
7905
|
+
queue.clear();
|
|
7906
|
+
await ctx2.sendActivity({ identifier: "rsa-only" }, {
|
|
7907
|
+
id: new URL("https://example.com/recipient"),
|
|
7908
|
+
inboxId: new URL("https://example.com/inbox")
|
|
7909
|
+
}, rsaOnlyRestored, { fanout: "force" });
|
|
7910
|
+
const rsaOnlyMessage = queue.messages.at(-1);
|
|
7911
|
+
assert(rsaOnlyMessage != null && rsaOnlyMessage.type === "fanout");
|
|
7912
|
+
assertEquals(rsaOnlyMessage.activity, rsaOnlyJson);
|
|
7913
|
+
queue.clear();
|
|
7914
|
+
await ctx2.sendActivity({ username: "john" }, {
|
|
7915
|
+
id: new URL("https://example.com/recipient"),
|
|
7916
|
+
inboxId: new URL("https://example.com/inbox")
|
|
7917
|
+
}, restored, { fanout: "force" });
|
|
7918
|
+
const namedFanout = queue.messages.at(-1);
|
|
7919
|
+
assert(namedFanout != null && namedFanout.type === "fanout");
|
|
7920
|
+
const namedJson = detachSignature(namedFanout.activity);
|
|
7921
|
+
assertEquals((Array.isArray(namedJson.proof) ? namedJson.proof : [namedJson.proof]).length, 1);
|
|
7922
|
+
assert(namedJson["@context"].includes("https://w3id.org/security/v1"));
|
|
7923
|
+
const noIdJson = await (await signObject(new vocab.Create({ actor: ctx2.getActorUri("john") }), edKey.privateKey, edKey.multikey.id, {
|
|
7924
|
+
contextLoader: documentLoader,
|
|
7925
|
+
context: oldContext
|
|
7926
|
+
})).toJsonLd({
|
|
7927
|
+
format: "compact",
|
|
7928
|
+
contextLoader: documentLoader,
|
|
7929
|
+
context: oldContext
|
|
7930
|
+
});
|
|
7931
|
+
const noIdRestored = await vocab.Create.fromJsonLd(noIdJson, {
|
|
7932
|
+
contextLoader: documentLoader,
|
|
7933
|
+
documentLoader
|
|
7934
|
+
});
|
|
7935
|
+
queue.clear();
|
|
7936
|
+
await ctx2.sendActivity([{
|
|
7937
|
+
privateKey: rsaPrivateKey2,
|
|
7938
|
+
keyId: rsaPublicKey2.id
|
|
7939
|
+
}], {
|
|
7940
|
+
id: new URL("https://example.com/recipient"),
|
|
7941
|
+
inboxId: new URL("https://example.com/inbox")
|
|
7942
|
+
}, noIdRestored);
|
|
7943
|
+
const noIdQueued = queue.messages.at(-1);
|
|
7944
|
+
assert(noIdQueued != null && noIdQueued.type === "outbox");
|
|
7945
|
+
assert(typeof detachSignature(noIdQueued.activity).id === "string");
|
|
7946
|
+
const currentJson = await (await signObject(new vocab.Create({
|
|
7947
|
+
id: new URL("https://example.com/activity/current"),
|
|
7948
|
+
actor: ctx2.getActorUri("john")
|
|
7949
|
+
}), edKey.privateKey, edKey.multikey.id, { contextLoader: documentLoader })).toJsonLd({
|
|
7950
|
+
format: "compact",
|
|
7951
|
+
contextLoader: documentLoader
|
|
7952
|
+
});
|
|
7953
|
+
const currentRestored = await vocab.Create.fromJsonLd(currentJson, {
|
|
7954
|
+
contextLoader: documentLoader,
|
|
7955
|
+
documentLoader
|
|
7956
|
+
});
|
|
7957
|
+
queue.clear();
|
|
7958
|
+
await ctx2.sendActivity({ username: "john" }, {
|
|
7959
|
+
id: new URL("https://example.com/recipient"),
|
|
7960
|
+
inboxId: new URL("https://example.com/inbox")
|
|
7961
|
+
}, currentRestored, { fanout: "force" });
|
|
7962
|
+
const currentFanout = queue.messages.at(-1);
|
|
7963
|
+
assert(currentFanout != null && currentFanout.type === "fanout");
|
|
7964
|
+
const currentQueued = detachSignature(currentFanout.activity);
|
|
7965
|
+
assertEquals((Array.isArray(currentQueued.proof) ? currentQueued.proof : [currentQueued.proof]).length, 2);
|
|
7966
|
+
});
|
|
7967
|
+
queue.clear();
|
|
7968
|
+
await t.step("activity transformers preserve proofs", async () => {
|
|
7969
|
+
const originalProof = new vocab.DataIntegrityProof({
|
|
7970
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
7971
|
+
verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
|
|
7972
|
+
proofPurpose: "assertionMethod",
|
|
7973
|
+
proofValue: new Uint8Array([
|
|
7974
|
+
1,
|
|
7975
|
+
2,
|
|
7976
|
+
3,
|
|
7977
|
+
4
|
|
7978
|
+
]),
|
|
7979
|
+
created: Temporal.Instant.from("2026-01-01T00:00:00Z")
|
|
7980
|
+
});
|
|
7981
|
+
const addedProof = new vocab.DataIntegrityProof({
|
|
7982
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
7983
|
+
verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
|
|
7984
|
+
proofPurpose: "assertionMethod",
|
|
7985
|
+
proofValue: new Uint8Array([
|
|
7986
|
+
5,
|
|
7987
|
+
6,
|
|
7988
|
+
7,
|
|
7989
|
+
8
|
|
7990
|
+
]),
|
|
7991
|
+
created: Temporal.Instant.from("2026-01-02T00:00:00Z")
|
|
7992
|
+
});
|
|
7993
|
+
const replacementProof = new vocab.DataIntegrityProof({
|
|
7994
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
7995
|
+
verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
|
|
7996
|
+
proofPurpose: "assertionMethod",
|
|
7997
|
+
proofValue: new Uint8Array([
|
|
7998
|
+
9,
|
|
7999
|
+
10,
|
|
8000
|
+
11,
|
|
8001
|
+
12
|
|
8002
|
+
]),
|
|
8003
|
+
created: Temporal.Instant.from("2026-01-03T00:00:00Z")
|
|
8004
|
+
});
|
|
8005
|
+
const restoredProof = new vocab.DataIntegrityProof({
|
|
8006
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
8007
|
+
verificationMethod: new URL("https://example.com/rsa-only#multikey-2"),
|
|
8008
|
+
proofPurpose: "assertionMethod",
|
|
8009
|
+
proofValue: new Uint8Array([
|
|
8010
|
+
13,
|
|
8011
|
+
14,
|
|
8012
|
+
15,
|
|
8013
|
+
16
|
|
8014
|
+
]),
|
|
8015
|
+
created: Temporal.Instant.from("2026-01-04T00:00:00Z")
|
|
8016
|
+
});
|
|
8017
|
+
const restoredProofHolder = {};
|
|
8018
|
+
const federation3 = new FederationImpl({
|
|
8019
|
+
kv,
|
|
8020
|
+
allowPrivateAddress: true,
|
|
8021
|
+
queue,
|
|
8022
|
+
activityTransformers: [(activity) => {
|
|
8023
|
+
if (activity.id?.href === "https://example.com/activity/transformed-proof") return activity.clone({ proofs: [originalProof, addedProof] });
|
|
8024
|
+
if (activity.id?.href === "https://example.com/activity/replaced-proof") return new vocab.Create({
|
|
8025
|
+
id: activity.id,
|
|
8026
|
+
actor: new URL("https://example.com/rsa-only"),
|
|
8027
|
+
object: new URL("https://example.com/note/replaced"),
|
|
8028
|
+
proofs: [replacementProof]
|
|
8029
|
+
});
|
|
8030
|
+
if (activity.id?.href === "https://example.com/activity/restored-proof") return activity.clone({ proofs: [restoredProofHolder.old, restoredProof] });
|
|
8031
|
+
return activity;
|
|
8032
|
+
}]
|
|
8033
|
+
});
|
|
8034
|
+
federation3.setActorDispatcher("/{identifier}", async (ctx, identifier) => {
|
|
8035
|
+
if (identifier !== "rsa-only") return null;
|
|
8036
|
+
const keys = await ctx.getActorKeyPairs(identifier);
|
|
8037
|
+
return new vocab.Person({
|
|
8038
|
+
id: ctx.getActorUri(identifier),
|
|
8039
|
+
preferredUsername: identifier,
|
|
8040
|
+
publicKey: keys[0].cryptographicKey,
|
|
8041
|
+
assertionMethods: keys.map((k) => k.multikey)
|
|
8042
|
+
});
|
|
8043
|
+
}).setKeyPairsDispatcher((_ctx, identifier) => identifier === "rsa-only" ? [{
|
|
8044
|
+
privateKey: rsaPrivateKey2,
|
|
8045
|
+
publicKey: rsaPublicKey2.publicKey
|
|
8046
|
+
}] : []);
|
|
8047
|
+
const ctx3 = new ContextImpl({
|
|
8048
|
+
data: void 0,
|
|
8049
|
+
federation: federation3,
|
|
8050
|
+
url: new URL("https://example.com/"),
|
|
8051
|
+
documentLoader,
|
|
8052
|
+
contextLoader: documentLoader
|
|
8053
|
+
});
|
|
8054
|
+
const activity = new vocab.Create({
|
|
8055
|
+
id: new URL("https://example.com/activity/transformed-proof"),
|
|
8056
|
+
actor: ctx3.getActorUri("rsa-only"),
|
|
8057
|
+
proofs: [originalProof]
|
|
8058
|
+
});
|
|
8059
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
8060
|
+
id: new URL("https://example.com/recipient"),
|
|
8061
|
+
inboxId: new URL("https://example.com/inbox")
|
|
8062
|
+
}, activity, { fanout: "force" });
|
|
8063
|
+
const fanout = queue.messages.at(-1);
|
|
8064
|
+
assert(fanout != null && fanout.type === "fanout");
|
|
8065
|
+
const fanoutJson = detachSignature(fanout.activity);
|
|
8066
|
+
assertEquals((Array.isArray(fanoutJson.proof) ? fanoutJson.proof : [fanoutJson.proof]).length, 2);
|
|
8067
|
+
const replacedActivity = new vocab.Create({
|
|
8068
|
+
id: new URL("https://example.com/activity/replaced-proof"),
|
|
8069
|
+
actor: ctx3.getActorUri("rsa-only"),
|
|
8070
|
+
proofs: [originalProof]
|
|
8071
|
+
});
|
|
8072
|
+
queue.clear();
|
|
8073
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
8074
|
+
id: new URL("https://example.com/recipient"),
|
|
8075
|
+
inboxId: new URL("https://example.com/inbox")
|
|
8076
|
+
}, replacedActivity, { fanout: "force" });
|
|
8077
|
+
const replacedFanout = queue.messages.at(-1);
|
|
8078
|
+
assert(replacedFanout != null && replacedFanout.type === "fanout");
|
|
8079
|
+
const replacedJson = detachSignature(replacedFanout.activity);
|
|
8080
|
+
assertEquals(replacedJson.object, "https://example.com/note/replaced");
|
|
8081
|
+
const replacedProofs = Array.isArray(replacedJson.proof) ? replacedJson.proof : [replacedJson.proof];
|
|
8082
|
+
assertEquals(replacedProofs.length, 1);
|
|
8083
|
+
const [keptProof] = replacedProofs;
|
|
8084
|
+
assertEquals(keptProof.created, "2026-01-03T00:00:00Z");
|
|
8085
|
+
const oldContext = [
|
|
8086
|
+
"https://w3id.org/identity/v1",
|
|
8087
|
+
"https://www.w3.org/ns/activitystreams",
|
|
8088
|
+
"https://w3id.org/security/data-integrity/v1"
|
|
8089
|
+
];
|
|
8090
|
+
const restoredJson = await (await signObject(new vocab.Create({
|
|
8091
|
+
id: new URL("https://example.com/activity/restored-proof"),
|
|
8092
|
+
actor: ctx3.getActorUri("rsa-only")
|
|
8093
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
8094
|
+
contextLoader: documentLoader,
|
|
8095
|
+
context: oldContext
|
|
8096
|
+
})).toJsonLd({
|
|
8097
|
+
format: "compact",
|
|
8098
|
+
contextLoader: documentLoader,
|
|
8099
|
+
context: oldContext
|
|
8100
|
+
});
|
|
8101
|
+
const restored = await vocab.Create.fromJsonLd(restoredJson, {
|
|
8102
|
+
contextLoader: documentLoader,
|
|
8103
|
+
documentLoader
|
|
8104
|
+
});
|
|
8105
|
+
for await (const proof of restored.getProofs({ contextLoader: documentLoader })) {
|
|
8106
|
+
restoredProofHolder.old = proof;
|
|
8107
|
+
break;
|
|
8108
|
+
}
|
|
8109
|
+
queue.clear();
|
|
8110
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
8111
|
+
id: new URL("https://example.com/recipient"),
|
|
8112
|
+
inboxId: new URL("https://example.com/inbox")
|
|
8113
|
+
}, restored, { fanout: "force" });
|
|
8114
|
+
const restoredFanout = queue.messages.at(-1);
|
|
8115
|
+
assert(restoredFanout != null && restoredFanout.type === "fanout");
|
|
8116
|
+
const restoredFanoutJson = detachSignature(restoredFanout.activity);
|
|
8117
|
+
const restoredProofs = Array.isArray(restoredFanoutJson.proof) ? restoredFanoutJson.proof : [restoredFanoutJson.proof];
|
|
8118
|
+
assertEquals(restoredProofs.length, 1);
|
|
8119
|
+
const [transformedProof] = restoredProofs;
|
|
8120
|
+
assertEquals(transformedProof.created, "2026-01-04T00:00:00Z");
|
|
8121
|
+
assert(Array.isArray(restoredFanoutJson["@context"]) && restoredFanoutJson["@context"].includes("https://w3id.org/security/v1"));
|
|
8122
|
+
const staleTimestampJson = await (await signObject(new vocab.Create({
|
|
8123
|
+
id: new URL("https://example.com/activity/stale-timestamp"),
|
|
8124
|
+
actor: ctx3.getActorUri("rsa-only")
|
|
8125
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
8126
|
+
contextLoader: documentLoader,
|
|
8127
|
+
context: oldContext
|
|
8128
|
+
})).toJsonLd({
|
|
8129
|
+
format: "compact",
|
|
8130
|
+
contextLoader: documentLoader,
|
|
8131
|
+
context: oldContext
|
|
8132
|
+
});
|
|
8133
|
+
const staleTimestampProof = Array.isArray(staleTimestampJson.proof) ? staleTimestampJson.proof[0] : staleTimestampJson.proof;
|
|
8134
|
+
staleTimestampProof.created = "2026-01-01T00:00:00+00:00";
|
|
8135
|
+
const staleTimestamp = await vocab.Create.fromJsonLd(staleTimestampJson, {
|
|
8136
|
+
contextLoader: documentLoader,
|
|
8137
|
+
documentLoader
|
|
8138
|
+
});
|
|
8139
|
+
queue.clear();
|
|
8140
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
8141
|
+
id: new URL("https://example.com/recipient"),
|
|
8142
|
+
inboxId: new URL("https://example.com/inbox")
|
|
8143
|
+
}, staleTimestamp, { fanout: "force" });
|
|
8144
|
+
const staleTimestampFanout = queue.messages.at(-1);
|
|
8145
|
+
assert(staleTimestampFanout != null && staleTimestampFanout.type === "fanout");
|
|
8146
|
+
assertEquals(detachSignature(staleTimestampFanout.activity), staleTimestampJson);
|
|
8147
|
+
const proofless = new vocab.Create({
|
|
8148
|
+
id: new URL("https://example.com/activity/proofless"),
|
|
8149
|
+
actor: ctx3.getActorUri("rsa-only")
|
|
8150
|
+
});
|
|
8151
|
+
let unformattedSerializations = 0;
|
|
8152
|
+
const originalToJsonLd = proofless.toJsonLd.bind(proofless);
|
|
8153
|
+
Object.defineProperty(proofless, "toJsonLd", { value: async (options) => {
|
|
8154
|
+
if (options?.format == null) unformattedSerializations++;
|
|
8155
|
+
return await originalToJsonLd(options);
|
|
8156
|
+
} });
|
|
8157
|
+
queue.clear();
|
|
8158
|
+
await ctx3.sendActivity({ identifier: "rsa-only" }, {
|
|
8159
|
+
id: new URL("https://example.com/recipient"),
|
|
8160
|
+
inboxId: new URL("https://example.com/inbox")
|
|
8161
|
+
}, proofless, { fanout: "skip" });
|
|
8162
|
+
assertEquals(unformattedSerializations, 0);
|
|
7325
8163
|
});
|
|
7326
8164
|
queue.clear();
|
|
7327
8165
|
await t.step("fanout: \"force\" preserves pre-signed proof normalization", async () => {
|
|
@@ -8316,6 +9154,63 @@ test("InboxContextImpl.forwardActivity()", async (t) => {
|
|
|
8316
9154
|
});
|
|
8317
9155
|
esm_default.hardReset();
|
|
8318
9156
|
});
|
|
9157
|
+
test("InboxContextImpl.forwardActivity() without created", async (t) => {
|
|
9158
|
+
for (const immediate of [true, false]) await t.step(immediate ? "immediate delivery" : "queued delivery", async () => {
|
|
9159
|
+
const delivered = [];
|
|
9160
|
+
const queued = [];
|
|
9161
|
+
esm_default.spyGlobal();
|
|
9162
|
+
esm_default.post("https://example.com/inbox", async (call) => {
|
|
9163
|
+
delivered.push(await call.request.json());
|
|
9164
|
+
return new Response(null, { status: 202 });
|
|
9165
|
+
});
|
|
9166
|
+
try {
|
|
9167
|
+
const federation = new FederationImpl({
|
|
9168
|
+
kv: new MemoryKvStore(),
|
|
9169
|
+
allowPrivateAddress: true,
|
|
9170
|
+
manuallyStartQueue: true,
|
|
9171
|
+
queue: { outbox: {
|
|
9172
|
+
enqueue(message) {
|
|
9173
|
+
queued.push(message);
|
|
9174
|
+
return Promise.resolve();
|
|
9175
|
+
},
|
|
9176
|
+
async listen() {}
|
|
9177
|
+
} }
|
|
9178
|
+
});
|
|
9179
|
+
const activity = structuredClone(ldSignatureWithoutCreated);
|
|
9180
|
+
assert(await verifyJsonLd(activity, {
|
|
9181
|
+
documentLoader: mockDocumentLoader,
|
|
9182
|
+
contextLoader: mockDocumentLoader
|
|
9183
|
+
}));
|
|
9184
|
+
await new InboxContextImpl(null, activity, activity.id, "https://www.w3.org/ns/activitystreams#Create", {
|
|
9185
|
+
data: void 0,
|
|
9186
|
+
federation,
|
|
9187
|
+
url: new URL("https://example.com/"),
|
|
9188
|
+
documentLoader: mockDocumentLoader,
|
|
9189
|
+
contextLoader: mockDocumentLoader
|
|
9190
|
+
}).forwardActivity([{
|
|
9191
|
+
privateKey: rsaPrivateKey2,
|
|
9192
|
+
keyId: rsaPublicKey2.id
|
|
9193
|
+
}], {
|
|
9194
|
+
id: new URL("https://example.com/recipient"),
|
|
9195
|
+
inboxId: new URL("https://example.com/inbox")
|
|
9196
|
+
}, {
|
|
9197
|
+
skipIfUnsigned: true,
|
|
9198
|
+
immediate
|
|
9199
|
+
});
|
|
9200
|
+
if (immediate) {
|
|
9201
|
+
assertEquals(delivered, [activity]);
|
|
9202
|
+
assertEquals(queued, []);
|
|
9203
|
+
} else {
|
|
9204
|
+
assertEquals(delivered, []);
|
|
9205
|
+
assertEquals(queued.length, 1);
|
|
9206
|
+
assertEquals(queued[0].type, "outbox");
|
|
9207
|
+
assertEquals(queued[0].activity, activity);
|
|
9208
|
+
}
|
|
9209
|
+
} finally {
|
|
9210
|
+
esm_default.hardReset();
|
|
9211
|
+
}
|
|
9212
|
+
});
|
|
9213
|
+
});
|
|
8319
9214
|
test("KvSpecDeterminer", async (t) => {
|
|
8320
9215
|
await t.step("should use default spec when not found in KV", async () => {
|
|
8321
9216
|
assertEquals(await new KvSpecDeterminer(new MemoryKvStore(), ["test", "spec"]).determineSpec("example.com"), "rfc9421");
|
|
@@ -8804,6 +9699,286 @@ test("ContextImpl.sendActivity() honors the private-address policy", async (t) =
|
|
|
8804
9699
|
}
|
|
8805
9700
|
});
|
|
8806
9701
|
});
|
|
9702
|
+
function deferredSignal() {
|
|
9703
|
+
let resolve;
|
|
9704
|
+
return {
|
|
9705
|
+
promise: new Promise((r) => resolve = r),
|
|
9706
|
+
resolve
|
|
9707
|
+
};
|
|
9708
|
+
}
|
|
9709
|
+
test("ContextImpl.sendActivity() waits for sibling deliveries on failure", async () => {
|
|
9710
|
+
const failingInbox = "http://127.0.0.1:3001/inbox/fail";
|
|
9711
|
+
const slowInbox = "http://127.0.0.1:3002/inbox/slow";
|
|
9712
|
+
const failingEntered = deferredSignal();
|
|
9713
|
+
const slowEntered = deferredSignal();
|
|
9714
|
+
const slowCompleted = deferredSignal();
|
|
9715
|
+
let releaseSlow;
|
|
9716
|
+
const slowGate = new Promise((resolve) => releaseSlow = resolve);
|
|
9717
|
+
let slowStarted = false;
|
|
9718
|
+
let slowSettled = false;
|
|
9719
|
+
esm_default.spyGlobal();
|
|
9720
|
+
esm_default.post(failingInbox, () => {
|
|
9721
|
+
failingEntered.resolve();
|
|
9722
|
+
return new Response(null, { status: 500 });
|
|
9723
|
+
});
|
|
9724
|
+
esm_default.post(slowInbox, async () => {
|
|
9725
|
+
slowStarted = true;
|
|
9726
|
+
slowEntered.resolve();
|
|
9727
|
+
await slowGate;
|
|
9728
|
+
slowSettled = true;
|
|
9729
|
+
slowCompleted.resolve();
|
|
9730
|
+
return new Response(null, { status: 202 });
|
|
9731
|
+
});
|
|
9732
|
+
let observed;
|
|
9733
|
+
let released = false;
|
|
9734
|
+
try {
|
|
9735
|
+
const ctx = createFederation({
|
|
9736
|
+
kv: new MemoryKvStore(),
|
|
9737
|
+
allowPrivateAddress: true
|
|
9738
|
+
}).createContext(new URL("https://example.com/"));
|
|
9739
|
+
const activity = new Create({
|
|
9740
|
+
id: new URL("https://example.com/activity/fanout"),
|
|
9741
|
+
actor: new URL("https://example.com/person")
|
|
9742
|
+
});
|
|
9743
|
+
let outerSettled = false;
|
|
9744
|
+
let outerError;
|
|
9745
|
+
observed = ctx.sendActivity([{
|
|
9746
|
+
privateKey: ed25519PrivateKey,
|
|
9747
|
+
keyId: ed25519Multikey.id
|
|
9748
|
+
}], [new Person({
|
|
9749
|
+
id: new URL("https://example.com/recipients/failing"),
|
|
9750
|
+
inbox: new URL(failingInbox)
|
|
9751
|
+
}), new Person({
|
|
9752
|
+
id: new URL("https://example.com/recipients/slow"),
|
|
9753
|
+
inbox: new URL(slowInbox)
|
|
9754
|
+
})], activity, { immediate: true }).then(() => {
|
|
9755
|
+
outerSettled = true;
|
|
9756
|
+
}, (error) => {
|
|
9757
|
+
outerSettled = true;
|
|
9758
|
+
outerError = error;
|
|
9759
|
+
});
|
|
9760
|
+
await Promise.all([failingEntered.promise, slowEntered.promise]);
|
|
9761
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
9762
|
+
assertFalse(outerSettled, "sendActivity() must wait for sibling deliveries before rejecting");
|
|
9763
|
+
releaseSlow();
|
|
9764
|
+
released = true;
|
|
9765
|
+
await observed;
|
|
9766
|
+
assert(slowSettled, "the delayed delivery should have settled");
|
|
9767
|
+
assertInstanceOf(outerError, SendActivityError);
|
|
9768
|
+
} finally {
|
|
9769
|
+
if (!released) releaseSlow();
|
|
9770
|
+
if (slowStarted) await slowCompleted.promise;
|
|
9771
|
+
await observed;
|
|
9772
|
+
esm_default.hardReset();
|
|
9773
|
+
}
|
|
9774
|
+
});
|
|
9775
|
+
test("InboxContextImpl.forwardActivity() waits for sibling deliveries on failure", async () => {
|
|
9776
|
+
const failingInbox = "http://127.0.0.1:3003/inbox/fail";
|
|
9777
|
+
const slowInbox = "http://127.0.0.1:3004/inbox/slow";
|
|
9778
|
+
const failingEntered = deferredSignal();
|
|
9779
|
+
const slowEntered = deferredSignal();
|
|
9780
|
+
const slowCompleted = deferredSignal();
|
|
9781
|
+
let releaseSlow;
|
|
9782
|
+
const slowGate = new Promise((resolve) => releaseSlow = resolve);
|
|
9783
|
+
let slowStarted = false;
|
|
9784
|
+
let slowSettled = false;
|
|
9785
|
+
esm_default.spyGlobal();
|
|
9786
|
+
esm_default.post(failingInbox, () => {
|
|
9787
|
+
failingEntered.resolve();
|
|
9788
|
+
return new Response(null, { status: 500 });
|
|
9789
|
+
});
|
|
9790
|
+
esm_default.post(slowInbox, async () => {
|
|
9791
|
+
slowStarted = true;
|
|
9792
|
+
slowEntered.resolve();
|
|
9793
|
+
await slowGate;
|
|
9794
|
+
slowSettled = true;
|
|
9795
|
+
slowCompleted.resolve();
|
|
9796
|
+
return new Response(null, { status: 202 });
|
|
9797
|
+
});
|
|
9798
|
+
let observed;
|
|
9799
|
+
let released = false;
|
|
9800
|
+
try {
|
|
9801
|
+
const federation = new FederationImpl({
|
|
9802
|
+
kv: new MemoryKvStore(),
|
|
9803
|
+
allowPrivateAddress: true
|
|
9804
|
+
});
|
|
9805
|
+
const activity = await signObject(new vocab.Create({
|
|
9806
|
+
id: new URL("https://example.com/activity/forward"),
|
|
9807
|
+
actor: new URL("https://example.com/person2")
|
|
9808
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
9809
|
+
contextLoader: mockDocumentLoader,
|
|
9810
|
+
documentLoader: mockDocumentLoader
|
|
9811
|
+
});
|
|
9812
|
+
const ctx = new InboxContextImpl(null, await activity.toJsonLd({ contextLoader: mockDocumentLoader }), activity.id?.href, getTypeId(activity).href, {
|
|
9813
|
+
data: void 0,
|
|
9814
|
+
federation,
|
|
9815
|
+
url: new URL("https://example.com/"),
|
|
9816
|
+
documentLoader: mockDocumentLoader,
|
|
9817
|
+
contextLoader: mockDocumentLoader
|
|
9818
|
+
});
|
|
9819
|
+
let outerSettled = false;
|
|
9820
|
+
let outerError;
|
|
9821
|
+
observed = ctx.forwardActivity([{
|
|
9822
|
+
privateKey: ed25519PrivateKey,
|
|
9823
|
+
keyId: ed25519Multikey.id
|
|
9824
|
+
}], [{
|
|
9825
|
+
id: new URL("https://example.com/recipients/failing"),
|
|
9826
|
+
inboxId: new URL(failingInbox)
|
|
9827
|
+
}, {
|
|
9828
|
+
id: new URL("https://example.com/recipients/slow"),
|
|
9829
|
+
inboxId: new URL(slowInbox)
|
|
9830
|
+
}], {
|
|
9831
|
+
immediate: true,
|
|
9832
|
+
skipIfUnsigned: true
|
|
9833
|
+
}).then(() => {
|
|
9834
|
+
outerSettled = true;
|
|
9835
|
+
}, (error) => {
|
|
9836
|
+
outerSettled = true;
|
|
9837
|
+
outerError = error;
|
|
9838
|
+
});
|
|
9839
|
+
await Promise.all([failingEntered.promise, slowEntered.promise]);
|
|
9840
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
9841
|
+
assertFalse(outerSettled, "forwardActivity() must wait for sibling deliveries before rejecting");
|
|
9842
|
+
releaseSlow();
|
|
9843
|
+
released = true;
|
|
9844
|
+
await observed;
|
|
9845
|
+
assert(slowSettled, "the delayed delivery should have settled");
|
|
9846
|
+
assertInstanceOf(outerError, SendActivityError);
|
|
9847
|
+
} finally {
|
|
9848
|
+
if (!released) releaseSlow();
|
|
9849
|
+
if (slowStarted) await slowCompleted.promise;
|
|
9850
|
+
await observed;
|
|
9851
|
+
esm_default.hardReset();
|
|
9852
|
+
}
|
|
9853
|
+
});
|
|
9854
|
+
test("FederationImpl.sendActivity() drains deliveries when fan-out setup fails", async () => {
|
|
9855
|
+
const slowInbox = "http://127.0.0.1:3005/inbox/slow";
|
|
9856
|
+
const slowEntered = deferredSignal();
|
|
9857
|
+
const slowCompleted = deferredSignal();
|
|
9858
|
+
let releaseSlow;
|
|
9859
|
+
const slowGate = new Promise((resolve) => releaseSlow = resolve);
|
|
9860
|
+
let slowStarted = false;
|
|
9861
|
+
let slowSettled = false;
|
|
9862
|
+
esm_default.spyGlobal();
|
|
9863
|
+
esm_default.post(slowInbox, async () => {
|
|
9864
|
+
slowStarted = true;
|
|
9865
|
+
slowEntered.resolve();
|
|
9866
|
+
await slowGate;
|
|
9867
|
+
slowSettled = true;
|
|
9868
|
+
slowCompleted.resolve();
|
|
9869
|
+
return new Response(null, { status: 202 });
|
|
9870
|
+
});
|
|
9871
|
+
let observed;
|
|
9872
|
+
let released = false;
|
|
9873
|
+
try {
|
|
9874
|
+
const federation = new FederationImpl({
|
|
9875
|
+
kv: new MemoryKvStore(),
|
|
9876
|
+
allowPrivateAddress: true
|
|
9877
|
+
});
|
|
9878
|
+
const context = federation.createContext(new URL("https://example.com/"));
|
|
9879
|
+
const activity = new Create({
|
|
9880
|
+
id: new URL("https://example.com/activity/setup-failure"),
|
|
9881
|
+
actor: new URL("https://example.com/person")
|
|
9882
|
+
});
|
|
9883
|
+
let outerSettled = false;
|
|
9884
|
+
let outerError;
|
|
9885
|
+
observed = federation.sendActivity([{
|
|
9886
|
+
privateKey: ed25519PrivateKey,
|
|
9887
|
+
keyId: ed25519Multikey.id
|
|
9888
|
+
}], {
|
|
9889
|
+
[slowInbox]: {
|
|
9890
|
+
actorIds: ["https://example.com/recipients/slow"],
|
|
9891
|
+
sharedInbox: false
|
|
9892
|
+
},
|
|
9893
|
+
"not a url": {
|
|
9894
|
+
actorIds: ["https://example.com/recipients/invalid"],
|
|
9895
|
+
sharedInbox: false
|
|
9896
|
+
}
|
|
9897
|
+
}, activity, {
|
|
9898
|
+
context,
|
|
9899
|
+
immediate: true
|
|
9900
|
+
}).then(() => {
|
|
9901
|
+
outerSettled = true;
|
|
9902
|
+
}, (error) => {
|
|
9903
|
+
outerSettled = true;
|
|
9904
|
+
outerError = error;
|
|
9905
|
+
});
|
|
9906
|
+
await slowEntered.promise;
|
|
9907
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
9908
|
+
assertFalse(outerSettled, "sendActivity() must drain started deliveries when fan-out setup fails");
|
|
9909
|
+
releaseSlow();
|
|
9910
|
+
released = true;
|
|
9911
|
+
await observed;
|
|
9912
|
+
assert(slowSettled, "the started delivery should have settled");
|
|
9913
|
+
assertInstanceOf(outerError, TypeError);
|
|
9914
|
+
} finally {
|
|
9915
|
+
if (!released) releaseSlow();
|
|
9916
|
+
if (slowStarted) await slowCompleted.promise;
|
|
9917
|
+
await observed;
|
|
9918
|
+
esm_default.hardReset();
|
|
9919
|
+
}
|
|
9920
|
+
});
|
|
9921
|
+
test("FederationImpl.sendActivity() handles rejections while building headers", async () => {
|
|
9922
|
+
const federation = new FederationImpl({ kv: new MemoryKvStore() });
|
|
9923
|
+
const context = federation.createContext(new URL("https://example.com/"));
|
|
9924
|
+
const activity = await signObject(new Create({
|
|
9925
|
+
id: new URL("https://example.com/activity/header-failure"),
|
|
9926
|
+
actor: new URL("https://example.com/person")
|
|
9927
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
9928
|
+
contextLoader: mockDocumentLoader,
|
|
9929
|
+
documentLoader: mockDocumentLoader
|
|
9930
|
+
});
|
|
9931
|
+
const subtle = crypto.subtle;
|
|
9932
|
+
const originalDigest = subtle.digest;
|
|
9933
|
+
let digestCalls = 0;
|
|
9934
|
+
let releaseSecondDigest;
|
|
9935
|
+
const secondDigestGate = new Promise((resolve) => {
|
|
9936
|
+
releaseSecondDigest = resolve;
|
|
9937
|
+
});
|
|
9938
|
+
let secondDigestStarted;
|
|
9939
|
+
const secondDigestEntered = new Promise((resolve) => {
|
|
9940
|
+
secondDigestStarted = resolve;
|
|
9941
|
+
});
|
|
9942
|
+
subtle.digest = async (algorithm, data) => {
|
|
9943
|
+
digestCalls++;
|
|
9944
|
+
if (digestCalls === 2) {
|
|
9945
|
+
secondDigestStarted();
|
|
9946
|
+
await secondDigestGate;
|
|
9947
|
+
}
|
|
9948
|
+
return await originalDigest.call(subtle, algorithm, data);
|
|
9949
|
+
};
|
|
9950
|
+
const capture = captureUnhandledRejections();
|
|
9951
|
+
let released = false;
|
|
9952
|
+
try {
|
|
9953
|
+
const observed = federation.sendActivity([{
|
|
9954
|
+
privateKey: ed25519PrivateKey,
|
|
9955
|
+
keyId: ed25519Multikey.id
|
|
9956
|
+
}], {
|
|
9957
|
+
"ftp://example.com/fail": {
|
|
9958
|
+
actorIds: ["https://example.com/recipients/failing"],
|
|
9959
|
+
sharedInbox: false
|
|
9960
|
+
},
|
|
9961
|
+
"http://127.0.0.1:3006/inbox": {
|
|
9962
|
+
actorIds: ["https://example.com/recipients/slow"],
|
|
9963
|
+
sharedInbox: false
|
|
9964
|
+
}
|
|
9965
|
+
}, activity, {
|
|
9966
|
+
context,
|
|
9967
|
+
immediate: true,
|
|
9968
|
+
collectionSync: "https://example.com/followers"
|
|
9969
|
+
}).catch((error) => error);
|
|
9970
|
+
await secondDigestEntered;
|
|
9971
|
+
await capture.settle();
|
|
9972
|
+
assertEquals(capture.reasons, [], "an early rejection must not surface as an unhandled rejection");
|
|
9973
|
+
releaseSecondDigest();
|
|
9974
|
+
released = true;
|
|
9975
|
+
await observed;
|
|
9976
|
+
} finally {
|
|
9977
|
+
if (!released) releaseSecondDigest();
|
|
9978
|
+
subtle.digest = originalDigest;
|
|
9979
|
+
capture.stop();
|
|
9980
|
+
}
|
|
9981
|
+
});
|
|
8807
9982
|
test("Federation.fetch() bounds inbox bodies before dispatch", async () => {
|
|
8808
9983
|
let dispatched = false;
|
|
8809
9984
|
const json = JSON.stringify({
|