@fedify/fedify 2.5.0-dev.2687 → 2.5.0-dev.2710
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/federation/mod.cjs +1 -1
- package/dist/federation/mod.js +1 -1
- package/dist/{federation-pFFwPyoZ.cjs → federation-JvzYDx0P.cjs} +3 -3
- package/dist/{http-CXX-QPzs.cjs → http-BG5cDmTS.cjs} +1 -1
- package/dist/{http-T7h9GBAN.js → http-MUf125Jc.js} +1 -1
- package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-A2po7h0_.cjs} +1 -1
- package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CbWc1BZA.js} +1 -1
- package/dist/{middleware-Bj91r7r2.js → middleware-DzzdJ7Wz.js} +3 -3
- package/dist/mod.cjs +4 -4
- package/dist/mod.js +4 -4
- package/dist/{portable-collection-Do5QA2oy.js → portable-collection-CAer9RWN.js} +1 -1
- package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +22 -9
- package/skills/fedify/SKILL.md +10 -0
- package/dist/accept-CPVqki78.mjs +0 -145
- package/dist/activity-listener-CELFAodc.mjs +0 -44
- package/dist/assert-D1Eafmd_.mjs +0 -23
- package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
- package/dist/assert_exists-cffSpJ7X.mjs +0 -28
- package/dist/assert_false-CPdRnc3E.mjs +0 -23
- package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
- package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
- package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
- package/dist/assert_rejects-CTptdYck.mjs +0 -39
- package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
- package/dist/assert_throws-BYITOvPO.mjs +0 -74
- package/dist/assertion_error-B-cx0fFA.mjs +0 -31
- package/dist/audience-CHQ-FlLD.mjs +0 -95
- package/dist/builder-D1FP_5nQ.mjs +0 -911
- package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
- package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
- package/dist/client-5SIFzW3q.mjs +0 -441
- package/dist/codec-C6rTrpIp.mjs +0 -147
- package/dist/collection-CnnP1UAv.mjs +0 -44
- package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
- package/dist/compat/outgoing-jsonld.test.mjs +0 -257
- package/dist/compat/public-audience.test.d.mts +0 -2
- package/dist/compat/public-audience.test.mjs +0 -187
- package/dist/compat/secured-document.test.d.mts +0 -2
- package/dist/compat/secured-document.test.mjs +0 -58
- package/dist/compat/transformers.test.d.mts +0 -2
- package/dist/compat/transformers.test.mjs +0 -62
- package/dist/compound-proof-DSHhnOEW.mjs +0 -1019
- package/dist/context-LgGFFSz7.mjs +0 -146
- package/dist/deno-C50ikGBU.mjs +0 -8
- package/dist/dist-_geWsuaI.mjs +0 -189
- package/dist/docloader-BY-SEID0.mjs +0 -136
- package/dist/esm-BHXXx4Wx.mjs +0 -1233
- package/dist/exporter-DVG68ozH.mjs +0 -263
- package/dist/federation/audience.test.d.mts +0 -2
- package/dist/federation/audience.test.mjs +0 -130
- package/dist/federation/builder.test.d.mts +0 -2
- package/dist/federation/builder.test.mjs +0 -396
- package/dist/federation/circuit-breaker.test.d.mts +0 -2
- package/dist/federation/circuit-breaker.test.mjs +0 -1277
- package/dist/federation/collection.test.d.mts +0 -2
- package/dist/federation/collection.test.mjs +0 -21
- package/dist/federation/compound-fanout.test.d.mts +0 -2
- package/dist/federation/compound-fanout.test.mjs +0 -231
- package/dist/federation/handler-compound-proof.test.d.mts +0 -2
- package/dist/federation/handler-compound-proof.test.mjs +0 -384
- package/dist/federation/handler.test.d.mts +0 -2
- package/dist/federation/handler.test.mjs +0 -5445
- package/dist/federation/hashlink-media.test.d.mts +0 -2
- package/dist/federation/hashlink-media.test.mjs +0 -422
- package/dist/federation/idempotency.test.d.mts +0 -2
- package/dist/federation/idempotency.test.mjs +0 -207
- package/dist/federation/inbox-actorless.test.d.mts +0 -2
- package/dist/federation/inbox-actorless.test.mjs +0 -522
- package/dist/federation/inbox-authentication.test.d.mts +0 -2
- package/dist/federation/inbox-authentication.test.mjs +0 -220
- package/dist/federation/inbox-report.test.d.mts +0 -2
- package/dist/federation/inbox-report.test.mjs +0 -719
- package/dist/federation/inbox-view.test.d.mts +0 -2
- package/dist/federation/inbox-view.test.mjs +0 -369
- package/dist/federation/inbox.test.d.mts +0 -2
- package/dist/federation/inbox.test.mjs +0 -139
- package/dist/federation/keycache.test.d.mts +0 -2
- package/dist/federation/keycache.test.mjs +0 -337
- package/dist/federation/kv.test.d.mts +0 -2
- package/dist/federation/kv.test.mjs +0 -88
- package/dist/federation/metrics.test.d.mts +0 -2
- package/dist/federation/metrics.test.mjs +0 -634
- package/dist/federation/middleware.test.d.mts +0 -2
- package/dist/federation/middleware.test.mjs +0 -9314
- package/dist/federation/mq.test.d.mts +0 -2
- package/dist/federation/mq.test.mjs +0 -591
- package/dist/federation/negotiation.test.d.mts +0 -2
- package/dist/federation/negotiation.test.mjs +0 -18
- package/dist/federation/outbound-body.test.d.mts +0 -2
- package/dist/federation/outbound-body.test.mjs +0 -149
- package/dist/federation/outbound-capture.test.d.mts +0 -2
- package/dist/federation/outbound-capture.test.mjs +0 -394
- package/dist/federation/outbound-dispatch.test.d.mts +0 -2
- package/dist/federation/outbound-dispatch.test.mjs +0 -368
- package/dist/federation/outbound-document.test.d.mts +0 -2
- package/dist/federation/outbound-document.test.mjs +0 -171
- package/dist/federation/outbound-provenance.test.d.mts +0 -2
- package/dist/federation/outbound-provenance.test.mjs +0 -543
- package/dist/federation/outbound-report.test.d.mts +0 -2
- package/dist/federation/outbound-report.test.mjs +0 -5475
- package/dist/federation/outbound-workers.test.d.mts +0 -2
- package/dist/federation/outbound-workers.test.mjs +0 -64
- package/dist/federation/outbound-workflow.test.d.mts +0 -2
- package/dist/federation/outbound-workflow.test.mjs +0 -154
- package/dist/federation/outgoing-proof.test.d.mts +0 -2
- package/dist/federation/outgoing-proof.test.mjs +0 -933
- package/dist/federation/portable-actor.test.d.mts +0 -2
- package/dist/federation/portable-actor.test.mjs +0 -496
- package/dist/federation/portable-chain.test.d.mts +0 -2
- package/dist/federation/portable-chain.test.mjs +0 -370
- package/dist/federation/portable-collection.test.d.mts +0 -2
- package/dist/federation/portable-collection.test.mjs +0 -832
- package/dist/federation/portable-delivery.test.d.mts +0 -2
- package/dist/federation/portable-delivery.test.mjs +0 -845
- package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
- package/dist/federation/portable-gateway-keys.test.mjs +0 -692
- package/dist/federation/portable-inbox.test.d.mts +0 -2
- package/dist/federation/portable-inbox.test.mjs +0 -1960
- package/dist/federation/portable-parse-uri.test.d.mts +0 -2
- package/dist/federation/portable-parse-uri.test.mjs +0 -348
- package/dist/federation/portable-route-activity.test.d.mts +0 -2
- package/dist/federation/portable-route-activity.test.mjs +0 -259
- package/dist/federation/portable.test.d.mts +0 -2
- package/dist/federation/portable.test.mjs +0 -1072
- package/dist/federation/retry.test.d.mts +0 -2
- package/dist/federation/retry.test.mjs +0 -42
- package/dist/federation/router.test.d.mts +0 -2
- package/dist/federation/router.test.mjs +0 -123
- package/dist/federation/send.test.d.mts +0 -2
- package/dist/federation/send.test.mjs +0 -1421
- package/dist/federation/tasks/codec.test.d.mts +0 -2
- package/dist/federation/tasks/codec.test.mjs +0 -302
- package/dist/federation/tasks/enqueue.test.d.mts +0 -2
- package/dist/federation/tasks/enqueue.test.mjs +0 -1095
- package/dist/federation/tasks/tasks.test.d.mts +0 -2
- package/dist/federation/tasks/tasks.test.mjs +0 -1229
- package/dist/federation/temporal.test.d.mts +0 -2
- package/dist/federation/temporal.test.mjs +0 -71
- package/dist/federation/webfinger.test.d.mts +0 -2
- package/dist/federation/webfinger.test.mjs +0 -944
- package/dist/http-BXbQQZDM.mjs +0 -1449
- package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
- package/dist/inbox-cS97XzOD.mjs +0 -399
- package/dist/inbox-view-D-d0Ar6o.mjs +0 -385
- package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
- package/dist/keycache-N2opu4-3.mjs +0 -221
- package/dist/keys-DIJNHW-Y.mjs +0 -120
- package/dist/kv-DBRWVx3Q.mjs +0 -104
- package/dist/kv-DCHkaJ9-.mjs +0 -92
- package/dist/kv-cache-fgbLHGVL.mjs +0 -121
- package/dist/ld-BpkhkDGj.mjs +0 -1752
- package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
- package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
- package/dist/metrics-Uqf8GomB.mjs +0 -818
- package/dist/middleware-DcXzz-YK.mjs +0 -9971
- package/dist/middleware-DgwZkvJR.mjs +0 -5
- package/dist/mq-eF96QxUT.mjs +0 -288
- package/dist/negotiation-BAKO9nih.mjs +0 -96
- package/dist/nodeinfo/client.test.d.mts +0 -2
- package/dist/nodeinfo/client.test.mjs +0 -1364
- package/dist/nodeinfo/handler.test.d.mts +0 -2
- package/dist/nodeinfo/handler.test.mjs +0 -94
- package/dist/nodeinfo/types.test.d.mts +0 -2
- package/dist/nodeinfo/types.test.mjs +0 -192
- package/dist/otel/exporter.test.d.mts +0 -2
- package/dist/otel/exporter.test.mjs +0 -887
- package/dist/outbound-body-CckPA5gc.mjs +0 -83
- package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
- package/dist/outbound-document-BMgwLXTY.mjs +0 -179
- package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
- package/dist/owner-BVenIFg1.mjs +0 -267
- package/dist/portable-collection-DIk9gpjL.mjs +0 -418
- package/dist/portable-key-C7pVaHNR.mjs +0 -549
- package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
- package/dist/proof-BlfZ95--.mjs +0 -1420
- package/dist/public-audience--klBIOk1.mjs +0 -197
- package/dist/retry-zX5xw5e0.mjs +0 -34
- package/dist/router-u5O5KCQr.mjs +0 -156
- package/dist/secured-document-CxzZZ9nL.mjs +0 -35
- package/dist/send-DEGHPGFk.mjs +0 -710
- package/dist/sig/accept.test.d.mts +0 -2
- package/dist/sig/accept.test.mjs +0 -416
- package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
- package/dist/sig/compound-proof-discovery.test.mjs +0 -331
- package/dist/sig/compound-proof-producer.test.d.mts +0 -2
- package/dist/sig/compound-proof-producer.test.mjs +0 -107
- package/dist/sig/compound-proof-verification.test.d.mts +0 -2
- package/dist/sig/compound-proof-verification.test.mjs +0 -1017
- package/dist/sig/compound-proof.test.d.mts +0 -2
- package/dist/sig/compound-proof.test.mjs +0 -411
- package/dist/sig/http.test.d.mts +0 -2
- package/dist/sig/http.test.mjs +0 -3328
- package/dist/sig/key-owner-evidence.test.d.mts +0 -2
- package/dist/sig/key-owner-evidence.test.mjs +0 -100
- package/dist/sig/key.test.d.mts +0 -2
- package/dist/sig/key.test.mjs +0 -1250
- package/dist/sig/ld.test.d.mts +0 -2
- package/dist/sig/ld.test.mjs +0 -1044
- package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
- package/dist/sig/mitra-receive-interop.test.mjs +0 -260
- package/dist/sig/mitra-send-interop.test.d.mts +0 -2
- package/dist/sig/mitra-send-interop.test.mjs +0 -461
- package/dist/sig/owner.test.d.mts +0 -2
- package/dist/sig/owner.test.mjs +0 -202
- package/dist/sig/portable-collection.test.d.mts +0 -2
- package/dist/sig/portable-collection.test.mjs +0 -697
- package/dist/sig/portable-interop.test.d.mts +0 -2
- package/dist/sig/portable-interop.test.mjs +0 -156
- package/dist/sig/portable-key-id.test.d.mts +0 -2
- package/dist/sig/portable-key-id.test.mjs +0 -67
- package/dist/sig/portable-key.test.d.mts +0 -2
- package/dist/sig/portable-key.test.mjs +0 -1438
- package/dist/sig/proof.test.d.mts +0 -2
- package/dist/sig/proof.test.mjs +0 -2638
- package/dist/sig/tootik-request-interop.test.d.mts +0 -2
- package/dist/sig/tootik-request-interop.test.mjs +0 -190
- package/dist/sig/tootik-send-interop.test.d.mts +0 -2
- package/dist/sig/tootik-send-interop.test.mjs +0 -331
- package/dist/sig/verification.test.d.mts +0 -2
- package/dist/sig/verification.test.mjs +0 -310
- package/dist/std__assert-DvMDRPes.mjs +0 -8
- package/dist/tasks-BCUmQbbz.mjs +0 -77
- package/dist/temporal-B4oQ8HpW.mjs +0 -95
- package/dist/testing/context.test.d.mts +0 -2
- package/dist/testing/context.test.mjs +0 -19
- package/dist/testing/kv.test.d.mts +0 -2
- package/dist/testing/kv.test.mjs +0 -101
- package/dist/testing/mod.d.mts +0 -6099
- package/dist/testing/mod.mjs +0 -9
- package/dist/testing-vrnD5Uaa.mjs +0 -8
- package/dist/types-DE_LV1JB.mjs +0 -46
- package/dist/utils/docloader.test.d.mts +0 -2
- package/dist/utils/docloader.test.mjs +0 -1076
- package/dist/utils/kv-cache.test.d.mts +0 -2
- package/dist/utils/kv-cache.test.mjs +0 -261
- package/dist/verification-C3954hQh.mjs +0 -5
- package/dist/verification-Dpfcw8ml.mjs +0 -105
- package/dist/vocab/cjs.test.d.mts +0 -2
- package/dist/vocab/cjs.test.mjs +0 -27
|
@@ -1,719 +0,0 @@
|
|
|
1
|
-
import "temporal-polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
globalThis.addEventListener = () => {};
|
|
4
|
-
import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
|
|
5
|
-
import { m as signJsonLd } from "../ld-BpkhkDGj.mjs";
|
|
6
|
-
import { s as signObject } from "../proof-BlfZ95--.mjs";
|
|
7
|
-
import { u as signRequest } from "../http-BXbQQZDM.mjs";
|
|
8
|
-
import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
|
|
9
|
-
import { r as createFederationBuilder } from "../builder-D1FP_5nQ.mjs";
|
|
10
|
-
import { o as createFederation, t as ContextImpl } from "../middleware-DcXzz-YK.mjs";
|
|
11
|
-
import { Create, Person } from "@fedify/vocab";
|
|
12
|
-
import { exportDidKey, parseIri } from "@fedify/vocab-runtime";
|
|
13
|
-
import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
14
|
-
import { deepStrictEqual, ok, rejects, strictEqual } from "node:assert/strict";
|
|
15
|
-
//#region src/federation/inbox-report.test.ts
|
|
16
|
-
const loaders = {
|
|
17
|
-
documentLoader: mockDocumentLoader,
|
|
18
|
-
contextLoader: mockDocumentLoader
|
|
19
|
-
};
|
|
20
|
-
function setup(skipSignatureVerification = false) {
|
|
21
|
-
const reports = [];
|
|
22
|
-
const [tracerProvider, spanExporter] = createTestTracerProvider();
|
|
23
|
-
const federation = createFederation({
|
|
24
|
-
kv: new MemoryKvStore(),
|
|
25
|
-
skipSignatureVerification,
|
|
26
|
-
tracerProvider,
|
|
27
|
-
documentLoaderFactory: () => mockDocumentLoader,
|
|
28
|
-
contextLoaderFactory: () => mockDocumentLoader
|
|
29
|
-
});
|
|
30
|
-
federation.setActorDispatcher("/users/{identifier}", (_ctx, id) => id === "missing" ? null : new Person({})).setKeyPairsDispatcher(() => []);
|
|
31
|
-
return {
|
|
32
|
-
federation,
|
|
33
|
-
setters: federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").onRequestFinished((_ctx, report) => {
|
|
34
|
-
reports.push(report);
|
|
35
|
-
}),
|
|
36
|
-
reports,
|
|
37
|
-
spanExporter
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
async function payload(id = "https://example.com/create", actor = "https://example.com/person2") {
|
|
41
|
-
return await new Create({
|
|
42
|
-
id: new URL(id),
|
|
43
|
-
actor: new URL(actor)
|
|
44
|
-
}).toJsonLd(loaders);
|
|
45
|
-
}
|
|
46
|
-
function request(body, path = "/inbox") {
|
|
47
|
-
return new Request(`https://example.com${path}`, {
|
|
48
|
-
method: "POST",
|
|
49
|
-
body: JSON.stringify(body),
|
|
50
|
-
headers: { "Content-Type": "application/activity+json" }
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
test("onRequestFinished classifies early rejection, JSON null, and excluded routes", async () => {
|
|
54
|
-
const { federation, reports } = setup(true);
|
|
55
|
-
strictEqual((await federation.fetch(request({}, "/users/missing/inbox"), { contextData: void 0 })).status, 404);
|
|
56
|
-
deepStrictEqual(reports[0].inbox, {
|
|
57
|
-
kind: "personal",
|
|
58
|
-
recipient: "missing"
|
|
59
|
-
});
|
|
60
|
-
deepStrictEqual(reports[0].payload, { status: "unavailable" });
|
|
61
|
-
deepStrictEqual(reports[0].authentication, { status: "notDetermined" });
|
|
62
|
-
deepStrictEqual(reports[0].outcome, {
|
|
63
|
-
type: "response",
|
|
64
|
-
status: 404,
|
|
65
|
-
disposition: "rejected",
|
|
66
|
-
reason: "recipientNotFound"
|
|
67
|
-
});
|
|
68
|
-
strictEqual((await federation.fetch(request(null), { contextData: void 0 })).status, 400);
|
|
69
|
-
deepStrictEqual(reports[1].payload, {
|
|
70
|
-
status: "parsed",
|
|
71
|
-
value: null
|
|
72
|
-
});
|
|
73
|
-
deepStrictEqual(reports[1].authentication, { status: "notDetermined" });
|
|
74
|
-
await federation.fetch(new Request("https://example.com/users/alice/inbox"), { contextData: void 0 });
|
|
75
|
-
await federation.fetch(request({}, "/unmatched"), { contextData: void 0 });
|
|
76
|
-
strictEqual(reports.length, 2);
|
|
77
|
-
await federation.fetch(new Request("https://example.com/inbox", {
|
|
78
|
-
method: "POST",
|
|
79
|
-
body: "{"
|
|
80
|
-
}), { contextData: void 0 });
|
|
81
|
-
deepStrictEqual(reports[2].outcome, {
|
|
82
|
-
type: "response",
|
|
83
|
-
status: 400,
|
|
84
|
-
disposition: "rejected",
|
|
85
|
-
reason: "invalidJson"
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
test("onRequestFinished leaves deferred policy errors undetermined", async () => {
|
|
89
|
-
const did = await exportDidKey(ed25519Multikey.publicKey);
|
|
90
|
-
const keyId = parseIri(`${did}#${did.substring(8)}`);
|
|
91
|
-
const otherDid = await exportDidKey((await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"])).publicKey);
|
|
92
|
-
for (const withProof of [false, true]) {
|
|
93
|
-
const contextUrl = `https://example.com/context/deferred-${withProof}`;
|
|
94
|
-
const remote = {
|
|
95
|
-
contextUrl: null,
|
|
96
|
-
documentUrl: contextUrl,
|
|
97
|
-
document: { "@context": { ext: "https://example.com/ext" } }
|
|
98
|
-
};
|
|
99
|
-
const contextLoader = (url) => url === contextUrl ? Promise.resolve(remote) : mockDocumentLoader(url);
|
|
100
|
-
const activity = new Create({
|
|
101
|
-
id: parseIri(`ap+ef61://${withProof ? otherDid : did}/activities/deferred-${withProof}`),
|
|
102
|
-
actor: parseIri(`ap+ef61://${did}/users/bob`)
|
|
103
|
-
});
|
|
104
|
-
const context = [
|
|
105
|
-
"https://www.w3.org/ns/activitystreams",
|
|
106
|
-
"https://w3id.org/security/data-integrity/v1",
|
|
107
|
-
contextUrl
|
|
108
|
-
];
|
|
109
|
-
const body = withProof ? await (await signObject(activity, ed25519PrivateKey, keyId, {
|
|
110
|
-
context,
|
|
111
|
-
contextLoader
|
|
112
|
-
})).toJsonLd({
|
|
113
|
-
format: "compact",
|
|
114
|
-
context,
|
|
115
|
-
contextLoader
|
|
116
|
-
}) : await activity.toJsonLd({
|
|
117
|
-
format: "compact",
|
|
118
|
-
context,
|
|
119
|
-
contextLoader
|
|
120
|
-
});
|
|
121
|
-
body.signature = {
|
|
122
|
-
type: "RsaSignature2017",
|
|
123
|
-
creator: rsaPublicKey3.id.href,
|
|
124
|
-
created: "2024-01-01T00:00:00Z",
|
|
125
|
-
signatureValue: "bogus"
|
|
126
|
-
};
|
|
127
|
-
let failOnce = true;
|
|
128
|
-
const reports = [];
|
|
129
|
-
const federation = createFederation({
|
|
130
|
-
kv: new MemoryKvStore(),
|
|
131
|
-
documentLoaderFactory: () => mockDocumentLoader,
|
|
132
|
-
contextLoaderFactory: () => async (url) => {
|
|
133
|
-
if (url === contextUrl && failOnce) {
|
|
134
|
-
failOnce = false;
|
|
135
|
-
throw new Error("Temporary context outage");
|
|
136
|
-
}
|
|
137
|
-
return await contextLoader(url);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
federation.setActorDispatcher("/users/{identifier}", () => new Person({})).setKeyPairsDispatcher(() => []);
|
|
141
|
-
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {}).onRequestFinished((_ctx, report) => {
|
|
142
|
-
reports.push(report);
|
|
143
|
-
});
|
|
144
|
-
const signed = await signRequest(request(body), rsaPrivateKey3, rsaPublicKey3.id);
|
|
145
|
-
await rejects(federation.fetch(signed, { contextData: void 0 }), (error) => {
|
|
146
|
-
strictEqual(reports.length, 1);
|
|
147
|
-
deepStrictEqual(reports[0].authentication, { status: "notDetermined" });
|
|
148
|
-
ok(reports[0].outcome.type === "exception");
|
|
149
|
-
strictEqual(reports[0].outcome.stage, "policy");
|
|
150
|
-
strictEqual(reports[0].outcome.error, error);
|
|
151
|
-
return true;
|
|
152
|
-
});
|
|
153
|
-
strictEqual(reports[0].attempts.some((attempt) => attempt.mechanism === "objectIntegrity" && attempt.status === "verified"), withProof);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
test("onRequestFinished awaits once and isolates observer failures", async () => {
|
|
157
|
-
const { federation, setters } = setup(true);
|
|
158
|
-
setters.on(Create, () => {});
|
|
159
|
-
let calls = 0;
|
|
160
|
-
let release;
|
|
161
|
-
const gate = new Promise((resolve) => {
|
|
162
|
-
release = resolve;
|
|
163
|
-
});
|
|
164
|
-
let entered;
|
|
165
|
-
const started = new Promise((resolve) => {
|
|
166
|
-
entered = resolve;
|
|
167
|
-
});
|
|
168
|
-
setters.onRequestFinished(async (_ctx, report) => {
|
|
169
|
-
calls++;
|
|
170
|
-
deepStrictEqual(report.authentication, { status: "skipped" });
|
|
171
|
-
strictEqual(report.outcome.type === "response" && report.outcome.disposition, "processed");
|
|
172
|
-
entered();
|
|
173
|
-
await gate;
|
|
174
|
-
throw new Error("observer failed");
|
|
175
|
-
});
|
|
176
|
-
let finished = false;
|
|
177
|
-
const response = federation.fetch(request(await payload()), { contextData: void 0 }).then((response) => {
|
|
178
|
-
finished = true;
|
|
179
|
-
return response;
|
|
180
|
-
});
|
|
181
|
-
await started;
|
|
182
|
-
strictEqual(finished, false);
|
|
183
|
-
release();
|
|
184
|
-
strictEqual((await response).status, 202);
|
|
185
|
-
strictEqual(calls, 1);
|
|
186
|
-
});
|
|
187
|
-
test("onRequestFinished preserves preparation exceptions and callback replacement", async () => {
|
|
188
|
-
const { federation, setters, reports } = setup();
|
|
189
|
-
const error = /* @__PURE__ */ new Error("preparation failed");
|
|
190
|
-
setters.setSharedKeyDispatcher(() => {
|
|
191
|
-
throw error;
|
|
192
|
-
});
|
|
193
|
-
setters.onRequestFinished((_ctx, report) => {
|
|
194
|
-
reports.push(report);
|
|
195
|
-
throw new Error("secondary failure");
|
|
196
|
-
});
|
|
197
|
-
await rejects(federation.fetch(request(await payload()), { contextData: void 0 }), (value) => value === error);
|
|
198
|
-
strictEqual(reports.length, 1);
|
|
199
|
-
deepStrictEqual(reports[0].outcome, {
|
|
200
|
-
type: "exception",
|
|
201
|
-
stage: "prepare",
|
|
202
|
-
error
|
|
203
|
-
});
|
|
204
|
-
deepStrictEqual(reports[0].authentication, { status: "notDetermined" });
|
|
205
|
-
});
|
|
206
|
-
test("onRequestFinished distinguishes custom responses from authentication", async () => {
|
|
207
|
-
const { federation, setters, reports } = setup();
|
|
208
|
-
setters.onUnverifiedActivity(() => new Response(null, { status: 202 }));
|
|
209
|
-
const body = await payload();
|
|
210
|
-
strictEqual((await federation.fetch(request(body), { contextData: void 0 })).status, 202);
|
|
211
|
-
deepStrictEqual(reports[0].authentication, {
|
|
212
|
-
status: "rejected",
|
|
213
|
-
reason: { type: "verificationFailed" }
|
|
214
|
-
});
|
|
215
|
-
deepStrictEqual(reports[0].outcome, {
|
|
216
|
-
type: "response",
|
|
217
|
-
status: 202,
|
|
218
|
-
disposition: "customResponse"
|
|
219
|
-
});
|
|
220
|
-
strictEqual(reports[0].attempts.at(-1)?.mechanism, "http");
|
|
221
|
-
setters.onUnverifiedActivity(() => {});
|
|
222
|
-
strictEqual((await federation.fetch(request(body), { contextData: void 0 })).status, 401);
|
|
223
|
-
strictEqual(reports[1].outcome.type === "response" && reports[1].outcome.disposition, "rejected");
|
|
224
|
-
});
|
|
225
|
-
test("onRequestFinished retains HTTP keys and separates ownership rejection", async () => {
|
|
226
|
-
const { federation, setters, reports } = setup();
|
|
227
|
-
setters.on(Create, () => {});
|
|
228
|
-
const signed = await signRequest(request(await payload()), rsaPrivateKey3, new URL("https://example.com/person2#key3"));
|
|
229
|
-
strictEqual((await federation.fetch(signed, { contextData: void 0 })).status, 202);
|
|
230
|
-
const report = reports[0];
|
|
231
|
-
strictEqual(report.authentication.status, "verified");
|
|
232
|
-
const attempt = report.attempts.find((attempt) => attempt.mechanism === "http");
|
|
233
|
-
ok(attempt?.status === "verified");
|
|
234
|
-
strictEqual(attempt.subject.id?.href, "https://example.com/create");
|
|
235
|
-
const check = attempt.checks[0];
|
|
236
|
-
ok(check.status === "verified" && check.key.type === "cryptographicKey");
|
|
237
|
-
strictEqual(check.key.publicKey.algorithm.name, "RSASSA-PKCS1-v1_5");
|
|
238
|
-
strictEqual(check.key.ownerId?.href, "https://example.com/person2");
|
|
239
|
-
strictEqual(check.key, check.triedKeys.at(-1));
|
|
240
|
-
strictEqual(attempt.signatures[0], check);
|
|
241
|
-
strictEqual(report.authentication.attempts[0], attempt);
|
|
242
|
-
await federation.fetch(signed, { contextData: void 0 });
|
|
243
|
-
deepStrictEqual(reports[1].outcome, {
|
|
244
|
-
type: "response",
|
|
245
|
-
status: 202,
|
|
246
|
-
disposition: "duplicate"
|
|
247
|
-
});
|
|
248
|
-
const mismatched = await signRequest(request(await payload("https://example.com/other", "https://example.com/person")), rsaPrivateKey3, new URL("https://example.com/person2#key3"));
|
|
249
|
-
strictEqual((await federation.fetch(mismatched, { contextData: void 0 })).status, 401);
|
|
250
|
-
strictEqual(reports[2].authentication.status, "rejected");
|
|
251
|
-
ok(reports[2].authentication.status === "rejected");
|
|
252
|
-
strictEqual(reports[2].authentication.reason.type, "actorKeyMismatch");
|
|
253
|
-
strictEqual(reports[2].attempts.at(-1)?.status, "verified");
|
|
254
|
-
});
|
|
255
|
-
test("onRequestFinished reports an activity ID on another origin than its actor", async () => {
|
|
256
|
-
const { federation, setters, reports, spanExporter } = setup();
|
|
257
|
-
let dispatched = false;
|
|
258
|
-
setters.on(Create, () => {
|
|
259
|
-
dispatched = true;
|
|
260
|
-
});
|
|
261
|
-
const signed = await signRequest(request(await payload("https://other.example/create")), rsaPrivateKey3, new URL("https://example.com/person2#key3"));
|
|
262
|
-
strictEqual((await federation.fetch(signed, { contextData: void 0 })).status, 401);
|
|
263
|
-
strictEqual(dispatched, false);
|
|
264
|
-
deepStrictEqual(reports[0].authentication, {
|
|
265
|
-
status: "rejected",
|
|
266
|
-
reason: {
|
|
267
|
-
type: "activity-origin-mismatch",
|
|
268
|
-
activityId: new URL("https://other.example/create"),
|
|
269
|
-
actorIds: [new URL("https://example.com/person2")]
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
deepStrictEqual(reports[0].outcome, {
|
|
273
|
-
type: "response",
|
|
274
|
-
status: 401,
|
|
275
|
-
disposition: "rejected",
|
|
276
|
-
reason: "authentication"
|
|
277
|
-
});
|
|
278
|
-
strictEqual(reports[0].attempts.at(-1)?.status, "verified");
|
|
279
|
-
strictEqual(spanExporter.getSpans("activitypub.inbox")[0].attributes["activitypub.verification.failure_reason"], "activity-origin-mismatch");
|
|
280
|
-
});
|
|
281
|
-
test("onRequestFinished retains LDS crypto success before HTTP fallback", async () => {
|
|
282
|
-
const { federation, reports } = setup();
|
|
283
|
-
const signed = await signRequest(request(await signJsonLd(await payload("https://example.com/lds", "https://example.com/person"), rsaPrivateKey3, new URL("https://example.com/person2#key3"), loaders)), rsaPrivateKey2, new URL("https://example.com/key2"));
|
|
284
|
-
strictEqual((await federation.fetch(signed, { contextData: void 0 })).status, 202);
|
|
285
|
-
const ld = reports[0].attempts.find((attempt) => attempt.mechanism === "linkedData");
|
|
286
|
-
ok(ld?.status === "rejected");
|
|
287
|
-
strictEqual(ld.reason.type, "uncoveredAttribution");
|
|
288
|
-
strictEqual(ld.checks[0].status, "verified");
|
|
289
|
-
strictEqual(reports[0].authentication.status, "verified");
|
|
290
|
-
});
|
|
291
|
-
test("onRequestFinished keeps valid OIP checks when attributions are uncovered", async () => {
|
|
292
|
-
const { federation, reports } = setup();
|
|
293
|
-
const activity = new Create({
|
|
294
|
-
id: new URL("https://example.com/proof"),
|
|
295
|
-
actor: new URL("https://example.com/person")
|
|
296
|
-
});
|
|
297
|
-
const signed = await signObject(activity, ed25519PrivateKey, ed25519Multikey.id, loaders);
|
|
298
|
-
strictEqual((await federation.fetch(request(await signed.toJsonLd(loaders)), { contextData: void 0 })).status, 401);
|
|
299
|
-
const proof = reports[0].attempts.find((attempt) => attempt.mechanism === "objectIntegrity");
|
|
300
|
-
ok(proof?.status === "rejected");
|
|
301
|
-
strictEqual(proof.reason.type, "uncoveredAttribution");
|
|
302
|
-
const check = proof.checks[0];
|
|
303
|
-
ok(check.status === "verified" && check.key.type === "multikey");
|
|
304
|
-
strictEqual(check.key.controllerId?.href, "https://example.com/person2");
|
|
305
|
-
strictEqual(reports[0].activity?.id?.href, activity.id?.href);
|
|
306
|
-
});
|
|
307
|
-
test("onRequestFinished reports listener failures with original values", async () => {
|
|
308
|
-
const { federation, setters, reports } = setup(true);
|
|
309
|
-
const error = /* @__PURE__ */ new Error("listener failed");
|
|
310
|
-
setters.on(Create, () => {
|
|
311
|
-
throw error;
|
|
312
|
-
});
|
|
313
|
-
strictEqual((await federation.fetch(request(await payload()), { contextData: void 0 })).status, 500);
|
|
314
|
-
deepStrictEqual(reports[0].outcome, {
|
|
315
|
-
type: "response",
|
|
316
|
-
status: 500,
|
|
317
|
-
disposition: "failed",
|
|
318
|
-
reason: "listenerError",
|
|
319
|
-
error
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
test("onRequestFinished builder snapshots callbacks", async () => {
|
|
323
|
-
const builder = createFederationBuilder();
|
|
324
|
-
builder.setActorDispatcher("/users/{identifier}", () => new Person({}));
|
|
325
|
-
const reports = [];
|
|
326
|
-
const setters = builder.setInboxListeners("/users/{identifier}/inbox", "/inbox").onRequestFinished((_ctx, report) => {
|
|
327
|
-
reports.push(report);
|
|
328
|
-
});
|
|
329
|
-
const federation = await builder.build({
|
|
330
|
-
kv: new MemoryKvStore(),
|
|
331
|
-
skipSignatureVerification: true,
|
|
332
|
-
documentLoaderFactory: () => mockDocumentLoader,
|
|
333
|
-
contextLoaderFactory: () => mockDocumentLoader
|
|
334
|
-
});
|
|
335
|
-
setters.onRequestFinished(() => {
|
|
336
|
-
throw new Error("new callback must not run");
|
|
337
|
-
});
|
|
338
|
-
await federation.fetch(request(await payload()), { contextData: void 0 });
|
|
339
|
-
strictEqual(reports.length, 1);
|
|
340
|
-
});
|
|
341
|
-
test("onRequestFinished key snapshots do not alias vocabulary metadata", async () => {
|
|
342
|
-
const { snapshotKey } = await import("../verification-C3954hQh.mjs");
|
|
343
|
-
const snapshot = snapshotKey(rsaPublicKey2);
|
|
344
|
-
snapshot.id.pathname = "/changed";
|
|
345
|
-
strictEqual(rsaPublicKey2.id.href, "https://example.com/key2");
|
|
346
|
-
strictEqual(snapshotKey(rsaPublicKey3).publicKey, rsaPublicKey3.publicKey);
|
|
347
|
-
});
|
|
348
|
-
test("onRequestFinished reports enqueue acceptance without adding queue fields", async () => {
|
|
349
|
-
const messages = [];
|
|
350
|
-
const reports = [];
|
|
351
|
-
const federation = createFederation({
|
|
352
|
-
kv: new MemoryKvStore(),
|
|
353
|
-
skipSignatureVerification: true,
|
|
354
|
-
manuallyStartQueue: true,
|
|
355
|
-
queue: { inbox: {
|
|
356
|
-
enqueue: (message) => {
|
|
357
|
-
messages.push(message);
|
|
358
|
-
return Promise.resolve();
|
|
359
|
-
},
|
|
360
|
-
listen: () => Promise.resolve()
|
|
361
|
-
} },
|
|
362
|
-
documentLoaderFactory: () => mockDocumentLoader,
|
|
363
|
-
contextLoaderFactory: () => mockDocumentLoader
|
|
364
|
-
});
|
|
365
|
-
federation.setActorDispatcher("/users/{identifier}", () => new Person({}));
|
|
366
|
-
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").onRequestFinished((_ctx, report) => {
|
|
367
|
-
reports.push(report);
|
|
368
|
-
});
|
|
369
|
-
strictEqual((await federation.fetch(request(await payload()), { contextData: void 0 })).status, 202);
|
|
370
|
-
deepStrictEqual(reports[0].outcome, {
|
|
371
|
-
type: "response",
|
|
372
|
-
status: 202,
|
|
373
|
-
disposition: "enqueued"
|
|
374
|
-
});
|
|
375
|
-
strictEqual(messages.length, 1);
|
|
376
|
-
ok(!("report" in messages[0]));
|
|
377
|
-
ok(!("attempts" in messages[0]));
|
|
378
|
-
});
|
|
379
|
-
test("onRequestFinished preserves a non-Error value thrown during enqueue", async () => {
|
|
380
|
-
const reports = [];
|
|
381
|
-
const federation = createFederation({
|
|
382
|
-
kv: new MemoryKvStore(),
|
|
383
|
-
skipSignatureVerification: true,
|
|
384
|
-
manuallyStartQueue: true,
|
|
385
|
-
queue: { inbox: {
|
|
386
|
-
enqueue: () => Promise.reject(void 0),
|
|
387
|
-
listen: () => Promise.resolve()
|
|
388
|
-
} },
|
|
389
|
-
documentLoaderFactory: () => mockDocumentLoader,
|
|
390
|
-
contextLoaderFactory: () => mockDocumentLoader
|
|
391
|
-
});
|
|
392
|
-
federation.setActorDispatcher("/users/{identifier}", () => new Person({}));
|
|
393
|
-
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").onRequestFinished((_ctx, report) => {
|
|
394
|
-
reports.push(report);
|
|
395
|
-
throw new Error("observer failure");
|
|
396
|
-
});
|
|
397
|
-
let threw = false;
|
|
398
|
-
try {
|
|
399
|
-
await federation.fetch(request(await payload()), { contextData: void 0 });
|
|
400
|
-
} catch (error) {
|
|
401
|
-
threw = true;
|
|
402
|
-
strictEqual(error, void 0);
|
|
403
|
-
}
|
|
404
|
-
strictEqual(threw, true);
|
|
405
|
-
strictEqual(reports.length, 1);
|
|
406
|
-
deepStrictEqual(reports[0].outcome, {
|
|
407
|
-
type: "exception",
|
|
408
|
-
stage: "dispatch",
|
|
409
|
-
error: void 0
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
test("onRequestFinished runs with tracing disabled", async () => {
|
|
413
|
-
const { AlwaysOffSampler, BasicTracerProvider } = await import("@opentelemetry/sdk-trace-base");
|
|
414
|
-
const provider = new BasicTracerProvider({ sampler: new AlwaysOffSampler() });
|
|
415
|
-
const reports = [];
|
|
416
|
-
const federation = createFederation({
|
|
417
|
-
kv: new MemoryKvStore(),
|
|
418
|
-
tracerProvider: provider,
|
|
419
|
-
skipSignatureVerification: true,
|
|
420
|
-
documentLoaderFactory: () => mockDocumentLoader,
|
|
421
|
-
contextLoaderFactory: () => mockDocumentLoader
|
|
422
|
-
});
|
|
423
|
-
federation.setActorDispatcher("/users/{identifier}", () => new Person({}));
|
|
424
|
-
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").onRequestFinished((_ctx, report) => {
|
|
425
|
-
reports.push(report);
|
|
426
|
-
});
|
|
427
|
-
await federation.fetch(request(await payload()), { contextData: void 0 });
|
|
428
|
-
strictEqual(reports.length, 1);
|
|
429
|
-
await provider.shutdown();
|
|
430
|
-
});
|
|
431
|
-
test("onRequestFinished preserves non-POST shared inbox behavior without reports", async () => {
|
|
432
|
-
const { federation, reports } = setup(true);
|
|
433
|
-
strictEqual((await federation.fetch(new Request("https://example.com/inbox", { headers: { Accept: "application/activity+json" } }), { contextData: void 0 })).status, 400);
|
|
434
|
-
strictEqual(reports.length, 0);
|
|
435
|
-
strictEqual((await federation.fetch(new Request("https://example.com/inbox", {
|
|
436
|
-
method: "PUT",
|
|
437
|
-
body: JSON.stringify(await payload()),
|
|
438
|
-
headers: { Accept: "application/activity+json" }
|
|
439
|
-
}), { contextData: void 0 })).status, 202);
|
|
440
|
-
strictEqual(reports.length, 0);
|
|
441
|
-
});
|
|
442
|
-
test("onRequestFinished covers errors constructing the initial request context", async () => {
|
|
443
|
-
const reports = [];
|
|
444
|
-
const error = /* @__PURE__ */ new Error("loader factory failed");
|
|
445
|
-
const federation = createFederation({
|
|
446
|
-
kv: new MemoryKvStore(),
|
|
447
|
-
documentLoaderFactory: () => {
|
|
448
|
-
throw error;
|
|
449
|
-
},
|
|
450
|
-
contextLoaderFactory: () => mockDocumentLoader
|
|
451
|
-
});
|
|
452
|
-
federation.setActorDispatcher("/users/{identifier}", () => new Person({}));
|
|
453
|
-
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").onRequestFinished((ctx, report) => {
|
|
454
|
-
strictEqual(ctx.data, "data");
|
|
455
|
-
strictEqual(ctx.request.url, "https://example.com/inbox");
|
|
456
|
-
reports.push(report);
|
|
457
|
-
});
|
|
458
|
-
await rejects(federation.fetch(request({}), { contextData: "data" }), (value) => value === error);
|
|
459
|
-
strictEqual(reports.length, 1);
|
|
460
|
-
deepStrictEqual(reports[0].outcome, {
|
|
461
|
-
type: "exception",
|
|
462
|
-
stage: "prepare",
|
|
463
|
-
error
|
|
464
|
-
});
|
|
465
|
-
});
|
|
466
|
-
test("onRequestFinished observes the final response decoration result", async () => {
|
|
467
|
-
const { federation, setters, reports } = setup();
|
|
468
|
-
const redirect = Response.redirect("https://example.com/redirect", 302);
|
|
469
|
-
let immutable = false;
|
|
470
|
-
try {
|
|
471
|
-
redirect.headers.set("X-Header-Probe", "probe");
|
|
472
|
-
} catch {
|
|
473
|
-
immutable = true;
|
|
474
|
-
}
|
|
475
|
-
setters.onUnverifiedActivity(() => redirect);
|
|
476
|
-
const delivery = request(await payload());
|
|
477
|
-
delivery.headers.set("Accept", "application/activity+json");
|
|
478
|
-
let thrown;
|
|
479
|
-
let response;
|
|
480
|
-
try {
|
|
481
|
-
response = await federation.fetch(delivery, { contextData: void 0 });
|
|
482
|
-
} catch (error) {
|
|
483
|
-
thrown = error;
|
|
484
|
-
}
|
|
485
|
-
strictEqual(reports.length, 1);
|
|
486
|
-
if (immutable) {
|
|
487
|
-
ok(thrown instanceof TypeError);
|
|
488
|
-
deepStrictEqual(reports[0].outcome, {
|
|
489
|
-
type: "exception",
|
|
490
|
-
stage: "respond",
|
|
491
|
-
error: thrown
|
|
492
|
-
});
|
|
493
|
-
} else {
|
|
494
|
-
strictEqual(thrown, void 0);
|
|
495
|
-
strictEqual(response?.status, 302);
|
|
496
|
-
deepStrictEqual(reports[0].outcome, {
|
|
497
|
-
type: "response",
|
|
498
|
-
status: 302,
|
|
499
|
-
disposition: "customResponse"
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
test("inbox request cancellation snapshots preserve exact reasons without stopping processing", async (t) => {
|
|
504
|
-
for (const [label, reason] of [
|
|
505
|
-
["live", void 0],
|
|
506
|
-
["object", { kind: "client disconnect" }],
|
|
507
|
-
["zero", 0],
|
|
508
|
-
["nan", NaN],
|
|
509
|
-
["symbol", Symbol("client")]
|
|
510
|
-
]) await t.step(label, async () => {
|
|
511
|
-
const { federation, setters, reports } = setup(true);
|
|
512
|
-
let processed = 0;
|
|
513
|
-
setters.on(Create, () => {
|
|
514
|
-
processed++;
|
|
515
|
-
});
|
|
516
|
-
const controller = new AbortController();
|
|
517
|
-
const input = new Request(request(await payload()), { signal: controller.signal });
|
|
518
|
-
input.headers.set("X-Request-Id", "cancellation-case");
|
|
519
|
-
if (label !== "live") controller.abort(reason);
|
|
520
|
-
strictEqual((await federation.fetch(input, { contextData: void 0 })).status, 202);
|
|
521
|
-
strictEqual(processed, 1);
|
|
522
|
-
strictEqual(reports.length, 1);
|
|
523
|
-
const report = reports[0];
|
|
524
|
-
deepStrictEqual(report.outcome, {
|
|
525
|
-
type: "response",
|
|
526
|
-
status: 202,
|
|
527
|
-
disposition: "processed"
|
|
528
|
-
});
|
|
529
|
-
deepStrictEqual(report.authentication, { status: "skipped" });
|
|
530
|
-
strictEqual(report.payload.status, "parsed");
|
|
531
|
-
strictEqual(report.requestId, "cancellation-case");
|
|
532
|
-
ok(report.inboxRequestId);
|
|
533
|
-
deepStrictEqual(report.local, {
|
|
534
|
-
origin: "https://example.com",
|
|
535
|
-
host: "example.com",
|
|
536
|
-
hostname: "example.com",
|
|
537
|
-
canonicalOrigin: "https://example.com"
|
|
538
|
-
});
|
|
539
|
-
ok(Object.isFrozen(report.local));
|
|
540
|
-
ok(Object.isFrozen(report.requestCancellation));
|
|
541
|
-
strictEqual(report.requestCancellation.type, label === "live" ? "not-aborted" : "aborted");
|
|
542
|
-
if (report.requestCancellation.type === "aborted") {
|
|
543
|
-
ok(Object.is(report.requestCancellation.reason, reason));
|
|
544
|
-
strictEqual(report.requestCancellation.reason, input.signal.reason);
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
});
|
|
548
|
-
test("inbox request cancellation waits for processing and preserves original local facts", async () => {
|
|
549
|
-
const { federation, setters, reports } = setup(true);
|
|
550
|
-
let entered;
|
|
551
|
-
const listening = new Promise((resolve) => {
|
|
552
|
-
entered = resolve;
|
|
553
|
-
});
|
|
554
|
-
let release;
|
|
555
|
-
const gate = new Promise((resolve) => {
|
|
556
|
-
release = resolve;
|
|
557
|
-
});
|
|
558
|
-
setters.on(Create, async (ctx) => {
|
|
559
|
-
ok(ctx instanceof ContextImpl);
|
|
560
|
-
ctx.url.hostname = "changed.example";
|
|
561
|
-
entered();
|
|
562
|
-
await gate;
|
|
563
|
-
});
|
|
564
|
-
const controller = new AbortController();
|
|
565
|
-
const reason = Symbol("mid-processing disconnect");
|
|
566
|
-
const input = new Request(request(await payload()), { signal: controller.signal });
|
|
567
|
-
const processing = federation.fetch(input, { contextData: void 0 });
|
|
568
|
-
try {
|
|
569
|
-
await listening;
|
|
570
|
-
controller.abort(reason);
|
|
571
|
-
strictEqual(reports.length, 0);
|
|
572
|
-
release();
|
|
573
|
-
strictEqual((await processing).status, 202);
|
|
574
|
-
strictEqual(reports.length, 1);
|
|
575
|
-
deepStrictEqual(reports[0].outcome, {
|
|
576
|
-
type: "response",
|
|
577
|
-
status: 202,
|
|
578
|
-
disposition: "processed"
|
|
579
|
-
});
|
|
580
|
-
deepStrictEqual(reports[0].requestCancellation, {
|
|
581
|
-
type: "aborted",
|
|
582
|
-
reason
|
|
583
|
-
});
|
|
584
|
-
strictEqual(reports[0].local?.hostname, "example.com");
|
|
585
|
-
controller.abort("later reason");
|
|
586
|
-
await Promise.resolve();
|
|
587
|
-
strictEqual(reports.length, 1);
|
|
588
|
-
strictEqual(reports[0].local?.origin, "https://example.com");
|
|
589
|
-
} finally {
|
|
590
|
-
release();
|
|
591
|
-
await processing;
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
test("inbox request cancellation after report construction does not rewrite its snapshot", async () => {
|
|
595
|
-
const { federation, setters, reports } = setup(true);
|
|
596
|
-
setters.on(Create, () => {});
|
|
597
|
-
let entered;
|
|
598
|
-
const observing = new Promise((resolve) => {
|
|
599
|
-
entered = resolve;
|
|
600
|
-
});
|
|
601
|
-
let release;
|
|
602
|
-
const gate = new Promise((resolve) => {
|
|
603
|
-
release = resolve;
|
|
604
|
-
});
|
|
605
|
-
setters.onRequestFinished(async (_ctx, report) => {
|
|
606
|
-
reports.push(report);
|
|
607
|
-
entered();
|
|
608
|
-
await gate;
|
|
609
|
-
throw new Error("recording failure");
|
|
610
|
-
});
|
|
611
|
-
const controller = new AbortController();
|
|
612
|
-
const input = new Request(request(await payload()), { signal: controller.signal });
|
|
613
|
-
const processing = federation.fetch(input, { contextData: void 0 });
|
|
614
|
-
try {
|
|
615
|
-
await observing;
|
|
616
|
-
controller.abort({ kind: "late disconnect" });
|
|
617
|
-
deepStrictEqual(reports[0].requestCancellation, { type: "not-aborted" });
|
|
618
|
-
release();
|
|
619
|
-
strictEqual((await processing).status, 202);
|
|
620
|
-
await Promise.resolve();
|
|
621
|
-
strictEqual(reports.length, 1);
|
|
622
|
-
deepStrictEqual(reports[0].requestCancellation, { type: "not-aborted" });
|
|
623
|
-
deepStrictEqual(reports[0].outcome, {
|
|
624
|
-
type: "response",
|
|
625
|
-
status: 202,
|
|
626
|
-
disposition: "processed"
|
|
627
|
-
});
|
|
628
|
-
} finally {
|
|
629
|
-
release();
|
|
630
|
-
await processing;
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
test("inbox request cancellation retains accepted queue work and its separate lifetime", async () => {
|
|
634
|
-
const controller = new AbortController();
|
|
635
|
-
const reason = Symbol("disconnect after acceptance");
|
|
636
|
-
const messages = [];
|
|
637
|
-
const reports = [];
|
|
638
|
-
let processed = 0;
|
|
639
|
-
let workerSignal;
|
|
640
|
-
const federation = createFederation({
|
|
641
|
-
kv: new MemoryKvStore(),
|
|
642
|
-
skipSignatureVerification: true,
|
|
643
|
-
manuallyStartQueue: true,
|
|
644
|
-
documentLoaderFactory: () => mockDocumentLoader,
|
|
645
|
-
contextLoaderFactory: () => mockDocumentLoader,
|
|
646
|
-
queue: { inbox: {
|
|
647
|
-
enqueue(message) {
|
|
648
|
-
messages.push(message);
|
|
649
|
-
controller.abort(reason);
|
|
650
|
-
return Promise.resolve();
|
|
651
|
-
},
|
|
652
|
-
listen: () => Promise.resolve()
|
|
653
|
-
} }
|
|
654
|
-
});
|
|
655
|
-
federation.setActorDispatcher("/users/{identifier}", () => new Person({}));
|
|
656
|
-
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, (ctx) => {
|
|
657
|
-
processed++;
|
|
658
|
-
workerSignal = Reflect.get(ctx, "signal");
|
|
659
|
-
}).onRequestFinished((_ctx, report) => {
|
|
660
|
-
reports.push(report);
|
|
661
|
-
});
|
|
662
|
-
const input = new Request(request(await payload()), { signal: controller.signal });
|
|
663
|
-
strictEqual((await federation.fetch(input, { contextData: void 0 })).status, 202);
|
|
664
|
-
strictEqual(messages.length, 1);
|
|
665
|
-
strictEqual(processed, 0);
|
|
666
|
-
strictEqual(reports.length, 1);
|
|
667
|
-
deepStrictEqual(reports[0].outcome, {
|
|
668
|
-
type: "response",
|
|
669
|
-
status: 202,
|
|
670
|
-
disposition: "enqueued"
|
|
671
|
-
});
|
|
672
|
-
deepStrictEqual(reports[0].requestCancellation, {
|
|
673
|
-
type: "aborted",
|
|
674
|
-
reason
|
|
675
|
-
});
|
|
676
|
-
strictEqual(Object.hasOwn(messages[0], "signal"), false);
|
|
677
|
-
strictEqual(Object.hasOwn(messages[0], "requestCancellation"), false);
|
|
678
|
-
await federation.processQueuedTask(void 0, messages[0]);
|
|
679
|
-
strictEqual(processed, 1);
|
|
680
|
-
strictEqual(workerSignal?.aborted === true, false);
|
|
681
|
-
strictEqual(reports.length, 1);
|
|
682
|
-
});
|
|
683
|
-
test("inbox request cancellation preserves early preparation failures and canonical source", async () => {
|
|
684
|
-
const error = /* @__PURE__ */ new Error("initial loader factory failed");
|
|
685
|
-
const reason = { kind: "client disconnected" };
|
|
686
|
-
const controller = new AbortController();
|
|
687
|
-
const reports = [];
|
|
688
|
-
const federation = createFederation({
|
|
689
|
-
kv: new MemoryKvStore(),
|
|
690
|
-
origin: "https://canonical.example",
|
|
691
|
-
documentLoaderFactory: () => {
|
|
692
|
-
throw error;
|
|
693
|
-
},
|
|
694
|
-
contextLoaderFactory: () => mockDocumentLoader
|
|
695
|
-
});
|
|
696
|
-
federation.setActorDispatcher("/users/{identifier}", () => new Person({}));
|
|
697
|
-
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").onRequestFinished((_ctx, report) => {
|
|
698
|
-
reports.push(report);
|
|
699
|
-
});
|
|
700
|
-
const input = new Request(request({}), { signal: controller.signal });
|
|
701
|
-
controller.abort(reason);
|
|
702
|
-
await rejects(federation.fetch(input, { contextData: void 0 }), (value) => value === error);
|
|
703
|
-
strictEqual(reports.length, 1);
|
|
704
|
-
deepStrictEqual(reports[0].outcome, {
|
|
705
|
-
type: "exception",
|
|
706
|
-
stage: "prepare",
|
|
707
|
-
error
|
|
708
|
-
});
|
|
709
|
-
deepStrictEqual(reports[0].authentication, { status: "notDetermined" });
|
|
710
|
-
deepStrictEqual(reports[0].payload, { status: "unavailable" });
|
|
711
|
-
deepStrictEqual(reports[0].requestCancellation, {
|
|
712
|
-
type: "aborted",
|
|
713
|
-
reason
|
|
714
|
-
});
|
|
715
|
-
strictEqual(reports[0].local?.origin, "https://example.com");
|
|
716
|
-
strictEqual(reports[0].local?.canonicalOrigin, "https://canonical.example");
|
|
717
|
-
});
|
|
718
|
-
//#endregion
|
|
719
|
-
export {};
|