Bump Copyright to 2021
[akkoma] / test / pleroma / web / activity_pub / mrf / reject_non_public_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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: clear_config([:mrf_rejectnonpublic])
12
13 describe "public message" do
14 test "it's allowed when address is public" do
15 actor = insert(:user, follower_address: "test-address")
16
17 message = %{
18 "actor" => actor.ap_id,
19 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
20 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
21 "type" => "Create"
22 }
23
24 assert {:ok, _message} = RejectNonPublic.filter(message)
25 end
26
27 test "it's allowed when cc address contain public address" do
28 actor = insert(:user, follower_address: "test-address")
29
30 message = %{
31 "actor" => actor.ap_id,
32 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
33 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
34 "type" => "Create"
35 }
36
37 assert {:ok, _message} = RejectNonPublic.filter(message)
38 end
39 end
40
41 describe "followers message" do
42 test "it's allowed when addrer of message in the follower addresses of user and it enabled in config" do
43 actor = insert(:user, follower_address: "test-address")
44
45 message = %{
46 "actor" => actor.ap_id,
47 "to" => ["test-address"],
48 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
49 "type" => "Create"
50 }
51
52 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
53 assert {:ok, _message} = RejectNonPublic.filter(message)
54 end
55
56 test "it's rejected when addrer of message in the follower addresses of user and it disabled in config" do
57 actor = insert(:user, follower_address: "test-address")
58
59 message = %{
60 "actor" => actor.ap_id,
61 "to" => ["test-address"],
62 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
63 "type" => "Create"
64 }
65
66 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], false)
67 assert {:reject, _} = RejectNonPublic.filter(message)
68 end
69 end
70
71 describe "direct message" do
72 test "it's allows when direct messages are allow" do
73 actor = insert(:user)
74
75 message = %{
76 "actor" => actor.ap_id,
77 "to" => ["https://www.w3.org/ns/activitystreams#Publid"],
78 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
79 "type" => "Create"
80 }
81
82 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
83 assert {:ok, _message} = RejectNonPublic.filter(message)
84 end
85
86 test "it's reject when direct messages aren't allow" do
87 actor = insert(:user)
88
89 message = %{
90 "actor" => actor.ap_id,
91 "to" => ["https://www.w3.org/ns/activitystreams#Publid~~~"],
92 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
93 "type" => "Create"
94 }
95
96 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], false)
97 assert {:reject, _} = RejectNonPublic.filter(message)
98 end
99 end
100 end