logo

pleroma

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

tag_policy_test.exs (4825B)


  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.ActivityPub.MRF.TagPolicyTest do
  5. use Pleroma.DataCase, async: true
  6. import Pleroma.Factory
  7. alias Pleroma.Web.ActivityPub.MRF.TagPolicy
  8. @public "https://www.w3.org/ns/activitystreams#Public"
  9. describe "mrf_tag:disable-any-subscription" do
  10. test "rejects message" do
  11. actor = insert(:user, tags: ["mrf_tag:disable-any-subscription"])
  12. message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => actor.ap_id}
  13. assert {:reject, _} = TagPolicy.filter(message)
  14. end
  15. end
  16. describe "mrf_tag:disable-remote-subscription" do
  17. test "rejects non-local follow requests" do
  18. actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])
  19. follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: false)
  20. message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id}
  21. assert {:reject, _} = TagPolicy.filter(message)
  22. end
  23. test "allows non-local follow requests" do
  24. actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])
  25. follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: true)
  26. message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id}
  27. assert {:ok, _message} = TagPolicy.filter(message)
  28. end
  29. end
  30. describe "mrf_tag:sandbox" do
  31. test "removes from public timelines" do
  32. actor = insert(:user, tags: ["mrf_tag:sandbox"])
  33. message = %{
  34. "actor" => actor.ap_id,
  35. "type" => "Create",
  36. "object" => %{},
  37. "to" => [@public, "f"],
  38. "cc" => [@public, "d"]
  39. }
  40. except_message = %{
  41. "actor" => actor.ap_id,
  42. "type" => "Create",
  43. "object" => %{"to" => ["f", actor.follower_address], "cc" => ["d"]},
  44. "to" => ["f", actor.follower_address],
  45. "cc" => ["d"]
  46. }
  47. assert TagPolicy.filter(message) == {:ok, except_message}
  48. end
  49. end
  50. describe "mrf_tag:force-unlisted" do
  51. test "removes from the federated timeline" do
  52. actor = insert(:user, tags: ["mrf_tag:force-unlisted"])
  53. message = %{
  54. "actor" => actor.ap_id,
  55. "type" => "Create",
  56. "object" => %{},
  57. "to" => [@public, "f"],
  58. "cc" => [actor.follower_address, "d"]
  59. }
  60. except_message = %{
  61. "actor" => actor.ap_id,
  62. "type" => "Create",
  63. "object" => %{"to" => ["f", actor.follower_address], "cc" => ["d", @public]},
  64. "to" => ["f", actor.follower_address],
  65. "cc" => ["d", @public]
  66. }
  67. assert TagPolicy.filter(message) == {:ok, except_message}
  68. end
  69. end
  70. describe "mrf_tag:media-strip" do
  71. test "removes attachments" do
  72. actor = insert(:user, tags: ["mrf_tag:media-strip"])
  73. message = %{
  74. "actor" => actor.ap_id,
  75. "type" => "Create",
  76. "object" => %{"attachment" => ["file1"]}
  77. }
  78. except_message = %{
  79. "actor" => actor.ap_id,
  80. "type" => "Create",
  81. "object" => %{}
  82. }
  83. assert TagPolicy.filter(message) == {:ok, except_message}
  84. end
  85. test "removes attachments in Updates" do
  86. actor = insert(:user, tags: ["mrf_tag:media-strip"])
  87. message = %{
  88. "actor" => actor.ap_id,
  89. "type" => "Update",
  90. "object" => %{"attachment" => ["file1"]}
  91. }
  92. except_message = %{
  93. "actor" => actor.ap_id,
  94. "type" => "Update",
  95. "object" => %{}
  96. }
  97. assert TagPolicy.filter(message) == {:ok, except_message}
  98. end
  99. end
  100. describe "mrf_tag:media-force-nsfw" do
  101. test "Mark as sensitive on presence of attachments" do
  102. actor = insert(:user, tags: ["mrf_tag:media-force-nsfw"])
  103. message = %{
  104. "actor" => actor.ap_id,
  105. "type" => "Create",
  106. "object" => %{"tag" => ["test"], "attachment" => ["file1"]}
  107. }
  108. except_message = %{
  109. "actor" => actor.ap_id,
  110. "type" => "Create",
  111. "object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
  112. }
  113. assert TagPolicy.filter(message) == {:ok, except_message}
  114. end
  115. test "Mark as sensitive on presence of attachments in Updates" do
  116. actor = insert(:user, tags: ["mrf_tag:media-force-nsfw"])
  117. message = %{
  118. "actor" => actor.ap_id,
  119. "type" => "Update",
  120. "object" => %{"tag" => ["test"], "attachment" => ["file1"]}
  121. }
  122. except_message = %{
  123. "actor" => actor.ap_id,
  124. "type" => "Update",
  125. "object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
  126. }
  127. assert TagPolicy.filter(message) == {:ok, except_message}
  128. end
  129. end
  130. end