@fedify/fedify 2.5.0-dev.2687 → 2.5.0-dev.2710

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/dist/federation/mod.cjs +1 -1
  2. package/dist/federation/mod.js +1 -1
  3. package/dist/{federation-pFFwPyoZ.cjs → federation-JvzYDx0P.cjs} +3 -3
  4. package/dist/{http-CXX-QPzs.cjs → http-BG5cDmTS.cjs} +1 -1
  5. package/dist/{http-T7h9GBAN.js → http-MUf125Jc.js} +1 -1
  6. package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-A2po7h0_.cjs} +1 -1
  7. package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CbWc1BZA.js} +1 -1
  8. package/dist/{middleware-Bj91r7r2.js → middleware-DzzdJ7Wz.js} +3 -3
  9. package/dist/mod.cjs +4 -4
  10. package/dist/mod.js +4 -4
  11. package/dist/{portable-collection-Do5QA2oy.js → portable-collection-CAer9RWN.js} +1 -1
  12. package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
  13. package/dist/sig/mod.cjs +2 -2
  14. package/dist/sig/mod.js +2 -2
  15. package/dist/utils/mod.cjs +1 -1
  16. package/dist/utils/mod.js +1 -1
  17. package/package.json +22 -9
  18. package/skills/fedify/SKILL.md +10 -0
  19. package/dist/accept-CPVqki78.mjs +0 -145
  20. package/dist/activity-listener-CELFAodc.mjs +0 -44
  21. package/dist/assert-D1Eafmd_.mjs +0 -23
  22. package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
  23. package/dist/assert_exists-cffSpJ7X.mjs +0 -28
  24. package/dist/assert_false-CPdRnc3E.mjs +0 -23
  25. package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
  26. package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
  27. package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
  28. package/dist/assert_rejects-CTptdYck.mjs +0 -39
  29. package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
  30. package/dist/assert_throws-BYITOvPO.mjs +0 -74
  31. package/dist/assertion_error-B-cx0fFA.mjs +0 -31
  32. package/dist/audience-CHQ-FlLD.mjs +0 -95
  33. package/dist/builder-D1FP_5nQ.mjs +0 -911
  34. package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
  35. package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
  36. package/dist/client-5SIFzW3q.mjs +0 -441
  37. package/dist/codec-C6rTrpIp.mjs +0 -147
  38. package/dist/collection-CnnP1UAv.mjs +0 -44
  39. package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
  40. package/dist/compat/outgoing-jsonld.test.mjs +0 -257
  41. package/dist/compat/public-audience.test.d.mts +0 -2
  42. package/dist/compat/public-audience.test.mjs +0 -187
  43. package/dist/compat/secured-document.test.d.mts +0 -2
  44. package/dist/compat/secured-document.test.mjs +0 -58
  45. package/dist/compat/transformers.test.d.mts +0 -2
  46. package/dist/compat/transformers.test.mjs +0 -62
  47. package/dist/compound-proof-DSHhnOEW.mjs +0 -1019
  48. package/dist/context-LgGFFSz7.mjs +0 -146
  49. package/dist/deno-C50ikGBU.mjs +0 -8
  50. package/dist/dist-_geWsuaI.mjs +0 -189
  51. package/dist/docloader-BY-SEID0.mjs +0 -136
  52. package/dist/esm-BHXXx4Wx.mjs +0 -1233
  53. package/dist/exporter-DVG68ozH.mjs +0 -263
  54. package/dist/federation/audience.test.d.mts +0 -2
  55. package/dist/federation/audience.test.mjs +0 -130
  56. package/dist/federation/builder.test.d.mts +0 -2
  57. package/dist/federation/builder.test.mjs +0 -396
  58. package/dist/federation/circuit-breaker.test.d.mts +0 -2
  59. package/dist/federation/circuit-breaker.test.mjs +0 -1277
  60. package/dist/federation/collection.test.d.mts +0 -2
  61. package/dist/federation/collection.test.mjs +0 -21
  62. package/dist/federation/compound-fanout.test.d.mts +0 -2
  63. package/dist/federation/compound-fanout.test.mjs +0 -231
  64. package/dist/federation/handler-compound-proof.test.d.mts +0 -2
  65. package/dist/federation/handler-compound-proof.test.mjs +0 -384
  66. package/dist/federation/handler.test.d.mts +0 -2
  67. package/dist/federation/handler.test.mjs +0 -5445
  68. package/dist/federation/hashlink-media.test.d.mts +0 -2
  69. package/dist/federation/hashlink-media.test.mjs +0 -422
  70. package/dist/federation/idempotency.test.d.mts +0 -2
  71. package/dist/federation/idempotency.test.mjs +0 -207
  72. package/dist/federation/inbox-actorless.test.d.mts +0 -2
  73. package/dist/federation/inbox-actorless.test.mjs +0 -522
  74. package/dist/federation/inbox-authentication.test.d.mts +0 -2
  75. package/dist/federation/inbox-authentication.test.mjs +0 -220
  76. package/dist/federation/inbox-report.test.d.mts +0 -2
  77. package/dist/federation/inbox-report.test.mjs +0 -719
  78. package/dist/federation/inbox-view.test.d.mts +0 -2
  79. package/dist/federation/inbox-view.test.mjs +0 -369
  80. package/dist/federation/inbox.test.d.mts +0 -2
  81. package/dist/federation/inbox.test.mjs +0 -139
  82. package/dist/federation/keycache.test.d.mts +0 -2
  83. package/dist/federation/keycache.test.mjs +0 -337
  84. package/dist/federation/kv.test.d.mts +0 -2
  85. package/dist/federation/kv.test.mjs +0 -88
  86. package/dist/federation/metrics.test.d.mts +0 -2
  87. package/dist/federation/metrics.test.mjs +0 -634
  88. package/dist/federation/middleware.test.d.mts +0 -2
  89. package/dist/federation/middleware.test.mjs +0 -9314
  90. package/dist/federation/mq.test.d.mts +0 -2
  91. package/dist/federation/mq.test.mjs +0 -591
  92. package/dist/federation/negotiation.test.d.mts +0 -2
  93. package/dist/federation/negotiation.test.mjs +0 -18
  94. package/dist/federation/outbound-body.test.d.mts +0 -2
  95. package/dist/federation/outbound-body.test.mjs +0 -149
  96. package/dist/federation/outbound-capture.test.d.mts +0 -2
  97. package/dist/federation/outbound-capture.test.mjs +0 -394
  98. package/dist/federation/outbound-dispatch.test.d.mts +0 -2
  99. package/dist/federation/outbound-dispatch.test.mjs +0 -368
  100. package/dist/federation/outbound-document.test.d.mts +0 -2
  101. package/dist/federation/outbound-document.test.mjs +0 -171
  102. package/dist/federation/outbound-provenance.test.d.mts +0 -2
  103. package/dist/federation/outbound-provenance.test.mjs +0 -543
  104. package/dist/federation/outbound-report.test.d.mts +0 -2
  105. package/dist/federation/outbound-report.test.mjs +0 -5475
  106. package/dist/federation/outbound-workers.test.d.mts +0 -2
  107. package/dist/federation/outbound-workers.test.mjs +0 -64
  108. package/dist/federation/outbound-workflow.test.d.mts +0 -2
  109. package/dist/federation/outbound-workflow.test.mjs +0 -154
  110. package/dist/federation/outgoing-proof.test.d.mts +0 -2
  111. package/dist/federation/outgoing-proof.test.mjs +0 -933
  112. package/dist/federation/portable-actor.test.d.mts +0 -2
  113. package/dist/federation/portable-actor.test.mjs +0 -496
  114. package/dist/federation/portable-chain.test.d.mts +0 -2
  115. package/dist/federation/portable-chain.test.mjs +0 -370
  116. package/dist/federation/portable-collection.test.d.mts +0 -2
  117. package/dist/federation/portable-collection.test.mjs +0 -832
  118. package/dist/federation/portable-delivery.test.d.mts +0 -2
  119. package/dist/federation/portable-delivery.test.mjs +0 -845
  120. package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
  121. package/dist/federation/portable-gateway-keys.test.mjs +0 -692
  122. package/dist/federation/portable-inbox.test.d.mts +0 -2
  123. package/dist/federation/portable-inbox.test.mjs +0 -1960
  124. package/dist/federation/portable-parse-uri.test.d.mts +0 -2
  125. package/dist/federation/portable-parse-uri.test.mjs +0 -348
  126. package/dist/federation/portable-route-activity.test.d.mts +0 -2
  127. package/dist/federation/portable-route-activity.test.mjs +0 -259
  128. package/dist/federation/portable.test.d.mts +0 -2
  129. package/dist/federation/portable.test.mjs +0 -1072
  130. package/dist/federation/retry.test.d.mts +0 -2
  131. package/dist/federation/retry.test.mjs +0 -42
  132. package/dist/federation/router.test.d.mts +0 -2
  133. package/dist/federation/router.test.mjs +0 -123
  134. package/dist/federation/send.test.d.mts +0 -2
  135. package/dist/federation/send.test.mjs +0 -1421
  136. package/dist/federation/tasks/codec.test.d.mts +0 -2
  137. package/dist/federation/tasks/codec.test.mjs +0 -302
  138. package/dist/federation/tasks/enqueue.test.d.mts +0 -2
  139. package/dist/federation/tasks/enqueue.test.mjs +0 -1095
  140. package/dist/federation/tasks/tasks.test.d.mts +0 -2
  141. package/dist/federation/tasks/tasks.test.mjs +0 -1229
  142. package/dist/federation/temporal.test.d.mts +0 -2
  143. package/dist/federation/temporal.test.mjs +0 -71
  144. package/dist/federation/webfinger.test.d.mts +0 -2
  145. package/dist/federation/webfinger.test.mjs +0 -944
  146. package/dist/http-BXbQQZDM.mjs +0 -1449
  147. package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
  148. package/dist/inbox-cS97XzOD.mjs +0 -399
  149. package/dist/inbox-view-D-d0Ar6o.mjs +0 -385
  150. package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
  151. package/dist/keycache-N2opu4-3.mjs +0 -221
  152. package/dist/keys-DIJNHW-Y.mjs +0 -120
  153. package/dist/kv-DBRWVx3Q.mjs +0 -104
  154. package/dist/kv-DCHkaJ9-.mjs +0 -92
  155. package/dist/kv-cache-fgbLHGVL.mjs +0 -121
  156. package/dist/ld-BpkhkDGj.mjs +0 -1752
  157. package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
  158. package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
  159. package/dist/metrics-Uqf8GomB.mjs +0 -818
  160. package/dist/middleware-DcXzz-YK.mjs +0 -9971
  161. package/dist/middleware-DgwZkvJR.mjs +0 -5
  162. package/dist/mq-eF96QxUT.mjs +0 -288
  163. package/dist/negotiation-BAKO9nih.mjs +0 -96
  164. package/dist/nodeinfo/client.test.d.mts +0 -2
  165. package/dist/nodeinfo/client.test.mjs +0 -1364
  166. package/dist/nodeinfo/handler.test.d.mts +0 -2
  167. package/dist/nodeinfo/handler.test.mjs +0 -94
  168. package/dist/nodeinfo/types.test.d.mts +0 -2
  169. package/dist/nodeinfo/types.test.mjs +0 -192
  170. package/dist/otel/exporter.test.d.mts +0 -2
  171. package/dist/otel/exporter.test.mjs +0 -887
  172. package/dist/outbound-body-CckPA5gc.mjs +0 -83
  173. package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
  174. package/dist/outbound-document-BMgwLXTY.mjs +0 -179
  175. package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
  176. package/dist/owner-BVenIFg1.mjs +0 -267
  177. package/dist/portable-collection-DIk9gpjL.mjs +0 -418
  178. package/dist/portable-key-C7pVaHNR.mjs +0 -549
  179. package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
  180. package/dist/proof-BlfZ95--.mjs +0 -1420
  181. package/dist/public-audience--klBIOk1.mjs +0 -197
  182. package/dist/retry-zX5xw5e0.mjs +0 -34
  183. package/dist/router-u5O5KCQr.mjs +0 -156
  184. package/dist/secured-document-CxzZZ9nL.mjs +0 -35
  185. package/dist/send-DEGHPGFk.mjs +0 -710
  186. package/dist/sig/accept.test.d.mts +0 -2
  187. package/dist/sig/accept.test.mjs +0 -416
  188. package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
  189. package/dist/sig/compound-proof-discovery.test.mjs +0 -331
  190. package/dist/sig/compound-proof-producer.test.d.mts +0 -2
  191. package/dist/sig/compound-proof-producer.test.mjs +0 -107
  192. package/dist/sig/compound-proof-verification.test.d.mts +0 -2
  193. package/dist/sig/compound-proof-verification.test.mjs +0 -1017
  194. package/dist/sig/compound-proof.test.d.mts +0 -2
  195. package/dist/sig/compound-proof.test.mjs +0 -411
  196. package/dist/sig/http.test.d.mts +0 -2
  197. package/dist/sig/http.test.mjs +0 -3328
  198. package/dist/sig/key-owner-evidence.test.d.mts +0 -2
  199. package/dist/sig/key-owner-evidence.test.mjs +0 -100
  200. package/dist/sig/key.test.d.mts +0 -2
  201. package/dist/sig/key.test.mjs +0 -1250
  202. package/dist/sig/ld.test.d.mts +0 -2
  203. package/dist/sig/ld.test.mjs +0 -1044
  204. package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
  205. package/dist/sig/mitra-receive-interop.test.mjs +0 -260
  206. package/dist/sig/mitra-send-interop.test.d.mts +0 -2
  207. package/dist/sig/mitra-send-interop.test.mjs +0 -461
  208. package/dist/sig/owner.test.d.mts +0 -2
  209. package/dist/sig/owner.test.mjs +0 -202
  210. package/dist/sig/portable-collection.test.d.mts +0 -2
  211. package/dist/sig/portable-collection.test.mjs +0 -697
  212. package/dist/sig/portable-interop.test.d.mts +0 -2
  213. package/dist/sig/portable-interop.test.mjs +0 -156
  214. package/dist/sig/portable-key-id.test.d.mts +0 -2
  215. package/dist/sig/portable-key-id.test.mjs +0 -67
  216. package/dist/sig/portable-key.test.d.mts +0 -2
  217. package/dist/sig/portable-key.test.mjs +0 -1438
  218. package/dist/sig/proof.test.d.mts +0 -2
  219. package/dist/sig/proof.test.mjs +0 -2638
  220. package/dist/sig/tootik-request-interop.test.d.mts +0 -2
  221. package/dist/sig/tootik-request-interop.test.mjs +0 -190
  222. package/dist/sig/tootik-send-interop.test.d.mts +0 -2
  223. package/dist/sig/tootik-send-interop.test.mjs +0 -331
  224. package/dist/sig/verification.test.d.mts +0 -2
  225. package/dist/sig/verification.test.mjs +0 -310
  226. package/dist/std__assert-DvMDRPes.mjs +0 -8
  227. package/dist/tasks-BCUmQbbz.mjs +0 -77
  228. package/dist/temporal-B4oQ8HpW.mjs +0 -95
  229. package/dist/testing/context.test.d.mts +0 -2
  230. package/dist/testing/context.test.mjs +0 -19
  231. package/dist/testing/kv.test.d.mts +0 -2
  232. package/dist/testing/kv.test.mjs +0 -101
  233. package/dist/testing/mod.d.mts +0 -6099
  234. package/dist/testing/mod.mjs +0 -9
  235. package/dist/testing-vrnD5Uaa.mjs +0 -8
  236. package/dist/types-DE_LV1JB.mjs +0 -46
  237. package/dist/utils/docloader.test.d.mts +0 -2
  238. package/dist/utils/docloader.test.mjs +0 -1076
  239. package/dist/utils/kv-cache.test.d.mts +0 -2
  240. package/dist/utils/kv-cache.test.mjs +0 -261
  241. package/dist/verification-C3954hQh.mjs +0 -5
  242. package/dist/verification-Dpfcw8ml.mjs +0 -105
  243. package/dist/vocab/cjs.test.d.mts +0 -2
  244. package/dist/vocab/cjs.test.mjs +0 -27
