1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.FederatorTest do
6 alias Pleroma.Web.Federator
7 alias Pleroma.Web.CommonAPI
13 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
17 describe "Publish an activity" do
20 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
23 Pleroma.Web.ActivityPub.Relay,
25 [publish: fn _activity -> send(self(), :relay_publish) end]
28 %{activity: activity, relay_mock: relay_mock}
31 test "with relays active, it publishes to the relay", %{
33 relay_mock: relay_mock
35 with_mocks([relay_mock]) do
36 Federator.publish(activity)
39 assert_received :relay_publish
42 test "with relays deactivated, it does not publish to the relay", %{
44 relay_mock: relay_mock
46 Pleroma.Config.put([:instance, :allow_relay], false)
48 with_mocks([relay_mock]) do
49 Federator.publish(activity)
52 refute_received :relay_publish
54 Pleroma.Config.put([:instance, :allow_relay], true)
58 describe "Receive an activity" do
59 test "successfully processes incoming AP docs with correct origin" do
61 "@context" => "https://www.w3.org/ns/activitystreams",
62 "actor" => "http://mastodon.example.org/users/admin",
64 "id" => "http://mastodon.example.org/users/admin/activities/1",
67 "content" => "hi world!",
68 "id" => "http://mastodon.example.org/users/admin/objects/1",
69 "attributedTo" => "http://mastodon.example.org/users/admin"
71 "to" => ["https://www.w3.org/ns/activitystreams#Public"]
74 {:ok, _activity} = Federator.incoming_ap_doc(params)
77 test "rejects incoming AP docs with incorrect origin" do
79 "@context" => "https://www.w3.org/ns/activitystreams",
80 "actor" => "https://niu.moe/users/rye",
82 "id" => "http://mastodon.example.org/users/admin/activities/1",
85 "content" => "hi world!",
86 "id" => "http://mastodon.example.org/users/admin/objects/1",
87 "attributedTo" => "http://mastodon.example.org/users/admin"
89 "to" => ["https://www.w3.org/ns/activitystreams#Public"]
92 :error = Federator.incoming_ap_doc(params)