Merge branch 'develop' into feature/matstodon-statuses-by-name
[akkoma] / test / web / activity_pub / mrf / reject_non_public_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8
9 alias Pleroma.Web.ActivityPub.MRF.RejectNonPublic
10
11 setup do
12 policy = Pleroma.Config.get([:mrf_rejectnonpublic])
13 on_exit(fn -> Pleroma.Config.put([:mrf_rejectnonpublic], policy) end)
14
15 :ok
16 end
17
18 describe "public message" do
19 test "it's allowed when address is public" do
20 actor = insert(:user, follower_address: "test-address")
21
22 message = %{
23 "actor" => actor.ap_id,
24 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
25 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
26 "type" => "Create"
27 }
28
29 assert {:ok, message} = RejectNonPublic.filter(message)
30 end
31
32 test "it's allowed when cc address contain public address" do
33 actor = insert(:user, follower_address: "test-address")
34
35 message = %{
36 "actor" => actor.ap_id,
37 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
38 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
39 "type" => "Create"
40 }
41
42 assert {:ok, message} = RejectNonPublic.filter(message)
43 end
44 end
45
46 describe "followers message" do
47 test "it's allowed when addrer of message in the follower addresses of user and it enabled in config" do
48 actor = insert(:user, follower_address: "test-address")
49
50 message = %{
51 "actor" => actor.ap_id,
52 "to" => ["test-address"],
53 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
54 "type" => "Create"
55 }
56
57 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
58 assert {:ok, message} = RejectNonPublic.filter(message)
59 end
60
61 test "it's rejected when addrer of message in the follower addresses of user and it disabled in config" do
62 actor = insert(:user, follower_address: "test-address")
63
64 message = %{
65 "actor" => actor.ap_id,
66 "to" => ["test-address"],
67 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
68 "type" => "Create"
69 }
70
71 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], false)
72 assert {:reject, nil} = RejectNonPublic.filter(message)
73 end
74 end
75
76 describe "direct message" do
77 test "it's allows when direct messages are allow" do
78 actor = insert(:user)
79
80 message = %{
81 "actor" => actor.ap_id,
82 "to" => ["https://www.w3.org/ns/activitystreams#Publid"],
83 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
84 "type" => "Create"
85 }
86
87 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
88 assert {:ok, message} = RejectNonPublic.filter(message)
89 end
90
91 test "it's reject when direct messages aren't allow" do
92 actor = insert(:user)
93
94 message = %{
95 "actor" => actor.ap_id,
96 "to" => ["https://www.w3.org/ns/activitystreams#Publid~~~"],
97 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
98 "type" => "Create"
99 }
100
101 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], false)
102 assert {:reject, nil} = RejectNonPublic.filter(message)
103 end
104 end
105 end