@@ -1,1364 +0,0 @@
1
- import "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { t as esm_default } from "../esm-BHXXx4Wx.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 { 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-5SIFzW3q.mjs";
9
- import { configure, reset } from "@logtape/logtape";
10
- import { UrlError } from "@fedify/vocab-runtime";
11
- import { test } from "@fedify/fixture";
12
- import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
13
- //#region src/nodeinfo/client.test.ts
14
- function getNodeInfoDirect(url, options) {
15
- return getNodeInfoInternal(url, options, { openHop: openDirectFetch });
16
- }
17
- function getNodeInfoValidated(url, options) {
18
- return getNodeInfoInternal(url, options, { openHop: (hopUrl) => new URL(hopUrl).hostname === "example.com" ? openDirectFetch(hopUrl) : openPublicFetch(hopUrl, { lookup: () => Promise.resolve([{
19
- address: "93.184.215.14",
20
- family: 4
21
- }]) }) });
22
- }
23
- test("getNodeInfo()", async (t) => {
24
- esm_default.spyGlobal();
25
- esm_default.get("https://example.com/.well-known/nodeinfo", { body: { links: [{
26
- rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
27
- href: "https://example.com/nodeinfo/2.1"
28
- }] } });
29
- const rawExpected = {
30
- software: {
31
- name: "foo",
32
- version: "1.2.3"
33
- },
34
- protocols: ["activitypub", "diaspora"],
35
- usage: {
36
- users: {},
37
- localPosts: 123,
38
- localComments: 456
39
- }
40
- };
41
- esm_default.get("https://example.com/nodeinfo/2.1", { body: rawExpected });
42
- esm_default.get("https://example.com/404", { status: 404 });
43
- const expected = {
44
- software: {
45
- name: "foo",
46
- version: "1.2.3"
47
- },
48
- protocols: ["activitypub", "diaspora"],
49
- usage: {
50
- users: {},
51
- localPosts: 123,
52
- localComments: 456
53
- }
54
- };
55
- await t.step("indirect", async () => {
56
- assertEquals(await getNodeInfoDirect("https://example.com/"), expected);
57
- assertEquals(await getNodeInfoDirect("https://example.com/", { parse: "none" }), rawExpected);
58
- });
59
- await t.step("direct", async () => {
60
- assertEquals(await getNodeInfoDirect("https://example.com/nodeinfo/2.1", { direct: true }), expected);
61
- });
62
- esm_default.removeRoutes();
63
- esm_default.get("https://example.com/.well-known/nodeinfo", { body: { links: [] } });
64
- await t.step("indirect: no links", async () => {
65
- assertEquals(await getNodeInfoDirect("https://example.com/"), void 0);
66
- });
67
- esm_default.removeRoutes();
68
- esm_default.get("https://example.com/.well-known/nodeinfo", { status: 404 });
69
- await t.step("indirect: 404", async () => {
70
- assertEquals(await getNodeInfoDirect("https://example.com/"), void 0);
71
- });
72
- await t.step("direct: 404", async () => {
73
- assertEquals(await getNodeInfoDirect("https://example.com/nodeinfo/2.0", { direct: true }), void 0);
74
- assertEquals(await getNodeInfoDirect("https://example.com/404", { direct: true }), void 0);
75
- });
76
- esm_default.hardReset();
77
- });
78
- test("getNodeInfo() blocks SSRF", async (t) => {
79
- esm_default.spyGlobal();
80
- await t.step("link href pointing to a loopback address", async () => {
81
- esm_default.removeRoutes();
82
- esm_default.get("https://example.com/.well-known/nodeinfo", { body: { links: [{
83
- rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
84
- href: "http://127.0.0.1:8080/internal"
85
- }] } });
86
- let internalFetched = false;
87
- esm_default.get("http://127.0.0.1:8080/internal", () => {
88
- internalFetched = true;
89
- return { body: { secret: "INTERNAL_DATA_LEAKED" } };
90
- });
91
- assertEquals(await getNodeInfoValidated("https://example.com/", { parse: "none" }), void 0);
92
- assertEquals(internalFetched, false);
93
- });
94
- await t.step("link href using a data: URL", async () => {
95
- esm_default.removeRoutes();
96
- esm_default.get("https://example.com/.well-known/nodeinfo", { body: { links: [{
97
- rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
98
- href: "data:application/json,{\"software\":{\"name\":\"x\"}}"
99
- }] } });
100
- assertEquals(await getNodeInfoValidated("https://example.com/", { parse: "none" }), void 0);
101
- });
102
- await t.step("redirect to a private address", async () => {
103
- esm_default.removeRoutes();
104
- esm_default.get("https://example.com/.well-known/nodeinfo", { body: { links: [{
105
- rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
106
- href: "https://example.com/nodeinfo/2.1"
107
- }] } });
108
- esm_default.get("https://example.com/nodeinfo/2.1", {
109
- status: 302,
110
- headers: { Location: "https://127.0.0.1:8080/internal" }
111
- });
112
- let internalFetched = false;
113
- esm_default.get("https://127.0.0.1:8080/internal", () => {
114
- internalFetched = true;
115
- return { body: { secret: "INTERNAL_DATA_LEAKED" } };
116
- });
117
- assertEquals(await getNodeInfoValidated("https://example.com/", { parse: "none" }), void 0);
118
- assertEquals(internalFetched, false);
119
- });
120
- await t.step("direct fetch of a private address", async () => {
121
- esm_default.removeRoutes();
122
- let internalFetched = false;
123
- esm_default.get("http://127.0.0.1:8080/nodeinfo", () => {
124
- internalFetched = true;
125
- return { body: { software: {
126
- name: "x",
127
- version: "1.0.0"
128
- } } };
129
- });
130
- assertEquals(await getNodeInfoValidated("http://127.0.0.1:8080/nodeinfo", {
131
- direct: true,
132
- parse: "none"
133
- }), void 0);
134
- assertEquals(internalFetched, false);
135
- });
136
- esm_default.hardReset();
137
- });
138
- test("parseNodeInfo()", () => {
139
- const input = {
140
- software: {
141
- name: "foo",
142
- version: "1.2.3",
143
- repository: "https://codeberg.org/foo/foo",
144
- homepage: "https://foo.example"
145
- },
146
- protocols: ["activitypub", "diaspora"],
147
- services: {
148
- inbound: [
149
- "atom1.0",
150
- "pop3",
151
- "twitter"
152
- ],
153
- outbound: [
154
- "atom1.0",
155
- "diaspora",
156
- "facebook"
157
- ]
158
- },
159
- openRegistrations: true,
160
- usage: {
161
- users: {
162
- activeHalfyear: 10,
163
- activeMonth: 20,
164
- total: 30
165
- },
166
- localPosts: 123,
167
- localComments: 456
168
- },
169
- metadata: {
170
- foo: 123,
171
- bar: "456"
172
- }
173
- };
174
- const output = {
175
- software: {
176
- name: "foo",
177
- version: "1.2.3",
178
- repository: new URL("https://codeberg.org/foo/foo"),
179
- homepage: new URL("https://foo.example")
180
- },
181
- protocols: ["activitypub", "diaspora"],
182
- services: {
183
- inbound: [
184
- "atom1.0",
185
- "pop3",
186
- "twitter"
187
- ],
188
- outbound: [
189
- "atom1.0",
190
- "diaspora",
191
- "facebook"
192
- ]
193
- },
194
- openRegistrations: true,
195
- usage: {
196
- users: {
197
- activeHalfyear: 10,
198
- activeMonth: 20,
199
- total: 30
200
- },
201
- localPosts: 123,
202
- localComments: 456
203
- },
204
- metadata: {
205
- foo: 123,
206
- bar: "456"
207
- }
208
- };
209
- assertEquals(parseNodeInfo(123), null);
210
- assertEquals(parseNodeInfo(123, { tryBestEffort: true }), null);
211
- assertEquals(parseNodeInfo(input), output);
212
- assertEquals(parseNodeInfo({
213
- ...input,
214
- software: {
215
- name: " FOO ",
216
- version: "1.2.3"
217
- }
218
- }), null);
219
- assertEquals(parseNodeInfo({
220
- ...input,
221
- software: {
222
- name: " FOO ",
223
- version: "1.2.3"
224
- }
225
- }, { tryBestEffort: true }), {
226
- ...output,
227
- software: {
228
- name: output.software.name,
229
- version: output.software.version
230
- }
231
- });
232
- assertEquals(parseNodeInfo({
233
- ...input,
234
- protocols: 123
235
- }), null);
236
- assertEquals(parseNodeInfo({
237
- ...input,
238
- protocols: 123
239
- }, { tryBestEffort: true }), {
240
- ...output,
241
- protocols: []
242
- });
243
- assertEquals(parseNodeInfo({
244
- ...input,
245
- protocols: ["activitypub", "foo"]
246
- }), null);
247
- assertEquals(parseNodeInfo({
248
- ...input,
249
- protocols: ["activitypub", "foo"]
250
- }, { tryBestEffort: true }), {
251
- ...output,
252
- protocols: ["activitypub"]
253
- });
254
- assertEquals(parseNodeInfo({
255
- ...input,
256
- services: 123
257
- }), null);
258
- assertEquals(parseNodeInfo({
259
- ...input,
260
- services: 123
261
- }, { tryBestEffort: true }), {
262
- software: output.software,
263
- protocols: output.protocols,
264
- openRegistrations: output.openRegistrations,
265
- usage: output.usage,
266
- metadata: output.metadata
267
- });
268
- assertEquals(parseNodeInfo({
269
- ...input,
270
- services: { inbound: ["atom1.0", "foo"] }
271
- }), null);
272
- assertEquals(parseNodeInfo({
273
- ...input,
274
- services: { inbound: ["atom1.0", "foo"] }
275
- }, { tryBestEffort: true }), {
276
- software: output.software,
277
- protocols: output.protocols,
278
- services: { inbound: ["atom1.0"] },
279
- openRegistrations: output.openRegistrations,
280
- usage: output.usage,
281
- metadata: output.metadata
282
- });
283
- assertEquals(parseNodeInfo({
284
- ...input,
285
- openRegistrations: 123
286
- }), null);
287
- assertEquals(parseNodeInfo({
288
- ...input,
289
- openRegistrations: 123
290
- }, { tryBestEffort: true }), {
291
- software: output.software,
292
- protocols: output.protocols,
293
- services: output.services,
294
- usage: output.usage,
295
- metadata: output.metadata
296
- });
297
- assertEquals(parseNodeInfo({
298
- ...input,
299
- usage: 123
300
- }), null);
301
- assertEquals(parseNodeInfo({
302
- ...input,
303
- usage: 123
304
- }, { tryBestEffort: true }), {
305
- software: output.software,
306
- protocols: output.protocols,
307
- services: output.services,
308
- openRegistrations: output.openRegistrations,
309
- usage: {
310
- users: {},
311
- localPosts: 0,
312
- localComments: 0
313
- },
314
- metadata: output.metadata
315
- });
316
- assertEquals(parseNodeInfo({
317
- ...input,
318
- metadata: 123
319
- }), null);
320
- assertEquals(parseNodeInfo({
321
- ...input,
322
- metadata: 123
323
- }, { tryBestEffort: true }), {
324
- software: output.software,
325
- protocols: output.protocols,
326
- services: output.services,
327
- openRegistrations: output.openRegistrations,
328
- usage: output.usage
329
- });
330
- });
331
- test("parseSoftware()", () => {
332
- assertEquals(parseSoftware({
333
- name: "foo",
334
- version: "1.2.3",
335
- repository: "https://codeberg.org/foo/foo",
336
- homepage: "https://foo.example"
337
- }), {
338
- name: "foo",
339
- version: "1.2.3",
340
- repository: new URL("https://codeberg.org/foo/foo"),
341
- homepage: new URL("https://foo.example")
342
- });
343
- assertEquals(parseSoftware({
344
- name: "foo",
345
- version: "4.5.6-beta.7+build.8"
346
- }), {
347
- name: "foo",
348
- version: "4.5.6-beta.7+build.8"
349
- });
350
- assertEquals(parseSoftware(123), null);
351
- assertEquals(parseSoftware(123, { tryBestEffort: true }), null);
352
- assertEquals(parseSoftware({ name: 123 }), null);
353
- assertEquals(parseSoftware({ name: 123 }, { tryBestEffort: true }), null);
354
- assertEquals(parseSoftware({ name: "" }), null);
355
- assertEquals(parseSoftware({ name: "" }, { tryBestEffort: true }), null);
356
- assertEquals(parseSoftware({ name: " FOO " }), null);
357
- assertEquals(parseSoftware({ name: " FOO " }, { tryBestEffort: true }), {
358
- name: "foo",
359
- version: "0.0.0"
360
- });
361
- assertEquals(parseSoftware({
362
- name: "foo",
363
- version: 123
364
- }), {
365
- name: "foo",
366
- version: "123"
367
- });
368
- assertEquals(parseSoftware({
369
- name: "foo",
370
- version: 123
371
- }, { tryBestEffort: true }), {
372
- name: "foo",
373
- version: "123"
374
- });
375
- assertEquals(parseSoftware({
376
- name: "foo",
377
- version: "abc"
378
- }), {
379
- name: "foo",
380
- version: "abc"
381
- });
382
- assertEquals(parseSoftware({
383
- name: "foo",
384
- version: "abc"
385
- }, { tryBestEffort: true }), {
386
- name: "foo",
387
- version: "abc"
388
- });
389
- assertEquals(parseSoftware({
390
- name: "foo",
391
- version: " 1.2.3 "
392
- }), {
393
- name: "foo",
394
- version: " 1.2.3 "
395
- });
396
- assertEquals(parseSoftware({
397
- name: "foo",
398
- version: " 1.2.3 "
399
- }, { tryBestEffort: true }), {
400
- name: "foo",
401
- version: " 1.2.3 "
402
- });
403
- assertEquals(parseSoftware({
404
- name: "foo",
405
- version: "1.2.3",
406
- repository: 123
407
- }), null);
408
- assertEquals(parseSoftware({
409
- name: "foo",
410
- version: "1.2.3",
411
- homepage: 456
412
- }), null);
413
- assertEquals(parseSoftware({
414
- name: "foo",
415
- version: "1.2.3",
416
- repository: 123,
417
- homepage: 456
418
- }, { tryBestEffort: true }), {
419
- name: "foo",
420
- version: "1.2.3"
421
- });
422
- assertEquals(parseSoftware({
423
- name: "foo",
424
- version: "1.2.3",
425
- repository: ""
426
- }), null);
427
- assertEquals(parseSoftware({
428
- name: "foo",
429
- version: "1.2.3",
430
- homepage: ""
431
- }), null);
432
- assertEquals(parseSoftware({
433
- name: "foo",
434
- version: "1.2.3",
435
- repository: "",
436
- homepage: ""
437
- }, { tryBestEffort: true }), {
438
- name: "foo",
439
- version: "1.2.3"
440
- });
441
- assertEquals(parseSoftware({
442
- name: "foo",
443
- version: "2.81",
444
- repository: "",
445
- homepage: ""
446
- }, { tryBestEffort: true }), {
447
- name: "foo",
448
- version: "2.81"
449
- });
450
- assertEquals(parseSoftware({
451
- name: "foo",
452
- version: "3",
453
- repository: "",
454
- homepage: ""
455
- }, { tryBestEffort: true }), {
456
- name: "foo",
457
- version: "3"
458
- });
459
- assertEquals(parseSoftware({
460
- name: "foo",
461
- version: "2.1.3.4",
462
- repository: "",
463
- homepage: ""
464
- }, { tryBestEffort: true }), {
465
- name: "foo",
466
- version: "2.1.3.4"
467
- });
468
- });
469
- test("parseProtocol()", () => {
470
- for (const protocol of [
471
- "activitypub",
472
- "buddycloud",
473
- "dfrn",
474
- "diaspora",
475
- "libertree",
476
- "ostatus",
477
- "pumpio",
478
- "tent",
479
- "xmpp",
480
- "zot"
481
- ]) assertEquals(parseProtocol(protocol), protocol);
482
- assertEquals(parseProtocol("foo"), null);
483
- });
484
- test("parseServices()", () => {
485
- assertEquals(parseServices({
486
- inbound: [
487
- "atom1.0",
488
- "pop3",
489
- "twitter"
490
- ],
491
- outbound: [
492
- "atom1.0",
493
- "diaspora",
494
- "facebook"
495
- ]
496
- }), {
497
- inbound: [
498
- "atom1.0",
499
- "pop3",
500
- "twitter"
501
- ],
502
- outbound: [
503
- "atom1.0",
504
- "diaspora",
505
- "facebook"
506
- ]
507
- });
508
- assertEquals(parseServices({ inbound: [
509
- "atom1.0",
510
- "pop3",
511
- "twitter"
512
- ] }), { inbound: [
513
- "atom1.0",
514
- "pop3",
515
- "twitter"
516
- ] });
517
- assertEquals(parseServices({ outbound: [
518
- "atom1.0",
519
- "diaspora",
520
- "facebook"
521
- ] }), { outbound: [
522
- "atom1.0",
523
- "diaspora",
524
- "facebook"
525
- ] });
526
- assertEquals(parseServices({}), {});
527
- assertEquals(parseServices(123), null);
528
- assertEquals(parseServices(123, { tryBestEffort: true }), {});
529
- assertEquals(parseServices({
530
- inbound: [
531
- "atom1.0",
532
- "pop3",
533
- "twitter",
534
- "foo"
535
- ],
536
- outbound: [
537
- "atom1.0",
538
- "diaspora",
539
- "facebook"
540
- ]
541
- }), null);
542
- assertEquals(parseServices({
543
- inbound: [
544
- "atom1.0",
545
- "pop3",
546
- "twitter"
547
- ],
548
- outbound: [
549
- "atom1.0",
550
- "diaspora",
551
- "facebook",
552
- "bar"
553
- ]
554
- }), null);
555
- assertEquals(parseServices({
556
- inbound: [
557
- "atom1.0",
558
- "pop3",
559
- "twitter",
560
- "foo"
561
- ],
562
- outbound: [
563
- "atom1.0",
564
- "diaspora",
565
- "facebook",
566
- "bar"
567
- ]
568
- }, { tryBestEffort: true }), {
569
- inbound: [
570
- "atom1.0",
571
- "pop3",
572
- "twitter"
573
- ],
574
- outbound: [
575
- "atom1.0",
576
- "diaspora",
577
- "facebook"
578
- ]
579
- });
580
- });
581
- test("parseInboundService()", () => {
582
- for (const service of [
583
- "atom1.0",
584
- "gnusocial",
585
- "imap",
586
- "pnut",
587
- "pop3",
588
- "pumpio",
589
- "rss2.0",
590
- "twitter"
591
- ]) assertEquals(parseInboundService(service), service);
592
- assertEquals(parseInboundService("foo"), null);
593
- });
594
- test("parseOutboundService()", () => {
595
- for (const service of [
596
- "atom1.0",
597
- "blogger",
598
- "buddycloud",
599
- "diaspora",
600
- "dreamwidth",
601
- "drupal",
602
- "facebook",
603
- "friendica",
604
- "gnusocial",
605
- "google",
606
- "insanejournal",
607
- "libertree",
608
- "linkedin",
609
- "livejournal",
610
- "mediagoblin",
611
- "myspace",
612
- "pinterest",
613
- "pnut",
614
- "posterous",
615
- "pumpio",
616
- "redmatrix",
617
- "rss2.0",
618
- "smtp",
619
- "tent",
620
- "tumblr",
621
- "twitter",
622
- "wordpress",
623
- "xmpp"
624
- ]) assertEquals(parseOutboundService(service), service);
625
- assertEquals(parseOutboundService("foo"), null);
626
- });
627
- test("parseUsage()", () => {
628
- assertEquals(parseUsage({
629
- users: {},
630
- localPosts: 123,
631
- localComments: 456
632
- }), {
633
- users: {},
634
- localPosts: 123,
635
- localComments: 456
636
- });
637
- assertEquals(parseUsage({
638
- users: {
639
- activeHalfyear: 10,
640
- activeMonth: 20,
641
- total: 30
642
- },
643
- localPosts: 123,
644
- localComments: 456
645
- }), {
646
- users: {
647
- activeHalfyear: 10,
648
- activeMonth: 20,
649
- total: 30
650
- },
651
- localPosts: 123,
652
- localComments: 456
653
- });
654
- assertEquals(parseUsage(123), null);
655
- assertEquals(parseUsage(123, { tryBestEffort: true }), null);
656
- assertEquals(parseUsage({
657
- users: {},
658
- localPosts: "123",
659
- localComments: 456
660
- }), null);
661
- assertEquals(parseUsage({
662
- users: {},
663
- localPosts: "123",
664
- localComments: 456
665
- }, { tryBestEffort: true }), {
666
- users: {},
667
- localPosts: 123,
668
- localComments: 456
669
- });
670
- assertEquals(parseUsage({
671
- users: {},
672
- localPosts: "",
673
- localComments: 456
674
- }), null);
675
- assertEquals(parseUsage({
676
- users: {},
677
- localPosts: "",
678
- localComments: 456
679
- }, { tryBestEffort: true }), {
680
- users: {},
681
- localPosts: 0,
682
- localComments: 456
683
- });
684
- assertEquals(parseUsage({
685
- users: {},
686
- localPosts: [],
687
- localComments: 456
688
- }), null);
689
- assertEquals(parseUsage({
690
- users: {},
691
- localPosts: [],
692
- localComments: 456
693
- }, { tryBestEffort: true }), {
694
- users: {},
695
- localPosts: 0,
696
- localComments: 456
697
- });
698
- assertEquals(parseUsage({
699
- users: {},
700
- localPosts: 123,
701
- localComments: "456"
702
- }), null);
703
- assertEquals(parseUsage({
704
- users: {},
705
- localPosts: 123,
706
- localComments: "456"
707
- }, { tryBestEffort: true }), {
708
- users: {},
709
- localPosts: 123,
710
- localComments: 456
711
- });
712
- assertEquals(parseUsage({
713
- users: {},
714
- localPosts: 123,
715
- localComments: ""
716
- }), null);
717
- assertEquals(parseUsage({
718
- users: {},
719
- localPosts: 123,
720
- localComments: ""
721
- }, { tryBestEffort: true }), {
722
- users: {},
723
- localPosts: 123,
724
- localComments: 0
725
- });
726
- assertEquals(parseUsage({
727
- users: null,
728
- localPosts: 123,
729
- localComments: []
730
- }), null);
731
- assertEquals(parseUsage({
732
- users: null,
733
- localPosts: 123,
734
- localComments: ""
735
- }, { tryBestEffort: true }), {
736
- users: {},
737
- localPosts: 123,
738
- localComments: 0
739
- });
740
- assertEquals(parseUsage({
741
- users: {},
742
- localPosts: 123,
743
- localComments: []
744
- }), null);
745
- assertEquals(parseUsage({
746
- users: {},
747
- localPosts: 123,
748
- localComments: []
749
- }, { tryBestEffort: true }), {
750
- users: {},
751
- localPosts: 123,
752
- localComments: 0
753
- });
754
- assertEquals(parseUsage({
755
- users: {
756
- activeHalfyear: "10",
757
- activeMonth: 20,
758
- total: 30
759
- },
760
- localPosts: 123,
761
- localComments: 456
762
- }), null);
763
- assertEquals(parseUsage({
764
- users: {
765
- activeHalfyear: "10",
766
- activeMonth: 20,
767
- total: 30
768
- },
769
- localPosts: 123,
770
- localComments: 456
771
- }, { tryBestEffort: true }), {
772
- users: {
773
- activeHalfyear: 10,
774
- activeMonth: 20,
775
- total: 30
776
- },
777
- localPosts: 123,
778
- localComments: 456
779
- });
780
- assertEquals(parseUsage({
781
- users: {
782
- activeHalfyear: "",
783
- activeMonth: 20,
784
- total: 30
785
- },
786
- localPosts: 123,
787
- localComments: 456
788
- }), null);
789
- assertEquals(parseUsage({
790
- users: {
791
- activeHalfyear: "",
792
- activeMonth: 20,
793
- total: 30
794
- },
795
- localPosts: 123,
796
- localComments: 456
797
- }, { tryBestEffort: true }), {
798
- users: {
799
- activeMonth: 20,
800
- total: 30
801
- },
802
- localPosts: 123,
803
- localComments: 456
804
- });
805
- assertEquals(parseUsage({
806
- users: {
807
- activeHalfyear: [],
808
- activeMonth: 20,
809
- total: 30
810
- },
811
- localPosts: 123,
812
- localComments: 456
813
- }), null);
814
- assertEquals(parseUsage({
815
- users: {
816
- activeHalfyear: [],
817
- activeMonth: 20,
818
- total: 30
819
- },
820
- localPosts: 123,
821
- localComments: 456
822
- }, { tryBestEffort: true }), {
823
- users: {
824
- activeMonth: 20,
825
- total: 30
826
- },
827
- localPosts: 123,
828
- localComments: 456
829
- });
830
- assertEquals(parseUsage({
831
- users: {
832
- activeHalfyear: 10,
833
- activeMonth: "20",
834
- total: 30
835
- },
836
- localPosts: 123,
837
- localComments: 456
838
- }), null);
839
- assertEquals(parseUsage({
840
- users: {
841
- activeHalfyear: 10,
842
- activeMonth: "20",
843
- total: 30
844
- },
845
- localPosts: 123,
846
- localComments: 456
847
- }, { tryBestEffort: true }), {
848
- users: {
849
- activeHalfyear: 10,
850
- activeMonth: 20,
851
- total: 30
852
- },
853
- localPosts: 123,
854
- localComments: 456
855
- });
856
- assertEquals(parseUsage({
857
- users: {
858
- activeHalfyear: 10,
859
- activeMonth: "",
860
- total: 30
861
- },
862
- localPosts: 123,
863
- localComments: 456
864
- }), null);
865
- assertEquals(parseUsage({
866
- users: {
867
- activeHalfyear: 10,
868
- activeMonth: "",
869
- total: 30
870
- },
871
- localPosts: 123,
872
- localComments: 456
873
- }, { tryBestEffort: true }), {
874
- users: {
875
- activeHalfyear: 10,
876
- total: 30
877
- },
878
- localPosts: 123,
879
- localComments: 456
880
- });
881
- assertEquals(parseUsage({
882
- users: {
883
- activeHalfyear: 10,
884
- activeMonth: [],
885
- total: 30
886
- },
887
- localPosts: 123,
888
- localComments: 456
889
- }), null);
890
- assertEquals(parseUsage({
891
- users: {
892
- activeHalfyear: 10,
893
- activeMonth: [],
894
- total: 30
895
- },
896
- localPosts: 123,
897
- localComments: 456
898
- }, { tryBestEffort: true }), {
899
- users: {
900
- activeHalfyear: 10,
901
- total: 30
902
- },
903
- localPosts: 123,
904
- localComments: 456
905
- });
906
- assertEquals(parseUsage({
907
- users: {
908
- activeHalfyear: 10,
909
- activeMonth: 20,
910
- total: "30"
911
- },
912
- localPosts: 123,
913
- localComments: 456
914
- }), null);
915
- assertEquals(parseUsage({
916
- users: {
917
- activeHalfyear: 10,
918
- activeMonth: 20,
919
- total: "30"
920
- },
921
- localPosts: 123,
922
- localComments: 456
923
- }, { tryBestEffort: true }), {
924
- users: {
925
- activeHalfyear: 10,
926
- activeMonth: 20,
927
- total: 30
928
- },
929
- localPosts: 123,
930
- localComments: 456
931
- });
932
- assertEquals(parseUsage({
933
- users: {
934
- activeHalfyear: 10,
935
- activeMonth: 20,
936
- total: ""
937
- },
938
- localPosts: 123,
939
- localComments: 456
940
- }), null);
941
- assertEquals(parseUsage({
942
- users: {
943
- activeHalfyear: 10,
944
- activeMonth: 20,
945
- total: ""
946
- },
947
- localPosts: 123,
948
- localComments: 456
949
- }, { tryBestEffort: true }), {
950
- users: {
951
- activeHalfyear: 10,
952
- activeMonth: 20
953
- },
954
- localPosts: 123,
955
- localComments: 456
956
- });
957
- assertEquals(parseUsage({
958
- users: {
959
- activeHalfyear: 10,
960
- activeMonth: 20,
961
- total: []
962
- },
963
- localPosts: 123,
964
- localComments: 456
965
- }), null);
966
- assertEquals(parseUsage({
967
- users: {
968
- activeHalfyear: 10,
969
- activeMonth: 20,
970
- total: []
971
- },
972
- localPosts: 123,
973
- localComments: 456
974
- }, { tryBestEffort: true }), {
975
- users: {
976
- activeHalfyear: 10,
977
- activeMonth: 20
978
- },
979
- localPosts: 123,
980
- localComments: 456
981
- });
982
- });
983
- test("getNodeInfo() bounds both discovery and document responses", async () => {
984
- esm_default.mockGlobal();
985
- const base = "https://8.8.8.8";
986
- const descriptor = { links: [{
987
- rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
988
- href: `${base}/nodeinfo`
989
- }] };
990
- let oversizedDescriptor = true;
991
- let oversizedDocument = true;
992
- const data = { padding: "a".repeat(256) };
993
- try {
994
- esm_default.get(`${base}/.well-known/nodeinfo`, () => new Response(JSON.stringify(descriptor), { headers: oversizedDescriptor ? { "Content-Length": String(16777217) } : {} }));
995
- esm_default.get(`${base}/nodeinfo`, () => new Response(JSON.stringify(data), { headers: oversizedDocument ? { "Content-Length": String(16777217) } : {} }));
996
- assertEquals(await getNodeInfo(base), void 0);
997
- assertEquals(esm_default.callHistory.calls(`${base}/nodeinfo`).length, 0);
998
- oversizedDescriptor = false;
999
- assertEquals(await getNodeInfo(base), void 0);
1000
- assertEquals(await getNodeInfo(`${base}/nodeinfo`, {
1001
- direct: true,
1002
- parse: "none"
1003
- }), void 0);
1004
- oversizedDocument = false;
1005
- assertEquals(await getNodeInfo(base, { parse: "none" }), data);
1006
- } finally {
1007
- esm_default.hardReset();
1008
- }
1009
- });
1010
- test("getNodeInfo() logs DNS failures as such", async (t) => {
1011
- for (const result of [
1012
- "throws",
1013
- "empty",
1014
- "private"
1015
- ]) await t.step(result, async () => {
1016
- const lookup = () => result === "throws" ? Promise.reject(/* @__PURE__ */ new Error("Resolver unavailable")) : Promise.resolve(result === "empty" ? [] : [{
1017
- address: "127.0.0.1",
1018
- family: 4
1019
- }]);
1020
- const records = [];
1021
- await configure({
1022
- sinks: { buffer: (record) => records.push(record) },
1023
- loggers: [{
1024
- category: "fedify",
1025
- sinks: ["buffer"],
1026
- lowestLevel: "debug"
1027
- }, {
1028
- category: ["logtape", "meta"],
1029
- sinks: []
1030
- }],
1031
- reset: true
1032
- });
1033
- try {
1034
- assertEquals(await getNodeInfoInternal("https://dns-failure.invalid/", {}, { openHop: (url) => openPublicFetch(url, { lookup }) }), void 0);
1035
- assertEquals(records.map((r) => [
1036
- r.level,
1037
- r.rawMessage,
1038
- r.properties.url
1039
- ]), [[
1040
- "error",
1041
- result === "private" ? "Refused to fetch a private or invalid URL {url}: {error}" : "DNS lookup failed for {url}: {error}",
1042
- "https://dns-failure.invalid/.well-known/nodeinfo"
1043
- ]]);
1044
- const { error } = records[0].properties;
1045
- assertInstanceOf(error, UrlError);
1046
- assertEquals(error.reason, result === "private" ? "disallowed" : "dns");
1047
- } finally {
1048
- await reset();
1049
- }
1050
- });
1051
- });
1052
- function recordHops(respond) {
1053
- const events = [];
1054
- const unsettled = [];
1055
- let opens = 0;
1056
- let closes = 0;
1057
- let responses = 0;
1058
- return {
1059
- events,
1060
- async openHop(url) {
1061
- opens++;
1062
- events.push(`open ${url}`);
1063
- const states = [];
1064
- let closed = false;
1065
- return {
1066
- url: new URL(url),
1067
- async fetch(input) {
1068
- if (closed) throw new TypeError("The fetch session is closed.");
1069
- const target = new URL(input instanceof Request ? input.url : input);
1070
- const id = ++responses;
1071
- events.push(`fetch ${target.href} #${id}`);
1072
- const fake = respond(target);
1073
- const state = {
1074
- id,
1075
- settled: false
1076
- };
1077
- states.push(state);
1078
- let sent = false;
1079
- const body = new ReadableStream({
1080
- pull(controller) {
1081
- if (!sent && fake.body != null && fake.body !== "") {
1082
- sent = true;
1083
- controller.enqueue(new TextEncoder().encode(fake.body));
1084
- return;
1085
- }
1086
- state.settled = true;
1087
- events.push(`consumed #${id}`);
1088
- controller.close();
1089
- },
1090
- cancel() {
1091
- state.settled = true;
1092
- events.push(`cancel #${id}`);
1093
- if (fake.cancelFails) throw new Error("Cancellation failed");
1094
- if (fake.cancelNeverSettles) return new Promise(() => {});
1095
- }
1096
- }, { highWaterMark: 0 });
1097
- const response = new Response(body, {
1098
- status: fake.status ?? 200,
1099
- headers: fake.headers
1100
- });
1101
- if (fake.url != null) Object.defineProperty(response, "url", { value: fake.url });
1102
- return response;
1103
- },
1104
- async close() {
1105
- if (closed) return;
1106
- closed = true;
1107
- closes++;
1108
- for (const state of states) if (!state.settled) unsettled.push(`#${state.id}`);
1109
- events.push(`close ${url}`);
1110
- }
1111
- };
1112
- },
1113
- assertInvariants() {
1114
- assertEquals(closes, opens);
1115
- assertEquals(unsettled, []);
1116
- }
1117
- };
1118
- }
1119
- test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
1120
- const wellKnown = "https://example.com/.well-known/nodeinfo";
1121
- const wellKnown2 = "https://example.com/.well-known/nodeinfo2";
1122
- const documentUrl = "https://example.com/nodeinfo/2.1";
1123
- const rawDocument = {
1124
- software: {
1125
- name: "foo",
1126
- version: "1.2.3"
1127
- },
1128
- protocols: ["activitypub"],
1129
- usage: {
1130
- users: {},
1131
- localPosts: 0,
1132
- localComments: 0
1133
- }
1134
- };
1135
- const descriptor = JSON.stringify({ links: [{
1136
- rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
1137
- href: documentUrl
1138
- }] });
1139
- await t.step("redirect", async () => {
1140
- const recorder = recordHops((url) => {
1141
- switch (url.href) {
1142
- case wellKnown: return {
1143
- status: 302,
1144
- headers: { Location: "/.well-known/nodeinfo2" },
1145
- body: "redirecting",
1146
- url: "https://93.184.215.14/.well-known/nodeinfo"
1147
- };
1148
- case wellKnown2: return { body: descriptor };
1149
- default: return { body: JSON.stringify(rawDocument) };
1150
- }
1151
- });
1152
- assertEquals(await getNodeInfoInternal("https://example.com/", { parse: "none" }, { openHop: recorder.openHop }), rawDocument);
1153
- assertEquals(recorder.events, [
1154
- `open ${wellKnown}`,
1155
- `fetch ${wellKnown} #1`,
1156
- "cancel #1",
1157
- `close ${wellKnown}`,
1158
- `open ${wellKnown2}`,
1159
- `fetch ${wellKnown2} #2`,
1160
- "consumed #2",
1161
- `close ${wellKnown2}`,
1162
- `open ${documentUrl}`,
1163
- `fetch ${documentUrl} #3`,
1164
- "consumed #3",
1165
- `close ${documentUrl}`
1166
- ]);
1167
- recorder.assertInvariants();
1168
- });
1169
- await t.step("non-2xx responses", async () => {
1170
- const recorder = recordHops(() => ({
1171
- status: 404,
1172
- body: "not found"
1173
- }));
1174
- assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
1175
- assertEquals(await getNodeInfoInternal(documentUrl, { direct: true }, { openHop: recorder.openHop }), void 0);
1176
- assertEquals(recorder.events, [
1177
- `open ${wellKnown}`,
1178
- `fetch ${wellKnown} #1`,
1179
- "cancel #1",
1180
- `close ${wellKnown}`,
1181
- `open ${documentUrl}`,
1182
- `fetch ${documentUrl} #2`,
1183
- "cancel #2",
1184
- `close ${documentUrl}`
1185
- ]);
1186
- recorder.assertInvariants();
1187
- });
1188
- await t.step("too many redirections", async () => {
1189
- const recorder = recordHops(() => ({
1190
- status: 302,
1191
- headers: { Location: "/.well-known/nodeinfo" },
1192
- body: "redirecting"
1193
- }));
1194
- assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
1195
- assertEquals(recorder.events.filter((e) => e.startsWith("open ")).length, 5);
1196
- assertEquals(recorder.events.filter((e) => e.startsWith("cancel ")).length, 5);
1197
- recorder.assertInvariants();
1198
- });
1199
- await t.step("failed redirect body cancellation", async () => {
1200
- const recorder = recordHops((url) => {
1201
- switch (url.href) {
1202
- case wellKnown: return {
1203
- status: 302,
1204
- headers: { Location: "/.well-known/nodeinfo2" },
1205
- body: "redirecting",
1206
- cancelFails: true
1207
- };
1208
- case wellKnown2: return { body: descriptor };
1209
- default: return {
1210
- status: 404,
1211
- body: "not found",
1212
- cancelFails: true
1213
- };
1214
- }
1215
- });
1216
- const records = [];
1217
- await configure({
1218
- sinks: { buffer: (record) => records.push(record) },
1219
- loggers: [{
1220
- category: "fedify",
1221
- sinks: ["buffer"],
1222
- lowestLevel: "debug"
1223
- }, {
1224
- category: ["logtape", "meta"],
1225
- sinks: []
1226
- }],
1227
- reset: true
1228
- });
1229
- try {
1230
- assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
1231
- const failures = records.filter((r) => r.rawMessage === "Failed to cancel the response body from {url}: {error}");
1232
- assertEquals(failures.map((r) => [r.level, r.properties.url]), [["debug", wellKnown], ["debug", documentUrl]]);
1233
- for (const { properties: { error } } of failures) {
1234
- assertInstanceOf(error, Error);
1235
- assertEquals(error.message, "Cancellation failed");
1236
- }
1237
- } finally {
1238
- await reset();
1239
- }
1240
- assertEquals(recorder.events, [
1241
- `open ${wellKnown}`,
1242
- `fetch ${wellKnown} #1`,
1243
- "cancel #1",
1244
- `close ${wellKnown}`,
1245
- `open ${wellKnown2}`,
1246
- `fetch ${wellKnown2} #2`,
1247
- "consumed #2",
1248
- `close ${wellKnown2}`,
1249
- `open ${documentUrl}`,
1250
- `fetch ${documentUrl} #3`,
1251
- "cancel #3",
1252
- `close ${documentUrl}`
1253
- ]);
1254
- recorder.assertInvariants();
1255
- });
1256
- await t.step("never-settling body cancellation", async () => {
1257
- const recorder = recordHops((url) => {
1258
- switch (url.href) {
1259
- case wellKnown: return {
1260
- status: 302,
1261
- headers: { Location: "/.well-known/nodeinfo2" },
1262
- body: "redirecting",
1263
- cancelNeverSettles: true
1264
- };
1265
- case wellKnown2: return { body: descriptor };
1266
- default: return {
1267
- status: 404,
1268
- body: "not found",
1269
- cancelNeverSettles: true
1270
- };
1271
- }
1272
- });
1273
- assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop })), void 0);
1274
- assertEquals(recorder.events, [
1275
- `open ${wellKnown}`,
1276
- `fetch ${wellKnown} #1`,
1277
- "cancel #1",
1278
- `close ${wellKnown}`,
1279
- `open ${wellKnown2}`,
1280
- `fetch ${wellKnown2} #2`,
1281
- "consumed #2",
1282
- `close ${wellKnown2}`,
1283
- `open ${documentUrl}`,
1284
- `fetch ${documentUrl} #3`,
1285
- "cancel #3",
1286
- `close ${documentUrl}`
1287
- ]);
1288
- recorder.assertInvariants();
1289
- });
1290
- await t.step("failure while consuming", async () => {
1291
- const recorder = recordHops(() => ({ body: "not json" }));
1292
- assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
1293
- assertEquals(recorder.events, [
1294
- `open ${wellKnown}`,
1295
- `fetch ${wellKnown} #1`,
1296
- "consumed #1",
1297
- `close ${wellKnown}`
1298
- ]);
1299
- recorder.assertInvariants();
1300
- });
1301
- });
1302
- /**
1303
- * Rejects if the given promise does not settle within the timeout, so that
1304
- * a hang fails the test instead of blocking it.
1305
- */
1306
- async function settleWithin(promise, ms = 5e3) {
1307
- let timer;
1308
- try {
1309
- return await Promise.race([promise, new Promise((_, reject) => {
1310
- timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Did not settle within ${ms} ms.`)), ms);
1311
- })]);
1312
- } finally {
1313
- clearTimeout(timer);
1314
- }
1315
- }
1316
- function neverCancellableResponse(init) {
1317
- return new Response(new ReadableStream({
1318
- start(controller) {
1319
- controller.enqueue(new TextEncoder().encode("never cancelled"));
1320
- },
1321
- cancel: () => new Promise(() => {})
1322
- }), init);
1323
- }
1324
- test("getNodeInfo() does not wait for cancelling response bodies", async (t) => {
1325
- const rawDocument = {
1326
- software: {
1327
- name: "foo",
1328
- version: "1.2.3"
1329
- },
1330
- protocols: ["activitypub"],
1331
- usage: {
1332
- users: {},
1333
- localPosts: 0,
1334
- localComments: 0
1335
- }
1336
- };
1337
- esm_default.mockGlobal();
1338
- try {
1339
- await t.step("redirect", async () => {
1340
- esm_default.removeRoutes();
1341
- esm_default.get("https://example.com/.well-known/nodeinfo", () => neverCancellableResponse({
1342
- status: 302,
1343
- headers: { Location: "/.well-known/nodeinfo2" }
1344
- }));
1345
- esm_default.get("https://example.com/.well-known/nodeinfo2", () => Response.json({ links: [{
1346
- rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
1347
- href: "https://example.com/nodeinfo/2.1"
1348
- }] }));
1349
- esm_default.get("https://example.com/nodeinfo/2.1", () => Response.json(rawDocument));
1350
- assertEquals(await settleWithin(getNodeInfoDirect("https://example.com/", { parse: "none" })), rawDocument);
1351
- });
1352
- await t.step("non-2xx responses", async () => {
1353
- esm_default.removeRoutes();
1354
- esm_default.get("https://example.com/.well-known/nodeinfo", () => neverCancellableResponse({ status: 404 }));
1355
- esm_default.get("https://example.com/nodeinfo/2.1", () => neverCancellableResponse({ status: 404 }));
1356
- assertEquals(await settleWithin(getNodeInfoDirect("https://example.com/")), void 0);
1357
- assertEquals(await settleWithin(getNodeInfoDirect("https://example.com/nodeinfo/2.1", { direct: true })), void 0);
1358
- });
1359
- } finally {
1360
- esm_default.hardReset();
1361
- }
1362
- });
1363
- //#endregion
1364
- export {};