Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.8KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 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. test "GET /.well-known/nodeinfo", %{conn: conn} do
  8. links =
  9. conn
  10. |> get("/.well-known/nodeinfo")
  11. |> json_response(200)
  12. |> Map.fetch!("links")
  13. Enum.each(links, fn link ->
  14. href = Map.fetch!(link, "href")
  15. conn
  16. |> get(href)
  17. |> json_response(200)
  18. end)
  19. end
  20. test "nodeinfo shows staff accounts", %{conn: conn} do
  21. moderator = insert(:user, %{local: true, info: %{is_moderator: true}})
  22. admin = insert(:user, %{local: true, info: %{is_admin: true}})
  23. conn =
  24. conn
  25. |> get("/nodeinfo/2.1.json")
  26. assert result = json_response(conn, 200)
  27. assert moderator.ap_id in result["metadata"]["staffAccounts"]
  28. assert admin.ap_id in result["metadata"]["staffAccounts"]
  29. end
  30. test "nodeinfo shows restricted nicknames", %{conn: conn} do
  31. conn =
  32. conn
  33. |> get("/nodeinfo/2.1.json")
  34. assert result = json_response(conn, 200)
  35. assert Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) ==
  36. result["metadata"]["restrictedNicknames"]
  37. end
  38. test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
  39. conn
  40. |> get("/.well-known/nodeinfo")
  41. |> json_response(200)
  42. conn =
  43. conn
  44. |> get("/nodeinfo/2.1.json")
  45. assert result = json_response(conn, 200)
  46. assert Pleroma.Application.repository() == result["software"]["repository"]
  47. end
  48. test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
  49. option = Pleroma.Config.get([:instance, :safe_dm_mentions])
  50. Pleroma.Config.put([:instance, :safe_dm_mentions], true)
  51. response =
  52. conn
  53. |> get("/nodeinfo/2.1.json")
  54. |> json_response(:ok)
  55. assert "safe_dm_mentions" in response["metadata"]["features"]
  56. Pleroma.Config.put([:instance, :safe_dm_mentions], false)
  57. response =
  58. conn
  59. |> get("/nodeinfo/2.1.json")
  60. |> json_response(:ok)
  61. refute "safe_dm_mentions" in response["metadata"]["features"]
  62. Pleroma.Config.put([:instance, :safe_dm_mentions], option)
  63. end
  64. test "it shows MRF transparency data if enabled", %{conn: conn} do
  65. option = Pleroma.Config.get([:instance, :mrf_transparency])
  66. Pleroma.Config.put([:instance, :mrf_transparency], true)
  67. simple_config = %{"reject" => ["example.com"]}
  68. Pleroma.Config.put(:mrf_simple, simple_config)
  69. response =
  70. conn
  71. |> get("/nodeinfo/2.1.json")
  72. |> json_response(:ok)
  73. assert response["metadata"]["federation"]["mrf_simple"] == simple_config
  74. Pleroma.Config.put([:instance, :mrf_transparency], option)
  75. Pleroma.Config.put(:mrf_simple, %{})
  76. end
  77. test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
  78. option = Pleroma.Config.get([:instance, :mrf_transparency])
  79. Pleroma.Config.put([:instance, :mrf_transparency], true)
  80. exclusions = Pleroma.Config.get([:instance, :mrf_transparency_exclusions])
  81. Pleroma.Config.put([:instance, :mrf_transparency_exclusions], ["other.site"])
  82. simple_config = %{"reject" => ["example.com", "other.site"]}
  83. expected_config = %{"reject" => ["example.com"]}
  84. Pleroma.Config.put(:mrf_simple, simple_config)
  85. response =
  86. conn
  87. |> get("/nodeinfo/2.1.json")
  88. |> json_response(:ok)
  89. assert response["metadata"]["federation"]["mrf_simple"] == expected_config
  90. assert response["metadata"]["federation"]["exclusions"] == true
  91. Pleroma.Config.put([:instance, :mrf_transparency], option)
  92. Pleroma.Config.put([:instance, :mrf_transparency_exclusions], exclusions)
  93. Pleroma.Config.put(:mrf_simple, %{})
  94. end
  95. end