1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.NodeInfoTest do
6 use Pleroma.Web.ConnCase, async: false
10 setup do: clear_config([:mrf_simple])
11 setup do: clear_config(:instance)
13 test "GET /.well-known/nodeinfo", %{conn: conn} do
16 |> get("/.well-known/nodeinfo")
18 |> Map.fetch!("links")
20 Enum.each(links, fn link ->
21 href = Map.fetch!(link, "href")
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)
35 |> get("/nodeinfo/2.1.json")
37 assert result = json_response(conn, 200)
39 assert moderator.ap_id in result["metadata"]["staffAccounts"]
40 assert admin.ap_id in result["metadata"]["staffAccounts"]
43 test "nodeinfo shows roles and privileges", %{conn: conn} do
44 clear_config([:instance, :moderator_privileges], [:cofe])
45 clear_config([:instance, :admin_privileges], [:suya, :cofe])
49 |> get("/nodeinfo/2.1.json")
51 assert result = json_response(conn, 200)
53 assert %{"admin" => ["suya", "cofe"], "moderator" => ["cofe"]} == result["metadata"]["roles"]
56 test "nodeinfo shows restricted nicknames", %{conn: conn} do
59 |> get("/nodeinfo/2.1.json")
61 assert result = json_response(conn, 200)
63 assert Config.get([Pleroma.User, :restricted_nicknames]) ==
64 result["metadata"]["restrictedNicknames"]
67 test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
69 |> get("/.well-known/nodeinfo")
74 |> get("/nodeinfo/2.1.json")
76 assert result = json_response(conn, 200)
77 assert Pleroma.Application.repository() == result["software"]["repository"]
80 test "returns fieldsLimits field", %{conn: conn} do
81 clear_config([:instance, :max_account_fields], 10)
82 clear_config([:instance, :max_remote_account_fields], 15)
83 clear_config([:instance, :account_field_name_length], 255)
84 clear_config([:instance, :account_field_value_length], 2048)
88 |> get("/nodeinfo/2.1.json")
91 assert response["metadata"]["fieldsLimits"]["maxFields"] == 10
92 assert response["metadata"]["fieldsLimits"]["maxRemoteFields"] == 15
93 assert response["metadata"]["fieldsLimits"]["nameLength"] == 255
94 assert response["metadata"]["fieldsLimits"]["valueLength"] == 2048
97 test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
98 clear_config([:instance, :safe_dm_mentions], true)
102 |> get("/nodeinfo/2.1.json")
103 |> json_response(:ok)
105 assert "safe_dm_mentions" in response["metadata"]["features"]
107 clear_config([:instance, :safe_dm_mentions], false)
111 |> get("/nodeinfo/2.1.json")
112 |> json_response(:ok)
114 refute "safe_dm_mentions" in response["metadata"]["features"]
117 describe "`metadata/federation/enabled`" do
118 setup do: clear_config([:instance, :federating])
120 test "it shows if federation is enabled/disabled", %{conn: conn} do
121 clear_config([:instance, :federating], true)
125 |> get("/nodeinfo/2.1.json")
126 |> json_response(:ok)
128 assert response["metadata"]["federation"]["enabled"] == true
130 clear_config([:instance, :federating], false)
134 |> get("/nodeinfo/2.1.json")
135 |> json_response(:ok)
137 assert response["metadata"]["federation"]["enabled"] == false
141 test "it shows default features flags", %{conn: conn} do
144 |> get("/nodeinfo/2.1.json")
145 |> json_response(:ok)
150 "mastodon_api_streaming",
152 "pleroma_explicit_addressing",
153 "shareable_emoji_packs",
155 "pleroma_emoji_reactions",
156 "pleroma:api/v1/notifications:include_types_filter",
157 "pleroma_chat_messages"
160 assert MapSet.subset?(
161 MapSet.new(default_features),
162 MapSet.new(response["metadata"]["features"])
166 describe "Quarantined instances" do
168 clear_config([:mrf, :transparency], true)
169 quarantined_instances = [{"example.com", "reason to quarantine"}]
170 clear_config([:instance, :quarantined_instances], quarantined_instances)
173 test "shows quarantined instances data if enabled", %{conn: conn} do
174 expected_config = ["example.com"]
178 |> get("/nodeinfo/2.1.json")
179 |> json_response(:ok)
181 assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
184 test "shows extra information in the quarantined_info field for relevant entries", %{
187 clear_config([:mrf, :transparency], true)
190 "quarantined_instances" => %{
191 "example.com" => %{"reason" => "reason to quarantine"}
197 |> get("/nodeinfo/2.1.json")
198 |> json_response(:ok)
200 assert response["metadata"]["federation"]["quarantined_instances_info"] == expected_config
204 describe "MRF SimplePolicy" do
206 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
207 clear_config([:mrf, :transparency], true)
210 test "shows MRF transparency data if enabled", %{conn: conn} do
211 simple_config = %{"reject" => [{"example.com", ""}]}
212 clear_config(:mrf_simple, simple_config)
214 expected_config = %{"reject" => ["example.com"]}
218 |> get("/nodeinfo/2.1.json")
219 |> json_response(:ok)
221 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
224 test "performs exclusions from MRF transparency data if configured", %{conn: conn} do
225 clear_config([:mrf, :transparency_exclusions], [
226 {"other.site", "We don't want them to know"}
229 simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
230 clear_config(:mrf_simple, simple_config)
232 expected_config = %{"reject" => ["example.com"]}
236 |> get("/nodeinfo/2.1.json")
237 |> json_response(:ok)
239 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
240 assert response["metadata"]["federation"]["exclusions"] == true
243 test "shows extra information in the mrf_simple_info field for relevant entries", %{
247 media_removal: [{"no.media", "LEEWWWDD >//<"}],
249 federated_timeline_removal: [{"no.ftl", ""}],
252 {"example.instance", "Some reason"},
253 {"uwu.owo", "awoo to much"},
261 {"peak.me", "I want to peak at what they don't want me to see, eheh"}
265 clear_config(:mrf_simple, simple_config)
267 clear_config([:mrf, :transparency_exclusions], [
268 {"peak.me", "I don't want them to know"}
272 "media_removal" => %{
273 "no.media" => %{"reason" => "LEEWWWDD >//<"}
276 "example.instance" => %{"reason" => "Some reason"},
277 "uwu.owo" => %{"reason" => "awoo to much"}
283 |> get("/nodeinfo/2.1.json")
284 |> json_response(:ok)
286 assert response["metadata"]["federation"]["mrf_simple_info"] == expected_config