logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

anti_followbot_policy_test.exs (2114B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 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
  6. import Pleroma.Factory
  7. alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy
  8. describe "blocking based on attributes" do
  9. test "matches followbots by nickname" do
  10. actor = insert(:user, %{nickname: "followbot@example.com"})
  11. target = insert(:user)
  12. message = %{
  13. "@context" => "https://www.w3.org/ns/activitystreams",
  14. "type" => "Follow",
  15. "actor" => actor.ap_id,
  16. "object" => target.ap_id,
  17. "id" => "https://example.com/activities/1234"
  18. }
  19. assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
  20. end
  21. test "matches followbots by display name" do
  22. actor = insert(:user, %{name: "Federation Bot"})
  23. target = insert(:user)
  24. message = %{
  25. "@context" => "https://www.w3.org/ns/activitystreams",
  26. "type" => "Follow",
  27. "actor" => actor.ap_id,
  28. "object" => target.ap_id,
  29. "id" => "https://example.com/activities/1234"
  30. }
  31. assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
  32. end
  33. end
  34. test "it allows non-followbots" do
  35. actor = insert(:user)
  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. {:ok, _} = AntiFollowbotPolicy.filter(message)
  45. end
  46. test "it gracefully handles nil display names" do
  47. actor = insert(:user, %{name: nil})
  48. target = insert(:user)
  49. message = %{
  50. "@context" => "https://www.w3.org/ns/activitystreams",
  51. "type" => "Follow",
  52. "actor" => actor.ap_id,
  53. "object" => target.ap_id,
  54. "id" => "https://example.com/activities/1234"
  55. }
  56. {:ok, _} = AntiFollowbotPolicy.filter(message)
  57. end
  58. end