X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ffederator_test.exs;h=592fdccd19168a86f3c42ff95f448a5c13df977a;hb=8b1e8bec2ffcb3a73eea93015d73b44c4996baff;hp=69dd4d7473c4df10d78e638bb22537db48f03c0b;hpb=167f810ff18fdc0271e6908d1d07c2f715e3f34f;p=akkoma
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 69dd4d747..592fdccd1 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -1,31 +1,35 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2020 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)
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
:ok
end
+ setup_all do: clear_config([:instance, :federating], true)
+ setup do: clear_config([:instance, :allow_relay])
+ setup do: clear_config([:mrf, :policies])
+ setup do: clear_config([:mrf_keyword])
+
describe "Publish an activity" do
setup do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
relay_mock = {
Pleroma.Web.ActivityPub.Relay,
@@ -42,6 +46,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
@@ -55,19 +60,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",
- Pleroma.Web.ActivityPub.Publisher,
- [:passthrough],
- [] do
+ test "it federates only to reachable instances via AP" do
user = insert(:user)
{inbox1, inbox2} =
@@ -77,14 +78,16 @@ defmodule Pleroma.Web.FederatorTest do
local: false,
nickname: "nick1@domain.com",
ap_id: "https://domain.com/users/nick1",
- info: %{ap_enabled: true, source_data: %{"inbox" => inbox1}}
+ inbox: inbox1,
+ ap_enabled: true
})
insert(:user, %{
local: false,
nickname: "nick2@domain2.com",
ap_id: "https://domain2.com/users/nick2",
- info: %{ap_enabled: true, source_data: %{"inbox" => inbox2}}
+ inbox: inbox2,
+ ap_enabled: true
})
dt = NaiveDateTime.utc_now()
@@ -93,94 +96,19 @@ defmodule Pleroma.Web.FederatorTest do
Instances.set_consistently_unreachable(URI.parse(inbox2).host)
{: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(
- Pleroma.Web.ActivityPub.Publisher.publish_one(%{
- inbox: inbox1,
- unreachable_since: dt
- })
- )
+ expected_dt = NaiveDateTime.to_iso8601(dt)
- refute called(Pleroma.Web.ActivityPub.Publisher.publish_one(%{inbox: inbox2}))
- end
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
- test_with_mock "it federates only to reachable instances via Websub",
- Pleroma.Web.Websub,
- [:passthrough],
- [] do
- user = insert(:user)
- websub_topic = Pleroma.Web.OStatus.feed_path(user)
-
- sub1 =
- insert(:websub_subscription, %{
- topic: websub_topic,
- state: "active",
- callback: "http://pleroma.soykaf.com/cb"
- })
-
- sub2 =
- insert(:websub_subscription, %{
- topic: websub_topic,
- state: "active",
- 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(
- Pleroma.Web.Websub.publish_one(%{
- callback: sub2.callback,
- unreachable_since: dt
- })
+ assert ObanHelpers.member?(
+ %{
+ "op" => "publish_one",
+ "params" => %{"inbox" => inbox1, "unreachable_since" => expected_dt}
+ },
+ all_enqueued(worker: PublisherWorker)
)
-
- refute called(Pleroma.Web.Websub.publish_one(%{callback: sub1.callback}))
- end
-
- test_with_mock "it federates only to reachable instances via Salmon",
- Pleroma.Web.Salmon,
- [:passthrough],
- [] do
- user = insert(:user)
-
- remote_user1 =
- insert(:user, %{
- local: false,
- nickname: "nick1@domain.com",
- ap_id: "https://domain.com/users/nick1",
- info: %{salmon: "https://domain.com/salmon"}
- })
-
- remote_user2 =
- insert(:user, %{
- local: false,
- nickname: "nick2@domain2.com",
- ap_id: "https://domain2.com/users/nick2",
- 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(
- Pleroma.Web.Salmon.publish_one(%{
- recipient: remote_user2,
- unreachable_since: dt
- })
- )
-
- refute called(Pleroma.Web.Salmon.publish_one(%{recipient: remote_user1}))
end
end
@@ -200,7 +128,11 @@ 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)
+
+ assert {:ok, job} = Federator.incoming_ap_doc(params)
+ assert {:error, :already_present} = ObanHelpers.perform(job)
end
test "rejects incoming AP docs with incorrect origin" do
@@ -218,7 +150,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, :origin_containment_failed} = 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(
+ [:mrf, :policies],
+ 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