@fedify/fedify 2.3.16-dev.2841 → 2.3.16
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-BlfpZlWF.mjs +16 -0
- package/dist/{builder-G4wSHQX-.mjs → builder-D4GE1Gmi.mjs} +3 -3
- package/dist/callback-kR_sx2zZ.d.mts +2661 -0
- package/dist/{client-BIBzqEIp.d.cts → client-9DPcy_Yx.d.ts} +16 -0
- package/dist/{client-jE7oGvRh.d.ts → client-B3ruDgWg.d.cts} +16 -0
- package/dist/{client-DpUNYKla.mjs → client-DFgYVbUA.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-CE_Tj_Oc.d.cts → context-CEE8vl-b.d.cts} +31 -14
- package/dist/{context-H_5tZXg-.d.ts → context-CTJwXHRu.d.ts} +31 -14
- package/dist/{deno-DmDVx5sE.mjs → deno-FtdqgHJA.mjs} +1 -1
- package/dist/{docloader-0fjyUmvI.mjs → docloader-B9iU4DP2.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/circuit-breaker.test.mjs +2 -2
- 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/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1191 -16
- 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 +293 -3
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-CKX94hfh.cjs → http-2RyDQ0tE.cjs} +6 -4
- package/dist/{http-DmP0sr2l.d.ts → http-Bs5mXWlH.d.ts} +3 -3
- package/dist/{http-CZPYFK3b.d.cts → http-D8DgRhHU.d.cts} +3 -3
- package/dist/{http-DCK-QQfE.mjs → http-D8tiOrZf.mjs} +7 -5
- package/dist/{http-DwIMsxu9.js → http-mLeLYFj-.js} +6 -4
- package/dist/{inbox-Bx6PCMeE.mjs → inbox-Dy8awbi8.mjs} +2 -2
- package/dist/{key-SkLDUmPM.mjs → key-o1SmN5s0.mjs} +4 -3
- package/dist/{kv-cache-BaJOO6O3.mjs → kv-cache-BwUrzCVO.mjs} +1 -1
- package/dist/{kv-cache-BnZ4KLMY.cjs → kv-cache-CI6Z0WiS.cjs} +1 -1
- package/dist/{kv-cache-xIexNacM.js → kv-cache-Dsq8C8D8.js} +1 -1
- package/dist/{ld-DUG6cq9q.mjs → ld-DCKrqj9y.mjs} +155 -22
- package/dist/ld-signature-Dgz_b89j.mjs +23 -0
- package/dist/{metrics-D3OnAgfj.mjs → metrics-CaoYRhNH.mjs} +1 -1
- package/dist/{middleware-CUwjLKp3.mjs → middleware-4p3opEMT.mjs} +1 -1
- package/dist/{middleware-C9RexCTx.cjs → middleware-CP-8P7kk.cjs} +492 -117
- package/dist/{middleware-DU2jy5eY.js → middleware-Cce0nLDw.js} +491 -117
- package/dist/{middleware-zEy-wJYI.mjs → middleware-D31fNcY4.mjs} +399 -109
- package/dist/{mod-C_gFmeNq.d.cts → mod-BD0-_vya.d.ts} +31 -13
- package/dist/{mod-HQXFvOHs.d.ts → mod-BMX6nsHP.d.cts} +31 -13
- package/dist/{mod-CDFFESfL.d.ts → mod-BTvP5Hva.d.ts} +1 -1
- package/dist/{mod-DMjhnFbg.d.ts → mod-DgMTlwUO.d.ts} +3 -3
- package/dist/{mod-DDVkmZ_h.d.cts → mod-Q1Fo3FJk.d.cts} +3 -3
- package/dist/{mod-DDjtbkZO.d.cts → mod-n51LED4J.d.cts} +1 -1
- 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-D4iTv7uM.mjs → outgoing-jsonld-BZEAVK_Q.mjs} +38 -8
- package/dist/{owner-Baf_LRb2.mjs → owner-Bdj0nHhf.mjs} +2 -2
- package/dist/{proof-CNGy7TJL.js → proof-B9XJiyz-.js} +1030 -858
- package/dist/{proof-BdAFbOFg.cjs → proof-CmcP8yqP.cjs} +1243 -1059
- package/dist/{proof-LTsbjXnQ.mjs → proof-DrbjYma9.mjs} +41 -16
- package/dist/{send-DOf5y1nB.mjs → send-VD_WG3dN.mjs} +100 -22
- 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-fl4sM1Gs.mjs → temporal-CMvoB-vD.mjs} +3 -5
- package/dist/testing/mod.d.mts +2 -2476
- 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/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/package.json +7 -7
- /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-BeTGV3wc.mjs} +0 -0
- /package/dist/{circuit-breaker-D1fxthDI.mjs → circuit-breaker-B1fLHmg2.mjs} +0 -0
- /package/dist/{circuit-breaker-test-utils-CAdwjgMi.mjs → circuit-breaker-test-utils-BGHm_MsT.mjs} +0 -0
- /package/dist/{collection-Cc3DVAhE.mjs → collection-Dp5ky45w.mjs} +0 -0
- /package/dist/{negotiation-DDstyBvc.mjs → negotiation-DC8nG6J_.mjs} +0 -0
- /package/dist/{public-audience-Dp4ZScSr.mjs → public-audience-rnYUGj8a.mjs} +0 -0
- /package/dist/{retry-CXg_MBI-.mjs → retry-C4G_vIgv.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
|
@@ -4,12 +4,16 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as esm_default } from "../esm-vrlUxr60.mjs";
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
6
6
|
import "../std__assert-BjJn2daJ.mjs";
|
|
7
|
+
import { t as assertRejects } from "../assert_rejects-D1HYAik3.mjs";
|
|
7
8
|
import { n as assertInstanceOf } from "../assert-CEO06XCw.mjs";
|
|
8
|
-
import {
|
|
9
|
+
import { t as assertStrictEquals } from "../assert_strict_equals-XEgZAlrj.mjs";
|
|
10
|
+
import { a as parseOutboundService, c as parseSoftware, i as parseNodeInfo, l as parseUsage, n as getNodeInfoInternal, o as parseProtocol, r as parseInboundService, s as parseServices, t as getNodeInfo } from "../client-DFgYVbUA.mjs";
|
|
9
11
|
import { configure, reset } from "@logtape/logtape";
|
|
10
12
|
import { test } from "@fedify/fixture";
|
|
11
13
|
import { UrlError } from "@fedify/vocab-runtime";
|
|
12
|
-
import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
14
|
+
import { detectRuntime, openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
15
|
+
import dns from "node:dns/promises";
|
|
16
|
+
import { createServer } from "node:http";
|
|
13
17
|
//#region src/nodeinfo/client.test.ts
|
|
14
18
|
function getNodeInfoDirect(url, options) {
|
|
15
19
|
return getNodeInfoInternal(url, options, { openHop: openDirectFetch });
|
|
@@ -1049,6 +1053,64 @@ test("getNodeInfo() logs DNS failures as such", async (t) => {
|
|
|
1049
1053
|
}
|
|
1050
1054
|
});
|
|
1051
1055
|
});
|
|
1056
|
+
test("getNodeInfo() bounds and cancels default Node.js DNS lookups", { ignore: detectRuntime() !== "node" }, async () => {
|
|
1057
|
+
const originalLookup = dns.lookup;
|
|
1058
|
+
const pending = [];
|
|
1059
|
+
const hostnames = [];
|
|
1060
|
+
const twoStarted = deferred();
|
|
1061
|
+
const records = [];
|
|
1062
|
+
dns.lookup = ((hostname) => {
|
|
1063
|
+
hostnames.push(hostname);
|
|
1064
|
+
const lookup = deferred();
|
|
1065
|
+
pending.push(lookup);
|
|
1066
|
+
if (hostnames.length === 2) twoStarted.resolve();
|
|
1067
|
+
return lookup.promise;
|
|
1068
|
+
});
|
|
1069
|
+
try {
|
|
1070
|
+
await configure({
|
|
1071
|
+
sinks: { buffer: (record) => records.push(record) },
|
|
1072
|
+
loggers: [{
|
|
1073
|
+
category: "fedify",
|
|
1074
|
+
sinks: ["buffer"],
|
|
1075
|
+
lowestLevel: "debug"
|
|
1076
|
+
}, {
|
|
1077
|
+
category: ["logtape", "meta"],
|
|
1078
|
+
sinks: []
|
|
1079
|
+
}],
|
|
1080
|
+
reset: true
|
|
1081
|
+
});
|
|
1082
|
+
const first = getNodeInfo("https://first.example/nodeinfo", {
|
|
1083
|
+
direct: true,
|
|
1084
|
+
timeout: 50
|
|
1085
|
+
});
|
|
1086
|
+
const second = getNodeInfo("https://second.example/nodeinfo", {
|
|
1087
|
+
direct: true,
|
|
1088
|
+
timeout: 50
|
|
1089
|
+
});
|
|
1090
|
+
await settleWithin(twoStarted.promise, 1e3);
|
|
1091
|
+
assertEquals(await settleWithin(getNodeInfo("https://third.example/nodeinfo", {
|
|
1092
|
+
direct: true,
|
|
1093
|
+
timeout: 20
|
|
1094
|
+
}), 1e3), void 0);
|
|
1095
|
+
assertEquals(await settleWithin(first, 1e3), void 0);
|
|
1096
|
+
assertEquals(await settleWithin(second, 1e3), void 0);
|
|
1097
|
+
assertEquals(hostnames, ["first.example", "second.example"]);
|
|
1098
|
+
for (const lookup of pending) lookup.resolve([{
|
|
1099
|
+
address: "93.184.215.14",
|
|
1100
|
+
family: 4
|
|
1101
|
+
}]);
|
|
1102
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1103
|
+
assertEquals(hostnames, ["first.example", "second.example"]);
|
|
1104
|
+
assertEquals(records.some((record) => String(record.rawMessage).includes("DNS lookup failed")), false);
|
|
1105
|
+
} finally {
|
|
1106
|
+
dns.lookup = originalLookup;
|
|
1107
|
+
for (const lookup of pending) lookup.resolve([{
|
|
1108
|
+
address: "93.184.215.14",
|
|
1109
|
+
family: 4
|
|
1110
|
+
}]);
|
|
1111
|
+
await reset();
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1052
1114
|
function recordHops(respond) {
|
|
1053
1115
|
const events = [];
|
|
1054
1116
|
const unsettled = [];
|
|
@@ -1116,6 +1178,347 @@ function recordHops(respond) {
|
|
|
1116
1178
|
}
|
|
1117
1179
|
};
|
|
1118
1180
|
}
|
|
1181
|
+
function deferred() {
|
|
1182
|
+
let resolve;
|
|
1183
|
+
return {
|
|
1184
|
+
promise: new Promise((done) => resolve = done),
|
|
1185
|
+
resolve
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
function waitForAbort(signal) {
|
|
1189
|
+
return new Promise((_, reject) => {
|
|
1190
|
+
if (signal?.aborted) {
|
|
1191
|
+
reject(signal.reason);
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
signal?.addEventListener("abort", () => reject(signal.reason), { once: true });
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
test("getNodeInfo() times out while waiting for response headers", async () => {
|
|
1198
|
+
const closed = deferred();
|
|
1199
|
+
let fetches = 0;
|
|
1200
|
+
let closes = 0;
|
|
1201
|
+
let signal;
|
|
1202
|
+
const records = [];
|
|
1203
|
+
await configure({
|
|
1204
|
+
sinks: { buffer: (record) => records.push(record) },
|
|
1205
|
+
loggers: [{
|
|
1206
|
+
category: "fedify",
|
|
1207
|
+
sinks: ["buffer"],
|
|
1208
|
+
lowestLevel: "debug"
|
|
1209
|
+
}, {
|
|
1210
|
+
category: ["logtape", "meta"],
|
|
1211
|
+
sinks: []
|
|
1212
|
+
}],
|
|
1213
|
+
reset: true
|
|
1214
|
+
});
|
|
1215
|
+
try {
|
|
1216
|
+
assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
|
|
1217
|
+
direct: true,
|
|
1218
|
+
timeout: 30
|
|
1219
|
+
}, { openHop: async (url, hopSignal) => {
|
|
1220
|
+
signal = hopSignal;
|
|
1221
|
+
return {
|
|
1222
|
+
url: new URL(url),
|
|
1223
|
+
fetch(_input, init) {
|
|
1224
|
+
fetches++;
|
|
1225
|
+
assertEquals(init?.signal, hopSignal);
|
|
1226
|
+
return waitForAbort(init?.signal);
|
|
1227
|
+
},
|
|
1228
|
+
async close() {
|
|
1229
|
+
closes++;
|
|
1230
|
+
closed.resolve();
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
} }), 1e3), void 0);
|
|
1234
|
+
await settleWithin(closed.promise, 1e3);
|
|
1235
|
+
assertEquals(fetches, 1);
|
|
1236
|
+
assertEquals(closes, 1);
|
|
1237
|
+
assertEquals(signal?.aborted, true);
|
|
1238
|
+
assertEquals(records.filter((record) => record.level === "error").length, 1);
|
|
1239
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1240
|
+
assertEquals(records.filter((record) => record.level === "error").length, 1);
|
|
1241
|
+
} finally {
|
|
1242
|
+
await reset();
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
test("getNodeInfo() times out while a small response body stalls", async () => {
|
|
1246
|
+
const closed = deferred();
|
|
1247
|
+
let bodyCancelled = false;
|
|
1248
|
+
let signal;
|
|
1249
|
+
assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
|
|
1250
|
+
direct: true,
|
|
1251
|
+
timeout: 30
|
|
1252
|
+
}, { async openHop(url, hopSignal) {
|
|
1253
|
+
signal = hopSignal;
|
|
1254
|
+
return {
|
|
1255
|
+
url: new URL(url),
|
|
1256
|
+
async fetch(_input, init) {
|
|
1257
|
+
assertEquals(init?.signal, hopSignal);
|
|
1258
|
+
return new Response(new ReadableStream({
|
|
1259
|
+
start(controller) {
|
|
1260
|
+
controller.enqueue(new TextEncoder().encode("{\"software\":"));
|
|
1261
|
+
},
|
|
1262
|
+
cancel() {
|
|
1263
|
+
bodyCancelled = true;
|
|
1264
|
+
}
|
|
1265
|
+
}));
|
|
1266
|
+
},
|
|
1267
|
+
async close() {
|
|
1268
|
+
closed.resolve();
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
} }), 1e3), void 0);
|
|
1272
|
+
await settleWithin(closed.promise, 1e3);
|
|
1273
|
+
assertEquals(signal?.aborted, true);
|
|
1274
|
+
assertEquals(bodyCancelled, true);
|
|
1275
|
+
});
|
|
1276
|
+
test({
|
|
1277
|
+
name: "getNodeInfo() aborts stalled HTTP responses",
|
|
1278
|
+
ignore: "navigator" in globalThis && navigator.userAgent === "Cloudflare-Workers" || "Deno" in globalThis && (await Deno.permissions.query({ name: "net" })).state !== "granted",
|
|
1279
|
+
async fn(t) {
|
|
1280
|
+
for (const stage of ["headers", "body"]) await t.step(stage, async () => {
|
|
1281
|
+
const disconnected = deferred();
|
|
1282
|
+
const server = createServer((request, response) => {
|
|
1283
|
+
response.on("close", () => disconnected.resolve());
|
|
1284
|
+
request.socket.on("close", () => disconnected.resolve());
|
|
1285
|
+
if (stage === "body") {
|
|
1286
|
+
response.writeHead(200, { "Content-Type": "application/json" });
|
|
1287
|
+
response.write("{\"software\":");
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
try {
|
|
1291
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
1292
|
+
const address = server.address();
|
|
1293
|
+
if (address == null || typeof address === "string") throw new Error("Expected a TCP server address.");
|
|
1294
|
+
assertEquals(await settleWithin(getNodeInfoInternal(`http://127.0.0.1:${address.port}/nodeinfo`, {
|
|
1295
|
+
direct: true,
|
|
1296
|
+
timeout: 200
|
|
1297
|
+
}, { openHop: openDirectFetch }), 2e3).catch((error) => {
|
|
1298
|
+
throw new Error(`${stage} lookup did not finish`, { cause: error });
|
|
1299
|
+
}), void 0);
|
|
1300
|
+
await settleWithin(disconnected.promise, 2e3).catch((error) => {
|
|
1301
|
+
throw new Error(`${stage} connection did not close`, { cause: error });
|
|
1302
|
+
});
|
|
1303
|
+
} finally {
|
|
1304
|
+
server.closeAllConnections();
|
|
1305
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
test("getNodeInfo() shares one timeout across discovery and document", async () => {
|
|
1311
|
+
const documentRequested = deferred();
|
|
1312
|
+
const documentClosed = deferred();
|
|
1313
|
+
let discoverySignal;
|
|
1314
|
+
let documentSignal;
|
|
1315
|
+
const descriptor = JSON.stringify({ links: [{
|
|
1316
|
+
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
|
|
1317
|
+
href: "https://example.com/nodeinfo/2.1"
|
|
1318
|
+
}] });
|
|
1319
|
+
const result = getNodeInfoInternal("https://example.com/", { timeout: 200 }, { async openHop(url) {
|
|
1320
|
+
const isDocument = url.endsWith("/nodeinfo/2.1");
|
|
1321
|
+
return {
|
|
1322
|
+
url: new URL(url),
|
|
1323
|
+
async fetch(_input, init) {
|
|
1324
|
+
if (isDocument) {
|
|
1325
|
+
documentSignal = init?.signal ?? void 0;
|
|
1326
|
+
documentRequested.resolve();
|
|
1327
|
+
return await waitForAbort(init?.signal);
|
|
1328
|
+
}
|
|
1329
|
+
discoverySignal = init?.signal ?? void 0;
|
|
1330
|
+
return new Response(descriptor);
|
|
1331
|
+
},
|
|
1332
|
+
async close() {
|
|
1333
|
+
if (isDocument) documentClosed.resolve();
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
} });
|
|
1337
|
+
await settleWithin(documentRequested.promise, 1e3);
|
|
1338
|
+
assertStrictEquals(documentSignal, discoverySignal);
|
|
1339
|
+
assertEquals(await settleWithin(result, 1e3), void 0);
|
|
1340
|
+
await settleWithin(documentClosed.promise, 1e3);
|
|
1341
|
+
assertEquals(discoverySignal?.aborted, true);
|
|
1342
|
+
});
|
|
1343
|
+
test("getNodeInfo() honors caller cancellation without a timeout", async () => {
|
|
1344
|
+
const caller = new AbortController();
|
|
1345
|
+
const closed = deferred();
|
|
1346
|
+
let requestSignal;
|
|
1347
|
+
assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
|
|
1348
|
+
direct: true,
|
|
1349
|
+
timeout: null,
|
|
1350
|
+
signal: caller.signal
|
|
1351
|
+
}, { async openHop(url, signal) {
|
|
1352
|
+
requestSignal = signal;
|
|
1353
|
+
return {
|
|
1354
|
+
url: new URL(url),
|
|
1355
|
+
fetch(_input, init) {
|
|
1356
|
+
assertStrictEquals(init?.signal, signal);
|
|
1357
|
+
caller.abort(/* @__PURE__ */ new Error("Caller stopped waiting"));
|
|
1358
|
+
return waitForAbort(init?.signal);
|
|
1359
|
+
},
|
|
1360
|
+
async close() {
|
|
1361
|
+
closed.resolve();
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
} }), 1e3), void 0);
|
|
1365
|
+
await settleWithin(closed.promise, 1e3);
|
|
1366
|
+
assertEquals(requestSignal?.aborted, true);
|
|
1367
|
+
});
|
|
1368
|
+
test("getNodeInfo() stops before fetching when caller already aborted", async () => {
|
|
1369
|
+
const caller = new AbortController();
|
|
1370
|
+
caller.abort();
|
|
1371
|
+
let opened = false;
|
|
1372
|
+
assertEquals(await getNodeInfoInternal("https://example.com/nodeinfo", {
|
|
1373
|
+
direct: true,
|
|
1374
|
+
signal: caller.signal
|
|
1375
|
+
}, { async openHop() {
|
|
1376
|
+
opened = true;
|
|
1377
|
+
throw new Error("Unexpected fetch");
|
|
1378
|
+
} }), void 0);
|
|
1379
|
+
assertEquals(opened, false);
|
|
1380
|
+
});
|
|
1381
|
+
test("getNodeInfo() closes a session opened just after its timeout", async () => {
|
|
1382
|
+
const closed = deferred();
|
|
1383
|
+
let fetches = 0;
|
|
1384
|
+
let closes = 0;
|
|
1385
|
+
assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
|
|
1386
|
+
direct: true,
|
|
1387
|
+
timeout: 25
|
|
1388
|
+
}, { async openHop(url) {
|
|
1389
|
+
await new Promise((resolve) => setTimeout(resolve, 55));
|
|
1390
|
+
return {
|
|
1391
|
+
url: new URL(url),
|
|
1392
|
+
async fetch() {
|
|
1393
|
+
fetches++;
|
|
1394
|
+
return Response.json({ software: {
|
|
1395
|
+
name: "x",
|
|
1396
|
+
version: "1"
|
|
1397
|
+
} });
|
|
1398
|
+
},
|
|
1399
|
+
async close() {
|
|
1400
|
+
closes++;
|
|
1401
|
+
closed.resolve();
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
} }), 1e3), void 0);
|
|
1405
|
+
await settleWithin(closed.promise, 1e3);
|
|
1406
|
+
assertEquals(fetches, 0);
|
|
1407
|
+
assertEquals(closes, 1);
|
|
1408
|
+
});
|
|
1409
|
+
test("getNodeInfo() does not log a late DNS failure as another error", async () => {
|
|
1410
|
+
const records = [];
|
|
1411
|
+
const finished = deferred();
|
|
1412
|
+
await configure({
|
|
1413
|
+
sinks: { buffer: (record) => records.push(record) },
|
|
1414
|
+
loggers: [{
|
|
1415
|
+
category: "fedify",
|
|
1416
|
+
sinks: ["buffer"],
|
|
1417
|
+
lowestLevel: "debug"
|
|
1418
|
+
}, {
|
|
1419
|
+
category: ["logtape", "meta"],
|
|
1420
|
+
sinks: []
|
|
1421
|
+
}],
|
|
1422
|
+
reset: true
|
|
1423
|
+
});
|
|
1424
|
+
try {
|
|
1425
|
+
assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
|
|
1426
|
+
direct: true,
|
|
1427
|
+
timeout: 25
|
|
1428
|
+
}, { async openHop() {
|
|
1429
|
+
try {
|
|
1430
|
+
await new Promise((resolve) => setTimeout(resolve, 55));
|
|
1431
|
+
throw new UrlError("DNS lookup failed", { reason: "dns" });
|
|
1432
|
+
} finally {
|
|
1433
|
+
finished.resolve();
|
|
1434
|
+
}
|
|
1435
|
+
} }), 1e3), void 0);
|
|
1436
|
+
await settleWithin(finished.promise, 1e3);
|
|
1437
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1438
|
+
assertEquals(records.filter((record) => record.level === "error").length, 1);
|
|
1439
|
+
} finally {
|
|
1440
|
+
await reset();
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
test("getNodeInfo() cancels a response returned after timeout", async () => {
|
|
1444
|
+
const closed = deferred();
|
|
1445
|
+
let bodyCancelled = false;
|
|
1446
|
+
let closes = 0;
|
|
1447
|
+
assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
|
|
1448
|
+
direct: true,
|
|
1449
|
+
timeout: 25
|
|
1450
|
+
}, { async openHop(url) {
|
|
1451
|
+
return {
|
|
1452
|
+
url: new URL(url),
|
|
1453
|
+
async fetch() {
|
|
1454
|
+
await new Promise((resolve) => setTimeout(resolve, 55));
|
|
1455
|
+
return new Response(new ReadableStream({ cancel() {
|
|
1456
|
+
bodyCancelled = true;
|
|
1457
|
+
} }));
|
|
1458
|
+
},
|
|
1459
|
+
async close() {
|
|
1460
|
+
closes++;
|
|
1461
|
+
closed.resolve();
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
} }), 1e3), void 0);
|
|
1465
|
+
await settleWithin(closed.promise, 1e3);
|
|
1466
|
+
assertEquals(closes, 1);
|
|
1467
|
+
assertEquals(bodyCancelled, true);
|
|
1468
|
+
});
|
|
1469
|
+
test("getNodeInfo() validates its timeout", async () => {
|
|
1470
|
+
for (const timeout of [
|
|
1471
|
+
0,
|
|
1472
|
+
-1,
|
|
1473
|
+
NaN,
|
|
1474
|
+
Infinity,
|
|
1475
|
+
2147483648
|
|
1476
|
+
]) await assertRejects(() => getNodeInfoInternal("https://example.com/", { timeout }), RangeError);
|
|
1477
|
+
});
|
|
1478
|
+
test("getNodeInfo() can disable its timeout", async () => {
|
|
1479
|
+
const value = { software: {
|
|
1480
|
+
name: "x",
|
|
1481
|
+
version: "1"
|
|
1482
|
+
} };
|
|
1483
|
+
assertEquals(await getNodeInfoInternal("https://example.com/nodeinfo", {
|
|
1484
|
+
direct: true,
|
|
1485
|
+
parse: "none",
|
|
1486
|
+
timeout: null
|
|
1487
|
+
}, { async openHop(url, signal) {
|
|
1488
|
+
assertEquals(signal, void 0);
|
|
1489
|
+
return {
|
|
1490
|
+
url: new URL(url),
|
|
1491
|
+
async fetch(_input, init) {
|
|
1492
|
+
assertEquals(init?.signal, void 0);
|
|
1493
|
+
return Response.json(value);
|
|
1494
|
+
},
|
|
1495
|
+
async close() {}
|
|
1496
|
+
};
|
|
1497
|
+
} }), value);
|
|
1498
|
+
});
|
|
1499
|
+
test("getNodeInfo() clears its timer after a successful fetch", async () => {
|
|
1500
|
+
let signal;
|
|
1501
|
+
const value = { software: {
|
|
1502
|
+
name: "x",
|
|
1503
|
+
version: "1"
|
|
1504
|
+
} };
|
|
1505
|
+
assertEquals(await getNodeInfoInternal("https://example.com/nodeinfo", {
|
|
1506
|
+
direct: true,
|
|
1507
|
+
parse: "none",
|
|
1508
|
+
timeout: 100
|
|
1509
|
+
}, { async openHop(url, hopSignal) {
|
|
1510
|
+
signal = hopSignal;
|
|
1511
|
+
return {
|
|
1512
|
+
url: new URL(url),
|
|
1513
|
+
async fetch() {
|
|
1514
|
+
return Response.json(value);
|
|
1515
|
+
},
|
|
1516
|
+
async close() {}
|
|
1517
|
+
};
|
|
1518
|
+
} }), value);
|
|
1519
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
1520
|
+
assertEquals(signal?.aborted, false);
|
|
1521
|
+
});
|
|
1119
1522
|
test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
|
|
1120
1523
|
const wellKnown = "https://example.com/.well-known/nodeinfo";
|
|
1121
1524
|
const wellKnown2 = "https://example.com/.well-known/nodeinfo2";
|
|
@@ -1186,9 +1589,9 @@ test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
|
|
|
1186
1589
|
recorder.assertInvariants();
|
|
1187
1590
|
});
|
|
1188
1591
|
await t.step("too many redirections", async () => {
|
|
1189
|
-
const recorder = recordHops(() => ({
|
|
1592
|
+
const recorder = recordHops((url) => ({
|
|
1190
1593
|
status: 302,
|
|
1191
|
-
headers: { Location: "
|
|
1594
|
+
headers: { Location: `?hop=${Number(url.searchParams.get("hop") ?? 0) + 1}` },
|
|
1192
1595
|
body: "redirecting"
|
|
1193
1596
|
}));
|
|
1194
1597
|
assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
|
|
@@ -1196,6 +1599,31 @@ test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
|
|
|
1196
1599
|
assertEquals(recorder.events.filter((e) => e.startsWith("cancel ")).length, 5);
|
|
1197
1600
|
recorder.assertInvariants();
|
|
1198
1601
|
});
|
|
1602
|
+
await t.step("self-redirect cycle", async () => {
|
|
1603
|
+
const recorder = recordHops(() => ({
|
|
1604
|
+
status: 302,
|
|
1605
|
+
headers: { Location: "/.well-known/nodeinfo#another-fragment" },
|
|
1606
|
+
body: "redirecting"
|
|
1607
|
+
}));
|
|
1608
|
+
assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
|
|
1609
|
+
assertEquals(recorder.events, [
|
|
1610
|
+
`open ${wellKnown}`,
|
|
1611
|
+
`fetch ${wellKnown} #1`,
|
|
1612
|
+
"cancel #1",
|
|
1613
|
+
`close ${wellKnown}`
|
|
1614
|
+
]);
|
|
1615
|
+
recorder.assertInvariants();
|
|
1616
|
+
});
|
|
1617
|
+
await t.step("two-URL redirect cycle", async () => {
|
|
1618
|
+
const recorder = recordHops((url) => ({
|
|
1619
|
+
status: 302,
|
|
1620
|
+
headers: { Location: url.href === wellKnown ? "/.well-known/nodeinfo2" : "/.well-known/nodeinfo" },
|
|
1621
|
+
body: "redirecting"
|
|
1622
|
+
}));
|
|
1623
|
+
assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
|
|
1624
|
+
assertEquals(recorder.events.filter((e) => e.startsWith("open ")), [`open ${wellKnown}`, `open ${wellKnown2}`]);
|
|
1625
|
+
recorder.assertInvariants();
|
|
1626
|
+
});
|
|
1199
1627
|
await t.step("failed redirect body cancellation", async () => {
|
|
1200
1628
|
const recorder = recordHops((url) => {
|
|
1201
1629
|
switch (url.href) {
|
|
@@ -5,7 +5,7 @@ import { r as createRequestContext } from "../context-CxbCIptr.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
6
6
|
import "../std__assert-BjJn2daJ.mjs";
|
|
7
7
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
8
|
-
import { _ as handleNodeInfo, o as createFederation, v as handleNodeInfoJrd } from "../middleware-
|
|
8
|
+
import { _ as handleNodeInfo, o as createFederation, v as handleNodeInfoJrd } from "../middleware-D31fNcY4.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
//#region src/nodeinfo/handler.test.ts
|
|
11
11
|
test("handleNodeInfo()", async () => {
|
package/dist/nodeinfo/mod.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const require_types = require("../types-
|
|
4
|
+
const require_types = require("../types-BWx7zw3Y.cjs");
|
|
5
5
|
exports.getNodeInfo = require_types.getNodeInfo;
|
|
6
6
|
exports.nodeInfoToJson = require_types.nodeInfoToJson;
|
|
7
7
|
exports.parseNodeInfo = require_types.parseNodeInfo;
|
package/dist/nodeinfo/mod.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-
|
|
2
|
+
import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-B3ruDgWg.cjs";
|
|
3
3
|
export { type GetNodeInfoOptions, InboundService, JsonValue, NodeInfo, OutboundService, type ParseNodeInfoOptions, Protocol, Services, Software, Usage, getNodeInfo, nodeInfoToJson, parseNodeInfo };
|
package/dist/nodeinfo/mod.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-
|
|
2
|
+
import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-9DPcy_Yx.js";
|
|
3
3
|
export { type GetNodeInfoOptions, InboundService, JsonValue, NodeInfo, OutboundService, type ParseNodeInfoOptions, Protocol, Services, Software, Usage, getNodeInfo, nodeInfoToJson, parseNodeInfo };
|
package/dist/nodeinfo/mod.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "../types-
|
|
3
|
+
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "../types-Dx_w2JSM.js";
|
|
4
4
|
export { getNodeInfo, nodeInfoToJson, parseNodeInfo };
|
|
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
5
5
|
import "../std__assert-BjJn2daJ.mjs";
|
|
6
6
|
import { t as assertThrows } from "../assert_throws-BbSMEFKo.mjs";
|
|
7
|
-
import { t as nodeInfoToJson } from "../types-
|
|
7
|
+
import { t as nodeInfoToJson } from "../types-BFowWFTT.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
//#region src/nodeinfo/types.test.ts
|
|
10
10
|
test("nodeInfoToJson()", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as preloadedOnlyDocumentLoader, t as normalizePublicAudience } from "./public-audience-
|
|
4
|
+
import { n as preloadedOnlyDocumentLoader, t as normalizePublicAudience } from "./public-audience-rnYUGj8a.mjs";
|
|
5
5
|
import { getLogger } from "@logtape/logtape";
|
|
6
6
|
import { preloadedContexts } from "@fedify/vocab-runtime";
|
|
7
7
|
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
@@ -166,38 +166,68 @@ function getLogSafeJsonLdMetadata(jsonLd) {
|
|
|
166
166
|
* the semantic-preservation check to succeed; otherwise canonicalization
|
|
167
167
|
* failures leave the original document unchanged.
|
|
168
168
|
*/
|
|
169
|
-
async function normalizeAttachmentArrays(jsonLd, contextLoader) {
|
|
169
|
+
async function normalizeAttachmentArrays(jsonLd, contextLoader, preserveSecured = false) {
|
|
170
170
|
const normalized = wrapScalarAttachments(jsonLd);
|
|
171
171
|
if (normalized === jsonLd) return jsonLd;
|
|
172
172
|
if (exceedsTraversalDepth(jsonLd)) {
|
|
173
173
|
logger.debug("Skipping attachment array normalization because the JSON-LD document exceeds the safe traversal depth; leaving it unchanged.");
|
|
174
174
|
return jsonLd;
|
|
175
175
|
}
|
|
176
|
-
|
|
177
|
-
const
|
|
176
|
+
const sourceLoader = contextLoader ?? preloadedOnlyDocumentLoader;
|
|
177
|
+
const pending = /* @__PURE__ */ new Map();
|
|
178
|
+
const loader = (url, options) => {
|
|
179
|
+
let result = pending.get(url);
|
|
180
|
+
if (result == null) {
|
|
181
|
+
result = sourceLoader(url, options);
|
|
182
|
+
pending.set(url, result);
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
};
|
|
178
186
|
try {
|
|
179
|
-
|
|
187
|
+
if (preserveSecured) {
|
|
188
|
+
if (hasSecurityPredicate(await jsonld.expand(jsonLd, { documentLoader: loader }))) return jsonLd;
|
|
189
|
+
}
|
|
190
|
+
if (!preserveSecured && hasKnownSafeContext(jsonLd)) return normalized;
|
|
191
|
+
const [before, after] = await Promise.allSettled([jsonld.canonize(jsonLd, {
|
|
180
192
|
format: "application/n-quads",
|
|
181
193
|
documentLoader: loader
|
|
182
194
|
}), jsonld.canonize(normalized, {
|
|
183
195
|
format: "application/n-quads",
|
|
184
196
|
documentLoader: loader
|
|
185
197
|
})]);
|
|
186
|
-
if (before ===
|
|
198
|
+
if (before.status === "rejected") throw before.reason;
|
|
199
|
+
if (after.status === "rejected") throw after.reason;
|
|
200
|
+
if (before.value === after.value) return normalized;
|
|
187
201
|
logger.warn("Wrapping scalar attachment values in arrays would change the canonical form of the JSON-LD document; leaving it unchanged. This usually means the active JSON-LD context redefines the `attachment` term. Document: {id}; type: {type}; context: {context}.", getLogSafeJsonLdMetadata(jsonLd));
|
|
188
202
|
} catch (error) {
|
|
189
203
|
logger.debug("Failed to verify attachment array normalization equivalence via JSON-LD canonicalization; leaving the JSON-LD document unchanged.\n{error}", { error });
|
|
190
204
|
}
|
|
191
205
|
return jsonLd;
|
|
192
206
|
}
|
|
207
|
+
function hasSecurityPredicate(value) {
|
|
208
|
+
if (Array.isArray(value)) return value.some(hasSecurityPredicate);
|
|
209
|
+
if (typeof value !== "object" || value == null) return false;
|
|
210
|
+
const record = value;
|
|
211
|
+
if (Object.hasOwn(record, "@value")) return false;
|
|
212
|
+
for (const [key, child] of Object.entries(record)) {
|
|
213
|
+
if (key === "https://w3id.org/security#proof" || key === "https://w3id.org/security#signature") return true;
|
|
214
|
+
if (hasSecurityPredicate(child)) return true;
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
193
218
|
/**
|
|
194
219
|
* Applies Fedify's internal JSON-LD wire-format interoperability workarounds
|
|
195
220
|
* to locally generated outgoing activities before they are signed, enqueued,
|
|
196
221
|
* or sent.
|
|
197
222
|
*/
|
|
198
|
-
async function normalizeOutgoingActivityJsonLd(jsonLd, contextLoader) {
|
|
223
|
+
async function normalizeOutgoingActivityJsonLd(jsonLd, contextLoader, preserveSecured = false) {
|
|
224
|
+
if (preserveSecured) try {
|
|
225
|
+
if (hasSecurityPredicate(await jsonld.expand(jsonLd, { documentLoader: contextLoader ?? preloadedOnlyDocumentLoader }))) return jsonLd;
|
|
226
|
+
} catch {
|
|
227
|
+
return jsonLd;
|
|
228
|
+
}
|
|
199
229
|
jsonLd = await normalizePublicAudience(jsonLd, contextLoader);
|
|
200
|
-
return await normalizeAttachmentArrays(jsonLd, contextLoader);
|
|
230
|
+
return await normalizeAttachmentArrays(jsonLd, contextLoader, preserveSecured);
|
|
201
231
|
}
|
|
202
232
|
//#endregion
|
|
203
233
|
export { normalizeAttachmentArrays as n, normalizeOutgoingActivityJsonLd as r, isPreloadedContextAttachmentSafe as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
-
import { c as verifyKeyOwnership, n as fetchActorDocument, t as exportJwk } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-FtdqgHJA.mjs";
|
|
5
|
+
import { c as verifyKeyOwnership, n as fetchActorDocument, t as exportJwk } from "./key-o1SmN5s0.mjs";
|
|
6
6
|
import { getLogger } from "@logtape/logtape";
|
|
7
7
|
import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
|
|
8
8
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|