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)
137 "mastodon_api_streaming",
139 "pleroma_explicit_addressing",
140 "shareable_emoji_packs",
142 "pleroma_emoji_reactions",
143 "pleroma:api/v1/notifications:include_types_filter",
144 "pleroma_chat_messages"
147 assert MapSet.subset?(
148 MapSet.new(default_features),
149 MapSet.new(response["metadata"]["features"])
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)
157 simple_config = %{"reject" => ["example.com"]}
158 clear_config(:mrf_simple, simple_config)
162 |> get("/nodeinfo/2.1.json")
163 |> json_response(:ok)
165 assert response["metadata"]["federation"]["mrf_simple"] == simple_config
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"])
173 simple_config = %{"reject" => ["example.com", "other.site"]}
174 clear_config(:mrf_simple, simple_config)
176 expected_config = %{"reject" => ["example.com"]}
180 |> get("/nodeinfo/2.1.json")
181 |> json_response(:ok)
183 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
184 assert response["metadata"]["federation"]["exclusions"] == true