@fedify/fedify 2.4.6-dev.2628 → 2.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attachment-arrays-5yDbmjEb.mjs +16 -0
- package/dist/{builder-kj5boG2l.mjs → builder-CadJYxhX.mjs} +2 -2
- package/dist/callback-DPDs_dxC.d.mts +5280 -0
- package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
- package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
- package/dist/{client-5SIFzW3q.mjs → client-DU3owZBD.mjs} +86 -11
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- package/dist/compat/mod.cjs +1 -1
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/mod.js +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{compound-proof-BoNAYSHt.mjs → compound-proof-CbWKyg2H.mjs} +2 -2
- package/dist/{context-D0gFIgev.d.cts → context-DUwicVx-.d.cts} +31 -14
- package/dist/{context-CVOOd9pD.d.ts → context-iGMHITvS.d.ts} +31 -14
- package/dist/{deno-ksnVeCA7.mjs → deno-BKSRi6w3.mjs} +1 -1
- package/dist/{docloader-BhVNi06k.mjs → docloader-BcDiJfFl.mjs} +2 -2
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/compound-fanout.test.mjs +4 -4
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler-compound-proof.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +206 -14
- package/dist/federation/hashlink-media.test.mjs +2 -2
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox-report.test.mjs +5 -5
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1188 -13
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +3 -3
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +1 -1
- package/dist/federation/outgoing-proof.test.mjs +4 -4
- package/dist/federation/portable-actor.test.mjs +3 -3
- package/dist/federation/portable-chain.test.mjs +3 -3
- package/dist/federation/portable-collection.test.mjs +4 -4
- package/dist/federation/portable-delivery.test.mjs +2 -2
- package/dist/federation/portable-gateway-keys.test.mjs +5 -5
- package/dist/federation/portable-inbox.test.mjs +4 -4
- package/dist/federation/portable-parse-uri.test.mjs +1 -1
- package/dist/federation/portable-route-activity.test.mjs +2 -2
- package/dist/federation/portable.test.mjs +3 -3
- package/dist/federation/send.test.mjs +293 -3
- package/dist/federation/tasks/enqueue.test.mjs +1 -1
- package/dist/federation/tasks/tasks.test.mjs +2 -2
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{federation-BtPz9sr3.cjs → federation-CM4nzbhO.cjs} +501 -145
- package/dist/{http-BSARoDPh.mjs → http-B6sfb5xN.mjs} +8 -6
- package/dist/{http-rH230xCD.js → http-BwgldAIk.js} +2803 -2633
- package/dist/{http-CeVcKQMZ.cjs → http-Tj9eQ_rd.cjs} +2640 -2458
- package/dist/{inbox-BdZenpZQ.mjs → inbox-B7NVkb8j.mjs} +2 -2
- package/dist/{key-VEL1QqHF.d.cts → key-CIdQA7Pc.d.cts} +5 -5
- package/dist/{key-CyCcut3h.d.ts → key-CjtBFzaE.d.ts} +5 -5
- package/dist/{kv-cache-CNfNI_95.js → kv-cache-C-5yfTw-.js} +1 -1
- package/dist/{kv-cache-Cxn7pNMx.mjs → kv-cache-CvWuigft.mjs} +1 -1
- package/dist/{kv-cache-BpGIONmd.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
- package/dist/{ld-DJZrjNuN.mjs → ld-BGnZDnia.mjs} +176 -24
- package/dist/ld-signature-D1tFSFK8.mjs +23 -0
- package/dist/{metrics-DtxsYIkN.mjs → metrics-DHUP4F1-.mjs} +1 -1
- package/dist/{middleware-DyEjt33n.mjs → middleware-CUb31OGG.mjs} +1 -1
- package/dist/{middleware-DDvck2q9.js → middleware-DX8wADUa.js} +452 -98
- package/dist/{middleware-DblGj642.mjs → middleware-mRXKHq68.mjs} +445 -176
- package/dist/{mod-B1Qt5cQQ.d.ts → mod-B6s6hA4y.d.ts} +3 -3
- package/dist/{mod-ss0wBUH1.d.cts → mod-CJf5GcVD.d.cts} +3 -3
- package/dist/{mod-makPMVMg.d.cts → mod-CSlxqNto.d.cts} +1 -1
- package/dist/{mod-CpyjFA9s.d.ts → mod-D2DiA8u5.d.cts} +29 -7
- package/dist/{mod-BTxJG7ZH.d.cts → mod-DKRf1FLm.d.ts} +29 -7
- package/dist/{mod-B5COx5Wd.d.ts → mod-Dqu6Dl1k.d.ts} +1 -1
- package/dist/mod.cjs +6 -6
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +6 -6
- package/dist/nodeinfo/client.test.mjs +432 -4
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/{outgoing-jsonld-4IJqPYos.mjs → outgoing-jsonld-Dsca6G_Y.mjs} +35 -4
- package/dist/{owner-2vfqhUJw.mjs → owner-DEiBiiqR.mjs} +4 -4
- package/dist/{portable-collection-Cs--KD5A.cjs → portable-collection--h11WDIi.cjs} +3 -2
- package/dist/{portable-collection-DKJwGO8S.mjs → portable-collection-D0-tInp2.mjs} +2 -2
- package/dist/{portable-collection-B7AQ_dW7.js → portable-collection-M6d5I5JQ.js} +3 -2
- package/dist/{portable-key-DXGepvtD.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
- package/dist/portable-verifier-CPA86vIP.js +22 -0
- package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
- package/dist/{proof-DW0FK6Cp.mjs → proof-C4pwAF2k.mjs} +31 -11
- package/dist/{send-CqsocpvF.mjs → send-ivzJCtb-.mjs} +100 -22
- package/dist/sig/compound-proof-discovery.test.mjs +1 -1
- package/dist/sig/compound-proof-producer.test.mjs +1 -1
- package/dist/sig/compound-proof-verification.test.mjs +2 -2
- package/dist/sig/compound-proof.test.mjs +3 -3
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key-types.test.d.mts +162 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +572 -7
- package/dist/sig/mitra-receive-interop.test.mjs +4 -4
- package/dist/sig/mitra-send-interop.test.mjs +3 -3
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/portable-collection.test.mjs +1 -1
- package/dist/sig/portable-interop.test.mjs +3 -3
- package/dist/sig/portable-key.test.mjs +5 -5
- package/dist/sig/proof.test.mjs +100 -6
- package/dist/sig/tootik-request-interop.test.mjs +4 -4
- package/dist/sig/tootik-send-interop.test.mjs +3 -3
- package/dist/sig/verification.test.mjs +3 -3
- package/dist/{temporal-Dm2E1-vs.mjs → temporal-B6OlxwK_.mjs} +3 -5
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +3 -5045
- package/dist/{transformers-DAtXl_Kc.js → transformers-BlJ53iKs.js} +3 -2
- package/dist/{transformers-BalCrSsr.cjs → transformers-aIK89ibB.cjs} +3 -2
- package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
- package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/kv-cache.test.mjs +1 -1
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/dist/utils/portable-verifier.test.d.mts +2 -0
- package/dist/utils/portable-verifier.test.mjs +126 -0
- package/package.json +6 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "temporal-polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
+
import { t as getDefaultPortableObjectVerifier } from "./portable-verifier-CPA86vIP.js";
|
|
3
4
|
import { getLogger } from "@logtape/logtape";
|
|
4
5
|
//#region src/compat/transformers.ts
|
|
5
6
|
const logger = getLogger([
|
|
@@ -29,7 +30,7 @@ function autoIdAssigner(activity, context) {
|
|
|
29
30
|
if (activity.id != null) return activity;
|
|
30
31
|
const id = new URL(`/#${activity.constructor.name}/${crypto.randomUUID()}`, context.origin);
|
|
31
32
|
logger.warn("As the activity to send does not have an id, a new id {id} has been generated for it. However, it is recommended to explicitly set the id for the activity.", { id: id.href });
|
|
32
|
-
return activity.clone({ id });
|
|
33
|
+
return activity.clone({ id }, { verifyPortableObject: getDefaultPortableObjectVerifier(activity) });
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* An activity transformer that dehydrates the actor property of an activity
|
|
@@ -78,7 +79,7 @@ function autoIdAssigner(activity, context) {
|
|
|
78
79
|
*/
|
|
79
80
|
function actorDehydrator(activity, _context) {
|
|
80
81
|
if (activity.actorIds.length < 1) return activity;
|
|
81
|
-
return activity.clone({ actors: activity.actorIds });
|
|
82
|
+
return activity.clone({ actors: activity.actorIds }, { verifyPortableObject: getDefaultPortableObjectVerifier(activity) });
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
84
85
|
* Gets the default activity transformers that are applied to all outgoing
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
2
|
+
const require_portable_verifier = require("./portable-verifier-DiLU8c9T.cjs");
|
|
2
3
|
//#region src/compat/transformers.ts
|
|
3
4
|
const logger = (0, require("@logtape/logtape").getLogger)([
|
|
4
5
|
"fedify",
|
|
@@ -27,7 +28,7 @@ function autoIdAssigner(activity, context) {
|
|
|
27
28
|
if (activity.id != null) return activity;
|
|
28
29
|
const id = new URL(`/#${activity.constructor.name}/${crypto.randomUUID()}`, context.origin);
|
|
29
30
|
logger.warn("As the activity to send does not have an id, a new id {id} has been generated for it. However, it is recommended to explicitly set the id for the activity.", { id: id.href });
|
|
30
|
-
return activity.clone({ id });
|
|
31
|
+
return activity.clone({ id }, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) });
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* An activity transformer that dehydrates the actor property of an activity
|
|
@@ -76,7 +77,7 @@ function autoIdAssigner(activity, context) {
|
|
|
76
77
|
*/
|
|
77
78
|
function actorDehydrator(activity, _context) {
|
|
78
79
|
if (activity.actorIds.length < 1) return activity;
|
|
79
|
-
return activity.clone({ actors: activity.actorIds });
|
|
80
|
+
return activity.clone({ actors: activity.actorIds }, { verifyPortableObject: require_portable_verifier.getDefaultPortableObjectVerifier(activity) });
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
83
|
* Gets the default activity transformers that are applied to all outgoing
|
|
@@ -2,7 +2,7 @@ import { Temporal } from "temporal-polyfill";
|
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
3
|
import { getLogger } from "@logtape/logtape";
|
|
4
4
|
import { FetchError, UrlError, getUserAgent } from "@fedify/vocab-runtime";
|
|
5
|
-
import { openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
5
|
+
import { detectRuntime, lookupAllAddressesBounded, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
6
6
|
//#region src/utils/body.ts
|
|
7
7
|
/** Decoded JSON body limit: 16 MiB. @internal */
|
|
8
8
|
const MAX_BODY_SIZE = 16 * 1024 * 1024;
|
|
@@ -24,13 +24,18 @@ function validateBodySizeLimit(maxBytes) {
|
|
|
24
24
|
* @param message The response or request to read.
|
|
25
25
|
* @param maxBytes The maximum number of decoded bytes to read.
|
|
26
26
|
* @param url The URL to include in errors and logs.
|
|
27
|
+
* @param signal An optional signal for cancelling the body read.
|
|
27
28
|
* @returns The decoded body text.
|
|
28
29
|
* @throws {BodyTooLargeError} If the body exceeds the limit.
|
|
29
30
|
* @internal
|
|
30
31
|
*/
|
|
31
|
-
async function readBoundedText(message, maxBytes, url) {
|
|
32
|
+
async function readBoundedText(message, maxBytes, url, signal) {
|
|
32
33
|
validateBodySizeLimit(maxBytes);
|
|
33
34
|
const reader = message.body?.getReader();
|
|
35
|
+
const onAbort = () => {
|
|
36
|
+
if (reader != null) reader.cancel(signal?.reason).catch(() => {});
|
|
37
|
+
};
|
|
38
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
34
39
|
const tooLarge = () => {
|
|
35
40
|
getLogger([
|
|
36
41
|
"fedify",
|
|
@@ -43,6 +48,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
43
48
|
throw new BodyTooLargeError(url, maxBytes);
|
|
44
49
|
};
|
|
45
50
|
try {
|
|
51
|
+
signal?.throwIfAborted();
|
|
46
52
|
const length = message.headers.get("Content-Length");
|
|
47
53
|
const encoding = message.headers.get("Content-Encoding");
|
|
48
54
|
if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
|
|
@@ -50,6 +56,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
50
56
|
let size = 0;
|
|
51
57
|
const textReader = new ReadableStream({ async pull(controller) {
|
|
52
58
|
const { done, value } = await reader.read();
|
|
59
|
+
signal?.throwIfAborted();
|
|
53
60
|
if (done) {
|
|
54
61
|
controller.close();
|
|
55
62
|
return;
|
|
@@ -62,6 +69,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
62
69
|
const chunks = [];
|
|
63
70
|
while (true) {
|
|
64
71
|
const { done, value } = await textReader.read();
|
|
72
|
+
signal?.throwIfAborted();
|
|
65
73
|
if (done) break;
|
|
66
74
|
chunks.push(value);
|
|
67
75
|
}
|
|
@@ -73,6 +81,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
73
81
|
if (reader != null) reader.cancel(error).catch(() => {});
|
|
74
82
|
throw error;
|
|
75
83
|
} finally {
|
|
84
|
+
signal?.removeEventListener("abort", onAbort);
|
|
76
85
|
reader?.releaseLock();
|
|
77
86
|
}
|
|
78
87
|
}
|
|
@@ -84,6 +93,8 @@ const logger = getLogger([
|
|
|
84
93
|
"client"
|
|
85
94
|
]);
|
|
86
95
|
const DEFAULT_MAX_REDIRECTION = 5;
|
|
96
|
+
const DEFAULT_TIMEOUT = 1e4;
|
|
97
|
+
const MAX_TIMEOUT = 2147483647;
|
|
87
98
|
/**
|
|
88
99
|
* Fetches a URL while guarding against SSRF. Every request—including each
|
|
89
100
|
* redirect hop—is made in its own session opened with `openPublicFetch()`,
|
|
@@ -100,20 +111,27 @@ const DEFAULT_MAX_REDIRECTION = 5;
|
|
|
100
111
|
* @param headers The request headers.
|
|
101
112
|
* @param consume The function to consume the final response with.
|
|
102
113
|
* @param deps The dependencies.
|
|
114
|
+
* @param signal The signal for the whole NodeInfo lookup.
|
|
103
115
|
* @returns The value returned by `consume`, or `null` if the URL is
|
|
104
116
|
* disallowed, its hostname cannot be resolved, or there are too many
|
|
105
117
|
* redirects.
|
|
106
118
|
* @internal
|
|
107
119
|
*/
|
|
108
|
-
async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
109
|
-
const openHop = deps.openHop ?? ((hopUrl) => openPublicFetch(hopUrl)
|
|
120
|
+
async function fetchPublicUrl(url, headers, consume, deps = {}, signal) {
|
|
121
|
+
const openHop = deps.openHop ?? ((hopUrl, signal) => openPublicFetch(hopUrl, detectRuntime() === "node" ? {
|
|
122
|
+
signal,
|
|
123
|
+
lookup: (hostname) => lookupAllAddressesBounded(hostname, signal)
|
|
124
|
+
} : { signal }));
|
|
110
125
|
let current = url instanceof URL ? url : new URL(url);
|
|
111
126
|
let redirected = 0;
|
|
127
|
+
const visited = /* @__PURE__ */ new Set([redirectKey(current)]);
|
|
112
128
|
while (true) {
|
|
129
|
+
signal?.throwIfAborted();
|
|
113
130
|
let session;
|
|
114
131
|
try {
|
|
115
|
-
session = await openHop(current.href);
|
|
132
|
+
session = await openHop(current.href, signal);
|
|
116
133
|
} catch (e) {
|
|
134
|
+
signal?.throwIfAborted();
|
|
117
135
|
if (e instanceof UrlError) {
|
|
118
136
|
if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
|
|
119
137
|
url: current.href,
|
|
@@ -129,10 +147,16 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
|
129
147
|
}
|
|
130
148
|
let location;
|
|
131
149
|
try {
|
|
150
|
+
signal?.throwIfAborted();
|
|
132
151
|
const response = await session.fetch(current, {
|
|
133
152
|
headers,
|
|
134
|
-
redirect: "manual"
|
|
153
|
+
redirect: "manual",
|
|
154
|
+
signal
|
|
135
155
|
});
|
|
156
|
+
if (signal?.aborted) {
|
|
157
|
+
cancelBody(response, current);
|
|
158
|
+
signal.throwIfAborted();
|
|
159
|
+
}
|
|
136
160
|
if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
|
|
137
161
|
location = response.headers.get("Location");
|
|
138
162
|
cancelBody(response, current);
|
|
@@ -155,9 +179,20 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
|
155
179
|
});
|
|
156
180
|
return null;
|
|
157
181
|
}
|
|
182
|
+
const key = redirectKey(next);
|
|
183
|
+
if (visited.has(key)) {
|
|
184
|
+
logger.error("Redirect cycle while fetching NodeInfo: {url}.", { url: next.href });
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
visited.add(key);
|
|
158
188
|
current = next;
|
|
159
189
|
}
|
|
160
190
|
}
|
|
191
|
+
function redirectKey(url) {
|
|
192
|
+
const withoutFragment = new URL(url);
|
|
193
|
+
withoutFragment.hash = "";
|
|
194
|
+
return withoutFragment.href;
|
|
195
|
+
}
|
|
161
196
|
/**
|
|
162
197
|
* Starts cancelling a response body that is not read, without waiting for it
|
|
163
198
|
* to settle. The cancellation of a branch of a tee (e.g., a body cloned by
|
|
@@ -188,6 +223,46 @@ async function getNodeInfo(url, options = {}) {
|
|
|
188
223
|
* @internal
|
|
189
224
|
*/
|
|
190
225
|
async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
226
|
+
const timeout = resolveTimeout(options.timeout);
|
|
227
|
+
if (timeout == null && options.signal == null) return await getNodeInfoWithSignal(url, options, deps);
|
|
228
|
+
const controller = new AbortController();
|
|
229
|
+
const timeoutReason = timeout == null ? void 0 : new DOMException(`The NodeInfo lookup timed out after ${timeout} ms.`, "TimeoutError");
|
|
230
|
+
const timer = timeout == null ? void 0 : setTimeout(() => controller.abort(timeoutReason), timeout);
|
|
231
|
+
const onCallerAbort = () => controller.abort(options.signal?.reason);
|
|
232
|
+
options.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
233
|
+
if (options.signal?.aborted) onCallerAbort();
|
|
234
|
+
let onAbort;
|
|
235
|
+
const aborted = new Promise((_, reject) => {
|
|
236
|
+
onAbort = () => reject(controller.signal.reason);
|
|
237
|
+
controller.signal.addEventListener("abort", onAbort, { once: true });
|
|
238
|
+
});
|
|
239
|
+
const loading = getNodeInfoWithSignal(url, options, deps, controller.signal);
|
|
240
|
+
loading.catch(() => {});
|
|
241
|
+
try {
|
|
242
|
+
return await Promise.race([loading, aborted]);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (!controller.signal.aborted) throw error;
|
|
245
|
+
if (controller.signal.reason === timeoutReason) logger.error("Timed out after {timeout} ms while fetching NodeInfo: {url}", {
|
|
246
|
+
timeout,
|
|
247
|
+
url: url.toString()
|
|
248
|
+
});
|
|
249
|
+
else logger.debug("Cancelled NodeInfo lookup for {url}.", { url: url.toString() });
|
|
250
|
+
return;
|
|
251
|
+
} finally {
|
|
252
|
+
clearTimeout(timer);
|
|
253
|
+
options.signal?.removeEventListener("abort", onCallerAbort);
|
|
254
|
+
if (onAbort != null) controller.signal.removeEventListener("abort", onAbort);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function resolveTimeout(timeout) {
|
|
258
|
+
if (timeout === void 0) return DEFAULT_TIMEOUT;
|
|
259
|
+
if (timeout === null) return null;
|
|
260
|
+
if (!Number.isFinite(timeout) || timeout <= 0) throw new RangeError(`The NodeInfo timeout must be a positive finite number of milliseconds, but got ${String(timeout)}.`);
|
|
261
|
+
const ms = Math.ceil(timeout);
|
|
262
|
+
if (ms > MAX_TIMEOUT) throw new RangeError(`The NodeInfo timeout must not be greater than ${MAX_TIMEOUT} milliseconds, but got ${timeout}.`);
|
|
263
|
+
return ms;
|
|
264
|
+
}
|
|
265
|
+
async function getNodeInfoWithSignal(url, options, deps, signal) {
|
|
191
266
|
try {
|
|
192
267
|
const headers = {
|
|
193
268
|
Accept: "application/json",
|
|
@@ -206,8 +281,8 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
|
206
281
|
cancelBody(response, wellKnownUrl);
|
|
207
282
|
return;
|
|
208
283
|
}
|
|
209
|
-
return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl)) };
|
|
210
|
-
}, deps);
|
|
284
|
+
return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl, signal)) };
|
|
285
|
+
}, deps, signal);
|
|
211
286
|
if (wellKnown == null) return void 0;
|
|
212
287
|
const wellKnownRd = wellKnown.rd;
|
|
213
288
|
const link = wellKnownRd?.links?.find((link) => link != null && "rel" in link && (link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.0" || link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.1") && "href" in link && link.href != null);
|
|
@@ -230,14 +305,14 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
|
230
305
|
cancelBody(response, nodeInfoUrl);
|
|
231
306
|
return;
|
|
232
307
|
}
|
|
233
|
-
return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl)) };
|
|
234
|
-
}, deps);
|
|
308
|
+
return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl, signal)) };
|
|
309
|
+
}, deps, signal);
|
|
235
310
|
if (document == null) return void 0;
|
|
236
311
|
const { data } = document;
|
|
237
312
|
if (options.parse === "none") return data;
|
|
238
313
|
return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
|
|
239
314
|
} catch (error) {
|
|
240
|
-
logger
|
|
315
|
+
logger[signal?.aborted ? "debug" : "error"]("Failed to fetch NodeInfo document from {url}: {error}", {
|
|
241
316
|
url: url.toString(),
|
|
242
317
|
error
|
|
243
318
|
});
|
|
@@ -23,13 +23,18 @@ function validateBodySizeLimit(maxBytes) {
|
|
|
23
23
|
* @param message The response or request to read.
|
|
24
24
|
* @param maxBytes The maximum number of decoded bytes to read.
|
|
25
25
|
* @param url The URL to include in errors and logs.
|
|
26
|
+
* @param signal An optional signal for cancelling the body read.
|
|
26
27
|
* @returns The decoded body text.
|
|
27
28
|
* @throws {BodyTooLargeError} If the body exceeds the limit.
|
|
28
29
|
* @internal
|
|
29
30
|
*/
|
|
30
|
-
async function readBoundedText(message, maxBytes, url) {
|
|
31
|
+
async function readBoundedText(message, maxBytes, url, signal) {
|
|
31
32
|
validateBodySizeLimit(maxBytes);
|
|
32
33
|
const reader = message.body?.getReader();
|
|
34
|
+
const onAbort = () => {
|
|
35
|
+
if (reader != null) reader.cancel(signal?.reason).catch(() => {});
|
|
36
|
+
};
|
|
37
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
33
38
|
const tooLarge = () => {
|
|
34
39
|
(0, _logtape_logtape.getLogger)([
|
|
35
40
|
"fedify",
|
|
@@ -42,6 +47,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
42
47
|
throw new BodyTooLargeError(url, maxBytes);
|
|
43
48
|
};
|
|
44
49
|
try {
|
|
50
|
+
signal?.throwIfAborted();
|
|
45
51
|
const length = message.headers.get("Content-Length");
|
|
46
52
|
const encoding = message.headers.get("Content-Encoding");
|
|
47
53
|
if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
|
|
@@ -49,6 +55,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
49
55
|
let size = 0;
|
|
50
56
|
const textReader = new ReadableStream({ async pull(controller) {
|
|
51
57
|
const { done, value } = await reader.read();
|
|
58
|
+
signal?.throwIfAborted();
|
|
52
59
|
if (done) {
|
|
53
60
|
controller.close();
|
|
54
61
|
return;
|
|
@@ -61,6 +68,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
61
68
|
const chunks = [];
|
|
62
69
|
while (true) {
|
|
63
70
|
const { done, value } = await textReader.read();
|
|
71
|
+
signal?.throwIfAborted();
|
|
64
72
|
if (done) break;
|
|
65
73
|
chunks.push(value);
|
|
66
74
|
}
|
|
@@ -72,6 +80,7 @@ async function readBoundedText(message, maxBytes, url) {
|
|
|
72
80
|
if (reader != null) reader.cancel(error).catch(() => {});
|
|
73
81
|
throw error;
|
|
74
82
|
} finally {
|
|
83
|
+
signal?.removeEventListener("abort", onAbort);
|
|
75
84
|
reader?.releaseLock();
|
|
76
85
|
}
|
|
77
86
|
}
|
|
@@ -83,6 +92,8 @@ const logger = (0, _logtape_logtape.getLogger)([
|
|
|
83
92
|
"client"
|
|
84
93
|
]);
|
|
85
94
|
const DEFAULT_MAX_REDIRECTION = 5;
|
|
95
|
+
const DEFAULT_TIMEOUT = 1e4;
|
|
96
|
+
const MAX_TIMEOUT = 2147483647;
|
|
86
97
|
/**
|
|
87
98
|
* Fetches a URL while guarding against SSRF. Every request—including each
|
|
88
99
|
* redirect hop—is made in its own session opened with `openPublicFetch()`,
|
|
@@ -99,20 +110,27 @@ const DEFAULT_MAX_REDIRECTION = 5;
|
|
|
99
110
|
* @param headers The request headers.
|
|
100
111
|
* @param consume The function to consume the final response with.
|
|
101
112
|
* @param deps The dependencies.
|
|
113
|
+
* @param signal The signal for the whole NodeInfo lookup.
|
|
102
114
|
* @returns The value returned by `consume`, or `null` if the URL is
|
|
103
115
|
* disallowed, its hostname cannot be resolved, or there are too many
|
|
104
116
|
* redirects.
|
|
105
117
|
* @internal
|
|
106
118
|
*/
|
|
107
|
-
async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
108
|
-
const openHop = deps.openHop ?? ((hopUrl) => (0, _fedify_vocab_runtime_internal.openPublicFetch)(hopUrl))
|
|
119
|
+
async function fetchPublicUrl(url, headers, consume, deps = {}, signal) {
|
|
120
|
+
const openHop = deps.openHop ?? ((hopUrl, signal) => (0, _fedify_vocab_runtime_internal.openPublicFetch)(hopUrl, (0, _fedify_vocab_runtime_internal.detectRuntime)() === "node" ? {
|
|
121
|
+
signal,
|
|
122
|
+
lookup: (hostname) => (0, _fedify_vocab_runtime_internal.lookupAllAddressesBounded)(hostname, signal)
|
|
123
|
+
} : { signal }));
|
|
109
124
|
let current = url instanceof URL ? url : new URL(url);
|
|
110
125
|
let redirected = 0;
|
|
126
|
+
const visited = /* @__PURE__ */ new Set([redirectKey(current)]);
|
|
111
127
|
while (true) {
|
|
128
|
+
signal?.throwIfAborted();
|
|
112
129
|
let session;
|
|
113
130
|
try {
|
|
114
|
-
session = await openHop(current.href);
|
|
131
|
+
session = await openHop(current.href, signal);
|
|
115
132
|
} catch (e) {
|
|
133
|
+
signal?.throwIfAborted();
|
|
116
134
|
if (e instanceof _fedify_vocab_runtime.UrlError) {
|
|
117
135
|
if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
|
|
118
136
|
url: current.href,
|
|
@@ -128,10 +146,16 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
|
128
146
|
}
|
|
129
147
|
let location;
|
|
130
148
|
try {
|
|
149
|
+
signal?.throwIfAborted();
|
|
131
150
|
const response = await session.fetch(current, {
|
|
132
151
|
headers,
|
|
133
|
-
redirect: "manual"
|
|
152
|
+
redirect: "manual",
|
|
153
|
+
signal
|
|
134
154
|
});
|
|
155
|
+
if (signal?.aborted) {
|
|
156
|
+
cancelBody(response, current);
|
|
157
|
+
signal.throwIfAborted();
|
|
158
|
+
}
|
|
135
159
|
if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
|
|
136
160
|
location = response.headers.get("Location");
|
|
137
161
|
cancelBody(response, current);
|
|
@@ -154,9 +178,20 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
|
154
178
|
});
|
|
155
179
|
return null;
|
|
156
180
|
}
|
|
181
|
+
const key = redirectKey(next);
|
|
182
|
+
if (visited.has(key)) {
|
|
183
|
+
logger.error("Redirect cycle while fetching NodeInfo: {url}.", { url: next.href });
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
visited.add(key);
|
|
157
187
|
current = next;
|
|
158
188
|
}
|
|
159
189
|
}
|
|
190
|
+
function redirectKey(url) {
|
|
191
|
+
const withoutFragment = new URL(url);
|
|
192
|
+
withoutFragment.hash = "";
|
|
193
|
+
return withoutFragment.href;
|
|
194
|
+
}
|
|
160
195
|
/**
|
|
161
196
|
* Starts cancelling a response body that is not read, without waiting for it
|
|
162
197
|
* to settle. The cancellation of a branch of a tee (e.g., a body cloned by
|
|
@@ -187,6 +222,46 @@ async function getNodeInfo(url, options = {}) {
|
|
|
187
222
|
* @internal
|
|
188
223
|
*/
|
|
189
224
|
async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
225
|
+
const timeout = resolveTimeout(options.timeout);
|
|
226
|
+
if (timeout == null && options.signal == null) return await getNodeInfoWithSignal(url, options, deps);
|
|
227
|
+
const controller = new AbortController();
|
|
228
|
+
const timeoutReason = timeout == null ? void 0 : new DOMException(`The NodeInfo lookup timed out after ${timeout} ms.`, "TimeoutError");
|
|
229
|
+
const timer = timeout == null ? void 0 : setTimeout(() => controller.abort(timeoutReason), timeout);
|
|
230
|
+
const onCallerAbort = () => controller.abort(options.signal?.reason);
|
|
231
|
+
options.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
232
|
+
if (options.signal?.aborted) onCallerAbort();
|
|
233
|
+
let onAbort;
|
|
234
|
+
const aborted = new Promise((_, reject) => {
|
|
235
|
+
onAbort = () => reject(controller.signal.reason);
|
|
236
|
+
controller.signal.addEventListener("abort", onAbort, { once: true });
|
|
237
|
+
});
|
|
238
|
+
const loading = getNodeInfoWithSignal(url, options, deps, controller.signal);
|
|
239
|
+
loading.catch(() => {});
|
|
240
|
+
try {
|
|
241
|
+
return await Promise.race([loading, aborted]);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (!controller.signal.aborted) throw error;
|
|
244
|
+
if (controller.signal.reason === timeoutReason) logger.error("Timed out after {timeout} ms while fetching NodeInfo: {url}", {
|
|
245
|
+
timeout,
|
|
246
|
+
url: url.toString()
|
|
247
|
+
});
|
|
248
|
+
else logger.debug("Cancelled NodeInfo lookup for {url}.", { url: url.toString() });
|
|
249
|
+
return;
|
|
250
|
+
} finally {
|
|
251
|
+
clearTimeout(timer);
|
|
252
|
+
options.signal?.removeEventListener("abort", onCallerAbort);
|
|
253
|
+
if (onAbort != null) controller.signal.removeEventListener("abort", onAbort);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function resolveTimeout(timeout) {
|
|
257
|
+
if (timeout === void 0) return DEFAULT_TIMEOUT;
|
|
258
|
+
if (timeout === null) return null;
|
|
259
|
+
if (!Number.isFinite(timeout) || timeout <= 0) throw new RangeError(`The NodeInfo timeout must be a positive finite number of milliseconds, but got ${String(timeout)}.`);
|
|
260
|
+
const ms = Math.ceil(timeout);
|
|
261
|
+
if (ms > MAX_TIMEOUT) throw new RangeError(`The NodeInfo timeout must not be greater than ${MAX_TIMEOUT} milliseconds, but got ${timeout}.`);
|
|
262
|
+
return ms;
|
|
263
|
+
}
|
|
264
|
+
async function getNodeInfoWithSignal(url, options, deps, signal) {
|
|
190
265
|
try {
|
|
191
266
|
const headers = {
|
|
192
267
|
Accept: "application/json",
|
|
@@ -205,8 +280,8 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
|
205
280
|
cancelBody(response, wellKnownUrl);
|
|
206
281
|
return;
|
|
207
282
|
}
|
|
208
|
-
return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl)) };
|
|
209
|
-
}, deps);
|
|
283
|
+
return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl, signal)) };
|
|
284
|
+
}, deps, signal);
|
|
210
285
|
if (wellKnown == null) return void 0;
|
|
211
286
|
const wellKnownRd = wellKnown.rd;
|
|
212
287
|
const link = wellKnownRd?.links?.find((link) => link != null && "rel" in link && (link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.0" || link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.1") && "href" in link && link.href != null);
|
|
@@ -229,14 +304,14 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
|
229
304
|
cancelBody(response, nodeInfoUrl);
|
|
230
305
|
return;
|
|
231
306
|
}
|
|
232
|
-
return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl)) };
|
|
233
|
-
}, deps);
|
|
307
|
+
return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl, signal)) };
|
|
308
|
+
}, deps, signal);
|
|
234
309
|
if (document == null) return void 0;
|
|
235
310
|
const { data } = document;
|
|
236
311
|
if (options.parse === "none") return data;
|
|
237
312
|
return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
|
|
238
313
|
} catch (error) {
|
|
239
|
-
logger
|
|
314
|
+
logger[signal?.aborted ? "debug" : "error"]("Failed to fetch NodeInfo document from {url}: {error}", {
|
|
240
315
|
url: url.toString(),
|
|
241
316
|
error
|
|
242
317
|
});
|
|
@@ -5,9 +5,9 @@ import { t as esm_default } from "../esm-BHXXx4Wx.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
6
6
|
import "../std__assert-DvMDRPes.mjs";
|
|
7
7
|
import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
|
|
8
|
-
import { p as verifyRequest } from "../http-
|
|
8
|
+
import { p as verifyRequest } from "../http-B6sfb5xN.mjs";
|
|
9
9
|
import { i as rsaPrivateKey2 } from "../keys-DIJNHW-Y.mjs";
|
|
10
|
-
import { n as getAuthenticatedDocumentLoader, t as createAuthenticatedDocumentLoader } from "../docloader-
|
|
10
|
+
import { n as getAuthenticatedDocumentLoader, t as createAuthenticatedDocumentLoader } from "../docloader-BcDiJfFl.mjs";
|
|
11
11
|
import { configure, reset } from "@logtape/logtape";
|
|
12
12
|
import { FetchError, UrlError } from "@fedify/vocab-runtime";
|
|
13
13
|
import { mockDocumentLoader, test } from "@fedify/fixture";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Temporal } from "temporal-polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as kvCache, t as MockKvStore } from "../kv-cache-
|
|
4
|
+
import { n as kvCache, t as MockKvStore } from "../kv-cache-CvWuigft.mjs";
|
|
5
5
|
import { preloadedContexts } from "@fedify/vocab-runtime";
|
|
6
6
|
import { deepStrictEqual, throws } from "node:assert";
|
|
7
7
|
import { createTestMeterProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
package/dist/utils/mod.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const require_kv_cache = require("../kv-cache-
|
|
3
|
+
const require_kv_cache = require("../kv-cache-Vbq0yM7W.cjs");
|
|
4
4
|
exports.getAuthenticatedDocumentLoader = require_kv_cache.getAuthenticatedDocumentLoader;
|
|
5
5
|
exports.kvCache = require_kv_cache.kvCache;
|
package/dist/utils/mod.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-
|
|
2
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-CJf5GcVD.cjs";
|
|
3
3
|
export { getAuthenticatedDocumentLoader, kvCache };
|
package/dist/utils/mod.d.ts
CHANGED
package/dist/utils/mod.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Temporal } from "temporal-polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../kv-cache-
|
|
3
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../kv-cache-C-5yfTw-.js";
|
|
4
4
|
export { getAuthenticatedDocumentLoader, kvCache };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import "temporal-polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
|
|
5
|
+
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
6
|
+
import { t as assertInstanceOf } from "../assert_instance_of-mrXWWNY-.mjs";
|
|
7
|
+
import "../std__assert-DvMDRPes.mjs";
|
|
8
|
+
import { t as assertStrictEquals } from "../assert_strict_equals-CYvBmkpC.mjs";
|
|
9
|
+
import { k as getDefaultPortableObjectVerifier } from "../ld-BGnZDnia.mjs";
|
|
10
|
+
import { a as signObject, r as createProof } from "../proof-C4pwAF2k.mjs";
|
|
11
|
+
import { n as ed25519PrivateKey, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
|
|
12
|
+
import { A as autoIdAssigner, k as actorDehydrator, n as FederationImpl } from "../middleware-mRXKHq68.mjs";
|
|
13
|
+
import { configure, reset } from "@logtape/logtape";
|
|
14
|
+
import { Create, Follow, Note } from "@fedify/vocab";
|
|
15
|
+
import { mockDocumentLoader, test } from "@fedify/fixture";
|
|
16
|
+
//#region src/utils/portable-verifier.test.ts
|
|
17
|
+
const did = "did:key:z6Mkabc";
|
|
18
|
+
const compatibleNoteId = `https://gw.example/.well-known/apgateway/${did}/objects/1`;
|
|
19
|
+
const documentLoader = (url) => {
|
|
20
|
+
if (url !== compatibleNoteId) return mockDocumentLoader(url);
|
|
21
|
+
return Promise.resolve({
|
|
22
|
+
contextUrl: null,
|
|
23
|
+
documentUrl: url,
|
|
24
|
+
document: {
|
|
25
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
26
|
+
id: `ap://${did}/objects/1`,
|
|
27
|
+
type: "Note",
|
|
28
|
+
content: "Portable note"
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
function createRecordingVerifier() {
|
|
33
|
+
const verifier = Object.assign(async () => {
|
|
34
|
+
verifier.calls++;
|
|
35
|
+
return { verified: true };
|
|
36
|
+
}, { calls: 0 });
|
|
37
|
+
return verifier;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Runs the callback while collecting warnings of the category that `clone()`
|
|
41
|
+
* logs when it drops a default verifier.
|
|
42
|
+
*/
|
|
43
|
+
async function collectPortableWarnings(callback) {
|
|
44
|
+
const records = [];
|
|
45
|
+
await reset();
|
|
46
|
+
try {
|
|
47
|
+
await configure({
|
|
48
|
+
sinks: { buffer: (record) => records.push(record) },
|
|
49
|
+
loggers: [{
|
|
50
|
+
category: [
|
|
51
|
+
"fedify",
|
|
52
|
+
"vocab",
|
|
53
|
+
"portable"
|
|
54
|
+
],
|
|
55
|
+
sinks: ["buffer"]
|
|
56
|
+
}, {
|
|
57
|
+
category: ["logtape", "meta"],
|
|
58
|
+
sinks: []
|
|
59
|
+
}]
|
|
60
|
+
});
|
|
61
|
+
await callback();
|
|
62
|
+
} finally {
|
|
63
|
+
await reset();
|
|
64
|
+
}
|
|
65
|
+
return records;
|
|
66
|
+
}
|
|
67
|
+
/** Asserts that the object verifies its portable references with `verifier`. */
|
|
68
|
+
async function assertVerifiesWith(object, verifier) {
|
|
69
|
+
const before = verifier.calls;
|
|
70
|
+
assertInstanceOf(await object.getObject({
|
|
71
|
+
documentLoader,
|
|
72
|
+
contextLoader: mockDocumentLoader
|
|
73
|
+
}), Note);
|
|
74
|
+
assertEquals(verifier.calls, before + 1);
|
|
75
|
+
}
|
|
76
|
+
test("getDefaultPortableObjectVerifier()", () => {
|
|
77
|
+
const verifier = createRecordingVerifier();
|
|
78
|
+
assertStrictEquals(getDefaultPortableObjectVerifier(new Note({}, { verifyPortableObject: verifier })), verifier);
|
|
79
|
+
assertStrictEquals(getDefaultPortableObjectVerifier(new Note({})), void 0);
|
|
80
|
+
assertStrictEquals(getDefaultPortableObjectVerifier({}), void 0);
|
|
81
|
+
});
|
|
82
|
+
test("signObject() keeps the default portable object verifier", async () => {
|
|
83
|
+
const verifier = createRecordingVerifier();
|
|
84
|
+
const create = new Create({
|
|
85
|
+
id: new URL("https://example.com/activities/1"),
|
|
86
|
+
actor: new URL("https://example.com/users/alice"),
|
|
87
|
+
object: new URL(compatibleNoteId)
|
|
88
|
+
}, {
|
|
89
|
+
contextLoader: mockDocumentLoader,
|
|
90
|
+
verifyPortableObject: verifier
|
|
91
|
+
});
|
|
92
|
+
let signed;
|
|
93
|
+
assertEquals(await collectPortableWarnings(async () => {
|
|
94
|
+
await createProof(create, ed25519PrivateKey, ed25519Multikey.id, { contextLoader: mockDocumentLoader });
|
|
95
|
+
signed = await signObject(create, ed25519PrivateKey, ed25519Multikey.id, {
|
|
96
|
+
contextLoader: mockDocumentLoader,
|
|
97
|
+
documentLoader: mockDocumentLoader
|
|
98
|
+
});
|
|
99
|
+
}), []);
|
|
100
|
+
assertInstanceOf(signed, Create);
|
|
101
|
+
await assertVerifiesWith(signed, verifier);
|
|
102
|
+
});
|
|
103
|
+
test("default activity transformers keep the default portable object verifier", async () => {
|
|
104
|
+
const context = new FederationImpl({ kv: new MemoryKvStore() }).createContext(new URL("http://example.com/"));
|
|
105
|
+
const verifier = createRecordingVerifier();
|
|
106
|
+
const follow = new Follow({
|
|
107
|
+
actor: new URL("http://example.com/actors/1"),
|
|
108
|
+
object: new URL(compatibleNoteId)
|
|
109
|
+
}, {
|
|
110
|
+
contextLoader: mockDocumentLoader,
|
|
111
|
+
verifyPortableObject: verifier
|
|
112
|
+
});
|
|
113
|
+
let assigned;
|
|
114
|
+
let dehydrated;
|
|
115
|
+
assertEquals(await collectPortableWarnings(() => {
|
|
116
|
+
assigned = autoIdAssigner(follow, context);
|
|
117
|
+
dehydrated = actorDehydrator(assigned.clone({ actor: new URL("http://example.com/actors/1") }, { verifyPortableObject: verifier }), context);
|
|
118
|
+
return Promise.resolve();
|
|
119
|
+
}), []);
|
|
120
|
+
assertInstanceOf(assigned, Follow);
|
|
121
|
+
assertInstanceOf(dehydrated, Follow);
|
|
122
|
+
await assertVerifiesWith(assigned, verifier);
|
|
123
|
+
await assertVerifiesWith(dehydrated, verifier);
|
|
124
|
+
});
|
|
125
|
+
//#endregion
|
|
126
|
+
export {};
|