@fedify/vocab 2.1.30 → 2.1.31

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.
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  globalThis.addEventListener = () => {};
3
- import { C as vocab_exports, S as Source, _ as Person, a as Collection, b as Question, c as Endpoints, d as Hashtag, f as Link, h as OrderedCollectionPage, l as Follow, m as Object$1, n as Activity, o as Create, p as Note, r as Announce, s as CryptographicKey, t as Accept, v as Place, y as PropertyValue } from "./vocab-BdFWN1ns.mjs";
3
+ import { C as vocab_exports, S as Source, _ as Person, a as Collection, b as Question, c as Endpoints, d as Hashtag, f as Link, h as OrderedCollectionPage, l as Follow, m as Object$1, n as Activity, o as Create, p as Note, r as Announce, s as CryptographicKey, t as Accept, v as Place, y as PropertyValue } from "./vocab-De7fFc2M.mjs";
4
4
  import { t as assertInstanceOf } from "./utils-CE8Dk5hm.mjs";
5
5
  import { mockDocumentLoader, test } from "@fedify/fixture";
6
6
  import { deepStrictEqual, notDeepStrictEqual, ok, rejects, strictEqual, throws } from "node:assert/strict";
@@ -366,7 +366,11 @@ test({
366
366
  }
367
367
  }
368
368
  });
