1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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 test "GET /.well-known/nodeinfo", %{conn: conn} do
13 |> get("/.well-known/nodeinfo")
15 |> Map.fetch!("links")
17 Enum.each(links, fn link ->
18 href = Map.fetch!(link, "href")
26 test "nodeinfo shows staff accounts", %{conn: conn} do
27 moderator = insert(:user, local: true, is_moderator: true)
28 admin = insert(:user, local: true, is_admin: true)
32 |> get("/nodeinfo/2.1.json")
34 assert result = json_response(conn, 200)
36 assert moderator.ap_id in result["metadata"]["staffAccounts"]
37 assert admin.ap_id in result["metadata"]["staffAccounts"]
40 test "nodeinfo shows restricted nicknames", %{conn: conn} do
43 |> get("/nodeinfo/2.1.json")
45 assert result = json_response(conn, 200)
47 assert Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) ==
48 result["metadata"]["restrictedNicknames"]
51 test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
53 |> get("/.well-known/nodeinfo")
58 |> get("/nodeinfo/2.1.json")
60 assert result = json_response(conn, 200)
61 assert Pleroma.Application.repository() == result["software"]["repository"]
64 test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
65 option = Pleroma.Config.get([:instance, :safe_dm_mentions])
66 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
70 |> get("/nodeinfo/2.1.json")
73 assert "safe_dm_mentions" in response["metadata"]["features"]
75 Pleroma.Config.put([:instance, :safe_dm_mentions], false)
79 |> get("/nodeinfo/2.1.json")
82 refute "safe_dm_mentions" in response["metadata"]["features"]
84 Pleroma.Config.put([:instance, :safe_dm_mentions], option)
87 test "it shows if federation is enabled/disabled", %{conn: conn} do
88 original = Pleroma.Config.get([:instance, :federating])
90 Pleroma.Config.put([:instance, :federating], true)
94 |> get("/nodeinfo/2.1.json")
97 assert response["metadata"]["federation"]["enabled"] == true
99 Pleroma.Config.put([:instance, :federating], false)
103 |> get("/nodeinfo/2.1.json")
104 |> json_response(:ok)
106 assert response["metadata"]["federation"]["enabled"] == false
108 Pleroma.Config.put([:instance, :federating], original)
111 test "it shows MRF transparency data if enabled", %{conn: conn} do
112 config = Pleroma.Config.get([:instance, :rewrite_policy])
113 Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
115 option = Pleroma.Config.get([:instance, :mrf_transparency])
116 Pleroma.Config.put([:instance, :mrf_transparency], true)
118 simple_config = %{"reject" => ["example.com"]}
119 Pleroma.Config.put(:mrf_simple, simple_config)
123 |> get("/nodeinfo/2.1.json")
124 |> json_response(:ok)
126 assert response["metadata"]["federation"]["mrf_simple"] == simple_config
128 Pleroma.Config.put([:instance, :rewrite_policy], config)
129 Pleroma.Config.put([:instance, :mrf_transparency], option)
130 Pleroma.Config.put(:mrf_simple, %{})
133 test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
134 config = Pleroma.Config.get([:instance, :rewrite_policy])
135 Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
137 option = Pleroma.Config.get([:instance, :mrf_transparency])
138 Pleroma.Config.put([:instance, :mrf_transparency], true)
140 exclusions = Pleroma.Config.get([:instance, :mrf_transparency_exclusions])
141 Pleroma.Config.put([:instance, :mrf_transparency_exclusions], ["other.site"])
143 simple_config = %{"reject" => ["example.com", "other.site"]}
144 expected_config = %{"reject" => ["example.com"]}
146 Pleroma.Config.put(:mrf_simple, simple_config)
150 |> get("/nodeinfo/2.1.json")
151 |> json_response(:ok)
153 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
154 assert response["metadata"]["federation"]["exclusions"] == true
156 Pleroma.Config.put([:instance, :rewrite_policy], config)
157 Pleroma.Config.put([:instance, :mrf_transparency], option)
158 Pleroma.Config.put([:instance, :mrf_transparency_exclusions], exclusions)
159 Pleroma.Config.put(:mrf_simple, %{})