logo

pleroma

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

no_empty_policy_test.exs (5619B)


  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.NoEmptyPolicyTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy
  7. setup_all do: clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy])
  8. test "Notes with content are exempt" do
  9. message = %{
  10. "actor" => "http://localhost:4001/users/testuser",
  11. "cc" => ["http://localhost:4001/users/testuser/followers"],
  12. "object" => %{
  13. "actor" => "http://localhost:4001/users/testuser",
  14. "attachment" => [],
  15. "cc" => ["http://localhost:4001/users/testuser/followers"],
  16. "source" => "this is a test post",
  17. "to" => ["https://www.w3.org/ns/activitystreams#Public"],
  18. "type" => "Note"
  19. },
  20. "to" => ["https://www.w3.org/ns/activitystreams#Public"],
  21. "type" => "Create"
  22. }
  23. assert NoEmptyPolicy.filter(message) == {:ok, message}
  24. end
  25. test "Polls are exempt" do
  26. message = %{
  27. "actor" => "http://localhost:4001/users/testuser",
  28. "cc" => ["http://localhost:4001/users/testuser/followers"],
  29. "object" => %{
  30. "actor" => "http://localhost:4001/users/testuser",
  31. "attachment" => [],
  32. "cc" => ["http://localhost:4001/users/testuser/followers"],
  33. "oneOf" => [
  34. %{
  35. "name" => "chocolate",
  36. "replies" => %{"totalItems" => 0, "type" => "Collection"},
  37. "type" => "Note"
  38. },
  39. %{
  40. "name" => "vanilla",
  41. "replies" => %{"totalItems" => 0, "type" => "Collection"},
  42. "type" => "Note"
  43. }
  44. ],
  45. "source" => "@user2",
  46. "to" => [
  47. "https://www.w3.org/ns/activitystreams#Public",
  48. "http://localhost:4001/users/user2"
  49. ],
  50. "type" => "Question"
  51. },
  52. "to" => [
  53. "https://www.w3.org/ns/activitystreams#Public",
  54. "http://localhost:4001/users/user2"
  55. ],
  56. "type" => "Create"
  57. }
  58. assert NoEmptyPolicy.filter(message) == {:ok, message}
  59. end
  60. test "Notes with attachments are exempt" do
  61. message = %{
  62. "actor" => "http://localhost:4001/users/testuser",
  63. "cc" => ["http://localhost:4001/users/testuser/followers"],
  64. "object" => %{
  65. "actor" => "http://localhost:4001/users/testuser",
  66. "attachment" => [
  67. %{
  68. "actor" => "http://localhost:4001/users/testuser",
  69. "mediaType" => "image/png",
  70. "name" => "",
  71. "type" => "Document",
  72. "url" => [
  73. %{
  74. "href" =>
  75. "http://localhost:4001/media/68ba231cf12e1382ce458f1979969f8ed5cc07ba198a02e653464abaf39bdb90.png",
  76. "mediaType" => "image/png",
  77. "type" => "Link"
  78. }
  79. ]
  80. }
  81. ],
  82. "cc" => ["http://localhost:4001/users/testuser/followers"],
  83. "source" => "@user2",
  84. "to" => [
  85. "https://www.w3.org/ns/activitystreams#Public",
  86. "http://localhost:4001/users/user2"
  87. ],
  88. "type" => "Note"
  89. },
  90. "to" => [
  91. "https://www.w3.org/ns/activitystreams#Public",
  92. "http://localhost:4001/users/user2"
  93. ],
  94. "type" => "Create"
  95. }
  96. assert NoEmptyPolicy.filter(message) == {:ok, message}
  97. end
  98. test "Notes with only mentions are denied" do
  99. message = %{
  100. "actor" => "http://localhost:4001/users/testuser",
  101. "cc" => ["http://localhost:4001/users/testuser/followers"],
  102. "object" => %{
  103. "actor" => "http://localhost:4001/users/testuser",
  104. "attachment" => [],
  105. "cc" => ["http://localhost:4001/users/testuser/followers"],
  106. "source" => "@user2",
  107. "to" => [
  108. "https://www.w3.org/ns/activitystreams#Public",
  109. "http://localhost:4001/users/user2"
  110. ],
  111. "type" => "Note"
  112. },
  113. "to" => [
  114. "https://www.w3.org/ns/activitystreams#Public",
  115. "http://localhost:4001/users/user2"
  116. ],
  117. "type" => "Create"
  118. }
  119. assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
  120. end
  121. test "Notes with no content are denied" do
  122. message = %{
  123. "actor" => "http://localhost:4001/users/testuser",
  124. "cc" => ["http://localhost:4001/users/testuser/followers"],
  125. "object" => %{
  126. "actor" => "http://localhost:4001/users/testuser",
  127. "attachment" => [],
  128. "cc" => ["http://localhost:4001/users/testuser/followers"],
  129. "source" => "",
  130. "to" => [
  131. "https://www.w3.org/ns/activitystreams#Public"
  132. ],
  133. "type" => "Note"
  134. },
  135. "to" => [
  136. "https://www.w3.org/ns/activitystreams#Public"
  137. ],
  138. "type" => "Create"
  139. }
  140. assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
  141. end
  142. test "works with Update" do
  143. message = %{
  144. "actor" => "http://localhost:4001/users/testuser",
  145. "cc" => ["http://localhost:4001/users/testuser/followers"],
  146. "object" => %{
  147. "actor" => "http://localhost:4001/users/testuser",
  148. "attachment" => [],
  149. "cc" => ["http://localhost:4001/users/testuser/followers"],
  150. "source" => "",
  151. "to" => [
  152. "https://www.w3.org/ns/activitystreams#Public"
  153. ],
  154. "type" => "Note"
  155. },
  156. "to" => [
  157. "https://www.w3.org/ns/activitystreams#Public"
  158. ],
  159. "type" => "Update"
  160. }
  161. assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
  162. end
  163. end