@fedify/vocab-runtime 2.4.0-pr.936.41 → 2.4.1
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/deno.json +4 -2
- package/dist/{tests/docloader-Ck8bcBir.mjs → contexts-B09jb9Pi.cjs} +173 -274
- package/dist/{tests/docloader-S_gQZ2tt.cjs → contexts-DWrj4AGR.js} +169 -293
- package/dist/{docloader-C_dir7Xb.d.ts → docloader-BMHljyYb.d.cts} +68 -2
- package/dist/{docloader-D2DTRiyA.d.cts → docloader-BMHljyYb.d.ts} +68 -2
- package/dist/internal/jsonld-cache.cjs +70 -1
- package/dist/internal/jsonld-cache.d.cts +35 -2
- package/dist/internal/jsonld-cache.d.ts +35 -2
- package/dist/internal/jsonld-cache.js +67 -2
- package/dist/internal/portable-dereference.cjs +721 -0
- package/dist/internal/portable-dereference.d.cts +349 -0
- package/dist/internal/portable-dereference.d.ts +349 -0
- package/dist/internal/portable-dereference.js +702 -0
- package/dist/internal/signed-representation.cjs +378 -0
- package/dist/internal/signed-representation.d.cts +144 -0
- package/dist/internal/signed-representation.d.ts +144 -0
- package/dist/internal/signed-representation.js +371 -0
- package/dist/jsonld.cjs +2 -2
- package/dist/mod.cjs +762 -4529
- package/dist/mod.d.cts +427 -9
- package/dist/mod.d.ts +427 -10
- package/dist/mod.js +742 -4524
- package/dist/portable-6Aj-7dZJ.d.cts +160 -0
- package/dist/portable-nkTiqH0w.d.ts +160 -0
- package/dist/tests/body-DpC9p-iG.mjs +130 -0
- package/dist/tests/body-cKLBprYm.cjs +153 -0
- package/dist/tests/body.test.cjs +89 -0
- package/dist/tests/body.test.d.cts +1 -0
- package/dist/tests/body.test.d.mts +1 -0
- package/dist/tests/body.test.mjs +90 -0
- package/dist/tests/contexts-C9Lj11SC.cjs +4533 -0
- package/dist/tests/contexts-duRA_dDC.mjs +4522 -0
- package/dist/tests/decimal.test.cjs +9 -7
- package/dist/tests/decimal.test.mjs +9 -6
- package/dist/tests/digest-3FeH2Y-Q.cjs +176 -0
- package/dist/tests/digest-COC7xDiQ.mjs +141 -0
- package/dist/tests/digest.test.cjs +102 -0
- package/dist/tests/digest.test.d.cts +1 -0
- package/dist/tests/digest.test.d.mts +1 -0
- package/dist/tests/digest.test.mjs +103 -0
- package/dist/tests/docloader-DyZ1JGIl.cjs +398 -0
- package/dist/tests/docloader-tUmMeXjU.mjs +375 -0
- package/dist/tests/docloader.test.cjs +816 -39
- package/dist/tests/docloader.test.mjs +810 -34
- package/dist/tests/internal/multicodec.test.cjs +2 -3
- package/dist/tests/internal/multicodec.test.mjs +2 -2
- package/dist/tests/internal/portable-dereference.test.cjs +172 -0
- package/dist/tests/internal/portable-dereference.test.d.cts +1 -0
- package/dist/tests/internal/portable-dereference.test.d.mts +1 -0
- package/dist/tests/internal/portable-dereference.test.mjs +173 -0
- package/dist/tests/jsonld-CmDhHNTx.cjs +12 -0
- package/dist/tests/jsonld-DweIJ07b.mjs +5 -0
- package/dist/tests/jsonld-cache-BEXiiM-V.cjs +386 -0
- package/dist/tests/jsonld-cache-DFnWsLuZ.mjs +339 -0
- package/dist/tests/jsonld-cache.test.cjs +102 -298
- package/dist/tests/jsonld-cache.test.mjs +95 -289
- package/dist/tests/{key-_wXwomh_.cjs → key-C-AYkdJJ.cjs} +11 -4
- package/dist/tests/{key-CDGDH_vC.mjs → key-C2Db_TAJ.mjs} +11 -3
- package/dist/tests/key.test.cjs +6 -5
- package/dist/tests/key.test.mjs +6 -4
- package/dist/tests/{langstr-Di5AvKpB.mjs → langstr-DYRmJqFn.mjs} +5 -2
- package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-_PqsL1ae.cjs} +5 -2
- package/dist/tests/langstr.test.cjs +11 -4
- package/dist/tests/langstr.test.mjs +9 -2
- package/dist/tests/langtag-CUppHs_s.mjs +45 -0
- package/dist/tests/langtag-Czjvxfzx.cjs +50 -0
- package/dist/tests/langtag.test.cjs +45 -0
- package/dist/tests/langtag.test.d.cts +1 -0
- package/dist/tests/langtag.test.d.mts +1 -0
- package/dist/tests/langtag.test.mjs +46 -0
- package/dist/tests/link.test.cjs +2 -3
- package/dist/tests/link.test.mjs +2 -2
- package/dist/tests/multibase/multibase.test.cjs +8 -9
- package/dist/tests/multibase/multibase.test.mjs +6 -6
- package/dist/tests/{multibase-Bz_UUDtL.cjs → multibase-B5Mea7Ip.cjs} +19 -2
- package/dist/tests/{multibase-B4bvakyA.mjs → multibase-BPnF_L4e.mjs} +12 -1
- package/dist/tests/portable-dereference-DmTYDy2p.mjs +250 -0
- package/dist/tests/portable-dereference-qTLMqe2_.cjs +279 -0
- package/dist/tests/portable-media-5p8azal0.cjs +153 -0
- package/dist/tests/portable-media-B_lt9MMA.mjs +148 -0
- package/dist/tests/portable-media.test.cjs +222 -0
- package/dist/tests/portable-media.test.d.cts +1 -0
- package/dist/tests/portable-media.test.d.mts +1 -0
- package/dist/tests/portable-media.test.mjs +223 -0
- package/dist/tests/portable-workers.test.cjs +36 -0
- package/dist/tests/portable-workers.test.d.cts +2 -0
- package/dist/tests/portable-workers.test.d.mts +2 -0
- package/dist/tests/portable-workers.test.mjs +35 -0
- package/dist/tests/{request-uk51rkhO.cjs → request-BgjA9wyl.cjs} +10 -4
- package/dist/tests/{request-C8CaGwtt.mjs → request-DodZNukP.mjs} +8 -2
- package/dist/tests/request.test.cjs +7 -4
- package/dist/tests/request.test.mjs +5 -2
- package/dist/tests/signed-representation.test.cjs +588 -0
- package/dist/tests/signed-representation.test.d.cts +1 -0
- package/dist/tests/signed-representation.test.d.mts +1 -0
- package/dist/tests/signed-representation.test.mjs +589 -0
- package/dist/tests/temporal.test.cjs +1 -2
- package/dist/tests/temporal.test.mjs +1 -1
- package/dist/tests/url-BNakuZ8k.cjs +998 -0
- package/dist/tests/url-DMxmp7ZG.mjs +859 -0
- package/dist/tests/url.test.cjs +489 -6
- package/dist/tests/url.test.mjs +489 -5
- package/dist/url-DrGTR8yv.cjs +993 -0
- package/dist/url-Dzyp-NsC.js +860 -0
- package/package.json +27 -4
- package/scripts/test-bun.mjs +17 -0
- package/src/body.test.ts +125 -0
- package/src/body.ts +152 -0
- package/src/contexts/cid-v1.json +114 -0
- package/src/contexts/fep-22cd.json +21 -0
- package/src/contexts/fep-6757.json +12 -0
- package/src/contexts/joinmastodon.json +1 -1
- package/src/contexts/miscellany.json +17 -0
- package/src/contexts.ts +47 -1
- package/src/digest.test.ts +220 -0
- package/src/digest.ts +229 -0
- package/src/docloader.test.ts +1066 -27
- package/src/docloader.ts +322 -105
- package/src/internal/jsonld-cache.ts +97 -1
- package/src/internal/portable-dereference.test.ts +254 -0
- package/src/internal/portable-dereference.ts +1000 -0
- package/src/internal/signed-representation.ts +565 -0
- package/src/jsonld-cache.test.ts +89 -0
- package/src/key.test.ts +9 -0
- package/src/key.ts +11 -1
- package/src/langstr.test.ts +18 -1
- package/src/langstr.ts +6 -2
- package/src/langtag.test.ts +53 -0
- package/src/langtag.ts +76 -0
- package/src/mod.ts +29 -0
- package/src/multibase/multibase.test.ts +5 -5
- package/src/portable-media.test.ts +293 -0
- package/src/portable-media.ts +264 -0
- package/src/portable-workers.test.ts +81 -0
- package/src/portable.ts +180 -0
- package/src/preprocessor.ts +7 -0
- package/src/request.test.ts +10 -1
- package/src/request.ts +9 -1
- package/src/signed-representation.test.ts +338 -0
- package/src/url.test.ts +823 -3
- package/src/url.ts +700 -23
- package/tsdown.config.ts +2 -0
- package/dist/tests/url-CsOV_B_P.cjs +0 -482
- package/dist/tests/url-Du7RQQgP.mjs +0 -392
- package/dist/url-DD4F0ULf.cjs +0 -483
- package/dist/url-DGVbSVVi.js +0 -393
- /package/dist/{chunk-M78iaK0I.cjs → rolldown-runtime-B7lfambq.cjs} +0 -0
- /package/dist/tests/{link-NUUWCdnK.mjs → link-Cevmc87v.mjs} +0 -0
- /package/dist/tests/{link-FguCydMA.cjs → link-DlKm8bEr.cjs} +0 -0
- /package/dist/tests/{multicodec-CxGVGa91.cjs → multicodec-CLRPeW4N.cjs} +0 -0
- /package/dist/tests/{multicodec-CyFp54fI.mjs → multicodec-CRIj_05H.mjs} +0 -0
- /package/dist/tests/{chunk-C2EiDwsr.cjs → rolldown-runtime-emK7D4bc.cjs} +0 -0
package/dist/tests/url.test.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
require("./
|
|
2
|
-
const require_url = require("./url-CsOV_B_P.cjs");
|
|
3
|
-
let node_assert = require("node:assert");
|
|
1
|
+
const require_url = require("./url-BNakuZ8k.cjs");
|
|
4
2
|
let node_test = require("node:test");
|
|
3
|
+
let node_assert = require("node:assert");
|
|
5
4
|
//#region src/url.test.ts
|
|
6
5
|
(0, node_test.test)("parseIri() accepts portable ActivityPub URI schemes", () => {
|
|
7
6
|
for (const iri of [
|
|
@@ -12,6 +11,39 @@ let node_test = require("node:test");
|
|
|
12
11
|
"AP+EF61://did:key:z6Mkabc/actor"
|
|
13
12
|
]) (0, node_assert.deepStrictEqual)(require_url.parseIri(iri), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
|
|
14
13
|
});
|
|
14
|
+
(0, node_test.test)("portable URI parsing refuses dot segments before URL normalization", () => {
|
|
15
|
+
const base = "ap://did:key:z6Mkabc";
|
|
16
|
+
for (const segment of [
|
|
17
|
+
".",
|
|
18
|
+
"..",
|
|
19
|
+
"%2e",
|
|
20
|
+
".%2E",
|
|
21
|
+
"%2e.",
|
|
22
|
+
"%2E%2e"
|
|
23
|
+
]) for (const path of [
|
|
24
|
+
`/${segment}`,
|
|
25
|
+
`/a/${segment}/b`,
|
|
26
|
+
`/a/${segment}`
|
|
27
|
+
]) {
|
|
28
|
+
const iri = base + path;
|
|
29
|
+
(0, node_assert.throws)(() => require_url.parseIri(iri), TypeError, iri);
|
|
30
|
+
(0, node_assert.throws)(() => require_url.parseJsonLdId(iri), TypeError, iri);
|
|
31
|
+
(0, node_assert.throws)(() => require_url.formatIri(iri), TypeError, iri);
|
|
32
|
+
}
|
|
33
|
+
for (const iri of [
|
|
34
|
+
`${base}/a/.\t./b`,
|
|
35
|
+
`${base}/a/..\n/b`,
|
|
36
|
+
` ${base}/a/../b`,
|
|
37
|
+
`${base}/a/.. `
|
|
38
|
+
]) (0, node_assert.throws)(() => require_url.parseIri(iri), TypeError, iri);
|
|
39
|
+
for (const path of [
|
|
40
|
+
"/a/.../b",
|
|
41
|
+
"/a/.x/b",
|
|
42
|
+
"/a/x.y/b",
|
|
43
|
+
"/a/%252e/b"
|
|
44
|
+
]) (0, node_assert.deepStrictEqual)(require_url.formatIri(require_url.parseIri(base + path)), `ap+ef61://did:key:z6Mkabc${path}`);
|
|
45
|
+
(0, node_assert.throws)(() => require_url.parseIri("child", `${base}/a/../b`), TypeError);
|
|
46
|
+
});
|
|
15
47
|
(0, node_test.test)("parseIri() normalizes DID scheme and method casing", () => {
|
|
16
48
|
for (const iri of [
|
|
17
49
|
"ap://DID:key:z6Mkabc/actor",
|
|
@@ -45,6 +77,20 @@ let node_test = require("node:test");
|
|
|
45
77
|
(0, node_assert.deepStrictEqual)(require_url.parseIri("attachments/1", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/attachments/1"));
|
|
46
78
|
(0, node_assert.throws)(() => require_url.parseIri("//example.com/outbox", "ap://did:key:z6Mkabc/objects/1"), TypeError);
|
|
47
79
|
});
|
|
80
|
+
(0, node_test.test)("parseIri() rejects lossy compatible ID string bases", () => {
|
|
81
|
+
const base = "https://server.example/.well-known/apgateway/did:key:z6MkAlice";
|
|
82
|
+
for (const segment of [
|
|
83
|
+
".",
|
|
84
|
+
"..",
|
|
85
|
+
"%2e",
|
|
86
|
+
"%2e%2e"
|
|
87
|
+
]) {
|
|
88
|
+
const rawBase = `${base}/a/${segment}/b`;
|
|
89
|
+
(0, node_assert.throws)(() => require_url.parseIri("child", rawBase), TypeError, rawBase);
|
|
90
|
+
(0, node_assert.throws)(() => require_url.parseJsonLdId("child", rawBase), TypeError, rawBase);
|
|
91
|
+
}
|
|
92
|
+
(0, node_assert.deepStrictEqual)(require_url.parseIri("child", "https://server.example/a/../b"), new URL("https://server.example/child"));
|
|
93
|
+
});
|
|
48
94
|
(0, node_test.test)("parseIri() resolves relative IRIs against at:// string bases", () => {
|
|
49
95
|
(0, node_assert.deepStrictEqual)(require_url.parseIri("/record", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/record"));
|
|
50
96
|
(0, node_assert.deepStrictEqual)(require_url.parseIri("reply", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
|
|
@@ -229,7 +275,11 @@ let node_test = require("node:test");
|
|
|
229
275
|
(0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:web:example.com%00/u/1");
|
|
230
276
|
});
|
|
231
277
|
(0, node_test.test)("parseGatewayUrl() accepts only HTTP(S) base URIs", () => {
|
|
232
|
-
for (const url of [
|
|
278
|
+
for (const url of [
|
|
279
|
+
"https://server.example",
|
|
280
|
+
"https://server.example/",
|
|
281
|
+
"http://server.example/"
|
|
282
|
+
]) {
|
|
233
283
|
(0, node_assert.deepStrictEqual)(require_url.parseGatewayUrl(url), new URL(url));
|
|
234
284
|
(0, node_assert.ok)(require_url.isGatewayUrl(new URL(url)));
|
|
235
285
|
}
|
|
@@ -239,11 +289,287 @@ let node_test = require("node:test");
|
|
|
239
289
|
"https://user@server.example/",
|
|
240
290
|
"https://server.example/path",
|
|
241
291
|
"https://server.example/?x=1",
|
|
242
|
-
"https://server.example
|
|
292
|
+
"https://server.example/?",
|
|
293
|
+
"https://server.example/#fragment",
|
|
294
|
+
"https://server.example/#"
|
|
243
295
|
]) {
|
|
244
|
-
(0, node_assert.throws)(() => require_url.parseGatewayUrl(url), TypeError);
|
|
296
|
+
(0, node_assert.throws)(() => require_url.parseGatewayUrl(url), (error) => error instanceof TypeError && error.message.startsWith("Invalid FEP-ef61 gateway: "));
|
|
245
297
|
(0, node_assert.ok)(!require_url.isGatewayUrl(new URL(url)));
|
|
246
298
|
}
|
|
299
|
+
const mutated = new URL("https://server.example/");
|
|
300
|
+
mutated.search = "?";
|
|
301
|
+
(0, node_assert.ok)(!require_url.isGatewayUrl(mutated));
|
|
302
|
+
mutated.search = "";
|
|
303
|
+
mutated.hash = "#";
|
|
304
|
+
(0, node_assert.ok)(!require_url.isGatewayUrl(mutated));
|
|
305
|
+
});
|
|
306
|
+
(0, node_test.test)("fromCompatibleEf61Id() converts compatible identifiers", () => {
|
|
307
|
+
for (const [input, expected] of [
|
|
308
|
+
["https://server.example/.well-known/apgateway/did:key:z6MkAlice/objects/1", "ap+ef61://did%3Akey%3Az6MkAlice/objects/1"],
|
|
309
|
+
["http://server.example:8080/.well-known/apgateway/did:key:z6MkAlice/actor", "ap+ef61://did%3Akey%3Az6MkAlice/actor"],
|
|
310
|
+
["https://server.example/.well-known/apgateway/did%3Akey%3Az6MkAlice/actor", "ap+ef61://did%3Akey%3Az6MkAlice/actor"],
|
|
311
|
+
["https://server.example/.well-known/apgateway/DID:key:z6MkAlice/actor", "ap+ef61://did%3Akey%3Az6MkAlice/actor"],
|
|
312
|
+
["https://server.example/.well-known/apgateway/did:key:z6MkAlice/a/b/c", "ap+ef61://did%3Akey%3Az6MkAlice/a/b/c"],
|
|
313
|
+
["https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor#main-key", "ap+ef61://did%3Akey%3Az6MkAlice/actor#main-key"],
|
|
314
|
+
["https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor#", "ap+ef61://did%3Akey%3Az6MkAlice/actor#"],
|
|
315
|
+
["https://server.example/.well-known/apgateway/did:key:z6MkAlice/outbox?page=2", "ap+ef61://did%3Akey%3Az6MkAlice/outbox?page=2"],
|
|
316
|
+
["https://server.example/.well-known/apgateway/did:key:z6MkAlice/a%2Fb", "ap+ef61://did%3Akey%3Az6MkAlice/a%2Fb"],
|
|
317
|
+
["https://server.example/.well-known/apgateway/did:web:example.com%3A8080/actor", "ap+ef61://did%3Aweb%3Aexample.com%253A8080/actor"],
|
|
318
|
+
["https://server.example/.well-known/apgateway/did:example:a%2525/x", "ap+ef61://did%3Aexample%3Aa%2525/x"]
|
|
319
|
+
]) {
|
|
320
|
+
(0, node_assert.deepStrictEqual)(require_url.fromCompatibleEf61Id(input)?.href, expected, input);
|
|
321
|
+
(0, node_assert.deepStrictEqual)(require_url.fromCompatibleEf61Id(new URL(input))?.href, expected, input);
|
|
322
|
+
}
|
|
323
|
+
const converted = require_url.fromCompatibleEf61Id("https://server.example/.well-known/apgateway/did:key:z6MkAlice/objects/1");
|
|
324
|
+
(0, node_assert.deepStrictEqual)(require_url.formatIri(converted), "ap+ef61://did:key:z6MkAlice/objects/1");
|
|
325
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri(converted.href), "ap+ef61://did:key:z6MkAlice/objects/1");
|
|
326
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual(require_url.fromCompatibleEf61Id("https://a.example/.well-known/apgateway/did:key:z6MkAlice/actor").href, require_url.fromCompatibleEf61Id("https://b.example/.well-known/apgateway/did:key:z6MkAlice/actor").href));
|
|
327
|
+
});
|
|
328
|
+
(0, node_test.test)("fromCompatibleEf61Id() returns null for other URLs", () => {
|
|
329
|
+
for (const input of [
|
|
330
|
+
"https://server.example/users/alice",
|
|
331
|
+
"https://server.example/.well-known/webfinger?resource=acct:a@b",
|
|
332
|
+
"https://server.example/.well-known/apgateway",
|
|
333
|
+
"https://server.example/.well-known/apgateway/",
|
|
334
|
+
"https://server.example/.well-known/apgateway/hl:zQmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
|
|
335
|
+
"https://server.example/.well-known/apgateway/objects/did:key:z6MkAlice/x",
|
|
336
|
+
"https://server.example/.well-known/apgatewayx/did:key:z6MkAlice/x",
|
|
337
|
+
"https://server.example/ap/did:key:z6MkAlice/actor",
|
|
338
|
+
"https://server.example/?id=/.well-known/apgateway/did:key:z6MkAlice/x",
|
|
339
|
+
"ap://did:key:z6MkAlice/actor",
|
|
340
|
+
"ap+ef61://did:key:z6MkAlice/actor",
|
|
341
|
+
"ftp://server.example/.well-known/apgateway/did:key:z6MkAlice/actor",
|
|
342
|
+
"not a URL",
|
|
343
|
+
"/.well-known/apgateway/did:key:z6MkAlice/actor"
|
|
344
|
+
]) (0, node_assert.deepStrictEqual)(require_url.fromCompatibleEf61Id(input), null, input);
|
|
345
|
+
(0, node_assert.deepStrictEqual)(require_url.fromCompatibleEf61Id(new URL("ap+ef61://did%3Akey%3Az6MkAlice/actor")), null);
|
|
346
|
+
(0, node_assert.deepStrictEqual)(require_url.fromCompatibleEf61Id(123), null);
|
|
347
|
+
});
|
|
348
|
+
(0, node_test.test)("fromCompatibleEf61Id() rejects malformed compatible identifiers", () => {
|
|
349
|
+
for (const input of [
|
|
350
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice",
|
|
351
|
+
"https://server.example/.well-known/apgateway/did:",
|
|
352
|
+
"https://server.example/.well-known/apgateway/did:key/actor",
|
|
353
|
+
"https://server.example/.well-known/apgateway/did:ke%y:z6MkAlice/actor",
|
|
354
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a%zz",
|
|
355
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a#%zz",
|
|
356
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?x=%zz",
|
|
357
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?@gateway=https%3A%2F%2Fevil.example",
|
|
358
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?page=2&%40gateway=x",
|
|
359
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?@%67ateway=x",
|
|
360
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?gateways=x",
|
|
361
|
+
"https://server.example/.well-known/apgateway/did:example:a%25/x",
|
|
362
|
+
"https://user:pass@server.example/.well-known/apgateway/did:key:z6MkAlice/a",
|
|
363
|
+
"https://user@server.example/.well-known/apgateway/did:key:z6MkAlice/a"
|
|
364
|
+
]) (0, node_assert.throws)(() => require_url.fromCompatibleEf61Id(input), TypeError, input);
|
|
365
|
+
});
|
|
366
|
+
(0, node_test.test)("fromCompatibleEf61Id() refuses raw paths changed by URL parsing", () => {
|
|
367
|
+
const base = "https://server.example/.well-known/apgateway/did:key:z6MkAlice";
|
|
368
|
+
for (const path of [
|
|
369
|
+
"/a/../b",
|
|
370
|
+
"/a/%2e%2E/b",
|
|
371
|
+
"/a/. ./b",
|
|
372
|
+
"/a/.. "
|
|
373
|
+
]) {
|
|
374
|
+
(0, node_assert.throws)(() => require_url.fromCompatibleEf61Id(base + path), TypeError, path);
|
|
375
|
+
(0, node_assert.throws)(() => require_url.parseIri(base + path), TypeError, path);
|
|
376
|
+
(0, node_assert.throws)(() => require_url.formatIri(base + path), TypeError, path);
|
|
377
|
+
}
|
|
378
|
+
for (const input of [
|
|
379
|
+
"https:/server.example/.well-known/apgateway/did:key:z6MkAlice/a/../b",
|
|
380
|
+
"https:server.example/.well-known/apgateway/did:key:z6MkAlice/a/../b",
|
|
381
|
+
"https:\\\\server.example\\.well-known\\apgateway\\did:key:z6MkAlice\\a\\..\\b",
|
|
382
|
+
` ${base}/../../other`
|
|
383
|
+
]) {
|
|
384
|
+
(0, node_assert.throws)(() => require_url.parseIri(input), TypeError, input);
|
|
385
|
+
(0, node_assert.throws)(() => require_url.formatIri(input), TypeError, input);
|
|
386
|
+
}
|
|
387
|
+
(0, node_assert.throws)(() => require_url.fromCompatibleEf61Id(` ${base}/actor`), TypeError);
|
|
388
|
+
(0, node_assert.throws)(() => require_url.fromCompatibleEf61Id(`https://server.example/foo/../.well-known/apgateway/did:key:z6MkAlice/actor`), TypeError);
|
|
389
|
+
(0, node_assert.deepStrictEqual)(require_url.fromCompatibleEf61Id(`${base}/a/%252e/b`)?.pathname, "/a/%252e/b");
|
|
390
|
+
(0, node_assert.deepStrictEqual)(require_url.fromCompatibleEf61Id("https://server.example/.WELL-KNOWN/apgateway/did:key:z6MkAlice/actor"), null);
|
|
391
|
+
});
|
|
392
|
+
(0, node_test.test)("toCompatibleEf61Id() converts portable URIs", () => {
|
|
393
|
+
const cases = [
|
|
394
|
+
[
|
|
395
|
+
"ap+ef61://did:key:z6MkAlice/objects/1",
|
|
396
|
+
"https://server.example",
|
|
397
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/objects/1"
|
|
398
|
+
],
|
|
399
|
+
[
|
|
400
|
+
"ap://did:key:z6MkAlice/objects/1",
|
|
401
|
+
"https://server.example/",
|
|
402
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/objects/1"
|
|
403
|
+
],
|
|
404
|
+
[
|
|
405
|
+
"ap://did%3Akey%3Az6MkAlice/actor",
|
|
406
|
+
new URL("http://server.example:8080"),
|
|
407
|
+
"http://server.example:8080/.well-known/apgateway/did:key:z6MkAlice/actor"
|
|
408
|
+
],
|
|
409
|
+
[
|
|
410
|
+
new URL("ap+ef61://did%3Akey%3Az6MkAlice/actor"),
|
|
411
|
+
"https://server.example",
|
|
412
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor"
|
|
413
|
+
],
|
|
414
|
+
[
|
|
415
|
+
new URL("ap://did%3Akey%3Az6MkAlice/actor"),
|
|
416
|
+
"https://SERVER.example",
|
|
417
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor"
|
|
418
|
+
],
|
|
419
|
+
[
|
|
420
|
+
"ap://did:key:z6MkAlice/a/b/c",
|
|
421
|
+
"https://server.example",
|
|
422
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a/b/c"
|
|
423
|
+
],
|
|
424
|
+
[
|
|
425
|
+
"ap://did:key:z6MkAlice/actor#main-key",
|
|
426
|
+
"https://server.example",
|
|
427
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor#main-key"
|
|
428
|
+
],
|
|
429
|
+
[
|
|
430
|
+
"ap://did:key:z6MkAlice/actor#",
|
|
431
|
+
"https://server.example",
|
|
432
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor#"
|
|
433
|
+
],
|
|
434
|
+
[
|
|
435
|
+
"ap://DID:key:z6MkAlice/actor",
|
|
436
|
+
"https://server.example",
|
|
437
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor"
|
|
438
|
+
],
|
|
439
|
+
[
|
|
440
|
+
"ap://did:example:a%2525/x",
|
|
441
|
+
"https://server.example",
|
|
442
|
+
"https://server.example/.well-known/apgateway/did:example:a%2525/x"
|
|
443
|
+
],
|
|
444
|
+
[
|
|
445
|
+
"ap://did:web:example.com%3A8080/actor",
|
|
446
|
+
"https://server.example",
|
|
447
|
+
"https://server.example/.well-known/apgateway/did:web:example.com%3A8080/actor"
|
|
448
|
+
],
|
|
449
|
+
[
|
|
450
|
+
"ap://did:key:z6MkAlice/a%2Fb/%252e",
|
|
451
|
+
"https://server.example",
|
|
452
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a%2Fb/%252e"
|
|
453
|
+
],
|
|
454
|
+
[
|
|
455
|
+
"ap://did:key:z6MkAlice/a\\b c é/%7euser",
|
|
456
|
+
"https://server.example",
|
|
457
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/a%5Cb%20c%09%C3%A9/~user"
|
|
458
|
+
]
|
|
459
|
+
];
|
|
460
|
+
for (const [portableId, gateway, expected] of cases) (0, node_assert.deepStrictEqual)(require_url.toCompatibleEf61Id(portableId, gateway).href, expected, String(portableId));
|
|
461
|
+
});
|
|
462
|
+
(0, node_test.test)("toCompatibleEf61Id() removes location hints from queries", () => {
|
|
463
|
+
const base = "https://server.example/.well-known/apgateway/did:key:z6MkAlice";
|
|
464
|
+
const cases = [
|
|
465
|
+
["ap://did:key:z6MkAlice/actor?@gateway=https%3A%2F%2Fa.example&@gateway=https%3A%2F%2Fb.example", `${base}/actor`],
|
|
466
|
+
["ap://did:key:z6MkAlice/actor?gateways=https%3A%2F%2Fa.example", `${base}/actor`],
|
|
467
|
+
["ap://did:key:z6MkAlice/actor?%40gateway=https%3A%2F%2Fa.example", `${base}/actor`],
|
|
468
|
+
["ap://did:key:z6MkAlice/actor?@%67ateway=https%3A%2F%2Fa.example", `${base}/actor`],
|
|
469
|
+
["ap://did:key:z6MkAlice/actor?@gateway", `${base}/actor`],
|
|
470
|
+
["ap://did:key:z6MkAlice/c?page=3&@gateway=https%3A%2F%2Fa.example&maxItems=20&page=4", `${base}/c?page=3&maxItems=20&page=4`],
|
|
471
|
+
["ap://did:key:z6MkAlice/c?a=1&&b=2#frag", `${base}/c?a=1&&b=2#frag`],
|
|
472
|
+
["ap://did:key:z6MkAlice/c?", `${base}/c?`],
|
|
473
|
+
["ap://did:key:z6MkAlice/c?x='y'", `${base}/c?x=%27y%27`],
|
|
474
|
+
["ap://did:key:z6MkAlice/c?@gate way=https%3A%2F%2Fa.example", `${base}/c?@gate%09way=https%3A%2F%2Fa.example`],
|
|
475
|
+
["ap://did:key:z6MkAlice/c?@gate\nway=1&x=\r2", `${base}/c?@gate%0Away=1&x=%0D2`],
|
|
476
|
+
["ap://did:key:z6MkAlice/c?%ff=1", `${base}/c?%FF=1`]
|
|
477
|
+
];
|
|
478
|
+
for (const [portableId, expected] of cases) {
|
|
479
|
+
const result = require_url.toCompatibleEf61Id(portableId, "https://server.example");
|
|
480
|
+
(0, node_assert.deepStrictEqual)(result.href, expected, portableId);
|
|
481
|
+
(0, node_assert.ok)(!/[?&](%40|@)gateway(=|&|$)/i.test(result.search), portableId);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
(0, node_test.test)("toCompatibleEf61Id() rejects invalid portable IDs", () => {
|
|
485
|
+
const cases = [
|
|
486
|
+
"https://server.example/actor",
|
|
487
|
+
"https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor",
|
|
488
|
+
"at://did:plc:example/record",
|
|
489
|
+
"ap://not-a-did/actor",
|
|
490
|
+
"ap://did:key:z6MkAlice",
|
|
491
|
+
"ap://did:key:z6MkAlice/a%zz",
|
|
492
|
+
"ap://did:key:z6MkAlice/a#%zz",
|
|
493
|
+
"ap://did:key:z6MkAlice/a?x=%zz",
|
|
494
|
+
"ap://did:key:z6MkAlice/.",
|
|
495
|
+
"ap://did:key:z6MkAlice/..",
|
|
496
|
+
"ap://did:key:z6MkAlice/a/./b",
|
|
497
|
+
"ap://did:key:z6MkAlice/a/../b",
|
|
498
|
+
"ap://did:key:z6MkAlice/a/%2e/b",
|
|
499
|
+
"ap://did:key:z6MkAlice/a/%2E%2e/b",
|
|
500
|
+
"ap://did:key:z6MkAlice/a/.%2e/b",
|
|
501
|
+
"ap://did:key:z6MkAlice/a/%2e./b",
|
|
502
|
+
new URL("https://server.example/actor"),
|
|
503
|
+
new URL("ap+ef61://user:pass@did%3Akey%3Az6MkAlice/actor"),
|
|
504
|
+
new URL("ap+ef61://did%3Akey%3Az6MkAlice:8080/actor"),
|
|
505
|
+
123
|
|
506
|
+
];
|
|
507
|
+
for (const portableId of cases) (0, node_assert.throws)(() => require_url.toCompatibleEf61Id(portableId, "https://server.example"), TypeError, String(portableId));
|
|
508
|
+
});
|
|
509
|
+
(0, node_test.test)("toCompatibleEf61Id() rejects gateways that are not HTTP(S) origins", () => {
|
|
510
|
+
const cases = [
|
|
511
|
+
"ftp://server.example",
|
|
512
|
+
"ap+ef61://did:key:z6MkAlice/actor",
|
|
513
|
+
"https://user:pass@server.example",
|
|
514
|
+
"https://user@server.example",
|
|
515
|
+
"https://server.example/ap",
|
|
516
|
+
"https://server.example/ap/",
|
|
517
|
+
"https://server.example/.well-known/apgateway",
|
|
518
|
+
"https://server.example/?x=1",
|
|
519
|
+
"https://server.example/?",
|
|
520
|
+
"https://server.example/#fragment",
|
|
521
|
+
"https://server.example/#",
|
|
522
|
+
"server.example",
|
|
523
|
+
"",
|
|
524
|
+
new URL("https://server.example/?"),
|
|
525
|
+
new URL("https://server.example/#"),
|
|
526
|
+
new URL("https://server.example/ap"),
|
|
527
|
+
new URL("ftp://server.example/"),
|
|
528
|
+
123
|
|
529
|
+
];
|
|
530
|
+
for (const gateway of cases) (0, node_assert.throws)(() => require_url.toCompatibleEf61Id("ap://did:key:z6MkAlice/actor", gateway), TypeError, String(gateway));
|
|
531
|
+
});
|
|
532
|
+
(0, node_test.test)("compatible identifier conversion round-trips", () => {
|
|
533
|
+
for (const portableId of [
|
|
534
|
+
"ap+ef61://did:key:z6MkAlice/objects/1",
|
|
535
|
+
"ap://did:key:z6MkAlice/actor",
|
|
536
|
+
"ap://did%3Akey%3Az6MkAlice/actor/inbox",
|
|
537
|
+
"ap://did:key:z6MkAlice/actor#",
|
|
538
|
+
"ap://did:key:z6MkAlice/actor#main-key",
|
|
539
|
+
"ap://did:key:z6MkAlice/a%2Fb/%252e",
|
|
540
|
+
"ap://did:key:z6MkAlice/a\\b c é",
|
|
541
|
+
"ap://did:example:a%2525/x",
|
|
542
|
+
"ap://did:web:example.com%3A8080/actor",
|
|
543
|
+
"ap://did:key:z6MkAlice/c?page=3&@gateway=https%3A%2F%2Fa.example"
|
|
544
|
+
]) {
|
|
545
|
+
const converted = require_url.fromCompatibleEf61Id(require_url.toCompatibleEf61Id(portableId, "https://server.example"));
|
|
546
|
+
(0, node_assert.ok)(converted != null, portableId);
|
|
547
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri(converted.href), require_url.canonicalizePortableUri(portableId), portableId);
|
|
548
|
+
}
|
|
549
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual(require_url.fromCompatibleEf61Id(require_url.toCompatibleEf61Id("ap://did:key:z6MkAlice/actor", "https://server.example")).href, require_url.fromCompatibleEf61Id(require_url.toCompatibleEf61Id("ap://did:key:z6MkAlice/actor#", "https://server.example")).href));
|
|
550
|
+
});
|
|
551
|
+
(0, node_test.test)("UrlError reason is independent of its cause", () => {
|
|
552
|
+
const cause = /* @__PURE__ */ new Error("Underlying failure");
|
|
553
|
+
(0, node_assert.strictEqual)(new require_url.UrlError("Rejected URL").reason, "disallowed");
|
|
554
|
+
const disallowedError = new require_url.UrlError("Rejected URL", { cause });
|
|
555
|
+
(0, node_assert.strictEqual)(disallowedError.reason, "disallowed");
|
|
556
|
+
(0, node_assert.strictEqual)(disallowedError.cause, cause);
|
|
557
|
+
const dnsError = new require_url.UrlError("Lookup failed", {
|
|
558
|
+
reason: "dns",
|
|
559
|
+
cause
|
|
560
|
+
});
|
|
561
|
+
(0, node_assert.strictEqual)(dnsError.reason, "dns");
|
|
562
|
+
(0, node_assert.strictEqual)(dnsError.cause, cause);
|
|
563
|
+
});
|
|
564
|
+
(0, node_test.test)("validatePublicUrl() classifies disallowed URLs", async () => {
|
|
565
|
+
for (const url of [
|
|
566
|
+
"ftp://example.com",
|
|
567
|
+
"https://localhost",
|
|
568
|
+
"https://127.0.0.1"
|
|
569
|
+
]) await (0, node_assert.rejects)(() => require_url.validatePublicUrl(url), {
|
|
570
|
+
name: "UrlError",
|
|
571
|
+
reason: "disallowed"
|
|
572
|
+
});
|
|
247
573
|
});
|
|
248
574
|
(0, node_test.test)("validatePublicUrl()", async () => {
|
|
249
575
|
await (0, node_assert.rejects)(() => require_url.validatePublicUrl("ftp://localhost"), require_url.UrlError);
|
|
@@ -271,6 +597,45 @@ let node_test = require("node:test");
|
|
|
271
597
|
await require_url.validatePublicUrl("https://[2001:db8::1]");
|
|
272
598
|
await require_url.validatePublicUrl("https://[64:ff9b::8.8.8.8]");
|
|
273
599
|
});
|
|
600
|
+
(0, node_test.test)("validateLookupAddresses() tolerates Cloudflare Workers CNAME entries", () => {
|
|
601
|
+
require_url.validateLookupAddresses([
|
|
602
|
+
{
|
|
603
|
+
address: "app-host.example.net.",
|
|
604
|
+
family: 4
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
address: "93.184.216.34",
|
|
608
|
+
family: 4
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
address: "2606:2800:220:1:248:1893:25c8:1946",
|
|
612
|
+
family: 6
|
|
613
|
+
}
|
|
614
|
+
]);
|
|
615
|
+
});
|
|
616
|
+
(0, node_test.test)("validateLookupAddresses() rejects unsafe or CNAME-only Cloudflare Workers results", () => {
|
|
617
|
+
(0, node_assert.throws)(() => require_url.validateLookupAddresses([{
|
|
618
|
+
address: "private-host.example.net.",
|
|
619
|
+
family: 4
|
|
620
|
+
}, {
|
|
621
|
+
address: "127.0.0.1",
|
|
622
|
+
family: 4
|
|
623
|
+
}]), {
|
|
624
|
+
name: "UrlError",
|
|
625
|
+
reason: "disallowed"
|
|
626
|
+
});
|
|
627
|
+
(0, node_assert.throws)(() => require_url.validateLookupAddresses([{
|
|
628
|
+
address: "app-host.example.net.",
|
|
629
|
+
family: 4
|
|
630
|
+
}]), {
|
|
631
|
+
name: "UrlError",
|
|
632
|
+
reason: "dns"
|
|
633
|
+
});
|
|
634
|
+
(0, node_assert.throws)(() => require_url.validateLookupAddresses([]), {
|
|
635
|
+
name: "UrlError",
|
|
636
|
+
reason: "dns"
|
|
637
|
+
});
|
|
638
|
+
});
|
|
274
639
|
(0, node_test.test)("isValidPublicIPv4Address()", () => {
|
|
275
640
|
(0, node_assert.ok)(require_url.isValidPublicIPv4Address("8.8.8.8"));
|
|
276
641
|
(0, node_assert.ok)(!require_url.isValidPublicIPv4Address("192.168.1.1"));
|
|
@@ -328,4 +693,122 @@ let node_test = require("node:test");
|
|
|
328
693
|
(0, node_assert.deepStrictEqual)(require_url.expandIPv6Address("2001:db8::1"), "2001:0db8:0000:0000:0000:0000:0000:0001");
|
|
329
694
|
(0, node_assert.deepStrictEqual)(require_url.expandIPv6Address("64:ff9b::8.8.8.8"), "0064:ff9b:0000:0000:0000:0000:0808:0808");
|
|
330
695
|
});
|
|
696
|
+
(0, node_test.test)("withGatewayHints() adds @gateway location hints", () => {
|
|
697
|
+
const expected = "ap+ef61://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fserver1.example&@gateway=https%3A%2F%2Fserver2.example";
|
|
698
|
+
for (const id of [
|
|
699
|
+
"ap://did:key:z6Mkabc/actor",
|
|
700
|
+
"ap+ef61://did:key:z6Mkabc/actor",
|
|
701
|
+
"ap://did%3Akey%3Az6Mkabc/actor",
|
|
702
|
+
require_url.parseIri("ap://did:key:z6Mkabc/actor"),
|
|
703
|
+
new URL("ap://did%3Akey%3Az6Mkabc/actor")
|
|
704
|
+
]) {
|
|
705
|
+
const hinted = require_url.withGatewayHints(id, ["https://server1.example", new URL("https://server2.example/")]);
|
|
706
|
+
(0, node_assert.ok)(hinted instanceof URL);
|
|
707
|
+
(0, node_assert.strictEqual)(hinted.href, "ap+ef61://did%3Akey%3Az6Mkabc/actor?@gateway=https%3A%2F%2Fserver1.example&@gateway=https%3A%2F%2Fserver2.example");
|
|
708
|
+
(0, node_assert.strictEqual)(require_url.formatIri(hinted), expected);
|
|
709
|
+
(0, node_assert.deepStrictEqual)(require_url.parseIri(require_url.formatIri(hinted)), hinted);
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
(0, node_test.test)("withGatewayHints() encodes and deduplicates gateway origins", () => {
|
|
713
|
+
function* gateways() {
|
|
714
|
+
yield "https://A.example:443";
|
|
715
|
+
yield "https://a.example/";
|
|
716
|
+
yield new URL("https://a.example");
|
|
717
|
+
yield "https://b.example:8443";
|
|
718
|
+
yield "http://c.example:80/";
|
|
719
|
+
yield "https://例え.jp";
|
|
720
|
+
}
|
|
721
|
+
(0, node_assert.strictEqual)(require_url.formatIri(require_url.withGatewayHints("ap://did:key:z6Mkabc/actor", gateways())), "ap+ef61://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fa.example&@gateway=https%3A%2F%2Fb.example%3A8443&@gateway=http%3A%2F%2Fc.example&@gateway=https%3A%2F%2Fxn--r8jz45g.jp");
|
|
722
|
+
(0, node_assert.strictEqual)(require_url.formatIri(require_url.withGatewayHints("ap://did:key:z6Mkabc/actor", /* @__PURE__ */ new Set(["https://b.example", "https://a.example"]))), "ap+ef61://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fb.example&@gateway=https%3A%2F%2Fa.example");
|
|
723
|
+
const many = Array.from({ length: 7 }, (_, i) => `https://server${i}.example`);
|
|
724
|
+
(0, node_assert.deepStrictEqual)(require_url.getGatewayHints(require_url.withGatewayHints("ap://did:key:z6Mkabc/actor", many)).map((url) => url.origin), many);
|
|
725
|
+
});
|
|
726
|
+
(0, node_test.test)("withGatewayHints() keeps other query parameters and fragments", () => {
|
|
727
|
+
(0, node_assert.strictEqual)(require_url.formatIri(require_url.withGatewayHints("ap://did:key:z6Mkabc/collection?page=3&maxItems=20&q=a+b%20c%2b", ["https://server.example"])), "ap+ef61://did:key:z6Mkabc/collection?page=3&maxItems=20&q=a+b%20c%2B&@gateway=https%3A%2F%2Fserver.example");
|
|
728
|
+
(0, node_assert.strictEqual)(require_url.formatIri(require_url.withGatewayHints("ap://did:key:z6Mkabc/actor?x=%26%3D#main-key", ["https://server.example"])), "ap+ef61://did:key:z6Mkabc/actor?x=%26%3D&@gateway=https%3A%2F%2Fserver.example#main-key");
|
|
729
|
+
(0, node_assert.strictEqual)(require_url.withGatewayHints("ap://did:key:z6Mkabc/actor#", ["https://s.example"]).href, "ap+ef61://did%3Akey%3Az6Mkabc/actor?@gateway=https%3A%2F%2Fs.example#");
|
|
730
|
+
});
|
|
731
|
+
(0, node_test.test)("withGatewayHints() replaces existing location hints", () => {
|
|
732
|
+
(0, node_assert.strictEqual)(require_url.formatIri(require_url.withGatewayHints("ap://did:key:z6Mkabc/collection?@gateway=https%3A%2F%2Fold.example&page=2&%40gateway=https%3A%2F%2Fold2.example&@gateway&gateways=https%3A%2F%2Flegacy.example&%2540gateway=kept", ["https://new.example"])), "ap+ef61://did:key:z6Mkabc/collection?page=2&%2540gateway=kept&@gateway=https%3A%2F%2Fnew.example");
|
|
733
|
+
for (const char of [
|
|
734
|
+
" ",
|
|
735
|
+
"\n",
|
|
736
|
+
"\r"
|
|
737
|
+
]) (0, node_assert.deepStrictEqual)(require_url.getGatewayHints(require_url.withGatewayHints(`ap://did:key:z6Mkabc/actor?@gate${char}way=https%3A%2F%2Fevil.example`, ["https://new.example"])).map((url) => url.href), ["https://new.example/"]);
|
|
738
|
+
});
|
|
739
|
+
(0, node_test.test)("withGatewayHints() with no gateways removes location hints", () => {
|
|
740
|
+
for (const [input, expected] of [
|
|
741
|
+
["ap://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fa.example", "ap+ef61://did%3Akey%3Az6Mkabc/actor"],
|
|
742
|
+
["ap://did:key:z6Mkabc/actor?&@gateway=https%3A%2F%2Fa.example&&p=1&", "ap+ef61://did%3Akey%3Az6Mkabc/actor?p=1"],
|
|
743
|
+
["ap://did:key:z6Mkabc/actor?", "ap+ef61://did%3Akey%3Az6Mkabc/actor"],
|
|
744
|
+
["ap://did:key:z6Mkabc/actor?gateways=https%3A%2F%2Fa.example#k", "ap+ef61://did%3Akey%3Az6Mkabc/actor#k"]
|
|
745
|
+
]) {
|
|
746
|
+
(0, node_assert.strictEqual)(require_url.withGatewayHints(input, []).href, expected, input);
|
|
747
|
+
(0, node_assert.strictEqual)(require_url.withoutGatewayHints(input).href, expected, input);
|
|
748
|
+
}
|
|
749
|
+
const input = require_url.parseIri("ap://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fa.example");
|
|
750
|
+
const href = input.href;
|
|
751
|
+
require_url.withoutGatewayHints(input);
|
|
752
|
+
(0, node_assert.strictEqual)(input.href, href);
|
|
753
|
+
});
|
|
754
|
+
(0, node_test.test)("withGatewayHints() rejects non-portable IDs", () => {
|
|
755
|
+
for (const id of [
|
|
756
|
+
"https://server.example/.well-known/apgateway/did:key:z6Mkabc/actor",
|
|
757
|
+
"https://example.com/actor",
|
|
758
|
+
"did:key:z6Mkabc#z6Mkabc",
|
|
759
|
+
"ap://did:key:z6Mkabc",
|
|
760
|
+
"ap://example.com/actor",
|
|
761
|
+
"ap://did:key:z6Mkabc/actor%zz",
|
|
762
|
+
new URL("https://example.com/actor"),
|
|
763
|
+
new URL("ap://did%3Akey%3Az6Mkabc:8080/actor"),
|
|
764
|
+
new URL("ap://user@did%3Akey%3Az6Mkabc/actor")
|
|
765
|
+
]) {
|
|
766
|
+
(0, node_assert.throws)(() => require_url.withGatewayHints(id, ["https://server.example"]), TypeError, String(id));
|
|
767
|
+
(0, node_assert.throws)(() => require_url.withoutGatewayHints(id), TypeError, String(id));
|
|
768
|
+
(0, node_assert.throws)(() => require_url.getGatewayHints(id), TypeError, String(id));
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
(0, node_test.test)("withGatewayHints() rejects paths that URLs cannot represent", () => {
|
|
772
|
+
for (const id of [
|
|
773
|
+
"ap://did:key:z6Mkabc/a/../actor",
|
|
774
|
+
"ap://did:key:z6Mkabc/a/./actor",
|
|
775
|
+
"ap://did:key:z6Mkabc/a/%2e%2e/actor",
|
|
776
|
+
"ap://did:key:z6Mkabc/a/%2E/actor"
|
|
777
|
+
]) {
|
|
778
|
+
(0, node_assert.throws)(() => require_url.withGatewayHints(id, ["https://server.example"]), TypeError, id);
|
|
779
|
+
(0, node_assert.throws)(() => require_url.withoutGatewayHints(id), TypeError, id);
|
|
780
|
+
}
|
|
781
|
+
(0, node_assert.strictEqual)(require_url.withoutGatewayHints("ap://did:key:z6Mkabc/a b").href, "ap+ef61://did%3Akey%3Az6Mkabc/a%09b");
|
|
782
|
+
});
|
|
783
|
+
(0, node_test.test)("withGatewayHints() rejects invalid gateways", () => {
|
|
784
|
+
for (const gateway of [
|
|
785
|
+
"https://server.example/path",
|
|
786
|
+
"https://server.example/?",
|
|
787
|
+
"https://server.example/#",
|
|
788
|
+
"https://server.example/?q=1",
|
|
789
|
+
"https://user:pass@server.example",
|
|
790
|
+
"ftp://server.example",
|
|
791
|
+
"ap://did:key:z6Mkabc/actor",
|
|
792
|
+
"server.example",
|
|
793
|
+
new URL("https://server.example/path")
|
|
794
|
+
]) (0, node_assert.throws)(() => require_url.withGatewayHints("ap://did:key:z6Mkabc/actor", [gateway]), TypeError, String(gateway));
|
|
795
|
+
(0, node_assert.throws)(() => require_url.withGatewayHints("ap://did:key:z6Mkabc/actor", "https://server.example"), TypeError);
|
|
796
|
+
});
|
|
797
|
+
(0, node_test.test)("getGatewayHints() reads @gateway location hints", () => {
|
|
798
|
+
(0, node_assert.deepStrictEqual)(require_url.getGatewayHints("ap://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fa.example&@gateway=invalid&%40gateway=https%3A%2F%2Fb.example%2F&@gateway=https%3A%2F%2Fa.example%2F&@gateway=https%3A%2F%2Fc.example%2Fpath&gateways=https%3A%2F%2Flegacy.example&page=1#k").map((url) => url.href), ["https://a.example/", "https://b.example/"]);
|
|
799
|
+
(0, node_assert.deepStrictEqual)(require_url.getGatewayHints("ap://did:key:z6Mkabc/actor"), []);
|
|
800
|
+
const questioned = "ap://did:key:z6Mkabc/actor??@gateway=https%3A%2F%2Fa.example";
|
|
801
|
+
(0, node_assert.deepStrictEqual)(require_url.getGatewayHints(questioned), []);
|
|
802
|
+
(0, node_assert.strictEqual)(require_url.withoutGatewayHints(questioned).href, "ap+ef61://did%3Akey%3Az6Mkabc/actor??@gateway=https%3A%2F%2Fa.example");
|
|
803
|
+
(0, node_assert.deepStrictEqual)(require_url.getGatewayHints(require_url.withGatewayHints(questioned, ["https://b.example"])).map((url) => url.href), ["https://b.example/"]);
|
|
804
|
+
(0, node_assert.deepStrictEqual)(require_url.getGatewayHints("ap://did:key:z6Mkabc/actor?@gate%09way=https%3A%2F%2Fa.example"), []);
|
|
805
|
+
(0, node_assert.deepStrictEqual)(require_url.getGatewayHints("ap://did:key:z6Mkabc/actor?@gate way=https%3A%2F%2Fa.example"), []);
|
|
806
|
+
});
|
|
807
|
+
(0, node_test.test)("withGatewayHints() round-trips with other portable ID helpers", () => {
|
|
808
|
+
const hinted = require_url.withGatewayHints("ap://did:key:z6Mkabc/objects/1#frag", ["https://server1.example", "https://server2.example"]);
|
|
809
|
+
(0, node_assert.strictEqual)(require_url.canonicalizePortableUri(require_url.formatIri(hinted)), "ap+ef61://did:key:z6Mkabc/objects/1#frag");
|
|
810
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual(require_url.formatIri(hinted), "ap://did:key:z6Mkabc/objects/1#frag"));
|
|
811
|
+
(0, node_assert.strictEqual)(require_url.toCompatibleEf61Id(hinted, "https://server1.example").href, "https://server1.example/.well-known/apgateway/did:key:z6Mkabc/objects/1#frag");
|
|
812
|
+
(0, node_assert.strictEqual)(require_url.formatIri(require_url.withoutGatewayHints(hinted)), "ap+ef61://did:key:z6Mkabc/objects/1#frag");
|
|
813
|
+
});
|
|
331
814
|
//#endregion
|