logo

pleroma

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

anti_followbot_policy_test.exs (3133B)


  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.AntiFollowbotPolicyTest do
  5. use Pleroma.DataCase, async: true
  6. import Pleroma.Factory
  7. alias Pleroma.User
  8. alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy
  9. describe "blocking based on attributes" do
  10. test "matches followbots by nickname" do
  11. actor = insert(:user, %{nickname: "followbot@example.com"})
  12. target = insert(:user)
  13. message = %{
  14. "@context" => "https://www.w3.org/ns/activitystreams",
  15. "type" => "Follow",
  16. "actor" => actor.ap_id,
  17. "object" => target.ap_id,
  18. "id" => "https://example.com/activities/1234"
  19. }
  20. assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
  21. end
  22. test "matches followbots by display name" do
  23. actor = insert(:user, %{name: "Federation Bot"})
  24. target = insert(:user)
  25. message = %{
  26. "@context" => "https://www.w3.org/ns/activitystreams",
  27. "type" => "Follow",
  28. "actor" => actor.ap_id,
  29. "object" => target.ap_id,
  30. "id" => "https://example.com/activities/1234"
  31. }
  32. assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
  33. end
  34. test "matches followbots by actor_type" do
  35. actor = insert(:user, %{actor_type: "Service"})
  36. target = insert(:user)
  37. message = %{
  38. "@context" => "https://www.w3.org/ns/activitystreams",
  39. "type" => "Follow",
  40. "actor" => actor.ap_id,
  41. "object" => target.ap_id,
  42. "id" => "https://example.com/activities/1234"
  43. }
  44. assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
  45. end
  46. end
  47. describe "it allows" do
  48. test "non-followbots" do
  49. actor = insert(:user)
  50. target = insert(:user)
  51. message = %{
  52. "@context" => "https://www.w3.org/ns/activitystreams",
  53. "type" => "Follow",
  54. "actor" => actor.ap_id,
  55. "object" => target.ap_id,
  56. "id" => "https://example.com/activities/1234"
  57. }
  58. {:ok, _} = AntiFollowbotPolicy.filter(message)
  59. end
  60. test "bots if the target follows the bots" do
  61. actor = insert(:user, %{actor_type: "Service"})
  62. target = insert(:user)
  63. User.follow(target, actor)
  64. message = %{
  65. "@context" => "https://www.w3.org/ns/activitystreams",
  66. "type" => "Follow",
  67. "actor" => actor.ap_id,
  68. "object" => target.ap_id,
  69. "id" => "https://example.com/activities/1234"
  70. }
  71. {:ok, _} = AntiFollowbotPolicy.filter(message)
  72. end
  73. end
  74. test "it gracefully handles nil display names" do
  75. actor = insert(:user, %{name: nil})
  76. target = insert(:user)
  77. message = %{
  78. "@context" => "https://www.w3.org/ns/activitystreams",
  79. "type" => "Follow",
  80. "actor" => actor.ap_id,
  81. "object" => target.ap_id,
  82. "id" => "https://example.com/activities/1234"
  83. }
  84. {:ok, _} = AntiFollowbotPolicy.filter(message)
  85. end
  86. end