Unverified Commit 97d0dcbf authored by Hong Minhee (洪 民憙)'s avatar Hong Minhee (洪 民憙) Committed by GitHub
Browse files

Merge pull request #281 from notJoon/fix-issue248

parents 0e336a3a eb9a205c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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
-------------
+45 −0
Original line number Diff line number Diff line
@@ -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();
  },
});
+10 −2
Original line number Diff line number Diff line
@@ -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}.
@@ -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.
@@ -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.",