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

This commit is contained in:
Lain Soykaf 2024-03-17 16:57:45 +04:00
parent 0450da88b6
commit caf855cf9c
2 changed files with 21 additions and 15 deletions

View file

@ -158,15 +158,10 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
end end
end end
defp should_federate?(inbox, public) do def should_federate?(nil, _), do: false
cond do def should_federate?(_, true), do: true
is_nil(inbox) ->
false
public -> def should_federate?(inbox, _) do
true
true ->
%{host: host} = URI.parse(inbox) %{host: host} = URI.parse(inbox)
quarantined_instances = quarantined_instances =
@ -176,7 +171,6 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
!Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host) !Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host)
end end
end
@spec recipients(User.t(), Activity.t()) :: [[User.t()]] @spec recipients(User.t(), Activity.t()) :: [[User.t()]]
defp recipients(actor, activity) do defp recipients(actor, activity) do

View file

@ -25,6 +25,17 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
setup_all do: clear_config([:instance, :federating], true) 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 describe "gather_webfinger_links/1" do
test "it returns links" do test "it returns links" do
user = insert(:user) user = insert(:user)
@ -205,6 +216,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
refute called(Instances.set_reachable(inbox)) refute called(Instances.set_reachable(inbox))
end end
@tag capture_log: true
test_with_mock "calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code", test_with_mock "calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",
Instances, Instances,
[:passthrough], [:passthrough],