logo

pleroma

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

follow_bot_policy_test.exs (4045B)


  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.FollowBotPolicyTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.User
  7. alias Pleroma.Web.ActivityPub.MRF.FollowBotPolicy
  8. import Pleroma.Factory
  9. describe "FollowBotPolicy" do
  10. test "follows remote users" do
  11. bot = insert(:user, actor_type: "Service")
  12. remote_user = insert(:user, local: false)
  13. clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
  14. message = %{
  15. "@context" => "https://www.w3.org/ns/activitystreams",
  16. "to" => [remote_user.follower_address],
  17. "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
  18. "type" => "Create",
  19. "object" => %{
  20. "content" => "Test post",
  21. "type" => "Note",
  22. "attributedTo" => remote_user.ap_id,
  23. "inReplyTo" => nil
  24. },
  25. "actor" => remote_user.ap_id
  26. }
  27. refute User.following?(bot, remote_user)
  28. assert User.get_follow_requests(remote_user) |> length == 0
  29. FollowBotPolicy.filter(message)
  30. assert User.get_follow_requests(remote_user) |> length == 1
  31. end
  32. test "does not follow users with #nobot in bio" do
  33. bot = insert(:user, actor_type: "Service")
  34. remote_user = insert(:user, %{local: false, bio: "go away bots! #nobot"})
  35. clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
  36. message = %{
  37. "@context" => "https://www.w3.org/ns/activitystreams",
  38. "to" => [remote_user.follower_address],
  39. "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
  40. "type" => "Create",
  41. "object" => %{
  42. "content" => "I don't like follow bots",
  43. "type" => "Note",
  44. "attributedTo" => remote_user.ap_id,
  45. "inReplyTo" => nil
  46. },
  47. "actor" => remote_user.ap_id
  48. }
  49. refute User.following?(bot, remote_user)
  50. assert User.get_follow_requests(remote_user) |> length == 0
  51. FollowBotPolicy.filter(message)
  52. assert User.get_follow_requests(remote_user) |> length == 0
  53. end
  54. test "does not follow local users" do
  55. bot = insert(:user, actor_type: "Service")
  56. local_user = insert(:user, local: true)
  57. clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
  58. message = %{
  59. "@context" => "https://www.w3.org/ns/activitystreams",
  60. "to" => [local_user.follower_address],
  61. "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
  62. "type" => "Create",
  63. "object" => %{
  64. "content" => "Hi I'm a local user",
  65. "type" => "Note",
  66. "attributedTo" => local_user.ap_id,
  67. "inReplyTo" => nil
  68. },
  69. "actor" => local_user.ap_id
  70. }
  71. refute User.following?(bot, local_user)
  72. assert User.get_follow_requests(local_user) |> length == 0
  73. FollowBotPolicy.filter(message)
  74. assert User.get_follow_requests(local_user) |> length == 0
  75. end
  76. test "does not follow users requiring follower approval" do
  77. bot = insert(:user, actor_type: "Service")
  78. remote_user = insert(:user, %{local: false, is_locked: true})
  79. clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
  80. message = %{
  81. "@context" => "https://www.w3.org/ns/activitystreams",
  82. "to" => [remote_user.follower_address],
  83. "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
  84. "type" => "Create",
  85. "object" => %{
  86. "content" => "I don't like randos following me",
  87. "type" => "Note",
  88. "attributedTo" => remote_user.ap_id,
  89. "inReplyTo" => nil
  90. },
  91. "actor" => remote_user.ap_id
  92. }
  93. refute User.following?(bot, remote_user)
  94. assert User.get_follow_requests(remote_user) |> length == 0
  95. FollowBotPolicy.filter(message)
  96. assert User.get_follow_requests(remote_user) |> length == 0
  97. end
  98. end
  99. end