Apply suggestion to config/description.exs
[akkoma] / test / web / node_info_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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 alias Pleroma.Config
11
12 setup do: clear_config([:mrf_simple])
13 setup do: clear_config(:instance)
14
15 test "GET /.well-known/nodeinfo", %{conn: conn} do
16 links =
17 conn
18 |> get("/.well-known/nodeinfo")
19 |> json_response(200)
20 |> Map.fetch!("links")
21
22 Enum.each(links, fn link ->
23 href = Map.fetch!(link, "href")
24
25 conn
26 |> get(href)
27 |> json_response(200)
28 end)
29 end
30
31 test "nodeinfo shows staff accounts", %{conn: conn} do
32 moderator = insert(:user, local: true, is_moderator: true)
33 admin = insert(:user, local: true, is_admin: true)
34
35 conn =
36 conn
37 |> get("/nodeinfo/2.1.json")
38
39 assert result = json_response(conn, 200)
40
41 assert moderator.ap_id in result["metadata"]["staffAccounts"]
42 assert admin.ap_id in result["metadata"]["staffAccounts"]
43 end
44
45 test "nodeinfo shows restricted nicknames", %{conn: conn} do
46 conn =
47 conn
48 |> get("/nodeinfo/2.1.json")
49
50 assert result = json_response(conn, 200)
51
52 assert Config.get([Pleroma.User, :restricted_nicknames]) ==
53 result["metadata"]["restrictedNicknames"]
54 end
55
56 test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
57 conn
58 |> get("/.well-known/nodeinfo")
59 |> json_response(200)
60
61 conn =
62 conn
63 |> get("/nodeinfo/2.1.json")
64
65 assert result = json_response(conn, 200)
66 assert Pleroma.Application.repository() == result["software"]["repository"]
67 end
68
69 test "returns fieldsLimits field", %{conn: conn} do
70 Config.put([:instance, :max_account_fields], 10)
71 Config.put([:instance, :max_remote_account_fields], 15)
72 Config.put([:instance, :account_field_name_length], 255)
73 Config.put([:instance, :account_field_value_length], 2048)
74
75 response =
76 conn
77 |> get("/nodeinfo/2.1.json")
78 |> json_response(:ok)
79
80 assert response["metadata"]["fieldsLimits"]["maxFields"] == 10
81 assert response["metadata"]["fieldsLimits"]["maxRemoteFields"] == 15
82 assert response["metadata"]["fieldsLimits"]["nameLength"] == 255
83 assert response["metadata"]["fieldsLimits"]["valueLength"] == 2048
84 end
85
86 test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
87 option = Config.get([:instance, :safe_dm_mentions])
88 Config.put([:instance, :safe_dm_mentions], true)
89
90 response =
91 conn
92 |> get("/nodeinfo/2.1.json")
93 |> json_response(:ok)
94
95 assert "safe_dm_mentions" in response["metadata"]["features"]
96
97 Config.put([:instance, :safe_dm_mentions], false)
98
99 response =
100 conn
101 |> get("/nodeinfo/2.1.json")
102 |> json_response(:ok)
103
104 refute "safe_dm_mentions" in response["metadata"]["features"]
105
106 Config.put([:instance, :safe_dm_mentions], option)
107 end
108
109 describe "`metadata/federation/enabled`" do
110 setup do: clear_config([:instance, :federating])
111
112 test "it shows if federation is enabled/disabled", %{conn: conn} do
113 Config.put([:instance, :federating], true)
114
115 response =
116 conn
117 |> get("/nodeinfo/2.1.json")
118 |> json_response(:ok)
119
120 assert response["metadata"]["federation"]["enabled"] == true
121
122 Config.put([:instance, :federating], false)
123
124 response =
125 conn
126 |> get("/nodeinfo/2.1.json")
127 |> json_response(:ok)
128
129 assert response["metadata"]["federation"]["enabled"] == false
130 end
131 end
132
133 test "it shows default features flags", %{conn: conn} do
134 response =
135 conn
136 |> get("/nodeinfo/2.1.json")
137 |> json_response(:ok)
138
139 default_features = [
140 "pleroma_api",
141 "mastodon_api",
142 "mastodon_api_streaming",
143 "polls",
144 "pleroma_explicit_addressing",
145 "shareable_emoji_packs",
146 "multifetch",
147 "pleroma_emoji_reactions",
148 "pleroma:api/v1/notifications:include_types_filter",
149 "pleroma_chat_messages"
150 ]
151
152 assert MapSet.subset?(
153 MapSet.new(default_features),
154 MapSet.new(response["metadata"]["features"])
155 )
156 end
157
158 test "it shows MRF transparency data if enabled", %{conn: conn} do
159 config = Config.get([:instance, :rewrite_policy])
160 Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
161
162 option = Config.get([:instance, :mrf_transparency])
163 Config.put([:instance, :mrf_transparency], true)
164
165 simple_config = %{"reject" => ["example.com"]}
166 Config.put(:mrf_simple, simple_config)
167
168 response =
169 conn
170 |> get("/nodeinfo/2.1.json")
171 |> json_response(:ok)
172
173 assert response["metadata"]["federation"]["mrf_simple"] == simple_config
174
175 Config.put([:instance, :rewrite_policy], config)
176 Config.put([:instance, :mrf_transparency], option)
177 Config.put(:mrf_simple, %{})
178 end
179
180 test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
181 config = Config.get([:instance, :rewrite_policy])
182 Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
183
184 option = Config.get([:instance, :mrf_transparency])
185 Config.put([:instance, :mrf_transparency], true)
186
187 exclusions = Config.get([:instance, :mrf_transparency_exclusions])
188 Config.put([:instance, :mrf_transparency_exclusions], ["other.site"])
189
190 simple_config = %{"reject" => ["example.com", "other.site"]}
191 expected_config = %{"reject" => ["example.com"]}
192
193 Config.put(:mrf_simple, simple_config)
194
195 response =
196 conn
197 |> get("/nodeinfo/2.1.json")
198 |> json_response(:ok)
199
200 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
201 assert response["metadata"]["federation"]["exclusions"] == true
202
203 Config.put([:instance, :rewrite_policy], config)
204 Config.put([:instance, :mrf_transparency], option)
205 Config.put([:instance, :mrf_transparency_exclusions], exclusions)
206 Config.put(:mrf_simple, %{})
207 end
208 end