1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.NodeInfoTest do
6 use Pleroma.Web.ConnCase
12 setup do: clear_config([:mrf_simple])
13 setup do: clear_config(:instance)
15 test "GET /.well-known/nodeinfo", %{conn: conn} do
18 |> get("/.well-known/nodeinfo")
20 |> Map.fetch!("links")
22 Enum.each(links, fn link ->
23 href = Map.fetch!(link, "href")
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)
37 |> get("/nodeinfo/2.1.json")
39 assert result = json_response(conn, 200)
41 assert moderator.ap_id in result["metadata"]["staffAccounts"]
42 assert admin.ap_id in result["metadata"]["staffAccounts"]
45 test "nodeinfo shows restricted nicknames", %{conn: conn} do
48 |> get("/nodeinfo/2.1.json")
50 assert result = json_response(conn, 200)
52 assert Config.get([Pleroma.User, :restricted_nicknames]) ==
53 result["metadata"]["restrictedNicknames"]
56 test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
58 |> get("/.well-known/nodeinfo")
63 |> get("/nodeinfo/2.1.json")
65 assert result = json_response(conn, 200)
66 assert Pleroma.Application.repository() == result["software"]["repository"]
69 test "returns fieldsLimits field", %{conn: conn} do
70 Config.put([:instance, :max_account_fields], 10)
71 Config.put([:instance, :max_remote_account_fields], 15)
72 Config.put([:instance, :account_field_name_length], 255)
73 Config.put([:instance, :account_field_value_length], 2048)
77 |> get("/nodeinfo/2.1.json")
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
86 test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
87 option = Config.get([:instance, :safe_dm_mentions])
88 Config.put([:instance, :safe_dm_mentions], true)
92 |> get("/nodeinfo/2.1.json")
95 assert "safe_dm_mentions" in response["metadata"]["features"]
97 Config.put([:instance, :safe_dm_mentions], false)
101 |> get("/nodeinfo/2.1.json")
102 |> json_response(:ok)
104 refute "safe_dm_mentions" in response["metadata"]["features"]
106 Config.put([:instance, :safe_dm_mentions], option)
109 describe "`metadata/federation/enabled`" do
110 setup do: clear_config([:instance, :federating])
112 test "it shows if federation is enabled/disabled", %{conn: conn} do
113 Config.put([:instance, :federating], true)
117 |> get("/nodeinfo/2.1.json")
118 |> json_response(:ok)
120 assert response["metadata"]["federation"]["enabled"] == true
122 Config.put([:instance, :federating], false)
126 |> get("/nodeinfo/2.1.json")
127 |> json_response(:ok)
129 assert response["metadata"]["federation"]["enabled"] == false
133 test "it shows default features flags", %{conn: conn} do
136 |> get("/nodeinfo/2.1.json")
137 |> json_response(:ok)
142 "mastodon_api_streaming",
144 "pleroma_explicit_addressing",
145 "shareable_emoji_packs",
147 "pleroma_emoji_reactions",
148 "pleroma:api/v1/notifications:include_types_filter",
149 "pleroma_chat_messages"
152 assert MapSet.subset?(
153 MapSet.new(default_features),
154 MapSet.new(response["metadata"]["features"])
158 test "it shows MRF transparency data if enabled", %{conn: conn} do
159 config = Config.get([:instance, :rewrite_policy])
160 Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
162 option = Config.get([:instance, :mrf_transparency])
163 Config.put([:instance, :mrf_transparency], true)
165 simple_config = %{"reject" => ["example.com"]}
166 Config.put(:mrf_simple, simple_config)
170 |> get("/nodeinfo/2.1.json")
171 |> json_response(:ok)
173 assert response["metadata"]["federation"]["mrf_simple"] == simple_config
175 Config.put([:instance, :rewrite_policy], config)
176 Config.put([:instance, :mrf_transparency], option)
177 Config.put(:mrf_simple, %{})
180 test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
181 config = Config.get([:instance, :rewrite_policy])
182 Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
184 option = Config.get([:instance, :mrf_transparency])
185 Config.put([:instance, :mrf_transparency], true)
187 exclusions = Config.get([:instance, :mrf_transparency_exclusions])
188 Config.put([:instance, :mrf_transparency_exclusions], ["other.site"])
190 simple_config = %{"reject" => ["example.com", "other.site"]}
191 expected_config = %{"reject" => ["example.com"]}
193 Config.put(:mrf_simple, simple_config)
197 |> get("/nodeinfo/2.1.json")
198 |> json_response(:ok)
200 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
201 assert response["metadata"]["federation"]["exclusions"] == true
203 Config.put([:instance, :rewrite_policy], config)
204 Config.put([:instance, :mrf_transparency], option)
205 Config.put([:instance, :mrf_transparency_exclusions], exclusions)
206 Config.put(:mrf_simple, %{})