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
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 clear_config([:instance, :max_account_fields], 10)
71 clear_config([:instance, :max_remote_account_fields], 15)
72 clear_config([:instance, :account_field_name_length], 255)
73 clear_config([: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 clear_config([:instance, :safe_dm_mentions], true)
91 |> get("/nodeinfo/2.1.json")
94 assert "safe_dm_mentions" in response["metadata"]["features"]
96 Config.put([:instance, :safe_dm_mentions], false)
100 |> get("/nodeinfo/2.1.json")
101 |> json_response(:ok)
103 refute "safe_dm_mentions" in response["metadata"]["features"]
106 describe "`metadata/federation/enabled`" do
107 setup do: clear_config([:instance, :federating])
109 test "it shows if federation is enabled/disabled", %{conn: conn} do
110 Config.put([:instance, :federating], true)
114 |> get("/nodeinfo/2.1.json")
115 |> json_response(:ok)
117 assert response["metadata"]["federation"]["enabled"] == true
119 Config.put([:instance, :federating], false)
123 |> get("/nodeinfo/2.1.json")
124 |> json_response(:ok)
126 assert response["metadata"]["federation"]["enabled"] == false
130 test "it shows default features flags", %{conn: conn} do
133 |> get("/nodeinfo/2.1.json")
134 |> json_response(:ok)
139 "mastodon_api_streaming",
141 "pleroma_explicit_addressing",
142 "shareable_emoji_packs",
144 "pleroma_emoji_reactions",
145 "pleroma:api/v1/notifications:include_types_filter",
146 "pleroma_chat_messages"
149 assert MapSet.subset?(
150 MapSet.new(default_features),
151 MapSet.new(response["metadata"]["features"])
155 test "it shows MRF transparency data if enabled", %{conn: conn} do
156 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
157 clear_config([:mrf, :transparency], true)
159 simple_config = %{"reject" => ["example.com"]}
160 clear_config(:mrf_simple, simple_config)
164 |> get("/nodeinfo/2.1.json")
165 |> json_response(:ok)
167 assert response["metadata"]["federation"]["mrf_simple"] == simple_config
170 test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
171 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
172 clear_config([:mrf, :transparency], true)
173 clear_config([:mrf, :transparency_exclusions], ["other.site"])
175 simple_config = %{"reject" => ["example.com", "other.site"]}
176 clear_config(:mrf_simple, simple_config)
178 expected_config = %{"reject" => ["example.com"]}
182 |> get("/nodeinfo/2.1.json")
183 |> json_response(:ok)
185 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
186 assert response["metadata"]["federation"]["exclusions"] == true