logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: caf855cf9cb9a5cadd2519237c9e7916007f4850
parent 0450da88b6f10f2eb61ecb1758f9f4b4e95182c8
Author: Lain Soykaf <lain@lain.com>
Date:   Sun, 17 Mar 2024 16:57:45 +0400

ActivityPub.Publisher: Don't try federating if a user doesn't have an inbox.

Diffstat:

Mlib/pleroma/web/activity_pub/publisher.ex24+++++++++---------------
Mtest/pleroma/web/activity_pub/publisher_test.exs12++++++++++++
2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex @@ -158,24 +158,18 @@ defmodule Pleroma.Web.ActivityPub.Publisher do end end - defp should_federate?(inbox, public) do - cond do - is_nil(inbox) -> - false + def should_federate?(nil, _), do: false + def should_federate?(_, true), do: true - public -> - true + def should_federate?(inbox, _) do + %{host: host} = URI.parse(inbox) - true -> - %{host: host} = URI.parse(inbox) + quarantined_instances = + Config.get([:instance, :quarantined_instances], []) + |> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples() + |> Pleroma.Web.ActivityPub.MRF.subdomains_regex() - quarantined_instances = - Config.get([:instance, :quarantined_instances], []) - |> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples() - |> Pleroma.Web.ActivityPub.MRF.subdomains_regex() - - !Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host) - end + !Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host) end @spec recipients(User.t(), Activity.t()) :: [[User.t()]] diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs @@ -25,6 +25,17 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do setup_all do: clear_config([:instance, :federating], true) + describe "should_federate?/1" do + test "it returns false when the inbox is nil" do + refute Publisher.should_federate?(nil, false) + refute Publisher.should_federate?(nil, true) + end + + test "it returns true when public is true" do + assert Publisher.should_federate?(false, true) + end + end + describe "gather_webfinger_links/1" do test "it returns links" do user = insert(:user) @@ -205,6 +216,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do refute called(Instances.set_reachable(inbox)) end + @tag capture_log: true test_with_mock "calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code", Instances, [:passthrough],