Merge pull request 'docs: Update links to list of akkoma instances' (#278) from norm...
[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 "akkoma_api",
137 "mastodon_api",
138 "mastodon_api_streaming",
139 "polls",
140 "pleroma_explicit_addressing",
141 "shareable_emoji_packs",
142 "multifetch",
143 "pleroma_emoji_reactions",
144 "pleroma:api/v1/notifications:include_types_filter"
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 test "Bubble instances", %{conn: conn} do
192 clear_config([:instance, :local_bubble], [])
193
194 response =
195 conn
196 |> get("/nodeinfo/2.1.json")
197 |> json_response(:ok)
198
199 assert response["metadata"]["localBubbleInstances"] == []
200 clear_config([:instance, :local_bubble], ["example.com"])
201
202 response =
203 conn
204 |> get("/nodeinfo/2.1.json")
205 |> json_response(:ok)
206
207 assert response["metadata"]["localBubbleInstances"] == ["example.com"]
208 end
209
210 describe "MRF SimplePolicy" do
211 setup do
212 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
213 clear_config([:mrf, :transparency], true)
214 end
215
216 test "shows MRF transparency data if enabled", %{conn: conn} do
217 simple_config = %{"reject" => [{"example.com", ""}]}
218 clear_config(:mrf_simple, simple_config)
219
220 expected_config = %{"reject" => ["example.com"]}
221
222 response =
223 conn
224 |> get("/nodeinfo/2.1.json")
225 |> json_response(:ok)
226
227 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
228 end
229
230 test "performs exclusions from MRF transparency data if configured", %{conn: conn} do
231 clear_config([:mrf, :transparency_exclusions], [
232 {"other.site", "We don't want them to know"}
233 ])
234
235 simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
236 clear_config(:mrf_simple, simple_config)
237
238 expected_config = %{"reject" => ["example.com"]}
239
240 response =
241 conn
242 |> get("/nodeinfo/2.1.json")
243 |> json_response(:ok)
244
245 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
246 assert response["metadata"]["federation"]["exclusions"] == true
247 end
248
249 test "shows extra information in the mrf_simple_info field for relevant entries", %{
250 conn: conn
251 } do
252 simple_config = %{
253 media_removal: [{"no.media", "LEEWWWDD >//<"}],
254 media_nsfw: [],
255 federated_timeline_removal: [{"no.ftl", ""}],
256 report_removal: [],
257 reject: [
258 {"example.instance", "Some reason"},
259 {"uwu.owo", "awoo to much"},
260 {"no.reason", ""}
261 ],
262 followers_only: [],
263 accept: [],
264 avatar_removal: [],
265 banner_removal: [],
266 reject_deletes: [
267 {"peak.me", "I want to peak at what they don't want me to see, eheh"}
268 ]
269 }
270
271 clear_config(:mrf_simple, simple_config)
272
273 clear_config([:mrf, :transparency_exclusions], [
274 {"peak.me", "I don't want them to know"}
275 ])
276
277 expected_config = %{
278 "media_removal" => %{
279 "no.media" => %{"reason" => "LEEWWWDD >//<"}
280 },
281 "reject" => %{
282 "example.instance" => %{"reason" => "Some reason"},
283 "uwu.owo" => %{"reason" => "awoo to much"}
284 }
285 }
286
287 response =
288 conn
289 |> get("/nodeinfo/2.1.json")
290 |> json_response(:ok)
291
292 assert response["metadata"]["federation"]["mrf_simple_info"] == expected_config
293 end
294 end
295 end