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