Loading .gitignore +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ dist/ deno.lock node_modules/ package-lock.json repomix-output.xml t.ts t2.ts fedify/webfinger/lookup.test.ts +39 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,45 @@ test({ assertEquals(await lookupWebFinger("acct:johndoe@example.com"), null); }); fetchMock.removeRoutes(); let redirectCount = 0; fetchMock.get( "begin:https://example.com/.well-known/webfinger", () => { redirectCount++; if (redirectCount < 3) { return { status: 302, headers: { Location: `/.well-known/webfinger?redirect=${redirectCount}` }, }; } return { body: expected }; }, ); await t.step("custom maxRedirection", async () => { // Test with maxRedirection: 2 (should fail) redirectCount = 0; assertEquals( await lookupWebFinger("acct:johndoe@example.com", { maxRedirection: 2 }), null, ); // Test with maxRedirection: 3 (should succeed) redirectCount = 0; assertEquals( await lookupWebFinger("acct:johndoe@example.com", { maxRedirection: 3 }), expected, ); // Test with default maxRedirection: 5 (should succeed) redirectCount = 0; assertEquals( await lookupWebFinger("acct:johndoe@example.com"), expected, ); }); fetchMock.hardReset(); }, }); Loading fedify/webfinger/lookup.ts +10 −2 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ import type { ResourceDescriptor } from "./jrd.ts"; const logger = getLogger(["fedify", "webfinger", "lookup"]); const MAX_REDIRECTION = 5; // TODO: Make this configurable. const DEFAULT_MAX_REDIRECTION = 5; /** * Options for {@link lookupWebFinger}. Loading @@ -40,6 +40,13 @@ export interface LookupWebFingerOptions { */ allowPrivateAddress?: boolean; /** * The maximum number of redirections to follow. * * Defaults to 5. */ maxRedirection?: number; /** * The OpenTelemetry tracer provider. If omitted, the global tracer provider * is used. Loading Loading @@ -155,7 +162,8 @@ async function lookupWebFingerInternal( response.headers.has("Location") ) { redirected++; if (redirected >= MAX_REDIRECTION) { const maxRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION; if (redirected >= maxRedirection) { logger.error( "Too many redirections ({redirections}) while fetching WebFinger " + "resource descriptor.", Loading Loading
.gitignore +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ dist/ deno.lock node_modules/ package-lock.json repomix-output.xml t.ts t2.ts
fedify/webfinger/lookup.test.ts +39 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,45 @@ test({ assertEquals(await lookupWebFinger("acct:johndoe@example.com"), null); }); fetchMock.removeRoutes(); let redirectCount = 0; fetchMock.get( "begin:https://example.com/.well-known/webfinger", () => { redirectCount++; if (redirectCount < 3) { return { status: 302, headers: { Location: `/.well-known/webfinger?redirect=${redirectCount}` }, }; } return { body: expected }; }, ); await t.step("custom maxRedirection", async () => { // Test with maxRedirection: 2 (should fail) redirectCount = 0; assertEquals( await lookupWebFinger("acct:johndoe@example.com", { maxRedirection: 2 }), null, ); // Test with maxRedirection: 3 (should succeed) redirectCount = 0; assertEquals( await lookupWebFinger("acct:johndoe@example.com", { maxRedirection: 3 }), expected, ); // Test with default maxRedirection: 5 (should succeed) redirectCount = 0; assertEquals( await lookupWebFinger("acct:johndoe@example.com"), expected, ); }); fetchMock.hardReset(); }, }); Loading
fedify/webfinger/lookup.ts +10 −2 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ import type { ResourceDescriptor } from "./jrd.ts"; const logger = getLogger(["fedify", "webfinger", "lookup"]); const MAX_REDIRECTION = 5; // TODO: Make this configurable. const DEFAULT_MAX_REDIRECTION = 5; /** * Options for {@link lookupWebFinger}. Loading @@ -40,6 +40,13 @@ export interface LookupWebFingerOptions { */ allowPrivateAddress?: boolean; /** * The maximum number of redirections to follow. * * Defaults to 5. */ maxRedirection?: number; /** * The OpenTelemetry tracer provider. If omitted, the global tracer provider * is used. Loading Loading @@ -155,7 +162,8 @@ async function lookupWebFingerInternal( response.headers.has("Location") ) { redirected++; if (redirected >= MAX_REDIRECTION) { const maxRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION; if (redirected >= maxRedirection) { logger.error( "Too many redirections ({redirections}) while fetching WebFinger " + "resource descriptor.", Loading