@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.
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.js +1 -1
- package/dist/{federation-pFFwPyoZ.cjs → federation-JvzYDx0P.cjs} +3 -3
- package/dist/{http-CXX-QPzs.cjs → http-BG5cDmTS.cjs} +1 -1
- package/dist/{http-T7h9GBAN.js → http-MUf125Jc.js} +1 -1
- package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-A2po7h0_.cjs} +1 -1
- package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CbWc1BZA.js} +1 -1
- package/dist/{middleware-Bj91r7r2.js → middleware-DzzdJ7Wz.js} +3 -3
- package/dist/mod.cjs +4 -4
- package/dist/mod.js +4 -4
- package/dist/{portable-collection-Do5QA2oy.js → portable-collection-CAer9RWN.js} +1 -1
- package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +22 -9
- package/skills/fedify/SKILL.md +10 -0
- package/dist/accept-CPVqki78.mjs +0 -145
- package/dist/activity-listener-CELFAodc.mjs +0 -44
- package/dist/assert-D1Eafmd_.mjs +0 -23
- package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
- package/dist/assert_exists-cffSpJ7X.mjs +0 -28
- package/dist/assert_false-CPdRnc3E.mjs +0 -23
- package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
- package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
- package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
- package/dist/assert_rejects-CTptdYck.mjs +0 -39
- package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
- package/dist/assert_throws-BYITOvPO.mjs +0 -74
- package/dist/assertion_error-B-cx0fFA.mjs +0 -31
- package/dist/audience-CHQ-FlLD.mjs +0 -95
- package/dist/builder-D1FP_5nQ.mjs +0 -911
- package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
- package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
- package/dist/client-5SIFzW3q.mjs +0 -441
- package/dist/codec-C6rTrpIp.mjs +0 -147
- package/dist/collection-CnnP1UAv.mjs +0 -44
- package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
- package/dist/compat/outgoing-jsonld.test.mjs +0 -257
- package/dist/compat/public-audience.test.d.mts +0 -2
- package/dist/compat/public-audience.test.mjs +0 -187
- package/dist/compat/secured-document.test.d.mts +0 -2
- package/dist/compat/secured-document.test.mjs +0 -58
- package/dist/compat/transformers.test.d.mts +0 -2
- package/dist/compat/transformers.test.mjs +0 -62
- package/dist/compound-proof-DSHhnOEW.mjs +0 -1019
- package/dist/context-LgGFFSz7.mjs +0 -146
- package/dist/deno-C50ikGBU.mjs +0 -8
- package/dist/dist-_geWsuaI.mjs +0 -189
- package/dist/docloader-BY-SEID0.mjs +0 -136
- package/dist/esm-BHXXx4Wx.mjs +0 -1233
- package/dist/exporter-DVG68ozH.mjs +0 -263
- package/dist/federation/audience.test.d.mts +0 -2
- package/dist/federation/audience.test.mjs +0 -130
- package/dist/federation/builder.test.d.mts +0 -2
- package/dist/federation/builder.test.mjs +0 -396
- package/dist/federation/circuit-breaker.test.d.mts +0 -2
- package/dist/federation/circuit-breaker.test.mjs +0 -1277
- package/dist/federation/collection.test.d.mts +0 -2
- package/dist/federation/collection.test.mjs +0 -21
- package/dist/federation/compound-fanout.test.d.mts +0 -2
- package/dist/federation/compound-fanout.test.mjs +0 -231
- package/dist/federation/handler-compound-proof.test.d.mts +0 -2
- package/dist/federation/handler-compound-proof.test.mjs +0 -384
- package/dist/federation/handler.test.d.mts +0 -2
- package/dist/federation/handler.test.mjs +0 -5445
- package/dist/federation/hashlink-media.test.d.mts +0 -2
- package/dist/federation/hashlink-media.test.mjs +0 -422
- package/dist/federation/idempotency.test.d.mts +0 -2
- package/dist/federation/idempotency.test.mjs +0 -207
- package/dist/federation/inbox-actorless.test.d.mts +0 -2
- package/dist/federation/inbox-actorless.test.mjs +0 -522
- package/dist/federation/inbox-authentication.test.d.mts +0 -2
- package/dist/federation/inbox-authentication.test.mjs +0 -220
- package/dist/federation/inbox-report.test.d.mts +0 -2
- package/dist/federation/inbox-report.test.mjs +0 -719
- package/dist/federation/inbox-view.test.d.mts +0 -2
- package/dist/federation/inbox-view.test.mjs +0 -369
- package/dist/federation/inbox.test.d.mts +0 -2
- package/dist/federation/inbox.test.mjs +0 -139
- package/dist/federation/keycache.test.d.mts +0 -2
- package/dist/federation/keycache.test.mjs +0 -337
- package/dist/federation/kv.test.d.mts +0 -2
- package/dist/federation/kv.test.mjs +0 -88
- package/dist/federation/metrics.test.d.mts +0 -2
- package/dist/federation/metrics.test.mjs +0 -634
- package/dist/federation/middleware.test.d.mts +0 -2
- package/dist/federation/middleware.test.mjs +0 -9314
- package/dist/federation/mq.test.d.mts +0 -2
- package/dist/federation/mq.test.mjs +0 -591
- package/dist/federation/negotiation.test.d.mts +0 -2
- package/dist/federation/negotiation.test.mjs +0 -18
- package/dist/federation/outbound-body.test.d.mts +0 -2
- package/dist/federation/outbound-body.test.mjs +0 -149
- package/dist/federation/outbound-capture.test.d.mts +0 -2
- package/dist/federation/outbound-capture.test.mjs +0 -394
- package/dist/federation/outbound-dispatch.test.d.mts +0 -2
- package/dist/federation/outbound-dispatch.test.mjs +0 -368
- package/dist/federation/outbound-document.test.d.mts +0 -2
- package/dist/federation/outbound-document.test.mjs +0 -171
- package/dist/federation/outbound-provenance.test.d.mts +0 -2
- package/dist/federation/outbound-provenance.test.mjs +0 -543
- package/dist/federation/outbound-report.test.d.mts +0 -2
- package/dist/federation/outbound-report.test.mjs +0 -5475
- package/dist/federation/outbound-workers.test.d.mts +0 -2
- package/dist/federation/outbound-workers.test.mjs +0 -64
- package/dist/federation/outbound-workflow.test.d.mts +0 -2
- package/dist/federation/outbound-workflow.test.mjs +0 -154
- package/dist/federation/outgoing-proof.test.d.mts +0 -2
- package/dist/federation/outgoing-proof.test.mjs +0 -933
- package/dist/federation/portable-actor.test.d.mts +0 -2
- package/dist/federation/portable-actor.test.mjs +0 -496
- package/dist/federation/portable-chain.test.d.mts +0 -2
- package/dist/federation/portable-chain.test.mjs +0 -370
- package/dist/federation/portable-collection.test.d.mts +0 -2
- package/dist/federation/portable-collection.test.mjs +0 -832
- package/dist/federation/portable-delivery.test.d.mts +0 -2
- package/dist/federation/portable-delivery.test.mjs +0 -845
- package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
- package/dist/federation/portable-gateway-keys.test.mjs +0 -692
- package/dist/federation/portable-inbox.test.d.mts +0 -2
- package/dist/federation/portable-inbox.test.mjs +0 -1960
- package/dist/federation/portable-parse-uri.test.d.mts +0 -2
- package/dist/federation/portable-parse-uri.test.mjs +0 -348
- package/dist/federation/portable-route-activity.test.d.mts +0 -2
- package/dist/federation/portable-route-activity.test.mjs +0 -259
- package/dist/federation/portable.test.d.mts +0 -2
- package/dist/federation/portable.test.mjs +0 -1072
- package/dist/federation/retry.test.d.mts +0 -2
- package/dist/federation/retry.test.mjs +0 -42
- package/dist/federation/router.test.d.mts +0 -2
- package/dist/federation/router.test.mjs +0 -123
- package/dist/federation/send.test.d.mts +0 -2
- package/dist/federation/send.test.mjs +0 -1421
- package/dist/federation/tasks/codec.test.d.mts +0 -2
- package/dist/federation/tasks/codec.test.mjs +0 -302
- package/dist/federation/tasks/enqueue.test.d.mts +0 -2
- package/dist/federation/tasks/enqueue.test.mjs +0 -1095
- package/dist/federation/tasks/tasks.test.d.mts +0 -2
- package/dist/federation/tasks/tasks.test.mjs +0 -1229
- package/dist/federation/temporal.test.d.mts +0 -2
- package/dist/federation/temporal.test.mjs +0 -71
- package/dist/federation/webfinger.test.d.mts +0 -2
- package/dist/federation/webfinger.test.mjs +0 -944
- package/dist/http-BXbQQZDM.mjs +0 -1449
- package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
- package/dist/inbox-cS97XzOD.mjs +0 -399
- package/dist/inbox-view-D-d0Ar6o.mjs +0 -385
- package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
- package/dist/keycache-N2opu4-3.mjs +0 -221
- package/dist/keys-DIJNHW-Y.mjs +0 -120
- package/dist/kv-DBRWVx3Q.mjs +0 -104
- package/dist/kv-DCHkaJ9-.mjs +0 -92
- package/dist/kv-cache-fgbLHGVL.mjs +0 -121
- package/dist/ld-BpkhkDGj.mjs +0 -1752
- package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
- package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
- package/dist/metrics-Uqf8GomB.mjs +0 -818
- package/dist/middleware-DcXzz-YK.mjs +0 -9971
- package/dist/middleware-DgwZkvJR.mjs +0 -5
- package/dist/mq-eF96QxUT.mjs +0 -288
- package/dist/negotiation-BAKO9nih.mjs +0 -96
- package/dist/nodeinfo/client.test.d.mts +0 -2
- package/dist/nodeinfo/client.test.mjs +0 -1364
- package/dist/nodeinfo/handler.test.d.mts +0 -2
- package/dist/nodeinfo/handler.test.mjs +0 -94
- package/dist/nodeinfo/types.test.d.mts +0 -2
- package/dist/nodeinfo/types.test.mjs +0 -192
- package/dist/otel/exporter.test.d.mts +0 -2
- package/dist/otel/exporter.test.mjs +0 -887
- package/dist/outbound-body-CckPA5gc.mjs +0 -83
- package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
- package/dist/outbound-document-BMgwLXTY.mjs +0 -179
- package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
- package/dist/owner-BVenIFg1.mjs +0 -267
- package/dist/portable-collection-DIk9gpjL.mjs +0 -418
- package/dist/portable-key-C7pVaHNR.mjs +0 -549
- package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
- package/dist/proof-BlfZ95--.mjs +0 -1420
- package/dist/public-audience--klBIOk1.mjs +0 -197
- package/dist/retry-zX5xw5e0.mjs +0 -34
- package/dist/router-u5O5KCQr.mjs +0 -156
- package/dist/secured-document-CxzZZ9nL.mjs +0 -35
- package/dist/send-DEGHPGFk.mjs +0 -710
- package/dist/sig/accept.test.d.mts +0 -2
- package/dist/sig/accept.test.mjs +0 -416
- package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
- package/dist/sig/compound-proof-discovery.test.mjs +0 -331
- package/dist/sig/compound-proof-producer.test.d.mts +0 -2
- package/dist/sig/compound-proof-producer.test.mjs +0 -107
- package/dist/sig/compound-proof-verification.test.d.mts +0 -2
- package/dist/sig/compound-proof-verification.test.mjs +0 -1017
- package/dist/sig/compound-proof.test.d.mts +0 -2
- package/dist/sig/compound-proof.test.mjs +0 -411
- package/dist/sig/http.test.d.mts +0 -2
- package/dist/sig/http.test.mjs +0 -3328
- package/dist/sig/key-owner-evidence.test.d.mts +0 -2
- package/dist/sig/key-owner-evidence.test.mjs +0 -100
- package/dist/sig/key.test.d.mts +0 -2
- package/dist/sig/key.test.mjs +0 -1250
- package/dist/sig/ld.test.d.mts +0 -2
- package/dist/sig/ld.test.mjs +0 -1044
- package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
- package/dist/sig/mitra-receive-interop.test.mjs +0 -260
- package/dist/sig/mitra-send-interop.test.d.mts +0 -2
- package/dist/sig/mitra-send-interop.test.mjs +0 -461
- package/dist/sig/owner.test.d.mts +0 -2
- package/dist/sig/owner.test.mjs +0 -202
- package/dist/sig/portable-collection.test.d.mts +0 -2
- package/dist/sig/portable-collection.test.mjs +0 -697
- package/dist/sig/portable-interop.test.d.mts +0 -2
- package/dist/sig/portable-interop.test.mjs +0 -156
- package/dist/sig/portable-key-id.test.d.mts +0 -2
- package/dist/sig/portable-key-id.test.mjs +0 -67
- package/dist/sig/portable-key.test.d.mts +0 -2
- package/dist/sig/portable-key.test.mjs +0 -1438
- package/dist/sig/proof.test.d.mts +0 -2
- package/dist/sig/proof.test.mjs +0 -2638
- package/dist/sig/tootik-request-interop.test.d.mts +0 -2
- package/dist/sig/tootik-request-interop.test.mjs +0 -190
- package/dist/sig/tootik-send-interop.test.d.mts +0 -2
- package/dist/sig/tootik-send-interop.test.mjs +0 -331
- package/dist/sig/verification.test.d.mts +0 -2
- package/dist/sig/verification.test.mjs +0 -310
- package/dist/std__assert-DvMDRPes.mjs +0 -8
- package/dist/tasks-BCUmQbbz.mjs +0 -77
- package/dist/temporal-B4oQ8HpW.mjs +0 -95
- package/dist/testing/context.test.d.mts +0 -2
- package/dist/testing/context.test.mjs +0 -19
- package/dist/testing/kv.test.d.mts +0 -2
- package/dist/testing/kv.test.mjs +0 -101
- package/dist/testing/mod.d.mts +0 -6099
- package/dist/testing/mod.mjs +0 -9
- package/dist/testing-vrnD5Uaa.mjs +0 -8
- package/dist/types-DE_LV1JB.mjs +0 -46
- package/dist/utils/docloader.test.d.mts +0 -2
- package/dist/utils/docloader.test.mjs +0 -1076
- package/dist/utils/kv-cache.test.d.mts +0 -2
- package/dist/utils/kv-cache.test.mjs +0 -261
- package/dist/verification-C3954hQh.mjs +0 -5
- package/dist/verification-Dpfcw8ml.mjs +0 -105
- package/dist/vocab/cjs.test.d.mts +0 -2
- package/dist/vocab/cjs.test.mjs +0 -27
|
@@ -1,944 +0,0 @@
|
|
|
1
|
-
import { Temporal } from "temporal-polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
globalThis.addEventListener = () => {};
|
|
4
|
-
import { r as createRequestContext } from "../context-LgGFFSz7.mjs";
|
|
5
|
-
import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
|
|
6
|
-
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
7
|
-
import { t as assertNotEquals } from "../assert_not_equals-CpPK2t89.mjs";
|
|
8
|
-
import "../std__assert-DvMDRPes.mjs";
|
|
9
|
-
import { o as createFederation, s as handleWebFinger } from "../middleware-DcXzz-YK.mjs";
|
|
10
|
-
import { Image, Link, Person, Tombstone } from "@fedify/vocab";
|
|
11
|
-
import { parseIri } from "@fedify/vocab-runtime";
|
|
12
|
-
import { createTestMeterProvider, test } from "@fedify/fixture";
|
|
13
|
-
//#region src/federation/webfinger.test.ts
|
|
14
|
-
test("handleWebFinger()", async (t) => {
|
|
15
|
-
const url = new URL("https://example.com/.well-known/webfinger");
|
|
16
|
-
function createContext(url) {
|
|
17
|
-
const context = createRequestContext({
|
|
18
|
-
federation: createFederation({ kv: new MemoryKvStore() }),
|
|
19
|
-
url,
|
|
20
|
-
data: void 0,
|
|
21
|
-
getActorUri(identifier) {
|
|
22
|
-
return new URL(`${url.origin}/users/${identifier}`);
|
|
23
|
-
},
|
|
24
|
-
async getActor(handle) {
|
|
25
|
-
const actor = await actorDispatcher(context, handle);
|
|
26
|
-
return actor instanceof Tombstone ? null : actor;
|
|
27
|
-
},
|
|
28
|
-
parseUri(uri) {
|
|
29
|
-
if (uri == null) return null;
|
|
30
|
-
if (uri.protocol === "acct:") return null;
|
|
31
|
-
if (!uri.pathname.startsWith("/users/")) return null;
|
|
32
|
-
const paths = uri.pathname.split("/");
|
|
33
|
-
return {
|
|
34
|
-
type: "actor",
|
|
35
|
-
identifier: paths[paths.length - 1]
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return context;
|
|
40
|
-
}
|
|
41
|
-
const actorDispatcher = (ctx, identifier) => {
|
|
42
|
-
if (identifier === "gone") return new Tombstone({
|
|
43
|
-
id: ctx.getActorUri(identifier),
|
|
44
|
-
deleted: Temporal.Instant.from("2024-01-15T00:00:00Z")
|
|
45
|
-
});
|
|
46
|
-
if (identifier !== "someone" && identifier !== "someone2") return null;
|
|
47
|
-
const actorUri = ctx.getActorUri(identifier);
|
|
48
|
-
return new Person({
|
|
49
|
-
id: actorUri,
|
|
50
|
-
name: identifier === "someone" ? "Someone" : "Someone 2",
|
|
51
|
-
preferredUsername: identifier === "someone" ? null : identifier === "someone2" ? "bar" : null,
|
|
52
|
-
icon: new Image({
|
|
53
|
-
url: new URL(`${actorUri.origin}/icon.jpg`),
|
|
54
|
-
mediaType: "image/jpeg"
|
|
55
|
-
}),
|
|
56
|
-
urls: [new URL(`${actorUri.origin}/@${identifier}`), new Link({
|
|
57
|
-
href: new URL(`${actorUri.origin}/@${identifier}`),
|
|
58
|
-
rel: "alternate",
|
|
59
|
-
mediaType: "text/html"
|
|
60
|
-
})]
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
let onNotFoundCalled = null;
|
|
64
|
-
const onNotFound = (request) => {
|
|
65
|
-
onNotFoundCalled = request;
|
|
66
|
-
return new Response("Not found", { status: 404 });
|
|
67
|
-
};
|
|
68
|
-
await t.step("no actor dispatcher", async () => {
|
|
69
|
-
const context = createContext(url);
|
|
70
|
-
const request = context.request;
|
|
71
|
-
assertEquals((await handleWebFinger(request, {
|
|
72
|
-
context,
|
|
73
|
-
onNotFound
|
|
74
|
-
})).status, 404);
|
|
75
|
-
assertEquals(onNotFoundCalled, request);
|
|
76
|
-
});
|
|
77
|
-
onNotFoundCalled = null;
|
|
78
|
-
await t.step("no resource", async () => {
|
|
79
|
-
const context = createContext(url);
|
|
80
|
-
const request = context.request;
|
|
81
|
-
const response = await handleWebFinger(request, {
|
|
82
|
-
context,
|
|
83
|
-
actorDispatcher,
|
|
84
|
-
onNotFound
|
|
85
|
-
});
|
|
86
|
-
assertEquals(response.status, 400);
|
|
87
|
-
assertEquals(await response.text(), "Missing resource parameter.");
|
|
88
|
-
assertEquals(onNotFoundCalled, null);
|
|
89
|
-
});
|
|
90
|
-
await t.step("invalid resource", async () => {
|
|
91
|
-
const u = new URL(url);
|
|
92
|
-
u.searchParams.set("resource", " invalid ");
|
|
93
|
-
const context = createContext(u);
|
|
94
|
-
const response = await handleWebFinger(new Request(u), {
|
|
95
|
-
context,
|
|
96
|
-
actorDispatcher,
|
|
97
|
-
onNotFound
|
|
98
|
-
});
|
|
99
|
-
assertEquals(response.status, 400);
|
|
100
|
-
assertEquals(await response.text(), "Invalid resource URL.");
|
|
101
|
-
assertEquals(onNotFoundCalled, null);
|
|
102
|
-
});
|
|
103
|
-
const expected = {
|
|
104
|
-
subject: "acct:someone@example.com",
|
|
105
|
-
aliases: ["https://example.com/users/someone"],
|
|
106
|
-
links: [
|
|
107
|
-
{
|
|
108
|
-
href: "https://example.com/users/someone",
|
|
109
|
-
rel: "self",
|
|
110
|
-
type: "application/activity+json"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
href: "https://example.com/@someone",
|
|
114
|
-
rel: "http://webfinger.net/rel/profile-page"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
href: "https://example.com/@someone",
|
|
118
|
-
rel: "alternate",
|
|
119
|
-
type: "text/html"
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
href: "https://example.com/icon.jpg",
|
|
123
|
-
rel: "http://webfinger.net/rel/avatar",
|
|
124
|
-
type: "image/jpeg"
|
|
125
|
-
}
|
|
126
|
-
]
|
|
127
|
-
};
|
|
128
|
-
await t.step("ok: resource=acct:...", async () => {
|
|
129
|
-
const u = new URL(url);
|
|
130
|
-
u.searchParams.set("resource", "acct:someone@example.com");
|
|
131
|
-
const context = createContext(u);
|
|
132
|
-
const request = context.request;
|
|
133
|
-
const response = await handleWebFinger(request, {
|
|
134
|
-
context,
|
|
135
|
-
actorDispatcher,
|
|
136
|
-
onNotFound
|
|
137
|
-
});
|
|
138
|
-
assertEquals(response.status, 200);
|
|
139
|
-
assertEquals(response.headers.get("Content-Type"), "application/jrd+json");
|
|
140
|
-
assertEquals(response.headers.get("Access-Control-Allow-Origin"), "*");
|
|
141
|
-
assertEquals(await response.json(), expected);
|
|
142
|
-
});
|
|
143
|
-
const expected2 = {
|
|
144
|
-
subject: "https://example.com/users/someone2",
|
|
145
|
-
aliases: ["acct:bar@example.com"],
|
|
146
|
-
links: [
|
|
147
|
-
{
|
|
148
|
-
href: "https://example.com/users/someone2",
|
|
149
|
-
rel: "self",
|
|
150
|
-
type: "application/activity+json"
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
href: "https://example.com/@someone2",
|
|
154
|
-
rel: "http://webfinger.net/rel/profile-page"
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
href: "https://example.com/@someone2",
|
|
158
|
-
rel: "alternate",
|
|
159
|
-
type: "text/html"
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
href: "https://example.com/icon.jpg",
|
|
163
|
-
rel: "http://webfinger.net/rel/avatar",
|
|
164
|
-
type: "image/jpeg"
|
|
165
|
-
}
|
|
166
|
-
]
|
|
167
|
-
};
|
|
168
|
-
await t.step("ok: resource=https:...", async () => {
|
|
169
|
-
const u = new URL(url);
|
|
170
|
-
u.searchParams.set("resource", "https://example.com/users/someone");
|
|
171
|
-
let context = createContext(u);
|
|
172
|
-
let request = context.request;
|
|
173
|
-
let response = await handleWebFinger(request, {
|
|
174
|
-
context,
|
|
175
|
-
actorDispatcher,
|
|
176
|
-
onNotFound
|
|
177
|
-
});
|
|
178
|
-
assertEquals(response.status, 200);
|
|
179
|
-
assertEquals(await response.json(), {
|
|
180
|
-
...expected,
|
|
181
|
-
aliases: [],
|
|
182
|
-
subject: "https://example.com/users/someone"
|
|
183
|
-
});
|
|
184
|
-
u.searchParams.set("resource", "https://example.com/users/someone2");
|
|
185
|
-
context = createContext(u);
|
|
186
|
-
request = context.request;
|
|
187
|
-
response = await handleWebFinger(request, {
|
|
188
|
-
context,
|
|
189
|
-
actorDispatcher,
|
|
190
|
-
onNotFound
|
|
191
|
-
});
|
|
192
|
-
assertEquals(response.status, 200);
|
|
193
|
-
assertEquals(await response.json(), expected2);
|
|
194
|
-
});
|
|
195
|
-
await t.step("gone: resource=acct:...", async () => {
|
|
196
|
-
const u = new URL(url);
|
|
197
|
-
u.searchParams.set("resource", "acct:gone@example.com");
|
|
198
|
-
const context = createContext(u);
|
|
199
|
-
const request = context.request;
|
|
200
|
-
const response = await handleWebFinger(request, {
|
|
201
|
-
context,
|
|
202
|
-
actorDispatcher,
|
|
203
|
-
onNotFound
|
|
204
|
-
});
|
|
205
|
-
assertEquals(response.status, 410);
|
|
206
|
-
assertEquals(response.headers.get("Access-Control-Allow-Origin"), "*");
|
|
207
|
-
assertEquals(onNotFoundCalled, null);
|
|
208
|
-
});
|
|
209
|
-
await t.step("gone: resource=https:...", async () => {
|
|
210
|
-
const u = new URL(url);
|
|
211
|
-
u.searchParams.set("resource", "https://example.com/users/gone");
|
|
212
|
-
const context = createContext(u);
|
|
213
|
-
const request = context.request;
|
|
214
|
-
const response = await handleWebFinger(request, {
|
|
215
|
-
context,
|
|
216
|
-
actorDispatcher,
|
|
217
|
-
onNotFound
|
|
218
|
-
});
|
|
219
|
-
assertEquals(response.status, 410);
|
|
220
|
-
assertEquals(response.headers.get("Access-Control-Allow-Origin"), "*");
|
|
221
|
-
assertEquals(onNotFoundCalled, null);
|
|
222
|
-
});
|
|
223
|
-
await t.step("not found: resource=acct:...", async () => {
|
|
224
|
-
const u = new URL(url);
|
|
225
|
-
u.searchParams.set("resource", "acct:no-one@example.com");
|
|
226
|
-
const context = createContext(u);
|
|
227
|
-
const request = context.request;
|
|
228
|
-
assertEquals((await handleWebFinger(request, {
|
|
229
|
-
context,
|
|
230
|
-
actorDispatcher,
|
|
231
|
-
onNotFound
|
|
232
|
-
})).status, 404);
|
|
233
|
-
assertEquals(onNotFoundCalled, request);
|
|
234
|
-
});
|
|
235
|
-
onNotFoundCalled = null;
|
|
236
|
-
await t.step("not found: resource=http:...", async () => {
|
|
237
|
-
const u = new URL(url);
|
|
238
|
-
u.searchParams.set("resource", "https://example.com/users/no-one");
|
|
239
|
-
let context = createContext(u);
|
|
240
|
-
let request = context.request;
|
|
241
|
-
let response = await handleWebFinger(request, {
|
|
242
|
-
context,
|
|
243
|
-
actorDispatcher,
|
|
244
|
-
onNotFound
|
|
245
|
-
});
|
|
246
|
-
assertEquals(response.status, 404);
|
|
247
|
-
assertEquals(onNotFoundCalled, request);
|
|
248
|
-
onNotFoundCalled = null;
|
|
249
|
-
u.searchParams.set("resource", "https://google.com/");
|
|
250
|
-
context = createContext(u);
|
|
251
|
-
request = context.request;
|
|
252
|
-
response = await handleWebFinger(request, {
|
|
253
|
-
context,
|
|
254
|
-
actorDispatcher,
|
|
255
|
-
onNotFound
|
|
256
|
-
});
|
|
257
|
-
assertEquals(response.status, 404);
|
|
258
|
-
assertEquals(onNotFoundCalled, request);
|
|
259
|
-
});
|
|
260
|
-
onNotFoundCalled = null;
|
|
261
|
-
const actorHandleMapper = (_ctx, username) => {
|
|
262
|
-
return username === "foo" ? "someone" : username === "bar" ? "someone2" : username === "qux" ? "someone2" : null;
|
|
263
|
-
};
|
|
264
|
-
await t.step("handle mapper", async () => {
|
|
265
|
-
const u = new URL(url);
|
|
266
|
-
u.searchParams.set("resource", "acct:foo@example.com");
|
|
267
|
-
let context = createContext(u);
|
|
268
|
-
let request = context.request;
|
|
269
|
-
let response = await handleWebFinger(request, {
|
|
270
|
-
context,
|
|
271
|
-
actorDispatcher,
|
|
272
|
-
actorHandleMapper,
|
|
273
|
-
onNotFound
|
|
274
|
-
});
|
|
275
|
-
assertEquals(response.status, 200);
|
|
276
|
-
assertEquals(await response.json(), {
|
|
277
|
-
...expected,
|
|
278
|
-
aliases: ["https://example.com/users/someone"],
|
|
279
|
-
subject: "acct:foo@example.com"
|
|
280
|
-
});
|
|
281
|
-
u.searchParams.set("resource", "acct:bar@example.com");
|
|
282
|
-
context = createContext(u);
|
|
283
|
-
request = context.request;
|
|
284
|
-
response = await handleWebFinger(request, {
|
|
285
|
-
context,
|
|
286
|
-
actorDispatcher,
|
|
287
|
-
actorHandleMapper,
|
|
288
|
-
onNotFound
|
|
289
|
-
});
|
|
290
|
-
assertEquals(response.status, 200);
|
|
291
|
-
assertEquals(await response.json(), {
|
|
292
|
-
...expected2,
|
|
293
|
-
aliases: ["https://example.com/users/someone2"],
|
|
294
|
-
subject: "acct:bar@example.com"
|
|
295
|
-
});
|
|
296
|
-
u.searchParams.set("resource", "https://example.com/users/someone");
|
|
297
|
-
context = createContext(u);
|
|
298
|
-
request = context.request;
|
|
299
|
-
response = await handleWebFinger(request, {
|
|
300
|
-
context,
|
|
301
|
-
actorDispatcher,
|
|
302
|
-
actorHandleMapper,
|
|
303
|
-
onNotFound
|
|
304
|
-
});
|
|
305
|
-
assertEquals(response.status, 200);
|
|
306
|
-
assertEquals(await response.json(), {
|
|
307
|
-
...expected,
|
|
308
|
-
aliases: [],
|
|
309
|
-
subject: "https://example.com/users/someone"
|
|
310
|
-
});
|
|
311
|
-
u.searchParams.set("resource", "acct:baz@example.com");
|
|
312
|
-
context = createContext(u);
|
|
313
|
-
request = context.request;
|
|
314
|
-
response = await handleWebFinger(request, {
|
|
315
|
-
context,
|
|
316
|
-
actorDispatcher,
|
|
317
|
-
actorHandleMapper,
|
|
318
|
-
onNotFound
|
|
319
|
-
});
|
|
320
|
-
assertEquals(response.status, 404);
|
|
321
|
-
});
|
|
322
|
-
const actorAliasMapper = (_ctx, resource) => {
|
|
323
|
-
if (resource.protocol !== "https:") return null;
|
|
324
|
-
if (resource.host !== "example.com") return null;
|
|
325
|
-
const m = /^\/@(\w+)$/.exec(resource.pathname);
|
|
326
|
-
if (m == null) return null;
|
|
327
|
-
return { username: m[1] };
|
|
328
|
-
};
|
|
329
|
-
await t.step("alias mapper", async () => {
|
|
330
|
-
const u = new URL(url);
|
|
331
|
-
u.searchParams.set("resource", "https://example.com/@someone");
|
|
332
|
-
let context = createContext(u);
|
|
333
|
-
let request = context.request;
|
|
334
|
-
let response = await handleWebFinger(request, {
|
|
335
|
-
context,
|
|
336
|
-
actorDispatcher,
|
|
337
|
-
actorAliasMapper,
|
|
338
|
-
onNotFound
|
|
339
|
-
});
|
|
340
|
-
assertEquals(response.status, 200);
|
|
341
|
-
assertEquals(await response.json(), {
|
|
342
|
-
...expected,
|
|
343
|
-
aliases: ["https://example.com/users/someone"],
|
|
344
|
-
subject: "https://example.com/@someone"
|
|
345
|
-
});
|
|
346
|
-
u.searchParams.set("resource", "https://example.com/@bar");
|
|
347
|
-
context = createContext(u);
|
|
348
|
-
request = context.request;
|
|
349
|
-
response = await handleWebFinger(request, {
|
|
350
|
-
context,
|
|
351
|
-
actorDispatcher,
|
|
352
|
-
actorHandleMapper,
|
|
353
|
-
actorAliasMapper,
|
|
354
|
-
onNotFound
|
|
355
|
-
});
|
|
356
|
-
assertEquals(response.status, 200);
|
|
357
|
-
assertEquals(await response.json(), {
|
|
358
|
-
...expected2,
|
|
359
|
-
aliases: ["acct:bar@example.com", "https://example.com/users/someone2"],
|
|
360
|
-
subject: "https://example.com/@bar"
|
|
361
|
-
});
|
|
362
|
-
u.searchParams.set("resource", "https://example.com/@no-one");
|
|
363
|
-
context = createContext(u);
|
|
364
|
-
request = context.request;
|
|
365
|
-
response = await handleWebFinger(request, {
|
|
366
|
-
context,
|
|
367
|
-
actorDispatcher,
|
|
368
|
-
actorAliasMapper,
|
|
369
|
-
onNotFound
|
|
370
|
-
});
|
|
371
|
-
assertEquals(response.status, 404);
|
|
372
|
-
u.searchParams.set("resource", "https://example.com/@no-one");
|
|
373
|
-
context = createContext(u);
|
|
374
|
-
request = context.request;
|
|
375
|
-
response = await handleWebFinger(request, {
|
|
376
|
-
context,
|
|
377
|
-
actorDispatcher,
|
|
378
|
-
actorHandleMapper,
|
|
379
|
-
actorAliasMapper,
|
|
380
|
-
onNotFound
|
|
381
|
-
});
|
|
382
|
-
assertEquals(response.status, 404);
|
|
383
|
-
});
|
|
384
|
-
await t.step("handleHost", async () => {
|
|
385
|
-
let u = new URL("https://ap.example.com/.well-known/webfinger");
|
|
386
|
-
u.searchParams.set("resource", "acct:someone@ap.example.com");
|
|
387
|
-
let context = createContext(u);
|
|
388
|
-
let request = context.request;
|
|
389
|
-
let response = await handleWebFinger(request, {
|
|
390
|
-
context,
|
|
391
|
-
host: "example.com",
|
|
392
|
-
actorDispatcher,
|
|
393
|
-
onNotFound
|
|
394
|
-
});
|
|
395
|
-
assertEquals(response.status, 200);
|
|
396
|
-
assertEquals(await response.json(), {
|
|
397
|
-
subject: "acct:someone@example.com",
|
|
398
|
-
aliases: ["https://ap.example.com/users/someone", "acct:someone@ap.example.com"],
|
|
399
|
-
links: [
|
|
400
|
-
{
|
|
401
|
-
href: "https://ap.example.com/users/someone",
|
|
402
|
-
rel: "self",
|
|
403
|
-
type: "application/activity+json"
|
|
404
|
-
},
|
|
405
|
-
{
|
|
406
|
-
href: "https://ap.example.com/@someone",
|
|
407
|
-
rel: "http://webfinger.net/rel/profile-page"
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
href: "https://ap.example.com/@someone",
|
|
411
|
-
rel: "alternate",
|
|
412
|
-
type: "text/html"
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
href: "https://ap.example.com/icon.jpg",
|
|
416
|
-
rel: "http://webfinger.net/rel/avatar",
|
|
417
|
-
type: "image/jpeg"
|
|
418
|
-
}
|
|
419
|
-
]
|
|
420
|
-
});
|
|
421
|
-
u.searchParams.set("resource", "acct:qux@ap.example.com");
|
|
422
|
-
context = createContext(u);
|
|
423
|
-
request = context.request;
|
|
424
|
-
response = await handleWebFinger(request, {
|
|
425
|
-
context,
|
|
426
|
-
host: "example.com",
|
|
427
|
-
actorDispatcher,
|
|
428
|
-
actorHandleMapper,
|
|
429
|
-
onNotFound
|
|
430
|
-
});
|
|
431
|
-
assertEquals(response.status, 200);
|
|
432
|
-
assertEquals(await response.json(), {
|
|
433
|
-
subject: "acct:bar@example.com",
|
|
434
|
-
aliases: [
|
|
435
|
-
"https://ap.example.com/users/someone2",
|
|
436
|
-
"acct:qux@ap.example.com",
|
|
437
|
-
"acct:bar@ap.example.com"
|
|
438
|
-
],
|
|
439
|
-
links: [
|
|
440
|
-
{
|
|
441
|
-
href: "https://ap.example.com/users/someone2",
|
|
442
|
-
rel: "self",
|
|
443
|
-
type: "application/activity+json"
|
|
444
|
-
},
|
|
445
|
-
{
|
|
446
|
-
href: "https://ap.example.com/@someone2",
|
|
447
|
-
rel: "http://webfinger.net/rel/profile-page"
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
href: "https://ap.example.com/@someone2",
|
|
451
|
-
rel: "alternate",
|
|
452
|
-
type: "text/html"
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
href: "https://ap.example.com/icon.jpg",
|
|
456
|
-
rel: "http://webfinger.net/rel/avatar",
|
|
457
|
-
type: "image/jpeg"
|
|
458
|
-
}
|
|
459
|
-
]
|
|
460
|
-
});
|
|
461
|
-
u = new URL(url);
|
|
462
|
-
u.searchParams.set("resource", "acct:someone@handle.example.com");
|
|
463
|
-
context = createContext(u);
|
|
464
|
-
request = context.request;
|
|
465
|
-
response = await handleWebFinger(request, {
|
|
466
|
-
context,
|
|
467
|
-
host: "handle.example.com",
|
|
468
|
-
actorDispatcher,
|
|
469
|
-
onNotFound
|
|
470
|
-
});
|
|
471
|
-
assertEquals(response.status, 200);
|
|
472
|
-
assertEquals(await response.json(), {
|
|
473
|
-
...expected,
|
|
474
|
-
subject: "acct:someone@handle.example.com"
|
|
475
|
-
});
|
|
476
|
-
u.searchParams.set("resource", "https://example.com/users/someone2");
|
|
477
|
-
context = createContext(u);
|
|
478
|
-
request = context.request;
|
|
479
|
-
response = await handleWebFinger(request, {
|
|
480
|
-
context,
|
|
481
|
-
host: "handle.example.com",
|
|
482
|
-
actorDispatcher,
|
|
483
|
-
onNotFound
|
|
484
|
-
});
|
|
485
|
-
assertEquals(response.status, 200);
|
|
486
|
-
assertEquals(await response.json(), {
|
|
487
|
-
...expected2,
|
|
488
|
-
aliases: ["acct:bar@handle.example.com", "acct:bar@example.com"],
|
|
489
|
-
subject: "https://example.com/users/someone2"
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
const expectedForLocalhostWithPort = {
|
|
493
|
-
subject: "acct:someone@localhost:8000",
|
|
494
|
-
aliases: ["https://localhost:8000/users/someone"],
|
|
495
|
-
links: [
|
|
496
|
-
{
|
|
497
|
-
href: "https://localhost:8000/users/someone",
|
|
498
|
-
rel: "self",
|
|
499
|
-
type: "application/activity+json"
|
|
500
|
-
},
|
|
501
|
-
{
|
|
502
|
-
href: "https://localhost:8000/@someone",
|
|
503
|
-
rel: "http://webfinger.net/rel/profile-page"
|
|
504
|
-
},
|
|
505
|
-
{
|
|
506
|
-
href: "https://localhost:8000/@someone",
|
|
507
|
-
rel: "alternate",
|
|
508
|
-
type: "text/html"
|
|
509
|
-
},
|
|
510
|
-
{
|
|
511
|
-
href: "https://localhost:8000/icon.jpg",
|
|
512
|
-
rel: "http://webfinger.net/rel/avatar",
|
|
513
|
-
type: "image/jpeg"
|
|
514
|
-
}
|
|
515
|
-
]
|
|
516
|
-
};
|
|
517
|
-
await t.step("on localhost with port, ok: resource=acct:...", async () => {
|
|
518
|
-
const u = new URL("https://localhost:8000/.well-known/webfinger");
|
|
519
|
-
u.searchParams.set("resource", "acct:someone@localhost:8000");
|
|
520
|
-
const context = createContext(u);
|
|
521
|
-
const request = context.request;
|
|
522
|
-
const response = await handleWebFinger(request, {
|
|
523
|
-
context,
|
|
524
|
-
actorDispatcher,
|
|
525
|
-
onNotFound
|
|
526
|
-
});
|
|
527
|
-
assertEquals(response.status, 200);
|
|
528
|
-
assertEquals(response.headers.get("Content-Type"), "application/jrd+json");
|
|
529
|
-
assertEquals(response.headers.get("Access-Control-Allow-Origin"), "*");
|
|
530
|
-
assertEquals(await response.json(), expectedForLocalhostWithPort);
|
|
531
|
-
});
|
|
532
|
-
const expectedForHostnameWithPort = {
|
|
533
|
-
subject: "acct:someone@example.com:8000",
|
|
534
|
-
aliases: ["http://example.com:8000/users/someone"],
|
|
535
|
-
links: [
|
|
536
|
-
{
|
|
537
|
-
href: "http://example.com:8000/users/someone",
|
|
538
|
-
rel: "self",
|
|
539
|
-
type: "application/activity+json"
|
|
540
|
-
},
|
|
541
|
-
{
|
|
542
|
-
href: "http://example.com:8000/@someone",
|
|
543
|
-
rel: "http://webfinger.net/rel/profile-page"
|
|
544
|
-
},
|
|
545
|
-
{
|
|
546
|
-
href: "http://example.com:8000/@someone",
|
|
547
|
-
rel: "alternate",
|
|
548
|
-
type: "text/html"
|
|
549
|
-
},
|
|
550
|
-
{
|
|
551
|
-
href: "http://example.com:8000/icon.jpg",
|
|
552
|
-
rel: "http://webfinger.net/rel/avatar",
|
|
553
|
-
type: "image/jpeg"
|
|
554
|
-
}
|
|
555
|
-
]
|
|
556
|
-
};
|
|
557
|
-
await t.step("on hostname with port, ok: resource=acct:...", async () => {
|
|
558
|
-
const u = new URL("http://example.com:8000/.well-known/webfinger");
|
|
559
|
-
u.searchParams.set("resource", "acct:someone@example.com:8000");
|
|
560
|
-
const context = createContext(u);
|
|
561
|
-
const request = context.request;
|
|
562
|
-
const response = await handleWebFinger(request, {
|
|
563
|
-
context,
|
|
564
|
-
actorDispatcher,
|
|
565
|
-
onNotFound
|
|
566
|
-
});
|
|
567
|
-
assertEquals(response.status, 200);
|
|
568
|
-
assertEquals(response.headers.get("Content-Type"), "application/jrd+json");
|
|
569
|
-
assertEquals(response.headers.get("Access-Control-Allow-Origin"), "*");
|
|
570
|
-
assertEquals(await response.json(), expectedForHostnameWithPort);
|
|
571
|
-
});
|
|
572
|
-
await t.step("webFingerLinksDispatcher", async () => {
|
|
573
|
-
const webFingerLinksDispatcher = (_ctx) => {
|
|
574
|
-
return [{
|
|
575
|
-
rel: "http://ostatus.org/schema/1.0/subscribe",
|
|
576
|
-
template: "https://example.com/follow?acct={uri}"
|
|
577
|
-
}];
|
|
578
|
-
};
|
|
579
|
-
const u = new URL(url);
|
|
580
|
-
u.searchParams.set("resource", "acct:someone@example.com");
|
|
581
|
-
const context = createContext(u);
|
|
582
|
-
const request = context.request;
|
|
583
|
-
const response = await handleWebFinger(request, {
|
|
584
|
-
context,
|
|
585
|
-
actorDispatcher,
|
|
586
|
-
webFingerLinksDispatcher,
|
|
587
|
-
onNotFound
|
|
588
|
-
});
|
|
589
|
-
assertEquals(response.status, 200);
|
|
590
|
-
assertEquals(await response.json(), {
|
|
591
|
-
...expected,
|
|
592
|
-
links: [...expected.links, {
|
|
593
|
-
rel: "http://ostatus.org/schema/1.0/subscribe",
|
|
594
|
-
template: "https://example.com/follow?acct={uri}"
|
|
595
|
-
}]
|
|
596
|
-
});
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
test("handleWebFinger() records webfinger.handle counter and duration", async (t) => {
|
|
600
|
-
const url = new URL("https://example.com/.well-known/webfinger");
|
|
601
|
-
const actorDispatcher = (ctx, identifier) => {
|
|
602
|
-
if (identifier === "gone") return new Tombstone({ id: ctx.getActorUri(identifier) });
|
|
603
|
-
if (identifier !== "someone") return null;
|
|
604
|
-
return new Person({
|
|
605
|
-
id: ctx.getActorUri(identifier),
|
|
606
|
-
preferredUsername: "someone"
|
|
607
|
-
});
|
|
608
|
-
};
|
|
609
|
-
const onNotFound = () => new Response("Not found", { status: 404 });
|
|
610
|
-
function createContext(u) {
|
|
611
|
-
return createRequestContext({
|
|
612
|
-
federation: createFederation({ kv: new MemoryKvStore() }),
|
|
613
|
-
url: u,
|
|
614
|
-
data: void 0,
|
|
615
|
-
getActorUri(identifier) {
|
|
616
|
-
return new URL(`${u.origin}/users/${identifier}`);
|
|
617
|
-
},
|
|
618
|
-
async getActor(handle) {
|
|
619
|
-
const actor = await actorDispatcher(this, handle);
|
|
620
|
-
return actor instanceof Tombstone ? null : actor;
|
|
621
|
-
},
|
|
622
|
-
parseUri(uri) {
|
|
623
|
-
if (uri == null) return null;
|
|
624
|
-
if (uri.protocol === "acct:") return null;
|
|
625
|
-
if (!uri.pathname.startsWith("/users/")) return null;
|
|
626
|
-
return {
|
|
627
|
-
type: "actor",
|
|
628
|
-
identifier: uri.pathname.split("/").pop()
|
|
629
|
-
};
|
|
630
|
-
}
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
await t.step("records result=resolved for a 200 response", async () => {
|
|
634
|
-
const u = new URL(url);
|
|
635
|
-
u.searchParams.set("resource", "acct:someone@example.com");
|
|
636
|
-
const context = createContext(u);
|
|
637
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
638
|
-
assertEquals((await handleWebFinger(context.request, {
|
|
639
|
-
context,
|
|
640
|
-
actorDispatcher,
|
|
641
|
-
onNotFound,
|
|
642
|
-
meterProvider
|
|
643
|
-
})).status, 200);
|
|
644
|
-
const counter = recorder.getMeasurement("webfinger.handle");
|
|
645
|
-
assertNotEquals(counter, void 0);
|
|
646
|
-
assertEquals(counter?.type, "counter");
|
|
647
|
-
assertEquals(counter?.value, 1);
|
|
648
|
-
assertEquals(counter?.attributes["webfinger.handle.result"], "resolved");
|
|
649
|
-
assertEquals(counter?.attributes["webfinger.resource.scheme"], "acct");
|
|
650
|
-
assertEquals(counter?.attributes["http.response.status_code"], 200);
|
|
651
|
-
const duration = recorder.getMeasurement("webfinger.handle.duration");
|
|
652
|
-
assertNotEquals(duration, void 0);
|
|
653
|
-
assertEquals(duration?.type, "histogram");
|
|
654
|
-
assertEquals(duration?.attributes["webfinger.handle.result"], "resolved");
|
|
655
|
-
});
|
|
656
|
-
await t.step("records result=invalid for a 400 response", async () => {
|
|
657
|
-
const context = createContext(new URL(url));
|
|
658
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
659
|
-
assertEquals((await handleWebFinger(context.request, {
|
|
660
|
-
context,
|
|
661
|
-
actorDispatcher,
|
|
662
|
-
onNotFound,
|
|
663
|
-
meterProvider
|
|
664
|
-
})).status, 400);
|
|
665
|
-
const counter = recorder.getMeasurement("webfinger.handle");
|
|
666
|
-
assertEquals(counter?.attributes["webfinger.handle.result"], "invalid");
|
|
667
|
-
assertEquals(counter?.attributes["http.response.status_code"], 400);
|
|
668
|
-
assertEquals("webfinger.resource.scheme" in (counter?.attributes ?? {}), false, "missing resource has no scheme attribute");
|
|
669
|
-
});
|
|
670
|
-
await t.step("records result=not_found for a 404 response", async () => {
|
|
671
|
-
const u = new URL(url);
|
|
672
|
-
u.searchParams.set("resource", "acct:absent@example.com");
|
|
673
|
-
const context = createContext(u);
|
|
674
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
675
|
-
assertEquals((await handleWebFinger(context.request, {
|
|
676
|
-
context,
|
|
677
|
-
actorDispatcher,
|
|
678
|
-
onNotFound,
|
|
679
|
-
meterProvider
|
|
680
|
-
})).status, 404);
|
|
681
|
-
const counter = recorder.getMeasurement("webfinger.handle");
|
|
682
|
-
assertEquals(counter?.attributes["webfinger.handle.result"], "not_found");
|
|
683
|
-
assertEquals(counter?.attributes["http.response.status_code"], 404);
|
|
684
|
-
assertEquals(counter?.attributes["webfinger.resource.scheme"], "acct");
|
|
685
|
-
});
|
|
686
|
-
await t.step("records result=tombstoned for a 410 response", async () => {
|
|
687
|
-
const u = new URL(url);
|
|
688
|
-
u.searchParams.set("resource", "acct:gone@example.com");
|
|
689
|
-
const context = createContext(u);
|
|
690
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
691
|
-
assertEquals((await handleWebFinger(context.request, {
|
|
692
|
-
context,
|
|
693
|
-
actorDispatcher,
|
|
694
|
-
onNotFound,
|
|
695
|
-
meterProvider
|
|
696
|
-
})).status, 410);
|
|
697
|
-
const counter = recorder.getMeasurement("webfinger.handle");
|
|
698
|
-
assertEquals(counter?.attributes["webfinger.handle.result"], "tombstoned");
|
|
699
|
-
assertEquals(counter?.attributes["http.response.status_code"], 410);
|
|
700
|
-
});
|
|
701
|
-
await t.step("records result=not_found when onNotFound returns 200", async () => {
|
|
702
|
-
const u = new URL(url);
|
|
703
|
-
u.searchParams.set("resource", "acct:absent@example.com");
|
|
704
|
-
const context = createContext(u);
|
|
705
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
706
|
-
assertEquals((await handleWebFinger(context.request, {
|
|
707
|
-
context,
|
|
708
|
-
actorDispatcher,
|
|
709
|
-
onNotFound: () => new Response("custom fallback", { status: 200 }),
|
|
710
|
-
meterProvider
|
|
711
|
-
})).status, 200);
|
|
712
|
-
const counter = recorder.getMeasurement("webfinger.handle");
|
|
713
|
-
assertEquals(counter?.attributes["webfinger.handle.result"], "not_found");
|
|
714
|
-
assertEquals(counter?.attributes["http.response.status_code"], 200);
|
|
715
|
-
});
|
|
716
|
-
await t.step("buckets unknown resource schemes as 'other' to keep metric cardinality bounded", async () => {
|
|
717
|
-
const u = new URL(url);
|
|
718
|
-
u.searchParams.set("resource", "ssh:nobody@example.com");
|
|
719
|
-
const context = createContext(u);
|
|
720
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
721
|
-
await handleWebFinger(context.request, {
|
|
722
|
-
context,
|
|
723
|
-
actorDispatcher,
|
|
724
|
-
onNotFound,
|
|
725
|
-
meterProvider
|
|
726
|
-
});
|
|
727
|
-
assertEquals(recorder.getMeasurement("webfinger.handle")?.attributes["webfinger.resource.scheme"], "other");
|
|
728
|
-
});
|
|
729
|
-
await t.step("omits measurements when no meterProvider is provided", async () => {
|
|
730
|
-
const u = new URL(url);
|
|
731
|
-
u.searchParams.set("resource", "acct:someone@example.com");
|
|
732
|
-
const context = createContext(u);
|
|
733
|
-
const [_unused, recorder] = createTestMeterProvider();
|
|
734
|
-
await handleWebFinger(context.request, {
|
|
735
|
-
context,
|
|
736
|
-
actorDispatcher,
|
|
737
|
-
onNotFound
|
|
738
|
-
});
|
|
739
|
-
assertEquals(recorder.getMeasurements("webfinger.handle").length, 0);
|
|
740
|
-
assertEquals(recorder.getMeasurements("webfinger.handle.duration").length, 0);
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
test("handleWebFinger() for FEP-ef61 portable actors", async (t) => {
|
|
744
|
-
const did = "did:key:z6Mkabc";
|
|
745
|
-
const compatibleId = `https://example.com/.well-known/apgateway/${did}/actor`;
|
|
746
|
-
const gateways = {
|
|
747
|
-
alice: [new URL("https://example.com")],
|
|
748
|
-
secondary: [new URL("https://primary.example"), new URL("https://example.com")],
|
|
749
|
-
anonymous: [new URL("https://example.com")],
|
|
750
|
-
nogateway: []
|
|
751
|
-
};
|
|
752
|
-
const actorDispatcher = (_ctx, identifier) => {
|
|
753
|
-
if (!(identifier in gateways)) return null;
|
|
754
|
-
return new Person({
|
|
755
|
-
id: parseIri(`ap://${did}/actor`),
|
|
756
|
-
preferredUsername: identifier === "anonymous" ? null : "alice",
|
|
757
|
-
gateways: gateways[identifier]
|
|
758
|
-
});
|
|
759
|
-
};
|
|
760
|
-
const actorAliasMapper = (_ctx, resource) => {
|
|
761
|
-
if (resource.href === compatibleId) return { identifier: "alice" };
|
|
762
|
-
if (resource.protocol === "ap+ef61:") return { identifier: "anonymous" };
|
|
763
|
-
if (resource.href === "acct:anonymous") return { identifier: "anonymous" };
|
|
764
|
-
return null;
|
|
765
|
-
};
|
|
766
|
-
async function query(resource, host = "example.com") {
|
|
767
|
-
const url = new URL(`https://${host}/.well-known/webfinger`);
|
|
768
|
-
url.searchParams.set("resource", resource);
|
|
769
|
-
const context = createRequestContext({
|
|
770
|
-
federation: createFederation({ kv: new MemoryKvStore() }),
|
|
771
|
-
url,
|
|
772
|
-
data: void 0,
|
|
773
|
-
getActorUri(identifier) {
|
|
774
|
-
return new URL(`${url.origin}/users/${identifier}`);
|
|
775
|
-
},
|
|
776
|
-
parseUri: () => null
|
|
777
|
-
});
|
|
778
|
-
return await handleWebFinger(context.request, {
|
|
779
|
-
context,
|
|
780
|
-
actorDispatcher,
|
|
781
|
-
actorAliasMapper,
|
|
782
|
-
onNotFound: () => new Response("Not found", { status: 404 })
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
const selfLink = {
|
|
786
|
-
rel: "self",
|
|
787
|
-
href: compatibleId,
|
|
788
|
-
type: "application/activity+json"
|
|
789
|
-
};
|
|
790
|
-
await t.step("acct: on the first gateway", async () => {
|
|
791
|
-
const response = await query("acct:alice@example.com");
|
|
792
|
-
assertEquals(response.status, 200);
|
|
793
|
-
assertEquals(await response.json(), {
|
|
794
|
-
subject: "acct:alice@example.com",
|
|
795
|
-
aliases: [compatibleId],
|
|
796
|
-
links: [selfLink]
|
|
797
|
-
});
|
|
798
|
-
});
|
|
799
|
-
await t.step("acct: on a secondary gateway", async () => {
|
|
800
|
-
const response = await query("acct:secondary@example.com");
|
|
801
|
-
assertEquals(response.status, 200);
|
|
802
|
-
const primaryCompatibleId = `https://primary.example/.well-known/apgateway/${did}/actor`;
|
|
803
|
-
assertEquals(await response.json(), {
|
|
804
|
-
subject: "acct:alice@primary.example",
|
|
805
|
-
aliases: [primaryCompatibleId, "acct:secondary@example.com"],
|
|
806
|
-
links: [{
|
|
807
|
-
...selfLink,
|
|
808
|
-
href: primaryCompatibleId
|
|
809
|
-
}]
|
|
810
|
-
});
|
|
811
|
-
});
|
|
812
|
-
await t.step("compatible identifier", async () => {
|
|
813
|
-
const response = await query(compatibleId);
|
|
814
|
-
assertEquals(response.status, 200);
|
|
815
|
-
assertEquals(await response.json(), {
|
|
816
|
-
subject: "acct:alice@example.com",
|
|
817
|
-
aliases: [compatibleId],
|
|
818
|
-
links: [selfLink]
|
|
819
|
-
});
|
|
820
|
-
});
|
|
821
|
-
await t.step("portable ID without preferredUsername", async () => {
|
|
822
|
-
const response = await query(`ap://${did}/actor`);
|
|
823
|
-
assertEquals(response.status, 200);
|
|
824
|
-
assertEquals(await response.json(), {
|
|
825
|
-
subject: compatibleId,
|
|
826
|
-
aliases: [],
|
|
827
|
-
links: [selfLink]
|
|
828
|
-
});
|
|
829
|
-
});
|
|
830
|
-
await t.step("acct: without preferredUsername", async () => {
|
|
831
|
-
const response = await query("acct:anonymous@example.com");
|
|
832
|
-
assertEquals(response.status, 200);
|
|
833
|
-
assertEquals(await response.json(), {
|
|
834
|
-
subject: "acct:anonymous@example.com",
|
|
835
|
-
aliases: [compatibleId],
|
|
836
|
-
links: [selfLink]
|
|
837
|
-
});
|
|
838
|
-
});
|
|
839
|
-
await t.step("acct: without a host or preferredUsername", async () => {
|
|
840
|
-
const response = await query("acct:anonymous");
|
|
841
|
-
assertEquals(response.status, 200);
|
|
842
|
-
assertEquals(await response.json(), {
|
|
843
|
-
subject: "acct:anonymous",
|
|
844
|
-
aliases: [compatibleId],
|
|
845
|
-
links: [selfLink]
|
|
846
|
-
});
|
|
847
|
-
});
|
|
848
|
-
await t.step("no gateways", async () => {
|
|
849
|
-
assertEquals((await query("acct:nogateway@example.com")).status, 404);
|
|
850
|
-
});
|
|
851
|
-
await t.step("another host", async () => {
|
|
852
|
-
assertEquals((await query("acct:alice@primary.example")).status, 404);
|
|
853
|
-
});
|
|
854
|
-
});
|
|
855
|
-
test("handleWebFinger() for FEP-ef61 compatible-ID actors", async (t) => {
|
|
856
|
-
const compatibleId = `https://example.com/.well-known/apgateway/did:key:z6Mkabc/actor`;
|
|
857
|
-
const actors = {
|
|
858
|
-
alice: {
|
|
859
|
-
id: compatibleId,
|
|
860
|
-
gateways: [new URL("https://example.com")]
|
|
861
|
-
},
|
|
862
|
-
secondary: {
|
|
863
|
-
id: compatibleId,
|
|
864
|
-
gateways: [new URL("https://primary.example"), new URL("https://example.com")]
|
|
865
|
-
},
|
|
866
|
-
malformed: {
|
|
867
|
-
id: `${compatibleId}?@gateway=https%3A%2F%2Fexample.com`,
|
|
868
|
-
gateways: [new URL("https://example.com")]
|
|
869
|
-
},
|
|
870
|
-
nogateway: {
|
|
871
|
-
id: compatibleId,
|
|
872
|
-
gateways: []
|
|
873
|
-
}
|
|
874
|
-
};
|
|
875
|
-
const actorDispatcher = (_ctx, identifier) => {
|
|
876
|
-
const actor = actors[identifier];
|
|
877
|
-
if (actor == null) return null;
|
|
878
|
-
return new Person({
|
|
879
|
-
id: new URL(actor.id),
|
|
880
|
-
preferredUsername: "alice",
|
|
881
|
-
gateways: actor.gateways
|
|
882
|
-
});
|
|
883
|
-
};
|
|
884
|
-
const actorAliasMapper = (_ctx, resource) => resource.href === compatibleId ? { identifier: "alice" } : null;
|
|
885
|
-
async function query(resource) {
|
|
886
|
-
const url = new URL("https://example.com/.well-known/webfinger");
|
|
887
|
-
url.searchParams.set("resource", resource);
|
|
888
|
-
const context = createRequestContext({
|
|
889
|
-
federation: createFederation({ kv: new MemoryKvStore() }),
|
|
890
|
-
url,
|
|
891
|
-
data: void 0,
|
|
892
|
-
getActorUri(identifier) {
|
|
893
|
-
return new URL(`${url.origin}/users/${identifier}`);
|
|
894
|
-
},
|
|
895
|
-
parseUri: () => null
|
|
896
|
-
});
|
|
897
|
-
return await handleWebFinger(context.request, {
|
|
898
|
-
context,
|
|
899
|
-
actorDispatcher,
|
|
900
|
-
actorAliasMapper,
|
|
901
|
-
onNotFound: () => new Response("Not found", { status: 404 })
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
const selfLink = {
|
|
905
|
-
rel: "self",
|
|
906
|
-
href: compatibleId,
|
|
907
|
-
type: "application/activity+json"
|
|
908
|
-
};
|
|
909
|
-
await t.step("acct: on the first gateway", async () => {
|
|
910
|
-
const response = await query("acct:alice@example.com");
|
|
911
|
-
assertEquals(response.status, 200);
|
|
912
|
-
assertEquals(await response.json(), {
|
|
913
|
-
subject: "acct:alice@example.com",
|
|
914
|
-
aliases: [compatibleId],
|
|
915
|
-
links: [selfLink]
|
|
916
|
-
});
|
|
917
|
-
});
|
|
918
|
-
await t.step("compatible identifier", async () => {
|
|
919
|
-
const response = await query(compatibleId);
|
|
920
|
-
assertEquals(response.status, 200);
|
|
921
|
-
assertEquals(await response.json(), {
|
|
922
|
-
subject: "acct:alice@example.com",
|
|
923
|
-
aliases: [compatibleId],
|
|
924
|
-
links: [selfLink]
|
|
925
|
-
});
|
|
926
|
-
});
|
|
927
|
-
await t.step("compatible identifier not on the first gateway", async () => {
|
|
928
|
-
const response = await query("acct:secondary@example.com");
|
|
929
|
-
assertEquals(response.status, 200);
|
|
930
|
-
assertEquals(await response.json(), {
|
|
931
|
-
subject: "acct:alice@primary.example",
|
|
932
|
-
aliases: [compatibleId, "acct:secondary@example.com"],
|
|
933
|
-
links: [selfLink]
|
|
934
|
-
});
|
|
935
|
-
});
|
|
936
|
-
await t.step("malformed compatible identifier", async () => {
|
|
937
|
-
assertEquals((await query("acct:malformed@example.com")).status, 404);
|
|
938
|
-
});
|
|
939
|
-
await t.step("no gateways", async () => {
|
|
940
|
-
assertEquals((await query("acct:nogateway@example.com")).status, 404);
|
|
941
|
-
});
|
|
942
|
-
});
|
|
943
|
-
//#endregion
|
|
944
|
-
export {};
|