Merge branch 'develop' into docs/apache-config
[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 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 clear_config([:instance, :max_account_fields], 10)
71 clear_config([:instance, :max_remote_account_fields], 15)
72 clear_config([:instance, :account_field_name_length], 255)
73 clear_config([: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 clear_config([:instance, :safe_dm_mentions], true)
88
89 response =
90 conn
91 |> get("/nodeinfo/2.1.json")
92 |> json_response(:ok)
93
94 assert "safe_dm_mentions" in response["metadata"]["features"]
95
96 Config.put([:instance, :safe_dm_mentions], false)
97
98 response =
99 conn
100 |> get("/nodeinfo/2.1.json")
101 |> json_response(:ok)
102
103 refute "safe_dm_mentions" in response["metadata"]["features"]
104 end
105
106 describe "`metadata/federation/enabled`" do
107 setup do: clear_config([:instance, :federating])
108
109 test "it shows if federation is enabled/disabled", %{conn: conn} do
110 Config.put([:instance, :federating], true)
111
112 response =
113 conn
114 |> get("/nodeinfo/2.1.json")
115 |> json_response(:ok)
116
117 assert response["metadata"]["federation"]["enabled"] == true
118
119 Config.put([:instance, :federating], false)
120
121 response =
122 conn
123 |> get("/nodeinfo/2.1.json")
124 |> json_response(:ok)
125
126 assert response["metadata"]["federation"]["enabled"] == false
127 end
128 end
129
130 test "it shows default features flags", %{conn: conn} do
131 response =
132 conn
133 |> get("/nodeinfo/2.1.json")
134 |> json_response(:ok)
135
136 default_features = [
137 "pleroma_api",
138 "mastodon_api",
139 "mastodon_api_streaming",
140 "polls",
141 "pleroma_explicit_addressing",
142 "shareable_emoji_packs",
143 "multifetch",
144 "pleroma_emoji_reactions",
145 "pleroma:api/v1/notifications:include_types_filter",
146 "pleroma_chat_messages"
147 ]
148
149 assert MapSet.subset?(
150 MapSet.new(default_features),
151 MapSet.new(response["metadata"]["features"])
152 )
153 end
154
155 test "it shows MRF transparency data if enabled", %{conn: conn} do
156 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
157 clear_config([:mrf, :transparency], true)
158
159 simple_config = %{"reject" => ["example.com"]}
160 clear_config(:mrf_simple, simple_config)
161
162 response =
163 conn
164 |> get("/nodeinfo/2.1.json")
165 |> json_response(:ok)
166
167 assert response["metadata"]["federation"]["mrf_simple"] == simple_config
168 end
169
170 test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
171 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
172 clear_config([:mrf, :transparency], true)
173 clear_config([:mrf, :transparency_exclusions], ["other.site"])
174
175 simple_config = %{"reject" => ["example.com", "other.site"]}
176 clear_config(:mrf_simple, simple_config)
177
178 expected_config = %{"reject" => ["example.com"]}
179
180 response =
181 conn
182 |> get("/nodeinfo/2.1.json")
183 |> json_response(:ok)
184
185 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
186 assert response["metadata"]["federation"]["exclusions"] == true
187 end
188 end