Merge branch 'feat/mrf-noemptypolicy' into 'develop'
[akkoma] / test / pleroma / web / activity_pub / mrf / no_empty_policy_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.NoEmptyPolicyTest do
6 use Pleroma.DataCase
7 alias Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy
8
9 setup_all do: clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy])
10
11 test "Notes with content are exempt" do
12 message = %{
13 "actor" => "http://localhost:4001/users/testuser",
14 "cc" => ["http://localhost:4001/users/testuser/followers"],
15 "object" => %{
16 "actor" => "http://localhost:4001/users/testuser",
17 "attachment" => [],
18 "cc" => ["http://localhost:4001/users/testuser/followers"],
19 "source" => "this is a test post",
20 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
21 "type" => "Note"
22 },
23 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
24 "type" => "Create"
25 }
26
27 assert NoEmptyPolicy.filter(message) == {:ok, message}
28 end
29
30 test "Polls are exempt" do
31 message = %{
32 "actor" => "http://localhost:4001/users/testuser",
33 "cc" => ["http://localhost:4001/users/testuser/followers"],
34 "object" => %{
35 "actor" => "http://localhost:4001/users/testuser",
36 "attachment" => [],
37 "cc" => ["http://localhost:4001/users/testuser/followers"],
38 "oneOf" => [
39 %{
40 "name" => "chocolate",
41 "replies" => %{"totalItems" => 0, "type" => "Collection"},
42 "type" => "Note"
43 },
44 %{
45 "name" => "vanilla",
46 "replies" => %{"totalItems" => 0, "type" => "Collection"},
47 "type" => "Note"
48 }
49 ],
50 "source" => "@user2",
51 "to" => [
52 "https://www.w3.org/ns/activitystreams#Public",
53 "http://localhost:4001/users/user2"
54 ],
55 "type" => "Question"
56 },
57 "to" => [
58 "https://www.w3.org/ns/activitystreams#Public",
59 "http://localhost:4001/users/user2"
60 ],
61 "type" => "Create"
62 }
63
64 assert NoEmptyPolicy.filter(message) == {:ok, message}
65 end
66
67 test "Notes with attachments are exempt" do
68 message = %{
69 "actor" => "http://localhost:4001/users/testuser",
70 "cc" => ["http://localhost:4001/users/testuser/followers"],
71 "object" => %{
72 "actor" => "http://localhost:4001/users/testuser",
73 "attachment" => [
74 %{
75 "actor" => "http://localhost:4001/users/testuser",
76 "mediaType" => "image/png",
77 "name" => "",
78 "type" => "Document",
79 "url" => [
80 %{
81 "href" =>
82 "http://localhost:4001/media/68ba231cf12e1382ce458f1979969f8ed5cc07ba198a02e653464abaf39bdb90.png",
83 "mediaType" => "image/png",
84 "type" => "Link"
85 }
86 ]
87 }
88 ],
89 "cc" => ["http://localhost:4001/users/testuser/followers"],
90 "source" => "@user2",
91 "to" => [
92 "https://www.w3.org/ns/activitystreams#Public",
93 "http://localhost:4001/users/user2"
94 ],
95 "type" => "Note"
96 },
97 "to" => [
98 "https://www.w3.org/ns/activitystreams#Public",
99 "http://localhost:4001/users/user2"
100 ],
101 "type" => "Create"
102 }
103
104 assert NoEmptyPolicy.filter(message) == {:ok, message}
105 end
106
107 test "Notes with only mentions are denied" do
108 message = %{
109 "actor" => "http://localhost:4001/users/testuser",
110 "cc" => ["http://localhost:4001/users/testuser/followers"],
111 "object" => %{
112 "actor" => "http://localhost:4001/users/testuser",
113 "attachment" => [],
114 "cc" => ["http://localhost:4001/users/testuser/followers"],
115 "source" => "@user2",
116 "to" => [
117 "https://www.w3.org/ns/activitystreams#Public",
118 "http://localhost:4001/users/user2"
119 ],
120 "type" => "Note"
121 },
122 "to" => [
123 "https://www.w3.org/ns/activitystreams#Public",
124 "http://localhost:4001/users/user2"
125 ],
126 "type" => "Create"
127 }
128
129 assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
130 end
131
132 test "Notes with no content are denied" do
133 message = %{
134 "actor" => "http://localhost:4001/users/testuser",
135 "cc" => ["http://localhost:4001/users/testuser/followers"],
136 "object" => %{
137 "actor" => "http://localhost:4001/users/testuser",
138 "attachment" => [],
139 "cc" => ["http://localhost:4001/users/testuser/followers"],
140 "source" => "",
141 "to" => [
142 "https://www.w3.org/ns/activitystreams#Public"
143 ],
144 "type" => "Note"
145 },
146 "to" => [
147 "https://www.w3.org/ns/activitystreams#Public"
148 ],
149 "type" => "Create"
150 }
151
152 assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
153 end
154 end