Merge pull request '[#37] fix frienderica pinned collection fetching' (#42) from...
[akkoma] / test / pleroma / web / node_info_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.NodeInfoTest do
6 use Pleroma.Web.ConnCase
7
8 import Pleroma.Factory
9
10 setup do: clear_config([:mrf_simple])
11 setup do: clear_config(:instance)
12
13 test "GET /.well-known/nodeinfo", %{conn: conn} do
14 links =
15 conn
16 |> get("/.well-known/nodeinfo")
17 |> json_response(200)
18 |> Map.fetch!("links")
19
20 Enum.each(links, fn link ->
21 href = Map.fetch!(link, "href")
22
23 conn
24 |> get(href)
25 |> json_response(200)
26 end)
27 end
28
29 test "nodeinfo shows staff accounts", %{conn: conn} do
30 moderator = insert(:user, local: true, is_moderator: true)
31 admin = insert(:user, local: true, is_admin: true)
32
33 conn =
34 conn
35 |> get("/nodeinfo/2.1.json")
36
37 assert result = json_response(conn, 200)
38
39 assert moderator.ap_id in result["metadata"]["staffAccounts"]
40 assert admin.ap_id in result["metadata"]["staffAccounts"]
41 end
42
43 test "nodeinfo shows restricted nicknames", %{conn: conn} do
44 conn =
45 conn
46 |> get("/nodeinfo/2.1.json")
47
48 assert result = json_response(conn, 200)
49
50 assert Config.get([Pleroma.User, :restricted_nicknames]) ==
51 result["metadata"]["restrictedNicknames"]
52 end
53
54 test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
55 conn
56 |> get("/.well-known/nodeinfo")
57 |> json_response(200)
58
59 conn =
60 conn
61 |> get("/nodeinfo/2.1.json")
62
63 assert result = json_response(conn, 200)
64 assert Pleroma.Application.repository() == result["software"]["repository"]
65 end
66
67 test "returns fieldsLimits field", %{conn: conn} do
68 clear_config([:instance, :max_account_fields], 10)
69 clear_config([:instance, :max_remote_account_fields], 15)
70 clear_config([:instance, :account_field_name_length], 255)
71 clear_config([:instance, :account_field_value_length], 2048)
72
73 response =
74 conn
75 |> get("/nodeinfo/2.1.json")
76 |> json_response(:ok)
77
78 assert response["metadata"]["fieldsLimits"]["maxFields"] == 10
79 assert response["metadata"]["fieldsLimits"]["maxRemoteFields"] == 15
80 assert response["metadata"]["fieldsLimits"]["nameLength"] == 255
81 assert response["metadata"]["fieldsLimits"]["valueLength"] == 2048
82 end
83
84 test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
85 clear_config([:instance, :safe_dm_mentions], true)
86
87 response =
88 conn
89 |> get("/nodeinfo/2.1.json")
90 |> json_response(:ok)
91
92 assert "safe_dm_mentions" in response["metadata"]["features"]
93
94 clear_config([:instance, :safe_dm_mentions], false)
95
96 response =
97 conn
98 |> get("/nodeinfo/2.1.json")
99 |> json_response(:ok)
100
101 refute "safe_dm_mentions" in response["metadata"]["features"]
102 end
103
104 describe "`metadata/federation/enabled`" do
105 setup do: clear_config([:instance, :federating])
106
107 test "it shows if federation is enabled/disabled", %{conn: conn} do
108 clear_config([:instance, :federating], true)
109
110 response =
111 conn
112 |> get("/nodeinfo/2.1.json")
113 |> json_response(:ok)
114
115 assert response["metadata"]["federation"]["enabled"] == true
116
117 clear_config([:instance, :federating], false)
118
119 response =
120 conn
121 |> get("/nodeinfo/2.1.json")
122 |> json_response(:ok)
123
124 assert response["metadata"]["federation"]["enabled"] == false
125 end
126 end
127
128 test "it shows default features flags", %{conn: conn} do
129 response =
130 conn
131 |> get("/nodeinfo/2.1.json")
132 |> json_response(:ok)
133
134 default_features = [
135 "pleroma_api",
136 "mastodon_api",
137 "mastodon_api_streaming",
138 "polls",
139 "pleroma_explicit_addressing",
140 "shareable_emoji_packs",
141 "multifetch",
142 "pleroma_emoji_reactions",
143 "pleroma:api/v1/notifications:include_types_filter",
144 "pleroma_chat_messages"
145 ]
146
147 assert MapSet.subset?(
148 MapSet.new(default_features),
149 MapSet.new(response["metadata"]["features"])
150 )
151 end
152
153 describe "Quarantined instances" do
154 setup do
155 clear_config([:mrf, :transparency], true)
156 quarantined_instances = [{"example.com", "reason to quarantine"}]
157 clear_config([:instance, :quarantined_instances], quarantined_instances)
158 end
159
160 test "shows quarantined instances data if enabled", %{conn: conn} do
161 expected_config = ["example.com"]
162
163 response =
164 conn
165 |> get("/nodeinfo/2.1.json")
166 |> json_response(:ok)
167
168 assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
169 end
170
171 test "shows extra information in the quarantined_info field for relevant entries", %{
172 conn: conn
173 } do
174 clear_config([:mrf, :transparency], true)
175
176 expected_config = %{
177 "quarantined_instances" => %{
178 "example.com" => %{"reason" => "reason to quarantine"}
179 }
180 }
181
182 response =
183 conn
184 |> get("/nodeinfo/2.1.json")
185 |> json_response(:ok)
186
187 assert response["metadata"]["federation"]["quarantined_instances_info"] == expected_config
188 end
189 end
190
191 describe "MRF SimplePolicy" do
192 setup do
193 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
194 clear_config([:mrf, :transparency], true)
195 end
196
197 test "shows MRF transparency data if enabled", %{conn: conn} do
198 simple_config = %{"reject" => [{"example.com", ""}]}
199 clear_config(:mrf_simple, simple_config)
200
201 expected_config = %{"reject" => ["example.com"]}
202
203 response =
204 conn
205 |> get("/nodeinfo/2.1.json")
206 |> json_response(:ok)
207
208 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
209 end
210
211 test "performs exclusions from MRF transparency data if configured", %{conn: conn} do
212 clear_config([:mrf, :transparency_exclusions], [
213 {"other.site", "We don't want them to know"}
214 ])
215
216 simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
217 clear_config(:mrf_simple, simple_config)
218
219 expected_config = %{"reject" => ["example.com"]}
220
221 response =
222 conn
223 |> get("/nodeinfo/2.1.json")
224 |> json_response(:ok)
225
226 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
227 assert response["metadata"]["federation"]["exclusions"] == true
228 end
229
230 test "shows extra information in the mrf_simple_info field for relevant entries", %{
231 conn: conn
232 } do
233 simple_config = %{
234 media_removal: [{"no.media", "LEEWWWDD >//<"}],
235 media_nsfw: [],
236 federated_timeline_removal: [{"no.ftl", ""}],
237 report_removal: [],
238 reject: [
239 {"example.instance", "Some reason"},
240 {"uwu.owo", "awoo to much"},
241 {"no.reason", ""}
242 ],
243 followers_only: [],
244 accept: [],
245 avatar_removal: [],
246 banner_removal: [],
247 reject_deletes: [
248 {"peak.me", "I want to peak at what they don't want me to see, eheh"}
249 ]
250 }
251
252 clear_config(:mrf_simple, simple_config)
253
254 clear_config([:mrf, :transparency_exclusions], [
255 {"peak.me", "I don't want them to know"}
256 ])
257
258 expected_config = %{
259 "media_removal" => %{
260 "no.media" => %{"reason" => "LEEWWWDD >//<"}
261 },
262 "reject" => %{
263 "example.instance" => %{"reason" => "Some reason"},
264 "uwu.owo" => %{"reason" => "awoo to much"}
265 }
266 }
267
268 response =
269 conn
270 |> get("/nodeinfo/2.1.json")
271 |> json_response(:ok)
272
273 assert response["metadata"]["federation"]["mrf_simple_info"] == expected_config
274 end
275 end
276 end