Added tests.
{"digest", digest}
]
) 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
else
{_post_result, response} ->
feed,
[{"Content-Type", "application/magic-envelope+xml"}]
) 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)
:ok
else
{"X-Hub-Signature", "sha1=#{signature}"}
]
) 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)
{:ok, code}
else
end
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,
[:passthrough],
[] do
assert called(Instances.set_unreachable(inbox))
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,
[:passthrough],
[] do
refute called(Instances.set_unreachable(inbox))
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
def data_uri do
info: %{ap_enabled: true, source_data: %{"inbox" => inbox2}}
})
- Instances.set_unreachable(
- URI.parse(inbox2).host,
- Instances.reachability_datetime_threshold()
- )
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(inbox1, dt)
+
+ Instances.set_consistently_unreachable(URI.parse(inbox2).host)
{:ok, _activity} =
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}))
end
callback: "https://pleroma2.soykaf.com/cb"
})
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(sub2.callback, dt)
+
Instances.set_consistently_unreachable(sub1.callback)
{: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}))
end
info: %{salmon: "https://domain2.com/salmon"}
})
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(remote_user2.ap_id, dt)
+
Instances.set_consistently_unreachable("domain.com")
{:ok, _activity} =
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}))
end
end