Loading CHANGES.md +6 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,12 @@ To be released. - The `--allow-private-address` or `-p` option allows looking up WebFinger information for private addresses (e.g., `localhost`). - Added `LookupWebFingerOptions.maxRedirection` option. [[#248], [#281] by Lee ByeongJun] [#248]: https://github.com/fedify-dev/fedify/issues/248 [#281]: https://github.com/fedify-dev/fedify/pull/281 Version 1.7.3 ------------- Loading fedify/webfinger/lookup.test.ts +45 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,51 @@ 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. * @default `5` * @since 1.8.0 */ 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
CHANGES.md +6 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,12 @@ To be released. - The `--allow-private-address` or `-p` option allows looking up WebFinger information for private addresses (e.g., `localhost`). - Added `LookupWebFingerOptions.maxRedirection` option. [[#248], [#281] by Lee ByeongJun] [#248]: https://github.com/fedify-dev/fedify/issues/248 [#281]: https://github.com/fedify-dev/fedify/pull/281 Version 1.7.3 ------------- Loading
fedify/webfinger/lookup.test.ts +45 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,51 @@ 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. * @default `5` * @since 1.8.0 */ 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