logo

pleroma

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

hellthread_policy_test.exs (2710B)


  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.HellthreadPolicyTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
  8. alias Pleroma.Web.CommonAPI
  9. setup do
  10. user = insert(:user)
  11. message = %{
  12. "actor" => user.ap_id,
  13. "cc" => [user.follower_address],
  14. "type" => "Create",
  15. "to" => [
  16. "https://www.w3.org/ns/activitystreams#Public",
  17. "https://instance.tld/users/user1",
  18. "https://instance.tld/users/user2",
  19. "https://instance.tld/users/user3"
  20. ],
  21. "object" => %{
  22. "type" => "Note"
  23. }
  24. }
  25. [user: user, message: message]
  26. end
  27. setup do: clear_config(:mrf_hellthread)
  28. test "doesn't die on chat messages" do
  29. clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
  30. user = insert(:user)
  31. other_user = insert(:user)
  32. {:ok, activity} = CommonAPI.post_chat_message(user, other_user, "moin")
  33. assert {:ok, _} = filter(activity.data)
  34. end
  35. describe "reject" do
  36. test "rejects the message if the recipient count is above reject_threshold", %{
  37. message: message
  38. } do
  39. clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
  40. assert {:reject, "[HellthreadPolicy] 3 recipients is over the limit of 2"} ==
  41. filter(message)
  42. end
  43. test "does not reject the message if the recipient count is below reject_threshold", %{
  44. message: message
  45. } do
  46. clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
  47. assert {:ok, ^message} = filter(message)
  48. end
  49. end
  50. describe "delist" do
  51. test "delists the message if the recipient count is above delist_threshold", %{
  52. user: user,
  53. message: message
  54. } do
  55. clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
  56. {:ok, message} = filter(message)
  57. assert user.follower_address in message["to"]
  58. assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
  59. end
  60. test "does not delist the message if the recipient count is below delist_threshold", %{
  61. message: message
  62. } do
  63. clear_config([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
  64. assert {:ok, ^message} = filter(message)
  65. end
  66. end
  67. test "excludes follower collection and public URI from threshold count", %{message: message} do
  68. clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
  69. assert {:ok, ^message} = filter(message)
  70. end
  71. end