add extra tests to should_federate?
Some checks failed
ci/woodpecker/push/docs Pipeline was successful
ci/woodpecker/pr/docs Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/pr/release Pipeline was successful
ci/woodpecker/pr/test Pipeline failed

This commit is contained in:
FloatingGhost 2022-07-25 17:37:48 +01:00
parent 2b7833cddb
commit f2c7502a0a
2 changed files with 18 additions and 4 deletions

View file

@ -103,7 +103,7 @@ defp signature_host(%URI{port: port, scheme: scheme, host: host}) do
end
end
defp should_federate?(inbox, public) do
defp should_federate?(inbox) do
%{host: host} = URI.parse(inbox)
quarantined_instances =
@ -188,7 +188,6 @@ def determine_inbox(
def publish(%User{} = actor, %{data: %{"bcc" => bcc}} = activity)
when is_list(bcc) and bcc != [] do
public = is_public?(activity)
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
recipients = recipients(actor, activity)
@ -197,7 +196,7 @@ def publish(%User{} = actor, %{data: %{"bcc" => bcc}} = activity)
recipients
|> Enum.filter(&User.ap_enabled?/1)
|> Enum.map(fn actor -> actor.inbox end)
|> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
|> Enum.filter(fn inbox -> should_federate?(inbox) end)
|> Instances.filter_reachable()
Repo.checkout(fn ->
@ -242,7 +241,7 @@ def publish(%User{} = actor, %Activity{} = activity) do
determine_inbox(activity, user)
end)
|> Enum.uniq()
|> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
|> Enum.filter(fn inbox -> should_federate?(inbox) end)
|> Instances.filter_reachable()
|> Enum.each(fn {inbox, unreachable_since} ->
Pleroma.Web.Federator.Publisher.enqueue_one(

View file

@ -290,11 +290,18 @@ test "publish to url with with different ports" do
user: actor,
recipients: [follower.ap_id]
)
public_note_activity =
insert(:note_activity,
user: actor,
recipients: [follower.ap_id, @as_public]
)
res = Publisher.publish(actor, note_activity)
assert res == :ok
:ok = Publisher.publish(actor, public_note_activity)
assert not called(
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
inbox: "https://domain.com/users/nick1/inbox",
@ -302,6 +309,13 @@ test "publish to url with with different ports" do
id: note_activity.data["id"]
})
)
assert not called(
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
inbox: "https://domain.com/users/nick1/inbox",
actor_id: actor.id,
id: public_note_activity.data["id"]
})
)
end
test_with_mock "Publishes a non-public activity to non-quarantined instances.",
@ -345,6 +359,7 @@ test "publish to url with with different ports" do
Pleroma.Web.Federator.Publisher,
[:passthrough],
[] do
Config.put([:instance, :quarantined_instances], [])
follower =
insert(:user, %{
local: false,