@fedify/fedify 2.2.20 → 2.2.21
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-CalAATqD.mjs +16 -0
- package/dist/{builder-BolQ56ab.mjs → builder-4ImvtjG4.mjs} +3 -3
- package/dist/callback-0KrwzutD.d.mts +2607 -0
- package/dist/{client-jE7oGvRh.d.ts → client-9DPcy_Yx.d.ts} +16 -0
- package/dist/{client-BIBzqEIp.d.cts → client-B3ruDgWg.d.cts} +16 -0
- package/dist/{client-DhxaVgOv.mjs → client-XYMC0Mmk.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.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/public-audience.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-CFQGaq5x.d.cts → context-CjWuov0g.d.cts} +31 -14
- package/dist/{context-DdbLVV_k.d.ts → context-DZqI2LJD.d.ts} +31 -14
- package/dist/{deno-BUj4roJc.mjs → deno-AWk3S2Ug.mjs} +1 -1
- package/dist/{docloader-CbtF_0cD.mjs → docloader-Bogpjg4d.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/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +2 -2
- package/dist/federation/middleware.test.mjs +1184 -8
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +283 -3
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-CQMVisM0.mjs → http-B3wCvgu8.mjs} +6 -4
- package/dist/{http-D8I7LBfx.cjs → http-BNaPJVnF.cjs} +6 -4
- package/dist/{http-C5g_VrA_.js → http-BpdLaGy8.js} +6 -4
- package/dist/{http-9IFUxdkp.d.cts → http-C8qLHs_Z.d.cts} +3 -3
- package/dist/{http-SbfezERn.d.ts → http-D8WmcRAF.d.ts} +3 -3
- package/dist/{inbox-CD8IDILN.mjs → inbox-DLy6WBXU.mjs} +1 -1
- package/dist/{key-C3o3DGap.mjs → key-Bhc8cQC7.mjs} +3 -2
- package/dist/{kv-cache-DC9LcfoC.cjs → kv-cache-Bj3CY9Jo.cjs} +1 -1
- package/dist/{kv-cache-CSKXXleR.js → kv-cache-CvjLUQTf.js} +1 -1
- package/dist/{ld-ijSr-0AB.mjs → ld-DTeykI0e.mjs} +153 -21
- package/dist/ld-signature-Dgz_b89j.mjs +23 -0
- package/dist/{middleware-DNueR0GD.cjs → middleware-BSQP4d9p.cjs} +475 -107
- package/dist/{middleware-DmcY2TWS.cjs → middleware-CWOzxb3o.cjs} +1 -1
- package/dist/{middleware-yqqfI7oJ.mjs → middleware-DkMsC5mQ.mjs} +1 -1
- package/dist/{middleware-sjhz30sm.js → middleware-Dx1iwFk8.js} +474 -107
- package/dist/{middleware-CYAaUTi5.mjs → middleware-dlGvSrXl.mjs} +386 -96
- package/dist/{mod-BYWp77-z.d.cts → mod-BmxqcEnU.d.ts} +30 -13
- package/dist/{mod-CVSKw-5H.d.cts → mod-DWEx2D4q.d.cts} +1 -1
- package/dist/{mod-BuRRdsfD.d.ts → mod-DnPmz3-S.d.ts} +1 -1
- package/dist/{mod-CM5_J_cx.d.ts → mod-INjDw-m0.d.cts} +30 -13
- package/dist/{mod-BRnwh2oy.d.ts → mod-REfljt0T.d.ts} +3 -3
- package/dist/{mod-Co7LEK9X.d.cts → mod-UvIGUHqW.d.cts} +3 -3
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +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/nodeinfo/types.test.mjs +1 -1
- package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
- package/dist/{owner-B8kXzD0q.mjs → owner-BsA7qMHB.mjs} +2 -2
- package/dist/{proof-CBQOjOgA.mjs → proof-C63Hqt9N.mjs} +40 -15
- package/dist/{proof-qiuGJCD7.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
- package/dist/{proof-DKX6nASL.js → proof-QV_o5ZqS.js} +1174 -1003
- package/dist/{send-DRpisX_f.mjs → send-CAdpwbFX.mjs} +92 -21
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key-types.test.d.mts +218 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +573 -8
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +96 -4
- package/dist/{temporal-BQGEINad.mjs → temporal-B3JGkVgk.mjs} +3 -5
- package/dist/testing/mod.d.mts +2 -2422
- package/dist/{types-DOvyymM4.cjs → types-BWx7zw3Y.cjs} +85 -10
- package/dist/{types-B1_pRFE_.js → types-Dx_w2JSM.js} +86 -11
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +5 -5
- /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
- /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
- /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
- /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { t as esm_default } from "../esm-DVILvP5e.mjs";
|
|
5
|
+
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
|
+
import "../std__assert-DNZ4Liil.mjs";
|
|
7
|
+
import { t as assert } from "../assert-BhQd8QHP.mjs";
|
|
8
|
+
import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-BAK-tUlf.mjs";
|
|
9
|
+
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
10
|
+
import { c as detachSignature, v as verifySignature } from "../ld-DTeykI0e.mjs";
|
|
11
|
+
import { r as normalizeOutgoingActivityJsonLd } from "../outgoing-jsonld-DHf_DYXp.mjs";
|
|
12
|
+
import { r as signObject } from "../proof-C63Hqt9N.mjs";
|
|
13
|
+
import { b as prepareActivityJsonLd, n as FederationImpl, t as ContextImpl } from "../middleware-dlGvSrXl.mjs";
|
|
14
|
+
import { mockDocumentLoader, test } from "@fedify/fixture";
|
|
15
|
+
import { Create, Image, Note, PUBLIC_COLLECTION, Person, PropertyValue, Update } from "@fedify/vocab";
|
|
16
|
+
import { decodeMultibase } from "@fedify/vocab-runtime";
|
|
17
|
+
import serialize from "json-canon";
|
|
18
|
+
//#region src/federation/delivery-attachments.test.ts
|
|
19
|
+
async function assertRawProof(document, proof, publicKey) {
|
|
20
|
+
const unsigned = { ...document };
|
|
21
|
+
delete unsigned.proof;
|
|
22
|
+
delete unsigned.signature;
|
|
23
|
+
const encoder = new TextEncoder();
|
|
24
|
+
const config = {
|
|
25
|
+
"@context": document["@context"],
|
|
26
|
+
type: "DataIntegrityProof",
|
|
27
|
+
cryptosuite: proof.cryptosuite,
|
|
28
|
+
verificationMethod: proof.verificationMethod,
|
|
29
|
+
proofPurpose: proof.proofPurpose,
|
|
30
|
+
created: proof.created
|
|
31
|
+
};
|
|
32
|
+
const configDigest = await crypto.subtle.digest("SHA-256", encoder.encode(serialize(config)));
|
|
33
|
+
const messageDigest = await crypto.subtle.digest("SHA-256", encoder.encode(serialize(unsigned)));
|
|
34
|
+
const bytes = new Uint8Array(configDigest.byteLength + messageDigest.byteLength);
|
|
35
|
+
bytes.set(new Uint8Array(configDigest));
|
|
36
|
+
bytes.set(new Uint8Array(messageDigest), configDigest.byteLength);
|
|
37
|
+
assert(await crypto.subtle.verify("Ed25519", publicKey, decodeMultibase(proof.proofValue).slice(), bytes), "The proof must cover the exact received JSON representation.");
|
|
38
|
+
}
|
|
39
|
+
test("attachment delivery keeps fetched profiles, proofs, and queued bytes consistent", async (t) => {
|
|
40
|
+
const secondEdKey = await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
|
|
41
|
+
const inbox = "https://example.com/attachment-inbox";
|
|
42
|
+
const received = [];
|
|
43
|
+
let responseStatus = 202;
|
|
44
|
+
esm_default.spyGlobal();
|
|
45
|
+
esm_default.post(inbox, async ({ request }) => {
|
|
46
|
+
received.push(await request.json());
|
|
47
|
+
return new Response(null, { status: responseStatus });
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
for (const scenario of [
|
|
51
|
+
"rsa",
|
|
52
|
+
"immediate",
|
|
53
|
+
"outbox",
|
|
54
|
+
"fanout",
|
|
55
|
+
"raw-fanout",
|
|
56
|
+
"raw-immediate",
|
|
57
|
+
"raw-outbox",
|
|
58
|
+
"rsa-fanout",
|
|
59
|
+
"retry"
|
|
60
|
+
]) await t.step(scenario, async () => {
|
|
61
|
+
const messages = [];
|
|
62
|
+
const federation = new FederationImpl({
|
|
63
|
+
kv: new MemoryKvStore(),
|
|
64
|
+
queue: {
|
|
65
|
+
enqueue(message) {
|
|
66
|
+
messages.push(message);
|
|
67
|
+
return Promise.resolve();
|
|
68
|
+
},
|
|
69
|
+
async listen() {}
|
|
70
|
+
},
|
|
71
|
+
manuallyStartQueue: true,
|
|
72
|
+
allowPrivateAddress: true
|
|
73
|
+
});
|
|
74
|
+
federation.setActorDispatcher("/users/{identifier}", (ctx, identifier) => new Person({
|
|
75
|
+
id: ctx.getActorUri(identifier),
|
|
76
|
+
preferredUsername: identifier,
|
|
77
|
+
attachments: [new PropertyValue({
|
|
78
|
+
name: "Website",
|
|
79
|
+
value: "https://example.com/"
|
|
80
|
+
})]
|
|
81
|
+
})).setKeyPairsDispatcher(() => [{
|
|
82
|
+
privateKey: rsaPrivateKey2,
|
|
83
|
+
publicKey: rsaPublicKey2.publicKey
|
|
84
|
+
}, ...scenario.startsWith("rsa") ? [] : [{
|
|
85
|
+
privateKey: ed25519PrivateKey,
|
|
86
|
+
publicKey: ed25519PublicKey.publicKey
|
|
87
|
+
}, {
|
|
88
|
+
privateKey: secondEdKey.privateKey,
|
|
89
|
+
publicKey: secondEdKey.publicKey
|
|
90
|
+
}]]);
|
|
91
|
+
const ctx = new ContextImpl({
|
|
92
|
+
data: void 0,
|
|
93
|
+
federation,
|
|
94
|
+
url: new URL("https://example.com/"),
|
|
95
|
+
documentLoader: mockDocumentLoader,
|
|
96
|
+
contextLoader: mockDocumentLoader
|
|
97
|
+
});
|
|
98
|
+
const actor = new Person({
|
|
99
|
+
id: ctx.getActorUri("alice"),
|
|
100
|
+
preferredUsername: "alice",
|
|
101
|
+
attachments: [new PropertyValue({
|
|
102
|
+
name: "Website",
|
|
103
|
+
value: "https://example.com/"
|
|
104
|
+
})]
|
|
105
|
+
});
|
|
106
|
+
const fetched = await (await federation.fetch(new Request(ctx.getActorUri("alice"), { headers: { Accept: "application/activity+json" } }), { contextData: void 0 })).json();
|
|
107
|
+
assert(Array.isArray(fetched.attachment));
|
|
108
|
+
const keyPairs = await ctx.getActorKeyPairs("alice");
|
|
109
|
+
const start = received.length;
|
|
110
|
+
await ctx.sendActivity(scenario.startsWith("raw-") ? keyPairs.map((kp) => ({
|
|
111
|
+
privateKey: kp.privateKey,
|
|
112
|
+
keyId: kp.keyId
|
|
113
|
+
})) : { identifier: "alice" }, {
|
|
114
|
+
id: new URL("https://example.com/recipient"),
|
|
115
|
+
inboxId: new URL(inbox)
|
|
116
|
+
}, new Update({
|
|
117
|
+
id: new URL(`https://example.com/updates/${scenario}`),
|
|
118
|
+
actor: actor.id,
|
|
119
|
+
object: actor,
|
|
120
|
+
tos: [PUBLIC_COLLECTION]
|
|
121
|
+
}), scenario === "immediate" || scenario === "raw-immediate" || scenario === "rsa" ? { immediate: true } : scenario === "fanout" || scenario === "raw-fanout" || scenario === "rsa-fanout" ? { fanout: "force" } : {});
|
|
122
|
+
if (scenario === "retry") {
|
|
123
|
+
const first = messages.shift();
|
|
124
|
+
assert(first?.type === "outbox");
|
|
125
|
+
const original = structuredClone(first.activity);
|
|
126
|
+
responseStatus = 503;
|
|
127
|
+
await federation.processQueuedTask(void 0, first);
|
|
128
|
+
responseStatus = 202;
|
|
129
|
+
const retried = messages[0];
|
|
130
|
+
assert(retried?.type === "outbox");
|
|
131
|
+
assertEquals(retried.attempt, 1);
|
|
132
|
+
assertEquals(retried.activity, original);
|
|
133
|
+
}
|
|
134
|
+
for (let count = 0; messages.length > 0; count++) {
|
|
135
|
+
assert(count < 10, "The delivery queue must drain.");
|
|
136
|
+
await federation.processQueuedTask(void 0, messages.shift());
|
|
137
|
+
}
|
|
138
|
+
assert(received.length > start);
|
|
139
|
+
const delivered = received.at(-1);
|
|
140
|
+
assertEquals(delivered.object.attachment, fetched.attachment);
|
|
141
|
+
assert(await verifySignature(delivered, {
|
|
142
|
+
contextLoader: mockDocumentLoader,
|
|
143
|
+
keyCache: {
|
|
144
|
+
get(id) {
|
|
145
|
+
return Promise.resolve(keyPairs.find((kp) => kp.cryptographicKey.id?.href === id.href)?.cryptographicKey ?? null);
|
|
146
|
+
},
|
|
147
|
+
async set() {}
|
|
148
|
+
}
|
|
149
|
+
}));
|
|
150
|
+
const wire = detachSignature(delivered);
|
|
151
|
+
assertEquals(wire.to, PUBLIC_COLLECTION.href);
|
|
152
|
+
const proofs = wire.proof == null ? [] : Array.isArray(wire.proof) ? wire.proof : [wire.proof];
|
|
153
|
+
assertEquals(proofs.length, scenario.startsWith("rsa") ? 0 : 2);
|
|
154
|
+
for (const proof of proofs) {
|
|
155
|
+
const key = keyPairs.find((kp) => kp.multikey.id?.href === proof.verificationMethod || kp.keyId.href === proof.verificationMethod);
|
|
156
|
+
assert(key != null);
|
|
157
|
+
await assertRawProof(wire, proof, key.publicKey);
|
|
158
|
+
}
|
|
159
|
+
if (scenario === "retry") assertEquals(received.at(-2), received.at(-1));
|
|
160
|
+
});
|
|
161
|
+
} finally {
|
|
162
|
+
esm_default.unmockGlobal();
|
|
163
|
+
esm_default.removeRoutes();
|
|
164
|
+
esm_default.clearHistory();
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
test("public attachment proofs cover the normalized 2.2 wire representation", async () => {
|
|
168
|
+
const signed = await signObject(new Create({
|
|
169
|
+
actor: new URL("https://example.com/actor"),
|
|
170
|
+
object: new Note({ attachments: [new Image({ url: new URL("https://example.com/image.png") })] })
|
|
171
|
+
}), ed25519PrivateKey, ed25519PublicKey.id, { contextLoader: mockDocumentLoader });
|
|
172
|
+
const raw = await signed.toJsonLd({
|
|
173
|
+
format: "compact",
|
|
174
|
+
contextLoader: mockDocumentLoader
|
|
175
|
+
});
|
|
176
|
+
assert(!Array.isArray(raw.object.attachment));
|
|
177
|
+
const normalized = await normalizeOutgoingActivityJsonLd(raw, mockDocumentLoader);
|
|
178
|
+
await assertRawProof(normalized, normalized.proof, ed25519PublicKey.publicKey);
|
|
179
|
+
const resignedJson = await (await signObject(signed, ed25519PrivateKey, ed25519PublicKey.id, { contextLoader: mockDocumentLoader })).toJsonLd({
|
|
180
|
+
format: "compact",
|
|
181
|
+
contextLoader: mockDocumentLoader
|
|
182
|
+
});
|
|
183
|
+
assert(!Array.isArray(resignedJson.object.attachment));
|
|
184
|
+
assert(Array.isArray(resignedJson.proof));
|
|
185
|
+
assertEquals(resignedJson.proof.length, 2);
|
|
186
|
+
const resignedWire = await normalizeOutgoingActivityJsonLd(resignedJson, mockDocumentLoader);
|
|
187
|
+
for (const proof of resignedJson.proof) await assertRawProof(resignedWire, proof, ed25519PublicKey.publicKey);
|
|
188
|
+
});
|
|
189
|
+
test("delivery preparation only selects changed proof-free attachment JSON", async () => {
|
|
190
|
+
assertEquals(await prepareActivityJsonLd(new Create({
|
|
191
|
+
actor: new URL("https://example.com/actor"),
|
|
192
|
+
object: new Note({ content: "No attachments" })
|
|
193
|
+
}), mockDocumentLoader), void 0);
|
|
194
|
+
const child = new Note({ attachments: [new Image({ url: new URL("https://example.com/image.png") })] });
|
|
195
|
+
const activity = new Create({
|
|
196
|
+
actor: new URL("https://example.com/actor"),
|
|
197
|
+
object: child
|
|
198
|
+
});
|
|
199
|
+
const before = structuredClone(await activity.toJsonLd());
|
|
200
|
+
const childBefore = structuredClone(await child.toJsonLd());
|
|
201
|
+
const prepared = await prepareActivityJsonLd(activity, mockDocumentLoader);
|
|
202
|
+
assert(prepared != null);
|
|
203
|
+
assert(Array.isArray(prepared.object.attachment));
|
|
204
|
+
assertEquals(await activity.toJsonLd(), before);
|
|
205
|
+
assertEquals(await child.toJsonLd(), childBefore);
|
|
206
|
+
const signedChild = await signObject(child, ed25519PrivateKey, ed25519PublicKey.id, { contextLoader: mockDocumentLoader });
|
|
207
|
+
assertEquals(await prepareActivityJsonLd(new Create({
|
|
208
|
+
actor: activity.actorId,
|
|
209
|
+
object: signedChild
|
|
210
|
+
}), mockDocumentLoader), void 0);
|
|
211
|
+
});
|
|
212
|
+
test("existing root proofs retain 2.2 signing with normalization opted in", async (t) => {
|
|
213
|
+
const inbox = "https://example.com/existing-proof-inbox";
|
|
214
|
+
let delivered;
|
|
215
|
+
esm_default.spyGlobal();
|
|
216
|
+
esm_default.post(inbox, async ({ request }) => {
|
|
217
|
+
delivered = await request.json();
|
|
218
|
+
return new Response(null, { status: 202 });
|
|
219
|
+
});
|
|
220
|
+
try {
|
|
221
|
+
for (const sender of ["actor", "raw"]) await t.step(sender, async () => {
|
|
222
|
+
const federation = new FederationImpl({
|
|
223
|
+
kv: new MemoryKvStore(),
|
|
224
|
+
allowPrivateAddress: true
|
|
225
|
+
});
|
|
226
|
+
federation.setActorDispatcher("/users/{identifier}", (ctx, identifier) => new Person({ id: ctx.getActorUri(identifier) })).setKeyPairsDispatcher(() => [{
|
|
227
|
+
privateKey: rsaPrivateKey2,
|
|
228
|
+
publicKey: rsaPublicKey2.publicKey
|
|
229
|
+
}, {
|
|
230
|
+
privateKey: ed25519PrivateKey,
|
|
231
|
+
publicKey: ed25519PublicKey.publicKey
|
|
232
|
+
}]);
|
|
233
|
+
const ctx = new ContextImpl({
|
|
234
|
+
data: void 0,
|
|
235
|
+
federation,
|
|
236
|
+
url: new URL("https://example.com/"),
|
|
237
|
+
documentLoader: mockDocumentLoader,
|
|
238
|
+
contextLoader: mockDocumentLoader
|
|
239
|
+
});
|
|
240
|
+
const activity = await signObject(new Update({
|
|
241
|
+
id: new URL(`https://example.com/existing-proof/${sender}`),
|
|
242
|
+
actor: ctx.getActorUri("alice"),
|
|
243
|
+
object: new Person({
|
|
244
|
+
id: ctx.getActorUri("alice"),
|
|
245
|
+
attachments: [new PropertyValue({
|
|
246
|
+
name: "Site",
|
|
247
|
+
value: "example"
|
|
248
|
+
})]
|
|
249
|
+
})
|
|
250
|
+
}), ed25519PrivateKey, ed25519PublicKey.id, { contextLoader: mockDocumentLoader });
|
|
251
|
+
const before = structuredClone(await activity.toJsonLd());
|
|
252
|
+
assertEquals(await prepareActivityJsonLd(activity, mockDocumentLoader), void 0);
|
|
253
|
+
await ctx.sendActivity(sender === "actor" ? { identifier: "alice" } : [{
|
|
254
|
+
privateKey: rsaPrivateKey2,
|
|
255
|
+
keyId: rsaPublicKey2.id
|
|
256
|
+
}, {
|
|
257
|
+
privateKey: ed25519PrivateKey,
|
|
258
|
+
keyId: ed25519PublicKey.id
|
|
259
|
+
}], {
|
|
260
|
+
id: new URL("https://example.com/recipient"),
|
|
261
|
+
inboxId: new URL(inbox)
|
|
262
|
+
}, activity, {
|
|
263
|
+
immediate: true,
|
|
264
|
+
normalizeExistingProofs: true
|
|
265
|
+
});
|
|
266
|
+
assert(delivered != null);
|
|
267
|
+
assert(Array.isArray(delivered.object.attachment));
|
|
268
|
+
assert(await verifySignature(delivered, {
|
|
269
|
+
contextLoader: mockDocumentLoader,
|
|
270
|
+
keyCache: {
|
|
271
|
+
get: () => Promise.resolve(rsaPublicKey2),
|
|
272
|
+
async set() {}
|
|
273
|
+
}
|
|
274
|
+
}));
|
|
275
|
+
const wire = detachSignature(delivered);
|
|
276
|
+
const proofs = Array.isArray(wire.proof) ? wire.proof : [wire.proof];
|
|
277
|
+
assertEquals(proofs.length, sender === "actor" ? 2 : 1);
|
|
278
|
+
for (const proof of proofs) await assertRawProof(wire, proof, ed25519PublicKey.publicKey);
|
|
279
|
+
assertEquals(await activity.toJsonLd(), before);
|
|
280
|
+
});
|
|
281
|
+
} finally {
|
|
282
|
+
esm_default.unmockGlobal();
|
|
283
|
+
esm_default.removeRoutes();
|
|
284
|
+
esm_default.clearHistory();
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
//#endregion
|
|
288
|
+
export {};
|
|
@@ -4,20 +4,23 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-Dk_tacqz.mjs";
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-DNZ4Liil.mjs";
|
|
7
|
+
import { r as assertFalse } from "../assert_throws-D4DNWrux.mjs";
|
|
7
8
|
import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
|
|
8
9
|
import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
|
|
9
10
|
import { r as parseAcceptSignature } from "../accept-Dd__NiUL.mjs";
|
|
10
|
-
import { a as generateCryptoKeyPair } from "../key-
|
|
11
|
-
import { c as signRequest } from "../http-
|
|
11
|
+
import { a as generateCryptoKeyPair } from "../key-Bhc8cQC7.mjs";
|
|
12
|
+
import { c as signRequest } from "../http-B3wCvgu8.mjs";
|
|
12
13
|
import { a as rsaPrivateKey3, c as rsaPublicKey3, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
|
|
13
14
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
14
|
-
import { a as compactJsonLd,
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
15
|
+
import { a as compactJsonLd, h as signJsonLd } from "../ld-DTeykI0e.mjs";
|
|
16
|
+
import { t as ldSignatureWithoutCreated } from "../ld-signature-Dgz_b89j.mjs";
|
|
17
|
+
import { r as signObject } from "../proof-C63Hqt9N.mjs";
|
|
18
|
+
import { c as handleActor, d as handleInbox, f as handleObject, h as respondWithObjectIfAcceptable, l as handleCollection, m as respondWithObject, o as createFederation, p as handleOutbox, u as handleCustomCollection } from "../middleware-dlGvSrXl.mjs";
|
|
19
|
+
import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
|
|
18
20
|
import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
19
21
|
import { Activity, Create, CryptographicKey, Multikey, Note, Person, Tombstone } from "@fedify/vocab";
|
|
20
22
|
import { FetchError } from "@fedify/vocab-runtime";
|
|
23
|
+
import { configure, reset } from "@logtape/logtape";
|
|
21
24
|
//#region src/federation/handler.test.ts
|
|
22
25
|
const QUOTE_CONTEXT_TERMS = {
|
|
23
26
|
QuoteAuthorization: "https://w3id.org/fep/044f#QuoteAuthorization",
|
|
@@ -601,8 +604,8 @@ test("handleCollection()", async () => {
|
|
|
601
604
|
assertEquals(response.status, 200);
|
|
602
605
|
assertEquals(response.headers.get("Content-Type"), "application/activity+json");
|
|
603
606
|
const createCtx = [
|
|
604
|
-
"https://w3id.org/identity/v1",
|
|
605
607
|
"https://www.w3.org/ns/activitystreams",
|
|
608
|
+
"https://w3id.org/security/v1",
|
|
606
609
|
"https://w3id.org/security/data-integrity/v1",
|
|
607
610
|
"https://gotosocial.org/ns",
|
|
608
611
|
{
|
|
@@ -649,7 +652,13 @@ test("handleCollection()", async () => {
|
|
|
649
652
|
"@id": "fedibird:emojiReactions",
|
|
650
653
|
"@type": "@id"
|
|
651
654
|
}
|
|
652
|
-
}
|
|
655
|
+
},
|
|
656
|
+
{ orderedItems: {
|
|
657
|
+
"@id": "https://www.w3.org/ns/activitystreams#items",
|
|
658
|
+
"@type": "@id",
|
|
659
|
+
"@container": "@list",
|
|
660
|
+
"@context": null
|
|
661
|
+
} }
|
|
653
662
|
],
|
|
654
663
|
id: "https://example.com/users/someone",
|
|
655
664
|
type: "OrderedCollection",
|
|
@@ -734,7 +743,13 @@ test("handleCollection()", async () => {
|
|
|
734
743
|
"@id": "fedibird:emojiReactions",
|
|
735
744
|
"@type": "@id"
|
|
736
745
|
}
|
|
737
|
-
}
|
|
746
|
+
},
|
|
747
|
+
{ orderedItems: {
|
|
748
|
+
"@id": "https://www.w3.org/ns/activitystreams#items",
|
|
749
|
+
"@type": "@id",
|
|
750
|
+
"@container": "@list",
|
|
751
|
+
"@context": null
|
|
752
|
+
} }
|
|
738
753
|
],
|
|
739
754
|
id: "https://example.com/users/someone",
|
|
740
755
|
type: "OrderedCollection",
|
|
@@ -854,7 +869,13 @@ test("handleCollection()", async () => {
|
|
|
854
869
|
"@id": "fedibird:emojiReactions",
|
|
855
870
|
"@type": "@id"
|
|
856
871
|
}
|
|
857
|
-
}
|
|
872
|
+
},
|
|
873
|
+
{ orderedItems: {
|
|
874
|
+
"@id": "https://www.w3.org/ns/activitystreams#items",
|
|
875
|
+
"@type": "@id",
|
|
876
|
+
"@container": "@list",
|
|
877
|
+
"@context": null
|
|
878
|
+
} }
|
|
858
879
|
],
|
|
859
880
|
id: "https://example.com/users/someone?cursor=0",
|
|
860
881
|
type: "OrderedCollectionPage",
|
|
@@ -914,7 +935,13 @@ test("handleCollection()", async () => {
|
|
|
914
935
|
"@id": "fedibird:emojiReactions",
|
|
915
936
|
"@type": "@id"
|
|
916
937
|
}
|
|
917
|
-
}
|
|
938
|
+
},
|
|
939
|
+
{ orderedItems: {
|
|
940
|
+
"@id": "https://www.w3.org/ns/activitystreams#items",
|
|
941
|
+
"@type": "@id",
|
|
942
|
+
"@container": "@list",
|
|
943
|
+
"@context": null
|
|
944
|
+
} }
|
|
918
945
|
],
|
|
919
946
|
id: "https://example.com/users/someone?cursor=2",
|
|
920
947
|
type: "OrderedCollectionPage",
|
|
@@ -2551,6 +2578,166 @@ test("handleOutbox()", async () => {
|
|
|
2551
2578
|
assertEquals(response.status, 500);
|
|
2552
2579
|
assertEquals(onErrorCalled, true);
|
|
2553
2580
|
});
|
|
2581
|
+
test("handleInbox() verifies Linked Data signatures without created", async (t) => {
|
|
2582
|
+
const inserted = structuredClone(ldSignatureWithoutCreated);
|
|
2583
|
+
const withTimestamp = {
|
|
2584
|
+
...inserted,
|
|
2585
|
+
signature: {
|
|
2586
|
+
...inserted.signature,
|
|
2587
|
+
created: "2024-09-12T16:50:46Z"
|
|
2588
|
+
}
|
|
2589
|
+
};
|
|
2590
|
+
const tampered = structuredClone(ldSignatureWithoutCreated);
|
|
2591
|
+
tampered.object.content = "tampered";
|
|
2592
|
+
const invalid = structuredClone(ldSignatureWithoutCreated);
|
|
2593
|
+
invalid.signature.signatureValue = "AAAA";
|
|
2594
|
+
const { signature: _, ...unsigned } = ldSignatureWithoutCreated;
|
|
2595
|
+
for (const [name, body, expected] of [
|
|
2596
|
+
[
|
|
2597
|
+
"valid LD-only",
|
|
2598
|
+
ldSignatureWithoutCreated,
|
|
2599
|
+
202
|
|
2600
|
+
],
|
|
2601
|
+
[
|
|
2602
|
+
"inserted created",
|
|
2603
|
+
withTimestamp,
|
|
2604
|
+
401
|
|
2605
|
+
],
|
|
2606
|
+
[
|
|
2607
|
+
"tampered content",
|
|
2608
|
+
tampered,
|
|
2609
|
+
401
|
|
2610
|
+
],
|
|
2611
|
+
[
|
|
2612
|
+
"invalid signature",
|
|
2613
|
+
invalid,
|
|
2614
|
+
401
|
|
2615
|
+
],
|
|
2616
|
+
[
|
|
2617
|
+
"unsigned",
|
|
2618
|
+
unsigned,
|
|
2619
|
+
401
|
|
2620
|
+
],
|
|
2621
|
+
[
|
|
2622
|
+
"malformed created",
|
|
2623
|
+
{
|
|
2624
|
+
...ldSignatureWithoutCreated,
|
|
2625
|
+
signature: {
|
|
2626
|
+
...ldSignatureWithoutCreated.signature,
|
|
2627
|
+
created: 123
|
|
2628
|
+
}
|
|
2629
|
+
},
|
|
2630
|
+
401
|
|
2631
|
+
],
|
|
2632
|
+
[
|
|
2633
|
+
"malformed creator",
|
|
2634
|
+
{
|
|
2635
|
+
...ldSignatureWithoutCreated,
|
|
2636
|
+
signature: {
|
|
2637
|
+
...ldSignatureWithoutCreated.signature,
|
|
2638
|
+
creator: {}
|
|
2639
|
+
}
|
|
2640
|
+
},
|
|
2641
|
+
401
|
|
2642
|
+
],
|
|
2643
|
+
[
|
|
2644
|
+
"malformed null",
|
|
2645
|
+
{
|
|
2646
|
+
...ldSignatureWithoutCreated,
|
|
2647
|
+
signature: null
|
|
2648
|
+
},
|
|
2649
|
+
401
|
|
2650
|
+
],
|
|
2651
|
+
[
|
|
2652
|
+
"malformed array",
|
|
2653
|
+
{
|
|
2654
|
+
...ldSignatureWithoutCreated,
|
|
2655
|
+
signature: []
|
|
2656
|
+
},
|
|
2657
|
+
401
|
|
2658
|
+
],
|
|
2659
|
+
[
|
|
2660
|
+
"malformed primitive",
|
|
2661
|
+
{
|
|
2662
|
+
...ldSignatureWithoutCreated,
|
|
2663
|
+
signature: "secret"
|
|
2664
|
+
},
|
|
2665
|
+
401
|
|
2666
|
+
]
|
|
2667
|
+
]) await t.step(name, async () => {
|
|
2668
|
+
const kv = new MemoryKvStore();
|
|
2669
|
+
const federation = createFederation({ kv });
|
|
2670
|
+
const request = new Request("https://example.com/inbox", {
|
|
2671
|
+
method: "POST",
|
|
2672
|
+
body: JSON.stringify(body)
|
|
2673
|
+
});
|
|
2674
|
+
const context = createRequestContext({
|
|
2675
|
+
federation,
|
|
2676
|
+
request,
|
|
2677
|
+
url: new URL(request.url),
|
|
2678
|
+
data: void 0,
|
|
2679
|
+
documentLoader: mockDocumentLoader,
|
|
2680
|
+
contextLoader: mockDocumentLoader
|
|
2681
|
+
});
|
|
2682
|
+
let deliveries = 0;
|
|
2683
|
+
const inboxListeners = new ActivityListenerSet();
|
|
2684
|
+
inboxListeners.add(Create, () => {
|
|
2685
|
+
deliveries++;
|
|
2686
|
+
});
|
|
2687
|
+
const records = [];
|
|
2688
|
+
await configure({
|
|
2689
|
+
sinks: { buffer: (record) => records.push(record) },
|
|
2690
|
+
loggers: [{
|
|
2691
|
+
category: ["fedify"],
|
|
2692
|
+
sinks: ["buffer"],
|
|
2693
|
+
lowestLevel: "debug"
|
|
2694
|
+
}, {
|
|
2695
|
+
category: ["logtape", "meta"],
|
|
2696
|
+
sinks: []
|
|
2697
|
+
}],
|
|
2698
|
+
reset: true
|
|
2699
|
+
});
|
|
2700
|
+
try {
|
|
2701
|
+
assertEquals((await handleInbox(request, {
|
|
2702
|
+
recipient: null,
|
|
2703
|
+
context,
|
|
2704
|
+
inboxContextFactory() {
|
|
2705
|
+
return createInboxContext({
|
|
2706
|
+
...context,
|
|
2707
|
+
clone: void 0
|
|
2708
|
+
});
|
|
2709
|
+
},
|
|
2710
|
+
kv,
|
|
2711
|
+
kvPrefixes: {
|
|
2712
|
+
activityIdempotence: ["_fedify", "activityIdempotence"],
|
|
2713
|
+
publicKey: ["_fedify", "publicKey"],
|
|
2714
|
+
acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
|
|
2715
|
+
},
|
|
2716
|
+
actorDispatcher: () => null,
|
|
2717
|
+
inboxListeners,
|
|
2718
|
+
onNotFound: () => new Response("Not found", { status: 404 }),
|
|
2719
|
+
signatureTimeWindow: { minutes: 5 },
|
|
2720
|
+
skipSignatureVerification: false
|
|
2721
|
+
})).status, expected);
|
|
2722
|
+
assertEquals(deliveries, expected === 202 ? 1 : 0);
|
|
2723
|
+
const malformedRecords = records.filter((r) => r.rawMessage === "Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.");
|
|
2724
|
+
assertEquals(malformedRecords.length, name.startsWith("malformed") ? 1 : 0);
|
|
2725
|
+
for (const record of malformedRecords) {
|
|
2726
|
+
assertEquals(record.category, [
|
|
2727
|
+
"fedify",
|
|
2728
|
+
"federation",
|
|
2729
|
+
"inbox"
|
|
2730
|
+
]);
|
|
2731
|
+
assertEquals(record.level, "debug");
|
|
2732
|
+
assertFalse(JSON.stringify(record).includes(ldSignatureWithoutCreated.signature.creator));
|
|
2733
|
+
assertFalse(JSON.stringify(record).includes(ldSignatureWithoutCreated.signature.signatureValue));
|
|
2734
|
+
assertFalse(JSON.stringify(record).includes("secret"));
|
|
2735
|
+
}
|
|
2736
|
+
} finally {
|
|
2737
|
+
await reset();
|
|
2738
|
+
}
|
|
2739
|
+
});
|
|
2740
|
+
});
|
|
2554
2741
|
test("handleInbox() preserves the raw signed payload for inboxContextFactory", async () => {
|
|
2555
2742
|
const federation = createFederation({ kv: new MemoryKvStore() });
|
|
2556
2743
|
const remoteContextUrl = "https://remote.example/contexts/ext";
|
|
@@ -3276,8 +3463,8 @@ test("handleCustomCollection()", async () => {
|
|
|
3276
3463
|
assertEquals(response.status, 200);
|
|
3277
3464
|
assertEquals(response.headers.get("Content-Type"), "application/activity+json");
|
|
3278
3465
|
const createCtx = [
|
|
3279
|
-
"https://w3id.org/identity/v1",
|
|
3280
3466
|
"https://www.w3.org/ns/activitystreams",
|
|
3467
|
+
"https://w3id.org/security/v1",
|
|
3281
3468
|
"https://w3id.org/security/data-integrity/v1",
|
|
3282
3469
|
"https://gotosocial.org/ns",
|
|
3283
3470
|
{
|
|
@@ -3325,8 +3512,13 @@ test("handleCustomCollection()", async () => {
|
|
|
3325
3512
|
}
|
|
3326
3513
|
}
|
|
3327
3514
|
];
|
|
3515
|
+
const ITEM_CONTEXT = [...CONTEXT, { items: {
|
|
3516
|
+
"@id": "https://www.w3.org/ns/activitystreams#items",
|
|
3517
|
+
"@type": "@id",
|
|
3518
|
+
"@context": null
|
|
3519
|
+
} }];
|
|
3328
3520
|
assertEquals(await response.json(), {
|
|
3329
|
-
"@context":
|
|
3521
|
+
"@context": ITEM_CONTEXT,
|
|
3330
3522
|
id: "https://example.com/",
|
|
3331
3523
|
type: "Collection",
|
|
3332
3524
|
items: [
|
|
@@ -3381,7 +3573,7 @@ test("handleCustomCollection()", async () => {
|
|
|
3381
3573
|
assertEquals(response.status, 200);
|
|
3382
3574
|
assertEquals(response.headers.get("Content-Type"), "application/activity+json");
|
|
3383
3575
|
assertEquals(await response.json(), {
|
|
3384
|
-
"@context":
|
|
3576
|
+
"@context": ITEM_CONTEXT,
|
|
3385
3577
|
id: "https://example.com/",
|
|
3386
3578
|
type: "Collection",
|
|
3387
3579
|
items: [
|
|
@@ -3439,7 +3631,7 @@ test("handleCustomCollection()", async () => {
|
|
|
3439
3631
|
assertEquals(response.status, 200);
|
|
3440
3632
|
assertEquals(response.headers.get("Content-Type"), "application/activity+json");
|
|
3441
3633
|
assertEquals(await response.json(), {
|
|
3442
|
-
"@context":
|
|
3634
|
+
"@context": ITEM_CONTEXT,
|
|
3443
3635
|
id: "https://example.com/?cursor=0",
|
|
3444
3636
|
type: "CollectionPage",
|
|
3445
3637
|
partOf: "https://example.com/",
|
|
@@ -3468,7 +3660,7 @@ test("handleCustomCollection()", async () => {
|
|
|
3468
3660
|
assertEquals(response.status, 200);
|
|
3469
3661
|
assertEquals(response.headers.get("Content-Type"), "application/activity+json");
|
|
3470
3662
|
assertEquals(await response.json(), {
|
|
3471
|
-
"@context":
|
|
3663
|
+
"@context": ITEM_CONTEXT,
|
|
3472
3664
|
id: "https://example.com/?cursor=2",
|
|
3473
3665
|
type: "CollectionPage",
|
|
3474
3666
|
partOf: "https://example.com/",
|
|
@@ -5,8 +5,8 @@ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
|
5
5
|
import "../std__assert-DNZ4Liil.mjs";
|
|
6
6
|
import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
|
|
7
7
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
8
|
-
import { r as signObject } from "../proof-
|
|
9
|
-
import { o as createFederation } from "../middleware-
|
|
8
|
+
import { r as signObject } from "../proof-C63Hqt9N.mjs";
|
|
9
|
+
import { o as createFederation } from "../middleware-dlGvSrXl.mjs";
|
|
10
10
|
import { mockDocumentLoader, test } from "@fedify/fixture";
|
|
11
11
|
import { Create, Follow, Person } from "@fedify/vocab";
|
|
12
12
|
//#region src/federation/idempotency.test.ts
|
|
@@ -3,8 +3,8 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
|
|
6
|
-
import { t as ActivityListenerSet } from "../activity-listener-
|
|
7
|
-
import { t as actorsHaveSameOrigin } from "../inbox-
|
|
6
|
+
import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
|
|
7
|
+
import { t as actorsHaveSameOrigin } from "../inbox-DLy6WBXU.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
import { Activity, Create, Invite, Offer, Update } from "@fedify/vocab";
|
|
10
10
|
//#region src/federation/inbox.test.ts
|