logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

node_info_test.exs (8490B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.NodeInfoTest do
  5. use Pleroma.Web.ConnCase, async: false
  6. import Pleroma.Factory
  7. setup do: clear_config([:mrf_simple])
  8. setup do: clear_config(:instance)
  9. test "GET /.well-known/nodeinfo", %{conn: conn} do
  10. links =
  11. conn
  12. |> get("/.well-known/nodeinfo")
  13. |> json_response(200)
  14. |> Map.fetch!("links")
  15. Enum.each(links, fn link ->
  16. href = Map.fetch!(link, "href")
  17. conn
  18. |> get(href)
  19. |> json_response(200)
  20. end)
  21. accept_types = [
  22. "application/activity+json",
  23. "application/json",
  24. "application/jrd+json"
  25. ]
  26. for type <- accept_types do
  27. conn
  28. |> put_req_header("accept", type)
  29. |> get("/.well-known/nodeinfo")
  30. |> json_response(200)
  31. end
  32. end
  33. test "nodeinfo shows staff accounts", %{conn: conn} do
  34. moderator = insert(:user, local: true, is_moderator: true)
  35. admin = insert(:user, local: true, is_admin: true)
  36. conn =
  37. conn
  38. |> get("/nodeinfo/2.1.json")
  39. assert result = json_response(conn, 200)
  40. assert moderator.ap_id in result["metadata"]["staffAccounts"]
  41. assert admin.ap_id in result["metadata"]["staffAccounts"]
  42. end
  43. test "nodeinfo shows roles and privileges", %{conn: conn} do
  44. clear_config([:instance, :moderator_privileges], [:cofe])
  45. clear_config([:instance, :admin_privileges], [:suya, :cofe])
  46. conn =
  47. conn
  48. |> get("/nodeinfo/2.1.json")
  49. assert result = json_response(conn, 200)
  50. assert %{"admin" => ["suya", "cofe"], "moderator" => ["cofe"]} == result["metadata"]["roles"]
  51. end
  52. test "nodeinfo shows restricted nicknames", %{conn: conn} do
  53. conn =
  54. conn
  55. |> get("/nodeinfo/2.1.json")
  56. assert result = json_response(conn, 200)
  57. assert Config.get([Pleroma.User, :restricted_nicknames]) ==
  58. result["metadata"]["restrictedNicknames"]
  59. end
  60. test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
  61. conn
  62. |> get("/.well-known/nodeinfo")
  63. |> json_response(200)
  64. conn =
  65. conn
  66. |> get("/nodeinfo/2.1.json")
  67. assert result = json_response(conn, 200)
  68. assert Pleroma.Application.repository() == result["software"]["repository"]
  69. end
  70. test "returns fieldsLimits field", %{conn: conn} do
  71. clear_config([:instance, :max_account_fields], 10)
  72. clear_config([:instance, :max_remote_account_fields], 15)
  73. clear_config([:instance, :account_field_name_length], 255)
  74. clear_config([:instance, :account_field_value_length], 2048)
  75. response =
  76. conn
  77. |> get("/nodeinfo/2.1.json")
  78. |> json_response(:ok)
  79. assert response["metadata"]["fieldsLimits"]["maxFields"] == 10
  80. assert response["metadata"]["fieldsLimits"]["maxRemoteFields"] == 15
  81. assert response["metadata"]["fieldsLimits"]["nameLength"] == 255
  82. assert response["metadata"]["fieldsLimits"]["valueLength"] == 2048
  83. end
  84. test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
  85. clear_config([:instance, :safe_dm_mentions], true)
  86. response =
  87. conn
  88. |> get("/nodeinfo/2.1.json")
  89. |> json_response(:ok)
  90. assert "safe_dm_mentions" in response["metadata"]["features"]
  91. clear_config([:instance, :safe_dm_mentions], false)
  92. response =
  93. conn
  94. |> get("/nodeinfo/2.1.json")
  95. |> json_response(:ok)
  96. refute "safe_dm_mentions" in response["metadata"]["features"]
  97. end
  98. describe "`metadata/federation/enabled`" do
  99. setup do: clear_config([:instance, :federating])
  100. test "it shows if federation is enabled/disabled", %{conn: conn} do
  101. clear_config([:instance, :federating], true)
  102. response =
  103. conn
  104. |> get("/nodeinfo/2.1.json")
  105. |> json_response(:ok)
  106. assert response["metadata"]["federation"]["enabled"] == true
  107. clear_config([:instance, :federating], false)
  108. response =
  109. conn
  110. |> get("/nodeinfo/2.1.json")
  111. |> json_response(:ok)
  112. assert response["metadata"]["federation"]["enabled"] == false
  113. end
  114. end
  115. test "it shows default features flags", %{conn: conn} do
  116. response =
  117. conn
  118. |> get("/nodeinfo/2.1.json")
  119. |> json_response(:ok)
  120. default_features = [
  121. "pleroma_api",
  122. "mastodon_api",
  123. "mastodon_api_streaming",
  124. "polls",
  125. "pleroma_explicit_addressing",
  126. "shareable_emoji_packs",
  127. "multifetch",
  128. "pleroma_emoji_reactions",
  129. "pleroma:api/v1/notifications:include_types_filter",
  130. "pleroma_chat_messages"
  131. ]
  132. assert MapSet.subset?(
  133. MapSet.new(default_features),
  134. MapSet.new(response["metadata"]["features"])
  135. )
  136. end
  137. describe "Quarantined instances" do
  138. setup do
  139. clear_config([:mrf, :transparency], true)
  140. quarantined_instances = [{"example.com", "reason to quarantine"}]
  141. clear_config([:instance, :quarantined_instances], quarantined_instances)
  142. end
  143. test "shows quarantined instances data if enabled", %{conn: conn} do
  144. expected_config = ["example.com"]
  145. response =
  146. conn
  147. |> get("/nodeinfo/2.1.json")
  148. |> json_response(:ok)
  149. assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
  150. end
  151. test "shows extra information in the quarantined_info field for relevant entries", %{
  152. conn: conn
  153. } do
  154. clear_config([:mrf, :transparency], true)
  155. expected_config = %{
  156. "quarantined_instances" => %{
  157. "example.com" => %{"reason" => "reason to quarantine"}
  158. }
  159. }
  160. response =
  161. conn
  162. |> get("/nodeinfo/2.1.json")
  163. |> json_response(:ok)
  164. assert response["metadata"]["federation"]["quarantined_instances_info"] == expected_config
  165. end
  166. end
  167. describe "MRF SimplePolicy" do
  168. setup do
  169. clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
  170. clear_config([:mrf, :transparency], true)
  171. end
  172. test "shows MRF transparency data if enabled", %{conn: conn} do
  173. simple_config = %{"reject" => [{"example.com", ""}]}
  174. clear_config(:mrf_simple, simple_config)
  175. expected_config = %{"reject" => ["example.com"]}
  176. response =
  177. conn
  178. |> get("/nodeinfo/2.1.json")
  179. |> json_response(:ok)
  180. assert response["metadata"]["federation"]["mrf_simple"] == expected_config
  181. end
  182. test "performs exclusions from MRF transparency data if configured", %{conn: conn} do
  183. clear_config([:mrf, :transparency_exclusions], [
  184. {"other.site", "We don't want them to know"}
  185. ])
  186. simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
  187. clear_config(:mrf_simple, simple_config)
  188. expected_config = %{"reject" => ["example.com"]}
  189. response =
  190. conn
  191. |> get("/nodeinfo/2.1.json")
  192. |> json_response(:ok)
  193. assert response["metadata"]["federation"]["mrf_simple"] == expected_config
  194. assert response["metadata"]["federation"]["exclusions"] == true
  195. end
  196. test "shows extra information in the mrf_simple_info field for relevant entries", %{
  197. conn: conn
  198. } do
  199. simple_config = %{
  200. media_removal: [{"no.media", "LEEWWWDD >//<"}],
  201. media_nsfw: [],
  202. federated_timeline_removal: [{"no.ftl", ""}],
  203. report_removal: [],
  204. reject: [
  205. {"example.instance", "Some reason"},
  206. {"uwu.owo", "awoo to much"},
  207. {"no.reason", ""}
  208. ],
  209. followers_only: [],
  210. accept: [],
  211. avatar_removal: [],
  212. banner_removal: [],
  213. reject_deletes: [
  214. {"peak.me", "I want to peak at what they don't want me to see, eheh"}
  215. ]
  216. }
  217. clear_config(:mrf_simple, simple_config)
  218. clear_config([:mrf, :transparency_exclusions], [
  219. {"peak.me", "I don't want them to know"}
  220. ])
  221. expected_config = %{
  222. "media_removal" => %{
  223. "no.media" => %{"reason" => "LEEWWWDD >//<"}
  224. },
  225. "reject" => %{
  226. "example.instance" => %{"reason" => "Some reason"},
  227. "uwu.owo" => %{"reason" => "awoo to much"}
  228. }
  229. }
  230. response =
  231. conn
  232. |> get("/nodeinfo/2.1.json")
  233. |> json_response(:ok)
  234. assert response["metadata"]["federation"]["mrf_simple_info"] == expected_config
  235. end
  236. end
  237. end