@fedify/fedify 2.0.36-dev.2760 → 2.0.36-dev.2828
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-D43igPLB.mjs +111 -0
- package/dist/{builder-CyuiJaas.mjs → builder-NquOFkEx.mjs} +3 -3
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +254 -0
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{deno-Bbso5CSl.mjs → deno-uX5OxSMQ.mjs} +1 -1
- package/dist/{docloader-CP5VuWA0.mjs → docloader-BVio_R-w.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 +280 -0
- package/dist/federation/handler.test.mjs +6 -6
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/keycache.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +7 -7
- package/dist/federation/mod.cjs +1 -1
- 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 +3 -3
- package/dist/federation/temporal.test.mjs +1 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-DBBUPm9V.cjs → http-Bp6bXNxO.cjs} +1 -1
- package/dist/{http-Cp7sQLeG.mjs → http-Cx49vN9O.mjs} +2 -2
- package/dist/{http-D03Qcwc-.js → http-DaxiTQXs.js} +1 -1
- package/dist/{inbox-DTuh59nR.mjs → inbox-Rw21yNrv.mjs} +1 -1
- package/dist/{key-CsY0Ifod.mjs → key-CxZXo3sZ.mjs} +1 -1
- package/dist/{kv-cache-CVxDhqGp.js → kv-cache-BEYK4z_E.js} +1 -1
- package/dist/{kv-cache-BpjVni_0.cjs → kv-cache-BjsvCInD.cjs} +1 -1
- package/dist/{ld-dYjiHKj1.mjs → ld-DTaV6DUm.mjs} +2 -2
- package/dist/{middleware-DFR4tBL2.js → middleware-Bnn9AKMf.js} +259 -32
- package/dist/{middleware-3x7W0auZ.mjs → middleware-BuQURchh.mjs} +170 -45
- package/dist/{middleware-5EN1mHvx.cjs → middleware-By3uBhIJ.cjs} +260 -32
- package/dist/{middleware-2zkNwQvz.cjs → middleware-ByAekFky.cjs} +1 -1
- package/dist/{middleware-DvCyN-xk.mjs → middleware-Cz87lzGU.mjs} +1 -1
- package/dist/mod.cjs +4 -4
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/{owner-A1Xol6Zh.mjs → owner-CEFC5tVI.mjs} +2 -2
- package/dist/{proof-CCZCT2xF.cjs → proof-Bl3zk5c6.cjs} +3 -3
- package/dist/{proof-DGOXBmlo.js → proof-Ct8tSLww.js} +2 -2
- package/dist/{proof-DCqYLXDl.mjs → proof-DFrHHTit.mjs} +2 -2
- package/dist/{send-yQno-6bP.mjs → send-Dn11B6x2.mjs} +2 -2
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key-types.test.d.mts +1 -1
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +2 -2
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +2 -2
- package/dist/{temporal-C26UV3h7.mjs → temporal-DEWMgahT.mjs} +1 -1
- package/dist/testing/mod.d.mts +1 -1
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +5 -5
- /package/dist/{callback-BFMEE_9V.d.mts → callback-ySj5p3Ml.d.mts} +0 -0
- /package/dist/{collection-ChgDTHLz.mjs → collection-BD6-SZ6O.mjs} +0 -0
- /package/dist/{keycache-crDMn2HK.mjs → keycache-BhLorx33.mjs} +0 -0
- /package/dist/{negotiation-BehA2uul.mjs → negotiation-DnsfFF8I.mjs} +0 -0
- /package/dist/{retry-B_E3V_Dx.mjs → retry-CJL0poaU.mjs} +0 -0
- /package/dist/{types-C37hquWI.mjs → types-DCP0WLdt.mjs} +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { preloadedContexts } from "@fedify/vocab-runtime";
|
|
5
|
+
import { getLogger } from "@logtape/logtape";
|
|
6
|
+
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
7
|
+
//#region src/compat/attachment-arrays.ts
|
|
8
|
+
const logger = getLogger([
|
|
9
|
+
"fedify",
|
|
10
|
+
"compat",
|
|
11
|
+
"attachment-arrays"
|
|
12
|
+
]);
|
|
13
|
+
const MAX_DEPTH = 64;
|
|
14
|
+
const ATTACHMENT = "https://www.w3.org/ns/activitystreams#attachment";
|
|
15
|
+
const PROOF = "https://w3id.org/security#proof";
|
|
16
|
+
/** Recognizes JSON-LD maps without accepting arrays or scalar values. */
|
|
17
|
+
function isMap(value) {
|
|
18
|
+
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
/** Copies only changed branches; cached vocabulary JSON belongs to its owner. */
|
|
21
|
+
function walk(value, depth = 0) {
|
|
22
|
+
if (depth >= MAX_DEPTH) throw new RangeError("JSON-LD nesting limit exceeded.");
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
const items = value.map((item) => walk(item, depth + 1));
|
|
25
|
+
return items.some((item, i) => item !== value[i]) ? items : value;
|
|
26
|
+
}
|
|
27
|
+
if (!isMap(value)) return value;
|
|
28
|
+
if (Object.hasOwn(value, "@value")) return value;
|
|
29
|
+
let result;
|
|
30
|
+
for (const [key, item] of Object.entries(value)) {
|
|
31
|
+
let next = key === "@context" ? item : walk(item, depth + 1);
|
|
32
|
+
if ((key === "attachment" || key === ATTACHMENT) && next != null && !Array.isArray(next) && !(isMap(next) && Object.hasOwn(next, "@list"))) next = [next];
|
|
33
|
+
if (next !== item) {
|
|
34
|
+
result ??= Object.assign(Object.create(null), value);
|
|
35
|
+
result[key] = next;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result ?? value;
|
|
39
|
+
}
|
|
40
|
+
const preloadedLoader = (url) => {
|
|
41
|
+
if (!Object.hasOwn(preloadedContexts, url)) return Promise.reject(/* @__PURE__ */ new Error("Unknown JSON-LD context: " + url));
|
|
42
|
+
return Promise.resolve({
|
|
43
|
+
contextUrl: null,
|
|
44
|
+
documentUrl: url,
|
|
45
|
+
document: preloadedContexts[url]
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
/** Reuses each context resolution across the complete equivalence check. */
|
|
49
|
+
function memoizeLoader(loader) {
|
|
50
|
+
const pending = /* @__PURE__ */ new Map();
|
|
51
|
+
return (url, options) => {
|
|
52
|
+
let result = pending.get(url);
|
|
53
|
+
if (result == null) {
|
|
54
|
+
result = loader(url, options);
|
|
55
|
+
pending.set(url, result);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Finds security predicates in expanded nodes, never inside JSON literals. */
|
|
61
|
+
function hasSecurityPredicate(value) {
|
|
62
|
+
if (Array.isArray(value)) return value.some(hasSecurityPredicate);
|
|
63
|
+
if (!isMap(value) || Object.hasOwn(value, "@value")) return false;
|
|
64
|
+
for (const [key, child] of Object.entries(value)) {
|
|
65
|
+
if (key === PROOF || key === "https://w3id.org/security#signature") return true;
|
|
66
|
+
if (hasSecurityPredicate(child)) return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Keeps singleton attachments in arrays for raw-JSON ActivityPub consumers.
|
|
72
|
+
* Mastodon's property_values() ignores valid compact JSON-LD scalar values,
|
|
73
|
+
* and its caller clears the profile fields in that case:
|
|
74
|
+
* https://github.com/mastodon/mastodon/blob/594166519a623584920c7e696bae9a009d9183ab/app/services/activitypub/process_account_service.rb#L465-L472
|
|
75
|
+
* Pixelfed likewise rejects singleton media attachments:
|
|
76
|
+
* https://github.com/pixelfed/pixelfed/issues/6588
|
|
77
|
+
*
|
|
78
|
+
* This workaround changes only attachment representation, after serialization.
|
|
79
|
+
* RDF equality protects custom contexts, including JSON literals; it does not
|
|
80
|
+
* protect JCS signatures. Any semantic proof or Linked Data signature leaves
|
|
81
|
+
* the whole serialized document unchanged, as does an unresolved context.
|
|
82
|
+
* This layer does not compose signed objects or repair vocabulary serialization.
|
|
83
|
+
* Remove this
|
|
84
|
+
* workaround only when the supported consumer versions, including deployed
|
|
85
|
+
* older releases, accept scalar attachments. Do not replace it with a
|
|
86
|
+
* vocabulary transformer: subsequent compaction collapses arrays.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
async function normalizeAttachmentArrays(document, contextLoader) {
|
|
90
|
+
try {
|
|
91
|
+
const normalized = walk(document);
|
|
92
|
+
if (normalized === document) return document;
|
|
93
|
+
const loader = memoizeLoader(contextLoader ?? preloadedLoader);
|
|
94
|
+
if (hasSecurityPredicate(await jsonld.expand(document, { documentLoader: loader }))) return document;
|
|
95
|
+
const [before, after] = await Promise.allSettled([jsonld.canonize(document, {
|
|
96
|
+
format: "application/n-quads",
|
|
97
|
+
documentLoader: loader
|
|
98
|
+
}), jsonld.canonize(normalized, {
|
|
99
|
+
format: "application/n-quads",
|
|
100
|
+
documentLoader: loader
|
|
101
|
+
})]);
|
|
102
|
+
if (before.status === "rejected") throw before.reason;
|
|
103
|
+
if (after.status === "rejected") throw after.reason;
|
|
104
|
+
if (before.value === after.value) return normalized;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
logger.debug("Could not safely normalize attachment arrays; preserving the document: {error}", { error });
|
|
107
|
+
}
|
|
108
|
+
return document;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { normalizeAttachmentArrays as t };
|
|
@@ -2,8 +2,8 @@ import "@js-temporal/polyfill";
|
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { n as RouterError, t as Router } from "./router-CrMLXoOr.mjs";
|
|
5
|
-
import { n as version, t as name } from "./deno-
|
|
6
|
-
import { t as InboxListenerSet } from "./inbox-
|
|
5
|
+
import { n as version, t as name } from "./deno-uX5OxSMQ.mjs";
|
|
6
|
+
import { t as InboxListenerSet } from "./inbox-Rw21yNrv.mjs";
|
|
7
7
|
import { getTypeId } from "@fedify/vocab";
|
|
8
8
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
9
9
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -43,7 +43,7 @@ var FederationBuilderImpl = class {
|
|
|
43
43
|
this.collectionTypeIds = {};
|
|
44
44
|
}
|
|
45
45
|
async build(options) {
|
|
46
|
-
const { FederationImpl } = await import("./middleware-
|
|
46
|
+
const { FederationImpl } = await import("./middleware-Cz87lzGU.mjs");
|
|
47
47
|
const f = new FederationImpl(options);
|
|
48
48
|
const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
|
|
49
49
|
f.router = this.router.clone();
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
|
+
import { n as assertStrictEquals } from "../std__assert-DflMZha5.mjs";
|
|
6
|
+
import { t as normalizeAttachmentArrays } from "../attachment-arrays-D43igPLB.mjs";
|
|
7
|
+
import { test } from "@fedify/fixture";
|
|
8
|
+
import { preloadedContexts } from "@fedify/vocab-runtime";
|
|
9
|
+
//#region src/compat/attachment-arrays.test.ts
|
|
10
|
+
const AS = "https://www.w3.org/ns/activitystreams";
|
|
11
|
+
const SEC = "https://w3id.org/security#";
|
|
12
|
+
test("attachment arrays: singleton, multiple, nested and expanded properties", async () => {
|
|
13
|
+
const document = {
|
|
14
|
+
"@context": AS,
|
|
15
|
+
type: "Collection",
|
|
16
|
+
items: [
|
|
17
|
+
{
|
|
18
|
+
type: "Note",
|
|
19
|
+
attachment: {
|
|
20
|
+
type: "Image",
|
|
21
|
+
url: "https://example.com/a"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: "Note",
|
|
26
|
+
attachment: ["https://example.com/b", "https://example.com/c"]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: "Note",
|
|
30
|
+
attachment: null
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "Note",
|
|
34
|
+
[`${AS}#attachment`]: "https://example.com/d"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
const before = structuredClone(document);
|
|
39
|
+
const result = await normalizeAttachmentArrays(document);
|
|
40
|
+
assertEquals(result, {
|
|
41
|
+
...document,
|
|
42
|
+
items: [
|
|
43
|
+
{
|
|
44
|
+
type: "Note",
|
|
45
|
+
attachment: [document.items[0].attachment]
|
|
46
|
+
},
|
|
47
|
+
document.items[1],
|
|
48
|
+
document.items[2],
|
|
49
|
+
{
|
|
50
|
+
type: "Note",
|
|
51
|
+
[`${AS}#attachment`]: ["https://example.com/d"]
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
assertEquals(document, before);
|
|
56
|
+
assertStrictEquals(await normalizeAttachmentArrays(result), result);
|
|
57
|
+
});
|
|
58
|
+
test("attachment arrays: preserve lists, contexts and value objects", async () => {
|
|
59
|
+
for (const document of [{
|
|
60
|
+
"@context": AS,
|
|
61
|
+
attachment: { "@list": ["https://example.com/a"] }
|
|
62
|
+
}, {
|
|
63
|
+
"@context": AS,
|
|
64
|
+
content: {
|
|
65
|
+
"@value": { attachment: 1 },
|
|
66
|
+
"@type": "@json"
|
|
67
|
+
}
|
|
68
|
+
}]) assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
69
|
+
});
|
|
70
|
+
test("attachment arrays: inline and remote contexts share one loader snapshot", async () => {
|
|
71
|
+
let loads = 0;
|
|
72
|
+
const loader = (url) => {
|
|
73
|
+
loads++;
|
|
74
|
+
return Promise.resolve({
|
|
75
|
+
documentUrl: url,
|
|
76
|
+
contextUrl: null,
|
|
77
|
+
document: preloadedContexts[AS]
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
const document = {
|
|
81
|
+
"@context": "https://example.com/context",
|
|
82
|
+
attachment: "https://example.com/a"
|
|
83
|
+
};
|
|
84
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
85
|
+
assertEquals(await normalizeAttachmentArrays(document, loader), {
|
|
86
|
+
...document,
|
|
87
|
+
attachment: [document.attachment]
|
|
88
|
+
});
|
|
89
|
+
assertEquals(loads, 1);
|
|
90
|
+
const inline = {
|
|
91
|
+
"@context": [AS, {
|
|
92
|
+
schema: "http://schema.org/",
|
|
93
|
+
value: "schema:value"
|
|
94
|
+
}],
|
|
95
|
+
attachment: { type: "Image" }
|
|
96
|
+
};
|
|
97
|
+
assertEquals(await normalizeAttachmentArrays(inline), {
|
|
98
|
+
...inline,
|
|
99
|
+
attachment: [inline.attachment]
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
test("attachment arrays: JSON literals and context redefinitions remain unchanged", async () => {
|
|
103
|
+
for (const document of [
|
|
104
|
+
{
|
|
105
|
+
"@context": [AS, { attachment: {
|
|
106
|
+
"@id": `${AS}#attachment`,
|
|
107
|
+
"@type": "@json"
|
|
108
|
+
} }],
|
|
109
|
+
attachment: { type: "Image" }
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"@context": [AS, { payload: {
|
|
113
|
+
"@id": "https://example.com/payload",
|
|
114
|
+
"@type": "@json"
|
|
115
|
+
} }],
|
|
116
|
+
attachment: "https://example.com/a",
|
|
117
|
+
payload: { attachment: { proof: "literal" } }
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"@context": [AS, "https://www.w3.org/ns/cid/v1"],
|
|
121
|
+
attachment: "https://example.com/a",
|
|
122
|
+
publicKeyJwk: { attachment: { type: "Image" } }
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"@context": [
|
|
126
|
+
AS,
|
|
127
|
+
null,
|
|
128
|
+
{
|
|
129
|
+
"@vocab": "https://example.com/",
|
|
130
|
+
attachment: {
|
|
131
|
+
"@id": "https://example.com/attachment",
|
|
132
|
+
"@type": "@json"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
attachment: { type: "Image" }
|
|
137
|
+
}
|
|
138
|
+
]) assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
139
|
+
});
|
|
140
|
+
test("attachment arrays: language and index maps retain their semantics", async () => {
|
|
141
|
+
for (const container of ["@language", "@index"]) {
|
|
142
|
+
const document = {
|
|
143
|
+
"@context": [AS, { attachment: {
|
|
144
|
+
"@id": `${AS}#attachment`,
|
|
145
|
+
"@container": container
|
|
146
|
+
} }],
|
|
147
|
+
attachment: container === "@language" ? { en: "example" } : { sample: { type: "Image" } }
|
|
148
|
+
};
|
|
149
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
test("attachment arrays: scoped contexts cannot change literal payloads", async () => {
|
|
153
|
+
const document = {
|
|
154
|
+
"@context": [AS, { Special: {
|
|
155
|
+
"@id": "https://example.com/Special",
|
|
156
|
+
"@context": { attachment: {
|
|
157
|
+
"@id": `${AS}#attachment`,
|
|
158
|
+
"@type": "@json"
|
|
159
|
+
} }
|
|
160
|
+
} }],
|
|
161
|
+
type: "Special",
|
|
162
|
+
attachment: { type: "Image" }
|
|
163
|
+
};
|
|
164
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
165
|
+
});
|
|
166
|
+
test("attachment arrays: root proofs and signed siblings are immutable", async () => {
|
|
167
|
+
const signed = Object.freeze({
|
|
168
|
+
"@context": [AS, { proof: `${SEC}proof` }],
|
|
169
|
+
attachment: "https://example.com/a",
|
|
170
|
+
proof: Object.freeze({ id: "https://example.com/proof" })
|
|
171
|
+
});
|
|
172
|
+
assertStrictEquals(await normalizeAttachmentArrays(signed), signed);
|
|
173
|
+
const document = {
|
|
174
|
+
"@context": AS,
|
|
175
|
+
type: "Collection",
|
|
176
|
+
items: [signed, {
|
|
177
|
+
type: "Note",
|
|
178
|
+
attachment: "https://example.com/b"
|
|
179
|
+
}]
|
|
180
|
+
};
|
|
181
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
182
|
+
for (const proof of [[], [{ proofValue: "one" }, { proofValue: "two" }]]) {
|
|
183
|
+
const root = {
|
|
184
|
+
"@context": [AS, { proof: `${SEC}proof` }],
|
|
185
|
+
attachment: "https://example.com/a",
|
|
186
|
+
proof
|
|
187
|
+
};
|
|
188
|
+
assertStrictEquals(await normalizeAttachmentArrays(root), root);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
test("attachment arrays: semantic proof aliases preserve the whole document", async () => {
|
|
192
|
+
for (const nested of [false, true]) {
|
|
193
|
+
const document = {
|
|
194
|
+
"@context": [AS, { seal: `${SEC}proof` }],
|
|
195
|
+
attachment: "https://example.com/a",
|
|
196
|
+
...nested ? { object: { seal: { "@id": "https://example.com/proof" } } } : { seal: { "@id": "https://example.com/proof" } }
|
|
197
|
+
};
|
|
198
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
199
|
+
}
|
|
200
|
+
const literal = {
|
|
201
|
+
"@context": AS,
|
|
202
|
+
content: `<${SEC}proof>`,
|
|
203
|
+
attachment: "https://example.com/a"
|
|
204
|
+
};
|
|
205
|
+
assertEquals(await normalizeAttachmentArrays(literal), {
|
|
206
|
+
...literal,
|
|
207
|
+
attachment: [literal.attachment]
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
test("attachment arrays: excessive depth and failing loaders preserve input", async () => {
|
|
211
|
+
let document = { attachment: "https://example.com/a" };
|
|
212
|
+
for (let i = 0; i < 70; i++) document = { object: document };
|
|
213
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
214
|
+
const custom = {
|
|
215
|
+
"@context": "https://example.com/unavailable",
|
|
216
|
+
attachment: "https://example.com/a"
|
|
217
|
+
};
|
|
218
|
+
assertStrictEquals(await normalizeAttachmentArrays(custom, () => Promise.reject(/* @__PURE__ */ new Error("unavailable"))), custom);
|
|
219
|
+
});
|
|
220
|
+
test("attachment arrays: context-coerced security-shaped JSON is ordinary data", async () => {
|
|
221
|
+
const data = { proof: { signature: "application data" } };
|
|
222
|
+
const document = {
|
|
223
|
+
"@context": [AS, { data: {
|
|
224
|
+
"@id": "https://example.com/data",
|
|
225
|
+
"@type": "@json"
|
|
226
|
+
} }],
|
|
227
|
+
attachment: "https://example.com/a",
|
|
228
|
+
data
|
|
229
|
+
};
|
|
230
|
+
assertEquals(await normalizeAttachmentArrays(document), {
|
|
231
|
+
...document,
|
|
232
|
+
attachment: [document.attachment]
|
|
233
|
+
});
|
|
234
|
+
assertEquals(document.data, data);
|
|
235
|
+
let deep = { signature: "application data" };
|
|
236
|
+
for (let i = 0; i < 70; i++) deep = { child: deep };
|
|
237
|
+
const large = {
|
|
238
|
+
...document,
|
|
239
|
+
data: deep
|
|
240
|
+
};
|
|
241
|
+
assertStrictEquals(await normalizeAttachmentArrays(large), large);
|
|
242
|
+
});
|
|
243
|
+
test("attachment arrays: root and nested semantic LD signatures block rewriting", async () => {
|
|
244
|
+
for (const nested of [false, true]) {
|
|
245
|
+
const document = {
|
|
246
|
+
"@context": [AS, { seal: `${SEC}signature` }],
|
|
247
|
+
attachment: "https://example.com/a",
|
|
248
|
+
...nested ? { object: { seal: { "@id": "https://example.com/sig" } } } : { seal: { "@id": "https://example.com/sig" } }
|
|
249
|
+
};
|
|
250
|
+
assertStrictEquals(await normalizeAttachmentArrays(document), document);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
//#endregion
|
|
254
|
+
export {};
|
|
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
|
|
6
6
|
import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
|
|
7
|
-
import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-
|
|
7
|
+
import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-BuQURchh.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
import { Follow, Person } from "@fedify/vocab";
|
|
10
10
|
//#region src/compat/transformers.test.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { o as validateCryptoKey } from "./key-
|
|
5
|
-
import { r as doubleKnockScoped } from "./http-
|
|
4
|
+
import { o as validateCryptoKey } from "./key-CxZXo3sZ.mjs";
|
|
5
|
+
import { r as doubleKnockScoped } from "./http-Cx49vN9O.mjs";
|
|
6
6
|
import { curry } from "es-toolkit";
|
|
7
7
|
import { FetchError, UrlError, createActivityPubRequest, getRemoteDocument, logRequest } from "@fedify/vocab-runtime";
|
|
8
8
|
import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
|
+
import "../std__assert-DflMZha5.mjs";
|
|
6
|
+
import { t as assert } from "../assert-BhQd8QHP.mjs";
|
|
7
|
+
import { n as ed25519PrivateKey, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
|
|
8
|
+
import { i as verifyProof, n as signObject } from "../proof-DFrHHTit.mjs";
|
|
9
|
+
import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
|
|
10
|
+
import { a as createFederation, f as respondWithObject, p as respondWithObjectIfAcceptable } from "../middleware-BuQURchh.mjs";
|
|
11
|
+
import { mockDocumentLoader, test } from "@fedify/fixture";
|
|
12
|
+
import { Note, Object as Object$1, OrderedCollection, PropertyValue, Service, Update } from "@fedify/vocab";
|
|
13
|
+
//#region src/federation/attachment-responses.test.ts
|
|
14
|
+
const ACCEPTS = ["application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""];
|
|
15
|
+
function profile(count) {
|
|
16
|
+
return new Service({
|
|
17
|
+
id: new URL("https://example.com/actors/app"),
|
|
18
|
+
preferredUsername: "app",
|
|
19
|
+
attachments: Array.from({ length: count }, (_, i) => new PropertyValue({
|
|
20
|
+
name: `Field ${i}`,
|
|
21
|
+
value: `https://example.com/${i}`
|
|
22
|
+
}))
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function attachmentValues(value) {
|
|
26
|
+
if (Array.isArray(value)) return value.flatMap(attachmentValues);
|
|
27
|
+
if (typeof value !== "object" || value == null) return [];
|
|
28
|
+
return Object.entries(value).flatMap(([key, item]) => key === "@context" ? [] : key === "attachment" ? [item] : attachmentValues(item));
|
|
29
|
+
}
|
|
30
|
+
test("attachment responses: actor, object, collections and pages negotiate both media types", async () => {
|
|
31
|
+
for (const count of [1, 2]) {
|
|
32
|
+
const actor = profile(count);
|
|
33
|
+
const update = new Update({
|
|
34
|
+
id: new URL("https://example.com/updates/1"),
|
|
35
|
+
actor: actor.id,
|
|
36
|
+
object: actor
|
|
37
|
+
});
|
|
38
|
+
const federation = createFederation({ kv: new MemoryKvStore() });
|
|
39
|
+
federation.setActorDispatcher("/actors/{identifier}", () => actor);
|
|
40
|
+
federation.setObjectDispatcher(Note, "/notes/{id}", () => new Note({ attachments: Array.from({ length: count }, () => new Note({ content: "attachment" })) }));
|
|
41
|
+
federation.setFollowersDispatcher("/actors/{identifier}/followers", () => ({ items: [actor] }));
|
|
42
|
+
federation.setCollectionDispatcher("objects", Object$1, "/collections/{id}", () => ({ items: [update] }));
|
|
43
|
+
federation.setOrderedCollectionDispatcher("ordered", Object$1, "/ordered/{id}", () => ({ items: [update] }));
|
|
44
|
+
for (const accept of ACCEPTS) for (const path of [
|
|
45
|
+
"/actors/app",
|
|
46
|
+
"/notes/1",
|
|
47
|
+
"/actors/app/followers",
|
|
48
|
+
"/actors/app/followers?cursor=a",
|
|
49
|
+
"/collections/1",
|
|
50
|
+
"/collections/1?cursor=a",
|
|
51
|
+
"/ordered/1",
|
|
52
|
+
"/ordered/1?cursor=a"
|
|
53
|
+
]) {
|
|
54
|
+
const response = await federation.fetch(new Request(`https://example.com${path}`, { headers: { Accept: accept } }), { contextData: void 0 });
|
|
55
|
+
assertEquals(response.status, 200, path);
|
|
56
|
+
assertEquals(response.headers.get("Content-Type"), "application/activity+json");
|
|
57
|
+
assertEquals(response.headers.get("Vary"), "Accept");
|
|
58
|
+
const values = attachmentValues(await response.json());
|
|
59
|
+
assert(values.length > 0, path);
|
|
60
|
+
for (const value of values) {
|
|
61
|
+
assert(Array.isArray(value), path);
|
|
62
|
+
assertEquals(value.length, count, path);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
test("attachment responses: helpers normalize without changing the vocabulary cache", async () => {
|
|
68
|
+
const json = await profile(1).toJsonLd();
|
|
69
|
+
const actor = await Service.fromJsonLd(json, { contextLoader: mockDocumentLoader });
|
|
70
|
+
const before = structuredClone(await actor.toJsonLd());
|
|
71
|
+
for (const options of [void 0, { contextLoader: mockDocumentLoader }]) {
|
|
72
|
+
const response = await respondWithObject(actor, options);
|
|
73
|
+
assert(Array.isArray((await response.json()).attachment));
|
|
74
|
+
for (const accept of ACCEPTS) {
|
|
75
|
+
const acceptable = await respondWithObjectIfAcceptable(actor, new Request("https://example.com/", { headers: { Accept: accept } }), options);
|
|
76
|
+
assert(acceptable != null);
|
|
77
|
+
assert(Array.isArray((await acceptable.json()).attachment));
|
|
78
|
+
assertEquals(acceptable.headers.get("Vary"), "Accept");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
assertEquals(await actor.toJsonLd(), before);
|
|
82
|
+
assertEquals(await respondWithObjectIfAcceptable(actor, new Request("https://example.com/", { headers: { Accept: "text/html" } })), null);
|
|
83
|
+
});
|
|
84
|
+
test("attachment responses: cached actor with deep JSON data remains servable", async () => {
|
|
85
|
+
let data = "leaf";
|
|
86
|
+
for (let i = 0; i < 70; i++) data = { child: data };
|
|
87
|
+
const original = {
|
|
88
|
+
"@context": ["https://www.w3.org/ns/activitystreams", { data: {
|
|
89
|
+
"@id": "https://example.com/data",
|
|
90
|
+
"@type": "@json"
|
|
91
|
+
} }],
|
|
92
|
+
type: "Service",
|
|
93
|
+
id: "https://example.com/actors/app",
|
|
94
|
+
preferredUsername: "app",
|
|
95
|
+
attachment: {
|
|
96
|
+
type: "Note",
|
|
97
|
+
content: "cached attachment"
|
|
98
|
+
},
|
|
99
|
+
data
|
|
100
|
+
};
|
|
101
|
+
const actor = await Service.fromJsonLd(original, { contextLoader: mockDocumentLoader });
|
|
102
|
+
const before = structuredClone(await actor.toJsonLd());
|
|
103
|
+
const federation = createFederation({ kv: new MemoryKvStore() });
|
|
104
|
+
federation.setActorDispatcher("/actors/{identifier}", () => actor);
|
|
105
|
+
for (const accept of ACCEPTS) {
|
|
106
|
+
const response = await federation.fetch(new Request("https://example.com/actors/app", { headers: { Accept: accept } }), { contextData: void 0 });
|
|
107
|
+
assertEquals(response.status, 200);
|
|
108
|
+
assertEquals(await response.json(), before);
|
|
109
|
+
}
|
|
110
|
+
assertEquals(await actor.toJsonLd(), before);
|
|
111
|
+
});
|
|
112
|
+
test("attachment responses: uncached collections serve unsigned cached children with deep or large JSON data", async () => {
|
|
113
|
+
let deep = "leaf";
|
|
114
|
+
for (let i = 0; i < 70; i++) deep = { child: deep };
|
|
115
|
+
for (const data of [deep, Array.from({ length: 100001 }, () => "leaf")]) {
|
|
116
|
+
const original = {
|
|
117
|
+
"@context": ["https://www.w3.org/ns/activitystreams", { data: {
|
|
118
|
+
"@id": "https://example.com/data",
|
|
119
|
+
"@type": "@json"
|
|
120
|
+
} }],
|
|
121
|
+
type: "Note",
|
|
122
|
+
id: "https://example.com/notes/cached",
|
|
123
|
+
content: "unsigned cached child",
|
|
124
|
+
data
|
|
125
|
+
};
|
|
126
|
+
const note = await Note.fromJsonLd(original, { contextLoader: mockDocumentLoader });
|
|
127
|
+
const before = structuredClone(await note.toJsonLd());
|
|
128
|
+
const collection = new OrderedCollection({ items: [note] });
|
|
129
|
+
const options = { contextLoader: mockDocumentLoader };
|
|
130
|
+
const serialized = structuredClone(await collection.toJsonLd(options));
|
|
131
|
+
for (const response of [await respondWithObject(collection, options), ...await Promise.all(ACCEPTS.map((accept) => respondWithObjectIfAcceptable(collection, new Request("https://example.com/", { headers: { Accept: accept } }), options)))]) {
|
|
132
|
+
assert(response != null);
|
|
133
|
+
assertEquals(response.status, 200);
|
|
134
|
+
assertEquals(await response.json(), serialized);
|
|
135
|
+
}
|
|
136
|
+
assertEquals(await note.toJsonLd(), before);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
test("attachment responses: large cached collection remains servable", async () => {
|
|
140
|
+
const original = {
|
|
141
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
142
|
+
type: "OrderedCollection",
|
|
143
|
+
id: "https://example.com/collection",
|
|
144
|
+
orderedItems: Array.from({ length: 100001 }, (_, i) => `https://example.com/items/${i}`)
|
|
145
|
+
};
|
|
146
|
+
const collection = await OrderedCollection.fromJsonLd(original, { contextLoader: mockDocumentLoader });
|
|
147
|
+
const before = structuredClone(await collection.toJsonLd());
|
|
148
|
+
const response = await respondWithObject(collection, { contextLoader: mockDocumentLoader });
|
|
149
|
+
assertEquals(response.status, 200);
|
|
150
|
+
assertEquals(await response.json(), before);
|
|
151
|
+
assertEquals(await collection.toJsonLd(), before);
|
|
152
|
+
});
|
|
153
|
+
test("attachment responses: cached signed roots pass through without invalidating their JCS proof", async () => {
|
|
154
|
+
const signed = await signObject(new Note({
|
|
155
|
+
id: new URL("https://example.com/notes/signed"),
|
|
156
|
+
attachments: [new Note({ content: "signed attachment" })]
|
|
157
|
+
}), ed25519PrivateKey, ed25519Multikey.id, { contextLoader: mockDocumentLoader });
|
|
158
|
+
const json = await signed.toJsonLd({
|
|
159
|
+
format: "compact",
|
|
160
|
+
contextLoader: mockDocumentLoader
|
|
161
|
+
});
|
|
162
|
+
const cached = await Note.fromJsonLd(json, { contextLoader: mockDocumentLoader });
|
|
163
|
+
const proofs = [];
|
|
164
|
+
for await (const proof of signed.getProofs()) proofs.push(proof);
|
|
165
|
+
assertEquals(proofs.length, 1);
|
|
166
|
+
const verification = {
|
|
167
|
+
contextLoader: mockDocumentLoader,
|
|
168
|
+
documentLoader: mockDocumentLoader
|
|
169
|
+
};
|
|
170
|
+
assert(await verifyProof(json, proofs[0], verification) != null);
|
|
171
|
+
const options = { contextLoader: mockDocumentLoader };
|
|
172
|
+
for (const response of [await respondWithObject(cached, options), ...await Promise.all(ACCEPTS.map((accept) => respondWithObjectIfAcceptable(cached, new Request("https://example.com/", { headers: { Accept: accept } }), options)))]) {
|
|
173
|
+
assert(response != null);
|
|
174
|
+
assertEquals(response.status, 200);
|
|
175
|
+
const body = await response.json();
|
|
176
|
+
assertEquals(body, json);
|
|
177
|
+
assert(await verifyProof(body, proofs[0], verification) != null);
|
|
178
|
+
}
|
|
179
|
+
assertEquals(await cached.toJsonLd(), json);
|
|
180
|
+
});
|
|
181
|
+
//#endregion
|
|
182
|
+
export {};
|
|
@@ -5,7 +5,7 @@ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
|
5
5
|
import { i as assertExists, n as assertStrictEquals } from "../std__assert-DflMZha5.mjs";
|
|
6
6
|
import { t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
|
|
7
7
|
import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
|
|
8
|
-
import { n as createFederationBuilder } from "../builder-
|
|
8
|
+
import { n as createFederationBuilder } from "../builder-NquOFkEx.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
import { Activity, Note, Person } from "@fedify/vocab";
|
|
11
11
|
//#region src/federation/builder.test.ts
|
|
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import "../std__assert-DflMZha5.mjs";
|
|
6
|
-
import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-
|
|
6
|
+
import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-BD6-SZ6O.mjs";
|
|
7
7
|
import { test } from "@fedify/fixture";
|
|
8
8
|
import { decodeHex } from "byte-encodings/hex";
|
|
9
9
|
//#region src/federation/collection.test.ts
|