Merge branch 'develop' into issue/1276
[akkoma] / test / web / node_info_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.NodeInfoTest do
6 use Pleroma.Web.ConnCase
7
8 import Pleroma.Factory
9
10 test "GET /.well-known/nodeinfo", %{conn: conn} do
11 links =
12 conn
13 |> get("/.well-known/nodeinfo")
14 |> json_response(200)
15 |> Map.fetch!("links")
16
17 Enum.each(links, fn link ->
18 href = Map.fetch!(link, "href")
19
20 conn
21 |> get(href)
22 |> json_response(200)
23 end)
24 end
25
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)
29
30 conn =
31 conn
32 |> get("/nodeinfo/2.1.json")
33
34 assert result = json_response(conn, 200)
35
36 assert moderator.ap_id in result["metadata"]["staffAccounts"]
37 assert admin.ap_id in result["metadata"]["staffAccounts"]
38 end
39
40 test "nodeinfo shows restricted nicknames", %{conn: conn} do
41 conn =
42 conn
43 |> get("/nodeinfo/2.1.json")
44
45 assert result = json_response(conn, 200)
46
47 assert Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) ==
48 result["metadata"]["restrictedNicknames"]
49 end
50
51 test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
52 conn
53 |> get("/.well-known/nodeinfo")
54 |> json_response(200)
55
56 conn =
57 conn
58 |> get("/nodeinfo/2.1.json")
59
60 assert result = json_response(conn, 200)
61 assert Pleroma.Application.repository() == result["software"]["repository"]
62 end
63
64 test "returns fieldsLimits field", %{conn: conn} do
65 max_account_fields = Pleroma.Config.get([:instance, :max_account_fields])
66 max_remote_account_fields = Pleroma.Config.get([:instance, :max_remote_account_fields])
67 account_field_name_length = Pleroma.Config.get([:instance, :account_field_name_length])
68 account_field_value_length = Pleroma.Config.get([:instance, :account_field_value_length])
69
70 Pleroma.Config.put([:instance, :max_account_fields], 10)
71 Pleroma.Config.put([:instance, :max_remote_account_fields], 15)
72 Pleroma.Config.put([:instance, :account_field_name_length], 255)
73 Pleroma.Config.put([:instance, :account_field_value_length], 2048)
74
75 response =
76 conn
77 |> get("/nodeinfo/2.1.json")
78 |> json_response(:ok)
79
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
84
85 Pleroma.Config.put([:instance, :max_account_fields], max_account_fields)
86 Pleroma.Config.put([:instance, :max_remote_account_fields], max_remote_account_fields)
87 Pleroma.Config.put([:instance, :account_field_name_length], account_field_name_length)
88 Pleroma.Config.put([:instance, :account_field_value_length], account_field_value_length)
89 end
90
91 test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
92 option = Pleroma.Config.get([:instance, :safe_dm_mentions])
93 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
94
95 response =
96 conn
97 |> get("/nodeinfo/2.1.json")
98 |> json_response(:ok)
99
100 assert "safe_dm_mentions" in response["metadata"]["features"]
101
102 Pleroma.Config.put([:instance, :safe_dm_mentions], false)
103
104 response =
105 conn
106 |> get("/nodeinfo/2.1.json")
107 |> json_response(:ok)
108
109 refute "safe_dm_mentions" in response["metadata"]["features"]
110
111 Pleroma.Config.put([:instance, :safe_dm_mentions], option)
112 end
113
114 test "it shows if federation is enabled/disabled", %{conn: conn} do
115 original = Pleroma.Config.get([:instance, :federating])
116
117 Pleroma.Config.put([:instance, :federating], true)
118
119 response =
120 conn
121 |> get("/nodeinfo/2.1.json")
122 |> json_response(:ok)
123
124 assert response["metadata"]["federation"]["enabled"] == true
125
126 Pleroma.Config.put([:instance, :federating], false)
127
128 response =
129 conn
130 |> get("/nodeinfo/2.1.json")
131 |> json_response(:ok)
132
133 assert response["metadata"]["federation"]["enabled"] == false
134
135 Pleroma.Config.put([:instance, :federating], original)
136 end
137
138 test "it shows MRF transparency data if enabled", %{conn: conn} do
139 config = Pleroma.Config.get([:instance, :rewrite_policy])
140 Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
141
142 option = Pleroma.Config.get([:instance, :mrf_transparency])
143 Pleroma.Config.put([:instance, :mrf_transparency], true)
144
145 simple_config = %{"reject" => ["example.com"]}
146 Pleroma.Config.put(:mrf_simple, simple_config)
147
148 response =
149 conn
150 |> get("/nodeinfo/2.1.json")
151 |> json_response(:ok)
152
153 assert response["metadata"]["federation"]["mrf_simple"] == simple_config
154
155 Pleroma.Config.put([:instance, :rewrite_policy], config)
156 Pleroma.Config.put([:instance, :mrf_transparency], option)
157 Pleroma.Config.put(:mrf_simple, %{})
158 end
159
160 test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
161 config = Pleroma.Config.get([:instance, :rewrite_policy])
162 Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
163
164 option = Pleroma.Config.get([:instance, :mrf_transparency])
165 Pleroma.Config.put([:instance, :mrf_transparency], true)
166
167 exclusions = Pleroma.Config.get([:instance, :mrf_transparency_exclusions])
168 Pleroma.Config.put([:instance, :mrf_transparency_exclusions], ["other.site"])
169
170 simple_config = %{"reject" => ["example.com", "other.site"]}
171 expected_config = %{"reject" => ["example.com"]}
172
173 Pleroma.Config.put(:mrf_simple, simple_config)
174
175 response =
176 conn
177 |> get("/nodeinfo/2.1.json")
178 |> json_response(:ok)
179
180 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
181 assert response["metadata"]["federation"]["exclusions"] == true
182
183 Pleroma.Config.put([:instance, :rewrite_policy], config)
184 Pleroma.Config.put([:instance, :mrf_transparency], option)
185 Pleroma.Config.put([:instance, :mrf_transparency_exclusions], exclusions)
186 Pleroma.Config.put(:mrf_simple, %{})
187 end
188 end