@fedify/testing 2.5.0-dev.2446 → 2.5.0-dev.2492
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.cjs +33 -5
- package/dist/mod.d.cts +8 -0
- package/dist/mod.d.ts +8 -0
- package/dist/mod.js +34 -6
- package/package.json +6 -7
package/dist/mod.cjs
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
let _fedify_fedify_sig = require("@fedify/fedify/sig");
|
|
4
4
|
let _fedify_vocab = require("@fedify/vocab");
|
|
5
5
|
let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
|
|
6
|
+
let _opentelemetry_api = require("@opentelemetry/api");
|
|
6
7
|
let _fedify_fedify_federation = require("@fedify/fedify/federation");
|
|
7
8
|
let es_toolkit = require("es-toolkit");
|
|
8
9
|
let node_assert_strict = require("node:assert/strict");
|
|
@@ -192,6 +193,18 @@ async function isSignedByAudience(getSignedKeyOwner, object, isMember) {
|
|
|
192
193
|
return false;
|
|
193
194
|
}
|
|
194
195
|
/**
|
|
196
|
+
* The authentication evidence of a mock inbox context that is not given one:
|
|
197
|
+
* nothing is authenticated.
|
|
198
|
+
*/
|
|
199
|
+
const EMPTY_AUTHENTICATION = globalThis.Object.freeze({
|
|
200
|
+
verified: false,
|
|
201
|
+
requestSigners: globalThis.Object.freeze([]),
|
|
202
|
+
documentSigners: globalThis.Object.freeze([]),
|
|
203
|
+
originAuthenticated: globalThis.Object.freeze([]),
|
|
204
|
+
expandedActivity: globalThis.Object.freeze([]),
|
|
205
|
+
baseUrl: null
|
|
206
|
+
});
|
|
207
|
+
/**
|
|
195
208
|
* Creates an InboxContext for testing purposes.
|
|
196
209
|
* Not exported - used internally only. Public API is in mock.ts
|
|
197
210
|
* @param args Partial InboxContext properties
|
|
@@ -209,6 +222,7 @@ function createInboxContext(args) {
|
|
|
209
222
|
data
|
|
210
223
|
})),
|
|
211
224
|
recipient: args.recipient ?? null,
|
|
225
|
+
authentication: args.authentication ?? EMPTY_AUTHENTICATION,
|
|
212
226
|
forwardActivity
|
|
213
227
|
};
|
|
214
228
|
}
|
|
@@ -428,9 +442,13 @@ var MockFederation = class {
|
|
|
428
442
|
outboxListenersInitialized = false;
|
|
429
443
|
contextData;
|
|
430
444
|
receivedActivities = [];
|
|
445
|
+
documentLoader;
|
|
446
|
+
contextLoader;
|
|
431
447
|
constructor(options = {}) {
|
|
432
448
|
this.options = options;
|
|
433
449
|
this.contextData = options.contextData;
|
|
450
|
+
this.documentLoader = options.documentLoader ?? (options.allowPrivateAddress ? (0, _fedify_vocab_runtime.getDocumentLoader)({ allowPrivateAddress: true }) : void 0);
|
|
451
|
+
this.contextLoader = options.contextLoader ?? this.documentLoader;
|
|
434
452
|
}
|
|
435
453
|
setNodeInfoDispatcher(path, dispatcher) {
|
|
436
454
|
this.nodeInfoDispatcher = dispatcher;
|
|
@@ -641,9 +659,9 @@ var MockFederation = class {
|
|
|
641
659
|
data: contextData,
|
|
642
660
|
federation: mockFederation,
|
|
643
661
|
meterProvider: this.options.meterProvider,
|
|
644
|
-
tracerProvider: this.options.tracerProvider,
|
|
645
|
-
documentLoader: this.
|
|
646
|
-
contextLoader: this.
|
|
662
|
+
tracerProvider: this.options.tracerProvider ?? (this.documentLoader == null ? void 0 : _opentelemetry_api.trace.getTracerProvider()),
|
|
663
|
+
documentLoader: this.documentLoader,
|
|
664
|
+
contextLoader: this.contextLoader,
|
|
647
665
|
verifyPortableObject: this.options.verifyPortableObject,
|
|
648
666
|
portableRequest: options.portableRequest
|
|
649
667
|
});
|
|
@@ -714,10 +732,20 @@ var MockFederation = class {
|
|
|
714
732
|
const typeName = activity.constructor.name;
|
|
715
733
|
const listeners = this.inboxListeners.get(typeName) || [];
|
|
716
734
|
if (listeners.length > 0 && this.contextData === void 0) throw new Error("MockFederation.receiveActivity(): contextData is not initialized. Please provide contextData through the constructor or call startQueue() before receiving activities.");
|
|
735
|
+
const receivedActivity = listeners.length > 0 && this.documentLoader != null ? activity.clone({}, {
|
|
736
|
+
documentLoader: this.documentLoader,
|
|
737
|
+
contextLoader: this.contextLoader
|
|
738
|
+
}) : activity;
|
|
739
|
+
if (receivedActivity !== activity) Reflect.set(receivedActivity, "_cachedJsonLd", Reflect.get(activity, "_cachedJsonLd"));
|
|
717
740
|
for (const listener of listeners) await listener(createInboxContext({
|
|
718
741
|
data: this.contextData,
|
|
719
|
-
federation: this
|
|
720
|
-
|
|
742
|
+
federation: this,
|
|
743
|
+
documentLoader: this.documentLoader,
|
|
744
|
+
contextLoader: this.contextLoader,
|
|
745
|
+
tracerProvider: this.options.tracerProvider ?? (this.documentLoader == null ? void 0 : _opentelemetry_api.trace.getTracerProvider()),
|
|
746
|
+
meterProvider: this.options.meterProvider,
|
|
747
|
+
verifyPortableObject: this.options.verifyPortableObject
|
|
748
|
+
}), receivedActivity);
|
|
721
749
|
}
|
|
722
750
|
/**
|
|
723
751
|
* Simulates posting an activity to a local actor outbox.
|
package/dist/mod.d.cts
CHANGED
|
@@ -161,6 +161,14 @@ declare function createFederation<TContextData>(options?: {
|
|
|
161
161
|
* @since 2.3.0
|
|
162
162
|
*/
|
|
163
163
|
meterProvider?: any;
|
|
164
|
+
/**
|
|
165
|
+
* Use HTTP document loading for received activities and contexts created by
|
|
166
|
+
* this federation, allowing private addresses such as localhost.
|
|
167
|
+
* If false or omitted, contexts retain their no-op mock loaders and
|
|
168
|
+
* received activities retain their own loaders.
|
|
169
|
+
* @since 2.0.35
|
|
170
|
+
*/
|
|
171
|
+
allowPrivateAddress?: boolean;
|
|
164
172
|
tracerProvider?: any; /** The document loader used by mock context lookups. @since 2.4.0 */
|
|
165
173
|
documentLoader?: DocumentLoader; /** The JSON-LD context loader used by mock context lookups. @since 2.4.0 */
|
|
166
174
|
contextLoader?: DocumentLoader;
|
package/dist/mod.d.ts
CHANGED
|
@@ -161,6 +161,14 @@ declare function createFederation<TContextData>(options?: {
|
|
|
161
161
|
* @since 2.3.0
|
|
162
162
|
*/
|
|
163
163
|
meterProvider?: any;
|
|
164
|
+
/**
|
|
165
|
+
* Use HTTP document loading for received activities and contexts created by
|
|
166
|
+
* this federation, allowing private addresses such as localhost.
|
|
167
|
+
* If false or omitted, contexts retain their no-op mock loaders and
|
|
168
|
+
* received activities retain their own loaders.
|
|
169
|
+
* @since 2.0.35
|
|
170
|
+
*/
|
|
171
|
+
allowPrivateAddress?: boolean;
|
|
164
172
|
tracerProvider?: any; /** The document loader used by mock context lookups. @since 2.4.0 */
|
|
165
173
|
documentLoader?: DocumentLoader; /** The JSON-LD context loader used by mock context lookups. @since 2.4.0 */
|
|
166
174
|
contextLoader?: DocumentLoader;
|
package/dist/mod.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Temporal } from "temporal-polyfill";
|
|
2
2
|
import { hasProofLike, hasSignatureLike } from "@fedify/fedify/sig";
|
|
3
3
|
import { Activity, CryptographicKey, Multikey, PUBLIC_COLLECTION, Tombstone, lookupObject, traverseCollection } from "@fedify/vocab";
|
|
4
|
-
import { arePortableUrisEqual, canonicalizePortableUri, decodeMultibase, formatIri, fromCompatibleEf61Id, getFe34Origin, parseDigestMultibase, parseHashlink, parseIri } from "@fedify/vocab-runtime";
|
|
4
|
+
import { arePortableUrisEqual, canonicalizePortableUri, decodeMultibase, formatIri, fromCompatibleEf61Id, getDocumentLoader, getFe34Origin, parseDigestMultibase, parseHashlink, parseIri } from "@fedify/vocab-runtime";
|
|
5
|
+
import { trace } from "@opentelemetry/api";
|
|
5
6
|
import { RouterError } from "@fedify/fedify/federation";
|
|
6
7
|
import { delay } from "es-toolkit";
|
|
7
8
|
import { deepStrictEqual, ok, strictEqual } from "node:assert/strict";
|
|
@@ -191,6 +192,18 @@ async function isSignedByAudience(getSignedKeyOwner, object, isMember) {
|
|
|
191
192
|
return false;
|
|
192
193
|
}
|
|
193
194
|
/**
|
|
195
|
+
* The authentication evidence of a mock inbox context that is not given one:
|
|
196
|
+
* nothing is authenticated.
|
|
197
|
+
*/
|
|
198
|
+
const EMPTY_AUTHENTICATION = globalThis.Object.freeze({
|
|
199
|
+
verified: false,
|
|
200
|
+
requestSigners: globalThis.Object.freeze([]),
|
|
201
|
+
documentSigners: globalThis.Object.freeze([]),
|
|
202
|
+
originAuthenticated: globalThis.Object.freeze([]),
|
|
203
|
+
expandedActivity: globalThis.Object.freeze([]),
|
|
204
|
+
baseUrl: null
|
|
205
|
+
});
|
|
206
|
+
/**
|
|
194
207
|
* Creates an InboxContext for testing purposes.
|
|
195
208
|
* Not exported - used internally only. Public API is in mock.ts
|
|
196
209
|
* @param args Partial InboxContext properties
|
|
@@ -208,6 +221,7 @@ function createInboxContext(args) {
|
|
|
208
221
|
data
|
|
209
222
|
})),
|
|
210
223
|
recipient: args.recipient ?? null,
|
|
224
|
+
authentication: args.authentication ?? EMPTY_AUTHENTICATION,
|
|
211
225
|
forwardActivity
|
|
212
226
|
};
|
|
213
227
|
}
|
|
@@ -427,9 +441,13 @@ var MockFederation = class {
|
|
|
427
441
|
outboxListenersInitialized = false;
|
|
428
442
|
contextData;
|
|
429
443
|
receivedActivities = [];
|
|
444
|
+
documentLoader;
|
|
445
|
+
contextLoader;
|
|
430
446
|
constructor(options = {}) {
|
|
431
447
|
this.options = options;
|
|
432
448
|
this.contextData = options.contextData;
|
|
449
|
+
this.documentLoader = options.documentLoader ?? (options.allowPrivateAddress ? getDocumentLoader({ allowPrivateAddress: true }) : void 0);
|
|
450
|
+
this.contextLoader = options.contextLoader ?? this.documentLoader;
|
|
433
451
|
}
|
|
434
452
|
setNodeInfoDispatcher(path, dispatcher) {
|
|
435
453
|
this.nodeInfoDispatcher = dispatcher;
|
|
@@ -640,9 +658,9 @@ var MockFederation = class {
|
|
|
640
658
|
data: contextData,
|
|
641
659
|
federation: mockFederation,
|
|
642
660
|
meterProvider: this.options.meterProvider,
|
|
643
|
-
tracerProvider: this.options.tracerProvider,
|
|
644
|
-
documentLoader: this.
|
|
645
|
-
contextLoader: this.
|
|
661
|
+
tracerProvider: this.options.tracerProvider ?? (this.documentLoader == null ? void 0 : trace.getTracerProvider()),
|
|
662
|
+
documentLoader: this.documentLoader,
|
|
663
|
+
contextLoader: this.contextLoader,
|
|
646
664
|
verifyPortableObject: this.options.verifyPortableObject,
|
|
647
665
|
portableRequest: options.portableRequest
|
|
648
666
|
});
|
|
@@ -713,10 +731,20 @@ var MockFederation = class {
|
|
|
713
731
|
const typeName = activity.constructor.name;
|
|
714
732
|
const listeners = this.inboxListeners.get(typeName) || [];
|
|
715
733
|
if (listeners.length > 0 && this.contextData === void 0) throw new Error("MockFederation.receiveActivity(): contextData is not initialized. Please provide contextData through the constructor or call startQueue() before receiving activities.");
|
|
734
|
+
const receivedActivity = listeners.length > 0 && this.documentLoader != null ? activity.clone({}, {
|
|
735
|
+
documentLoader: this.documentLoader,
|
|
736
|
+
contextLoader: this.contextLoader
|
|
737
|
+
}) : activity;
|
|
738
|
+
if (receivedActivity !== activity) Reflect.set(receivedActivity, "_cachedJsonLd", Reflect.get(activity, "_cachedJsonLd"));
|
|
716
739
|
for (const listener of listeners) await listener(createInboxContext({
|
|
717
740
|
data: this.contextData,
|
|
718
|
-
federation: this
|
|
719
|
-
|
|
741
|
+
federation: this,
|
|
742
|
+
documentLoader: this.documentLoader,
|
|
743
|
+
contextLoader: this.contextLoader,
|
|
744
|
+
tracerProvider: this.options.tracerProvider ?? (this.documentLoader == null ? void 0 : trace.getTracerProvider()),
|
|
745
|
+
meterProvider: this.options.meterProvider,
|
|
746
|
+
verifyPortableObject: this.options.verifyPortableObject
|
|
747
|
+
}), receivedActivity);
|
|
720
748
|
}
|
|
721
749
|
/**
|
|
722
750
|
* Simulates posting an activity to a local actor outbox.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/testing",
|
|
3
|
-
"version": "2.5.0-dev.
|
|
3
|
+
"version": "2.5.0-dev.2492+4648c04e",
|
|
4
4
|
"description": "Testing utilities for Fedify applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -47,13 +47,14 @@
|
|
|
47
47
|
"package.json"
|
|
48
48
|
],
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@fedify/fedify": "^2.5.0-dev.
|
|
50
|
+
"@fedify/fedify": "^2.5.0-dev.2492+4648c04e"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
+
"@opentelemetry/api": "~1.9.1",
|
|
53
54
|
"es-toolkit": "1.46.1",
|
|
54
55
|
"temporal-polyfill": "^1.0.1",
|
|
55
|
-
"@fedify/vocab": "2.5.0-dev.
|
|
56
|
-
"@fedify/vocab
|
|
56
|
+
"@fedify/vocab-runtime": "^2.5.0-dev.2492+4648c04e",
|
|
57
|
+
"@fedify/vocab": "2.5.0-dev.2492+4648c04e"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@standard-schema/spec": "^1.1.0",
|
|
@@ -61,9 +62,7 @@
|
|
|
61
62
|
"@std/async": "npm:@jsr/std__async@^1.0.13",
|
|
62
63
|
"tsdown": "^0.22.0",
|
|
63
64
|
"typescript": "^6.0.0",
|
|
64
|
-
"@fedify/fixture": "^2.0.0"
|
|
65
|
-
"@fedify/vocab": "^2.5.0-dev.2446+2014cb03",
|
|
66
|
-
"@fedify/vocab-runtime": "^2.5.0-dev.2446+2014cb03"
|
|
65
|
+
"@fedify/fixture": "^2.0.0"
|
|
67
66
|
},
|
|
68
67
|
"scripts": {
|
|
69
68
|
"build:self": "tsdown",
|