logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

node_info_test.exs (5315B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.NodeInfoTest do
  5. use Pleroma.Web.ConnCase
  6. import Pleroma.Factory
  7. alias Pleroma.Config
  8. setup do: clear_config([:mrf_simple])
  9. setup do: clear_config(:instance)
  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. Enum.each(links, fn link ->
  17. href = Map.fetch!(link, "href")
  18. conn
  19. |> get(href)
  20. |> json_response(200)
  21. end)
  22. end
  23. test "nodeinfo shows staff accounts", %{conn: conn} do
  24. moderator = insert(:user, local: true, is_moderator: true)
  25. admin = insert(:user, local: true, is_admin: true)
  26. conn =
  27. conn
  28. |> get("/nodeinfo/2.1.json")
  29. assert result = json_response(conn, 200)
  30. assert moderator.ap_id in result["metadata"]["staffAccounts"]
  31. assert admin.ap_id in result["metadata"]["staffAccounts"]
  32. end
  33. test "nodeinfo shows restricted nicknames", %{conn: conn} do
  34. conn =
  35. conn
  36. |> get("/nodeinfo/2.1.json")
  37. assert result = json_response(conn, 200)
  38. assert Config.get([Pleroma.User, :restricted_nicknames]) ==
  39. result["metadata"]["restrictedNicknames"]
  40. end
  41. test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
  42. conn
  43. |> get("/.well-known/nodeinfo")
  44. |> json_response(200)
  45. conn =
  46. conn
  47. |> get("/nodeinfo/2.1.json")
  48. assert result = json_response(conn, 200)
  49. assert Pleroma.Application.repository() == result["software"]["repository"]
  50. end
  51. test "returns fieldsLimits field", %{conn: conn} do
  52. clear_config([:instance, :max_account_fields], 10)
  53. clear_config([:instance, :max_remote_account_fields], 15)
  54. clear_config([:instance, :account_field_name_length], 255)
  55. clear_config([:instance, :account_field_value_length], 2048)
  56. response =
  57. conn
  58. |> get("/nodeinfo/2.1.json")
  59. |> json_response(:ok)
  60. assert response["metadata"]["fieldsLimits"]["maxFields"] == 10
  61. assert response["metadata"]["fieldsLimits"]["maxRemoteFields"] == 15
  62. assert response["metadata"]["fieldsLimits"]["nameLength"] == 255
  63. assert response["metadata"]["fieldsLimits"]["valueLength"] == 2048
  64. end
  65. test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
  66. clear_config([:instance, :safe_dm_mentions], true)
  67. response =
  68. conn
  69. |> get("/nodeinfo/2.1.json")
  70. |> json_response(:ok)
  71. assert "safe_dm_mentions" in response["metadata"]["features"]
  72. Config.put([:instance, :safe_dm_mentions], false)
  73. response =
  74. conn
  75. |> get("/nodeinfo/2.1.json")
  76. |> json_response(:ok)
  77. refute "safe_dm_mentions" in response["metadata"]["features"]
  78. end
  79. describe "`metadata/federation/enabled`" do
  80. setup do: clear_config([:instance, :federating])
  81. test "it shows if federation is enabled/disabled", %{conn: conn} do
  82. Config.put([:instance, :federating], true)
  83. response =
  84. conn
  85. |> get("/nodeinfo/2.1.json")
  86. |> json_response(:ok)
  87. assert response["metadata"]["federation"]["enabled"] == true
  88. Config.put([:instance, :federating], false)
  89. response =
  90. conn
  91. |> get("/nodeinfo/2.1.json")
  92. |> json_response(:ok)
  93. assert response["metadata"]["federation"]["enabled"] == false
  94. end
  95. end
  96. test "it shows default features flags", %{conn: conn} do
  97. response =
  98. conn
  99. |> get("/nodeinfo/2.1.json")
  100. |> json_response(:ok)
  101. default_features = [
  102. "pleroma_api",
  103. "mastodon_api",
  104. "mastodon_api_streaming",
  105. "polls",
  106. "pleroma_explicit_addressing",
  107. "shareable_emoji_packs",
  108. "multifetch",
  109. "pleroma_emoji_reactions",
  110. "pleroma:api/v1/notifications:include_types_filter",
  111. "pleroma_chat_messages"
  112. ]
  113. assert MapSet.subset?(
  114. MapSet.new(default_features),
  115. MapSet.new(response["metadata"]["features"])
  116. )
  117. end
  118. test "it shows MRF transparency data if enabled", %{conn: conn} do
  119. clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
  120. clear_config([:mrf, :transparency], true)
  121. simple_config = %{"reject" => ["example.com"]}
  122. clear_config(:mrf_simple, simple_config)
  123. response =
  124. conn
  125. |> get("/nodeinfo/2.1.json")
  126. |> json_response(:ok)
  127. assert response["metadata"]["federation"]["mrf_simple"] == simple_config
  128. end
  129. test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
  130. clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
  131. clear_config([:mrf, :transparency], true)
  132. clear_config([:mrf, :transparency_exclusions], ["other.site"])
  133. simple_config = %{"reject" => ["example.com", "other.site"]}
  134. clear_config(:mrf_simple, simple_config)
  135. expected_config = %{"reject" => ["example.com"]}
  136. response =
  137. conn
  138. |> get("/nodeinfo/2.1.json")
  139. |> json_response(:ok)
  140. assert response["metadata"]["federation"]["mrf_simple"] == expected_config
  141. assert response["metadata"]["federation"]["exclusions"] == true
  142. end
  143. end