forked from mirrors/akkoma
[#582] Made single-pub task call Instance.set_reachable/1 if set_reachable
is not specified.
Added tests.
This commit is contained in:
parent
b40b4bc4e5
commit
3913b0196e
5 changed files with 108 additions and 12 deletions
|
@ -792,7 +792,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
{"digest", digest}
|
{"digest", digest}
|
||||||
]
|
]
|
||||||
) do
|
) do
|
||||||
if params[:unreachable_since], do: Instances.set_reachable(inbox)
|
if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since],
|
||||||
|
do: Instances.set_reachable(inbox)
|
||||||
|
|
||||||
result
|
result
|
||||||
else
|
else
|
||||||
{_post_result, response} ->
|
{_post_result, response} ->
|
||||||
|
|
|
@ -173,7 +173,9 @@ defmodule Pleroma.Web.Salmon do
|
||||||
feed,
|
feed,
|
||||||
[{"Content-Type", "application/magic-envelope+xml"}]
|
[{"Content-Type", "application/magic-envelope+xml"}]
|
||||||
) do
|
) do
|
||||||
if params[:unreachable_since], do: Instances.set_reachable(url)
|
if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since],
|
||||||
|
do: Instances.set_reachable(url)
|
||||||
|
|
||||||
Logger.debug(fn -> "Pushed to #{url}, code #{code}" end)
|
Logger.debug(fn -> "Pushed to #{url}, code #{code}" end)
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
|
|
|
@ -283,7 +283,9 @@ defmodule Pleroma.Web.Websub do
|
||||||
{"X-Hub-Signature", "sha1=#{signature}"}
|
{"X-Hub-Signature", "sha1=#{signature}"}
|
||||||
]
|
]
|
||||||
) do
|
) do
|
||||||
if params[:unreachable_since], do: Instances.set_reachable(callback)
|
if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since],
|
||||||
|
do: Instances.set_reachable(callback)
|
||||||
|
|
||||||
Logger.info(fn -> "Pushed to #{callback}, code #{code}" end)
|
Logger.info(fn -> "Pushed to #{callback}, code #{code}" end)
|
||||||
{:ok, code}
|
{:ok, code}
|
||||||
else
|
else
|
||||||
|
|
|
@ -698,7 +698,57 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "publish_one/1" do
|
describe "publish_one/1" do
|
||||||
test_with_mock "it calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",
|
test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is not specified",
|
||||||
|
Instances,
|
||||||
|
[:passthrough],
|
||||||
|
[] do
|
||||||
|
actor = insert(:user)
|
||||||
|
inbox = "http://200.site/users/nick1/inbox"
|
||||||
|
|
||||||
|
assert {:ok, _} = ActivityPub.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
|
||||||
|
|
||||||
|
assert called(Instances.set_reachable(inbox))
|
||||||
|
end
|
||||||
|
|
||||||
|
test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is set",
|
||||||
|
Instances,
|
||||||
|
[:passthrough],
|
||||||
|
[] do
|
||||||
|
actor = insert(:user)
|
||||||
|
inbox = "http://200.site/users/nick1/inbox"
|
||||||
|
|
||||||
|
assert {:ok, _} =
|
||||||
|
ActivityPub.publish_one(%{
|
||||||
|
inbox: inbox,
|
||||||
|
json: "{}",
|
||||||
|
actor: actor,
|
||||||
|
id: 1,
|
||||||
|
unreachable_since: NaiveDateTime.utc_now()
|
||||||
|
})
|
||||||
|
|
||||||
|
assert called(Instances.set_reachable(inbox))
|
||||||
|
end
|
||||||
|
|
||||||
|
test_with_mock "does NOT call `Instances.set_reachable` on successful federation if `unreachable_since` is nil",
|
||||||
|
Instances,
|
||||||
|
[:passthrough],
|
||||||
|
[] do
|
||||||
|
actor = insert(:user)
|
||||||
|
inbox = "http://200.site/users/nick1/inbox"
|
||||||
|
|
||||||
|
assert {:ok, _} =
|
||||||
|
ActivityPub.publish_one(%{
|
||||||
|
inbox: inbox,
|
||||||
|
json: "{}",
|
||||||
|
actor: actor,
|
||||||
|
id: 1,
|
||||||
|
unreachable_since: nil
|
||||||
|
})
|
||||||
|
|
||||||
|
refute called(Instances.set_reachable(inbox))
|
||||||
|
end
|
||||||
|
|
||||||
|
test_with_mock "calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",
|
||||||
Instances,
|
Instances,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
|
@ -724,7 +774,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
assert called(Instances.set_unreachable(inbox))
|
assert called(Instances.set_unreachable(inbox))
|
||||||
end
|
end
|
||||||
|
|
||||||
test_with_mock "it does NOT call `Instances.set_unreachable` if target is reachable",
|
test_with_mock "does NOT call `Instances.set_unreachable` if target is reachable",
|
||||||
Instances,
|
Instances,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
|
@ -735,6 +785,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
|
|
||||||
refute called(Instances.set_unreachable(inbox))
|
refute called(Instances.set_unreachable(inbox))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_with_mock "does NOT call `Instances.set_unreachable` if target instance has non-nil `unreachable_since`",
|
||||||
|
Instances,
|
||||||
|
[:passthrough],
|
||||||
|
[] do
|
||||||
|
actor = insert(:user)
|
||||||
|
inbox = "http://connrefused.site/users/nick1/inbox"
|
||||||
|
|
||||||
|
assert {:error, _} =
|
||||||
|
ActivityPub.publish_one(%{
|
||||||
|
inbox: inbox,
|
||||||
|
json: "{}",
|
||||||
|
actor: actor,
|
||||||
|
id: 1,
|
||||||
|
unreachable_since: NaiveDateTime.utc_now()
|
||||||
|
})
|
||||||
|
|
||||||
|
refute called(Instances.set_unreachable(inbox))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def data_uri do
|
def data_uri do
|
||||||
|
|
|
@ -95,15 +95,18 @@ defmodule Pleroma.Web.FederatorTest do
|
||||||
info: %{ap_enabled: true, source_data: %{"inbox" => inbox2}}
|
info: %{ap_enabled: true, source_data: %{"inbox" => inbox2}}
|
||||||
})
|
})
|
||||||
|
|
||||||
Instances.set_unreachable(
|
dt = NaiveDateTime.utc_now()
|
||||||
URI.parse(inbox2).host,
|
Instances.set_unreachable(inbox1, dt)
|
||||||
Instances.reachability_datetime_threshold()
|
|
||||||
)
|
Instances.set_consistently_unreachable(URI.parse(inbox2).host)
|
||||||
|
|
||||||
{:ok, _activity} =
|
{:ok, _activity} =
|
||||||
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
|
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
|
||||||
|
|
||||||
assert called(Federator.enqueue(:publish_single_ap, %{inbox: inbox1}))
|
assert called(
|
||||||
|
Federator.enqueue(:publish_single_ap, %{inbox: inbox1, unreachable_since: dt})
|
||||||
|
)
|
||||||
|
|
||||||
refute called(Federator.enqueue(:publish_single_ap, %{inbox: inbox2}))
|
refute called(Federator.enqueue(:publish_single_ap, %{inbox: inbox2}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -128,11 +131,20 @@ defmodule Pleroma.Web.FederatorTest do
|
||||||
callback: "https://pleroma2.soykaf.com/cb"
|
callback: "https://pleroma2.soykaf.com/cb"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
dt = NaiveDateTime.utc_now()
|
||||||
|
Instances.set_unreachable(sub2.callback, dt)
|
||||||
|
|
||||||
Instances.set_consistently_unreachable(sub1.callback)
|
Instances.set_consistently_unreachable(sub1.callback)
|
||||||
|
|
||||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
|
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
|
||||||
|
|
||||||
assert called(Federator.enqueue(:publish_single_websub, %{callback: sub2.callback}))
|
assert called(
|
||||||
|
Federator.enqueue(:publish_single_websub, %{
|
||||||
|
callback: sub2.callback,
|
||||||
|
unreachable_since: dt
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
refute called(Federator.enqueue(:publish_single_websub, %{callback: sub1.callback}))
|
refute called(Federator.enqueue(:publish_single_websub, %{callback: sub1.callback}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -158,12 +170,21 @@ defmodule Pleroma.Web.FederatorTest do
|
||||||
info: %{salmon: "https://domain2.com/salmon"}
|
info: %{salmon: "https://domain2.com/salmon"}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
dt = NaiveDateTime.utc_now()
|
||||||
|
Instances.set_unreachable(remote_user2.ap_id, dt)
|
||||||
|
|
||||||
Instances.set_consistently_unreachable("domain.com")
|
Instances.set_consistently_unreachable("domain.com")
|
||||||
|
|
||||||
{:ok, _activity} =
|
{:ok, _activity} =
|
||||||
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
|
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
|
||||||
|
|
||||||
assert called(Federator.enqueue(:publish_single_salmon, %{recipient: remote_user2}))
|
assert called(
|
||||||
|
Federator.enqueue(:publish_single_salmon, %{
|
||||||
|
recipient: remote_user2,
|
||||||
|
unreachable_since: dt
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
refute called(Federator.enqueue(:publish_single_websub, %{recipient: remote_user1}))
|
refute called(Federator.enqueue(:publish_single_websub, %{recipient: remote_user1}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue