X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fweb%2Ffederator_test.exs;h=43a715706fd06424575a795b7ace49c641cf768f;hb=0a5b106ddd333f2dec2b62badeca98e6091ba805;hp=52729eb507627db0255f96266439539664244c93;hpb=627e5a0a4992cc19fc65a7e93a09c470c8e2bf33;p=akkoma
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 52729eb50..43a715706 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -1,20 +1,34 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FederatorTest do
alias Pleroma.Instances
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Federator
+ alias Pleroma.Workers.PublisherWorker
+
use Pleroma.DataCase
+ use Oban.Testing, repo: Pleroma.Repo
+
import Pleroma.Factory
import Mock
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
:ok
end
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
+ end
+
+ clear_config([:instance, :allow_relay])
+ clear_config([:instance, :rewrite_policy])
+ clear_config([:mrf_keyword])
+
describe "Publish an activity" do
setup do
user = insert(:user)
@@ -35,6 +49,7 @@ defmodule Pleroma.Web.FederatorTest do
} do
with_mocks([relay_mock]) do
Federator.publish(activity)
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
end
assert_received :relay_publish
@@ -48,19 +63,15 @@ defmodule Pleroma.Web.FederatorTest do
with_mocks([relay_mock]) do
Federator.publish(activity)
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
end
refute_received :relay_publish
-
- Pleroma.Config.put([:instance, :allow_relay], true)
end
end
describe "Targets reachability filtering in `publish`" do
- test_with_mock "it federates only to reachable instances via AP",
- Federator,
- [:passthrough],
- [] do
+ test "it federates only to reachable instances via AP" do
user = insert(:user)
{inbox1, inbox2} =
@@ -88,15 +99,20 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(Federator.publish_single_ap(%{inbox: inbox1, unreachable_since: dt}))
+ expected_dt = NaiveDateTime.to_iso8601(dt)
+
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
- refute called(Federator.publish_single_ap(%{inbox: inbox2}))
+ assert ObanHelpers.member?(
+ %{
+ "op" => "publish_one",
+ "params" => %{"inbox" => inbox1, "unreachable_since" => expected_dt}
+ },
+ all_enqueued(worker: PublisherWorker)
+ )
end
- test_with_mock "it federates only to reachable instances via Websub",
- Federator,
- [:passthrough],
- [] do
+ test "it federates only to reachable instances via Websub" do
user = insert(:user)
websub_topic = Pleroma.Web.OStatus.feed_path(user)
@@ -121,23 +137,27 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
- assert called(
- Federator.publish_single_websub(%{
- callback: sub2.callback,
- unreachable_since: dt
- })
- )
+ expected_callback = sub2.callback
+ expected_dt = NaiveDateTime.to_iso8601(dt)
+
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
- refute called(Federator.publish_single_websub(%{callback: sub1.callback}))
+ assert ObanHelpers.member?(
+ %{
+ "op" => "publish_one",
+ "params" => %{
+ "callback" => expected_callback,
+ "unreachable_since" => expected_dt
+ }
+ },
+ all_enqueued(worker: PublisherWorker)
+ )
end
- test_with_mock "it federates only to reachable instances via Salmon",
- Federator,
- [:passthrough],
- [] do
+ test "it federates only to reachable instances via Salmon" do
user = insert(:user)
- remote_user1 =
+ _remote_user1 =
insert(:user, %{
local: false,
nickname: "nick1@domain.com",
@@ -153,6 +173,8 @@ defmodule Pleroma.Web.FederatorTest do
info: %{salmon: "https://domain2.com/salmon"}
})
+ remote_user2_id = remote_user2.id
+
dt = NaiveDateTime.utc_now()
Instances.set_unreachable(remote_user2.ap_id, dt)
@@ -161,14 +183,20 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(
- Federator.publish_single_salmon(%{
- recipient: remote_user2,
- unreachable_since: dt
- })
- )
+ expected_dt = NaiveDateTime.to_iso8601(dt)
- refute called(Federator.publish_single_websub(%{recipient: remote_user1}))
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
+
+ assert ObanHelpers.member?(
+ %{
+ "op" => "publish_one",
+ "params" => %{
+ "recipient_id" => remote_user2_id,
+ "unreachable_since" => expected_dt
+ }
+ },
+ all_enqueued(worker: PublisherWorker)
+ )
end
end
@@ -188,7 +216,8 @@ defmodule Pleroma.Web.FederatorTest do
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
- {:ok, _activity} = Federator.incoming_ap_doc(params)
+ assert {:ok, job} = Federator.incoming_ap_doc(params)
+ assert {:ok, _activity} = ObanHelpers.perform(job)
end
test "rejects incoming AP docs with incorrect origin" do
@@ -206,7 +235,24 @@ defmodule Pleroma.Web.FederatorTest do
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
- :error = Federator.incoming_ap_doc(params)
+ assert {:ok, job} = Federator.incoming_ap_doc(params)
+ assert :error = ObanHelpers.perform(job)
+ end
+
+ test "it does not crash if MRF rejects the post" do
+ Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
+
+ Pleroma.Config.put(
+ [:instance, :rewrite_policy],
+ Pleroma.Web.ActivityPub.MRF.KeywordPolicy
+ )
+
+ params =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+
+ assert {:ok, job} = Federator.incoming_ap_doc(params)
+ assert :error = ObanHelpers.perform(job)
end
end
end