1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.NodeInfoTest do
6 use Pleroma.Web.ConnCase
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 restricted nicknames", %{conn: conn} do
46 |> get("/nodeinfo/2.1.json")
48 assert result = json_response(conn, 200)
50 assert Config.get([Pleroma.User, :restricted_nicknames]) ==
51 result["metadata"]["restrictedNicknames"]
54 test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
56 |> get("/.well-known/nodeinfo")
61 |> get("/nodeinfo/2.1.json")
63 assert result = json_response(conn, 200)
64 assert Pleroma.Application.repository() == result["software"]["repository"]
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)
75 |> get("/nodeinfo/2.1.json")
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
84 test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
85 clear_config([:instance, :safe_dm_mentions], true)
89 |> get("/nodeinfo/2.1.json")
92 assert "safe_dm_mentions" in response["metadata"]["features"]
94 clear_config([:instance, :safe_dm_mentions], false)
98 |> get("/nodeinfo/2.1.json")
101 refute "safe_dm_mentions" in response["metadata"]["features"]
104 describe "`metadata/federation/enabled`" do
105 setup do: clear_config([:instance, :federating])
107 test "it shows if federation is enabled/disabled", %{conn: conn} do
108 clear_config([:instance, :federating], true)
112 |> get("/nodeinfo/2.1.json")
113 |> json_response(:ok)
115 assert response["metadata"]["federation"]["enabled"] == true
117 clear_config([:instance, :federating], false)
121 |> get("/nodeinfo/2.1.json")
122 |> json_response(:ok)
124 assert response["metadata"]["federation"]["enabled"] == false
128 test "it shows default features flags", %{conn: conn} do
131 |> get("/nodeinfo/2.1.json")
132 |> json_response(:ok)
138 "mastodon_api_streaming",
140 "pleroma_explicit_addressing",
141 "shareable_emoji_packs",
143 "pleroma_emoji_reactions",
144 "pleroma:api/v1/notifications:include_types_filter"
147 assert MapSet.subset?(
148 MapSet.new(default_features),
149 MapSet.new(response["metadata"]["features"])
153 describe "Quarantined instances" do
155 clear_config([:mrf, :transparency], true)
156 quarantined_instances = [{"example.com", "reason to quarantine"}]
157 clear_config([:instance, :quarantined_instances], quarantined_instances)
160 test "shows quarantined instances data if enabled", %{conn: conn} do
161 expected_config = ["example.com"]
165 |> get("/nodeinfo/2.1.json")
166 |> json_response(:ok)
168 assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
171 test "shows extra information in the quarantined_info field for relevant entries", %{
174 clear_config([:mrf, :transparency], true)
177 "quarantined_instances" => %{
178 "example.com" => %{"reason" => "reason to quarantine"}
184 |> get("/nodeinfo/2.1.json")
185 |> json_response(:ok)
187 assert response["metadata"]["federation"]["quarantined_instances_info"] == expected_config
191 test "Bubble instances", %{conn: conn} do
192 clear_config([:instance, :local_bubble], [])
196 |> get("/nodeinfo/2.1.json")
197 |> json_response(:ok)
199 assert response["metadata"]["localBubbleInstances"] == []
200 clear_config([:instance, :local_bubble], ["example.com"])
204 |> get("/nodeinfo/2.1.json")
205 |> json_response(:ok)
207 assert response["metadata"]["localBubbleInstances"] == ["example.com"]
210 describe "MRF SimplePolicy" do
212 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
213 clear_config([:mrf, :transparency], true)
216 test "shows MRF transparency data if enabled", %{conn: conn} do
217 simple_config = %{"reject" => [{"example.com", ""}]}
218 clear_config(:mrf_simple, simple_config)
220 expected_config = %{"reject" => ["example.com"]}
224 |> get("/nodeinfo/2.1.json")
225 |> json_response(:ok)
227 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
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"}
235 simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
236 clear_config(:mrf_simple, simple_config)
238 expected_config = %{"reject" => ["example.com"]}
242 |> get("/nodeinfo/2.1.json")
243 |> json_response(:ok)
245 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
246 assert response["metadata"]["federation"]["exclusions"] == true
249 test "shows extra information in the mrf_simple_info field for relevant entries", %{
253 media_removal: [{"no.media", "LEEWWWDD >//<"}],
255 federated_timeline_removal: [{"no.ftl", ""}],
258 {"example.instance", "Some reason"},
259 {"uwu.owo", "awoo to much"},
267 {"peak.me", "I want to peak at what they don't want me to see, eheh"}
271 clear_config(:mrf_simple, simple_config)
273 clear_config([:mrf, :transparency_exclusions], [
274 {"peak.me", "I don't want them to know"}
278 "media_removal" => %{
279 "no.media" => %{"reason" => "LEEWWWDD >//<"}
282 "example.instance" => %{"reason" => "Some reason"},
283 "uwu.owo" => %{"reason" => "awoo to much"}
289 |> get("/nodeinfo/2.1.json")
290 |> json_response(:ok)
292 assert response["metadata"]["federation"]["mrf_simple_info"] == expected_config