1 defmodule Pleroma.Web.FederatorTest do
2 alias Pleroma.Web.Federator
3 alias Pleroma.Web.CommonAPI
8 test "enqueues an element according to priority" do
9 queue = [%{item: 1, priority: 2}]
11 new_queue = Federator.enqueue_sorted(queue, 2, 1)
12 assert new_queue == [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
14 new_queue = Federator.enqueue_sorted(queue, 2, 3)
15 assert new_queue == [%{item: 1, priority: 2}, %{item: 2, priority: 3}]
18 test "pop first item" do
19 queue = [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
21 assert {2, [%{item: 1, priority: 2}]} = Federator.queue_pop(queue)
24 describe "Publish an activity" do
27 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
30 Pleroma.Web.ActivityPub.Relay,
32 [publish: fn _activity -> send(self(), :relay_publish) end]
35 %{activity: activity, relay_mock: relay_mock}
38 test "with relays active, it publishes to the relay", %{
40 relay_mock: relay_mock
42 with_mocks([relay_mock]) do
43 Federator.handle(:publish, activity)
46 assert_received :relay_publish
49 test "with relays deactivated, it does not publish to the relay", %{
51 relay_mock: relay_mock
53 Pleroma.Config.put([:instance, :allow_relay], false)
55 with_mocks([relay_mock]) do
56 Federator.handle(:publish, activity)
59 refute_received :relay_publish
61 Pleroma.Config.put([:instance, :allow_relay], true)
65 describe "Receive an activity" do
66 test "successfully processes incoming AP docs with correct origin" do
68 "@context" => "https://www.w3.org/ns/activitystreams",
69 "actor" => "http://mastodon.example.org/users/admin",
71 "id" => "http://mastodon.example.org/users/admin/activities/1",
74 "content" => "hi world!",
75 "id" => "http://mastodon.example.org/users/admin/objects/1",
76 "attributedTo" => "http://mastodon.example.org/users/admin"
78 "to" => ["https://www.w3.org/ns/activitystreams#Public"]
81 {:ok, _activity} = Federator.handle(:incoming_ap_doc, params)
84 test "rejects incoming AP docs with incorrect origin" do
86 "@context" => "https://www.w3.org/ns/activitystreams",
87 "actor" => "https://niu.moe/users/rye",
89 "id" => "http://mastodon.example.org/users/admin/activities/1",
92 "content" => "hi world!",
93 "id" => "http://mastodon.example.org/users/admin/objects/1",
94 "attributedTo" => "http://mastodon.example.org/users/admin"
96 "to" => ["https://www.w3.org/ns/activitystreams#Public"]
99 :error = Federator.handle(:incoming_ap_doc, params)