369
- deepStrictEqual(await new Activity({ object: new URL("https://example.com/not-found") }).getObject({ suppressError: true }), null);
369
+ deepStrictEqual(await new Activity({ object: new URL("https://example.com/not-found") }).getObject({
370
+ documentLoader: mockDocumentLoader,
371
+ contextLoader: mockDocumentLoader,
372
+ suppressError: true
373
+ }), null);
370
374
  const object3 = await (await Activity.fromJsonLd({
371
375
  "@context": "https://www.w3.org/ns/activitystreams",
372
376
  type: "Create",
@@ -403,7 +407,11 @@ test({
403
407
  assertInstanceOf(objects[1], Object$1);
404
408
  deepStrictEqual(objects[1].name, "Second object");
405
409
  const activity2 = new Activity({ objects: [new URL("https://example.com/not-found"), new Object$1({ name: "Second object" })] });
406
- const objects2 = await Array.fromAsync(activity2.getObjects({ suppressError: true }));
410
+ const objects2 = await Array.fromAsync(activity2.getObjects({
411
+ documentLoader: mockDocumentLoader,
412
+ contextLoader: mockDocumentLoader,
413
+ suppressError: true
414
+ }));
407
415
  deepStrictEqual(objects2.length, 1);
408
416
  assertInstanceOf(objects2[0], Object$1);
409
417
  deepStrictEqual(objects2[0].name, "Second object");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab",
3
- "version": "2.1.30",
3
+ "version": "2.1.31",
4
4
  "homepage": "https://fedify.dev/",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,14 +41,14 @@
41
41
  "@js-temporal/polyfill": "^0.5.1",
42
42
  "@multiformats/base-x": "^4.0.1",
43
43
  "@logtape/logtape": "^2.0.5",
44
- "@opentelemetry/api": "^1.9.0",
44
+ "@opentelemetry/api": "~1.9.0",
45
45
  "asn1js": "^3.0.6",
46
46
  "es-toolkit": "1.43.0",
47
47
  "jsonld": "^9.0.0",
48
48
  "pkijs": "^3.3.3",
49
- "@fedify/vocab-tools": "2.1.30",
50
- "@fedify/webfinger": "2.1.30",
51
- "@fedify/vocab-runtime": "2.1.30"
49
+ "@fedify/vocab-tools": "2.1.31",
50
+ "@fedify/vocab-runtime": "2.1.31",
51
+ "@fedify/webfinger": "2.1.31"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/node": "^22.17.0",
@@ -9,6 +9,12 @@ import { lookupObject, traverseCollection } from "./lookup.ts";
9
9
  import { assertInstanceOf } from "./utils.ts";
10
10
  import { Collection, Note, Object, Person } from "./vocab.ts";
11
11
 
12
+ // lookupObject() accepts this option without declaring it, since Fedify's
13
+ // Context passes it. It makes WebFinger lookups use the global fetch()
14
+ // (fetch-mock here) without resolving hostnames, so that the tests do not
15
+ // depend on the real DNS:
16
+ const allowPrivateAddress = { allowPrivateAddress: true };
17
+
12
18
  test("lookupObject()", {
13
19
  sanitizeResources: false,
14
20
  sanitizeOps: false,
@@ -42,6 +48,7 @@ test("lookupObject()", {
42
48
  const options = {
43
49
  documentLoader: mockDocumentLoader,
44
50
  contextLoader: mockDocumentLoader,
51
+ ...allowPrivateAddress,
45
52
  };
46
53
 
47
54
  await t.step("actor", async () => {
@@ -479,6 +486,7 @@ test("FEP-fe34: lookupObject() cross-origin security", {
479
486
 
480
487
  // Default behavior should return null
481
488
  const result1 = await lookupObject("@user@example.com", {
489
+ ...allowPrivateAddress,
482
490
  documentLoader: webfingerDocumentLoader,
483
491
  contextLoader: mockDocumentLoader,
484
492
  });
@@ -488,6 +496,7 @@ test("FEP-fe34: lookupObject() cross-origin security", {
488
496
  await rejects(
489
497
  () =>
490
498
  lookupObject("@user@example.com", {
499
+ ...allowPrivateAddress,
491
500
  documentLoader: webfingerDocumentLoader,
492
501
  contextLoader: mockDocumentLoader,
493
502
  crossOrigin: "throw",
@@ -498,6 +507,7 @@ test("FEP-fe34: lookupObject() cross-origin security", {
498
507
 
499
508
  // With crossOrigin: trust, should return the object
500
509
  const result2 = await lookupObject("@user@example.com", {
510
+ ...allowPrivateAddress,
501
511
  documentLoader: webfingerDocumentLoader,
502
512
  contextLoader: mockDocumentLoader,
503
513
  crossOrigin: "trust",
@@ -597,12 +607,22 @@ test("FEP-fe34: lookupObject() cross-origin security", {
597
607
  throw new Error("Network error");
598
608
  };
599
609
 
610
+ // The WebFinger fallback must not reach the network:
611
+ fetchMock.spyGlobal();
612
+ fetchMock.get("begin:https://example.com/.well-known/webfinger", 404);
613
+
600
614
  // Network errors should not be confused with cross-origin errors
601
- const result = await lookupObject("https://example.com/note", {
602
- documentLoader: errorDocumentLoader,
603
- contextLoader: mockDocumentLoader,
604
- crossOrigin: "throw",
605
- });
615
+ let result;
616
+ try {
617
+ result = await lookupObject("https://example.com/note", {
618
+ ...allowPrivateAddress,
619
+ documentLoader: errorDocumentLoader,
620
+ contextLoader: mockDocumentLoader,
621
+ crossOrigin: "throw",
622
+ });
623
+ } finally {
624
+ fetchMock.hardReset();
625
+ }
606
626
 
607
627
  // Should return null because the document loader failed,
608
628
  // not because of cross-origin policy
package/src/vocab.test.ts CHANGED
@@ -552,7 +552,14 @@ test({
552
552
  const activity2 = new Activity({
553
553
  object: new URL("https://example.com/not-found"),
554
554
  });
555
- deepStrictEqual(await activity2.getObject({ suppressError: true }), null);
555
+ deepStrictEqual(
556
+ await activity2.getObject({
557
+ documentLoader: mockDocumentLoader,
558
+ contextLoader: mockDocumentLoader,
559
+ suppressError: true,
560
+ }),
561
+ null,
562
+ );
556
563
 
557
564
  const activity3 = await Activity.fromJsonLd({
558
565
  "@context": "https://www.w3.org/ns/activitystreams",
@@ -607,7 +614,11 @@ test({
607
614
  ],
608
615
  });
609
616
  const objects2 = await Array.fromAsync(
610
- activity2.getObjects({ suppressError: true }),
617
+ activity2.getObjects({
618
+ documentLoader: mockDocumentLoader,
619
+ contextLoader: mockDocumentLoader,
620
+ suppressError: true,
621
+ }),
611
622
  );
612
623
  deepStrictEqual(objects2.length, 1);
613
624
  assertInstanceOf(objects2[0], Object);