Merge branch 'develop' into 'fix/2412-filters'
[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 test "it shows MRF transparency data if enabled", %{conn: conn} do
154 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
155 clear_config([:mrf, :transparency], true)
156
157 simple_config = %{"reject" => ["example.com"]}
158 clear_config(:mrf_simple, simple_config)
159
160 response =
161 conn
162 |> get("/nodeinfo/2.1.json")
163 |> json_response(:ok)
164
165 assert response["metadata"]["federation"]["mrf_simple"] == simple_config
166 end
167
168 test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
169 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
170 clear_config([:mrf, :transparency], true)
171 clear_config([:mrf, :transparency_exclusions], ["other.site"])
172
173 simple_config = %{"reject" => ["example.com", "other.site"]}
174 clear_config(:mrf_simple, simple_config)
175
176 expected_config = %{"reject" => ["example.com"]}
177
178 response =
179 conn
180 |> get("/nodeinfo/2.1.json")
181 |> json_response(:ok)
182
183 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
184 assert response["metadata"]["federation"]["exclusions"] == true
185 end
186 end