Revert Rich Media censorship for sensitive statuses
[akkoma] / test / tasks / relay_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.Tasks.Pleroma.RelayTest do
6 alias Pleroma.Activity
7 alias Pleroma.User
8 alias Pleroma.Web.ActivityPub.ActivityPub
9 alias Pleroma.Web.ActivityPub.Relay
10 alias Pleroma.Web.ActivityPub.Utils
11 use Pleroma.DataCase
12
13 import Pleroma.Factory
14
15 setup_all do
16 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
17
18 Mix.shell(Mix.Shell.Process)
19
20 on_exit(fn ->
21 Mix.shell(Mix.Shell.IO)
22 end)
23
24 :ok
25 end
26
27 describe "running follow" do
28 test "relay is followed" do
29 target_instance = "http://mastodon.example.org/users/admin"
30
31 Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
32
33 local_user = Relay.get_actor()
34 assert local_user.ap_id =~ "/relay"
35
36 target_user = User.get_cached_by_ap_id(target_instance)
37 refute target_user.local
38
39 activity = Utils.fetch_latest_follow(local_user, target_user)
40 assert activity.data["type"] == "Follow"
41 assert activity.data["actor"] == local_user.ap_id
42 assert activity.data["object"] == target_user.ap_id
43
44 :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
45
46 assert_receive {:mix_shell, :info,
47 [
48 "http://mastodon.example.org/users/admin - no Accept received (relay didn't follow back)"
49 ]}
50 end
51 end
52
53 describe "running unfollow" do
54 test "relay is unfollowed" do
55 user = insert(:user)
56 target_instance = user.ap_id
57
58 Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
59
60 %User{ap_id: follower_id} = local_user = Relay.get_actor()
61 target_user = User.get_cached_by_ap_id(target_instance)
62 follow_activity = Utils.fetch_latest_follow(local_user, target_user)
63 User.follow(local_user, target_user)
64 assert "#{target_instance}/followers" in User.following(local_user)
65 Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
66
67 cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
68 assert cancelled_activity.data["state"] == "cancelled"
69
70 [undo_activity] =
71 ActivityPub.fetch_activities([], %{
72 type: "Undo",
73 actor_id: follower_id,
74 limit: 1,
75 skip_preload: true,
76 invisible_actors: true
77 })
78
79 assert undo_activity.data["type"] == "Undo"
80 assert undo_activity.data["actor"] == local_user.ap_id
81 assert undo_activity.data["object"]["id"] == cancelled_activity.data["id"]
82 refute "#{target_instance}/followers" in User.following(local_user)
83 end
84 end
85
86 describe "mix pleroma.relay list" do
87 test "Prints relay subscription list" do
88 :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
89
90 refute_receive {:mix_shell, :info, _}
91
92 relay_user = Relay.get_actor()
93
94 ["http://mastodon.example.org/users/admin", "https://mstdn.io/users/mayuutann"]
95 |> Enum.each(fn ap_id ->
96 {:ok, user} = User.get_or_fetch_by_ap_id(ap_id)
97 User.follow(relay_user, user)
98 end)
99
100 :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
101
102 assert_receive {:mix_shell, :info, ["https://mstdn.io/users/mayuutann"]}
103 assert_receive {:mix_shell, :info, ["http://mastodon.example.org/users/admin"]}
104 end
105 end
106 end