logo

pleroma

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

mention_policy_test.exs (2539B)


  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.MentionPolicyTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Web.ActivityPub.MRF.MentionPolicy
  7. setup do: clear_config(:mrf_mention)
  8. test "pass filter if allow list is empty" do
  9. Pleroma.Config.delete([:mrf_mention])
  10. message = %{
  11. "type" => "Create",
  12. "to" => ["https://example.com/ok"],
  13. "cc" => ["https://example.com/blocked"]
  14. }
  15. assert MentionPolicy.filter(message) == {:ok, message}
  16. end
  17. describe "allow" do
  18. test "empty" do
  19. Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
  20. message = %{
  21. "type" => "Create"
  22. }
  23. assert MentionPolicy.filter(message) == {:ok, message}
  24. end
  25. test "to" do
  26. Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
  27. message = %{
  28. "type" => "Create",
  29. "to" => ["https://example.com/ok"]
  30. }
  31. assert MentionPolicy.filter(message) == {:ok, message}
  32. end
  33. test "cc" do
  34. Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
  35. message = %{
  36. "type" => "Create",
  37. "cc" => ["https://example.com/ok"]
  38. }
  39. assert MentionPolicy.filter(message) == {:ok, message}
  40. end
  41. test "both" do
  42. Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
  43. message = %{
  44. "type" => "Create",
  45. "to" => ["https://example.com/ok"],
  46. "cc" => ["https://example.com/ok2"]
  47. }
  48. assert MentionPolicy.filter(message) == {:ok, message}
  49. end
  50. end
  51. describe "deny" do
  52. test "to" do
  53. Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
  54. message = %{
  55. "type" => "Create",
  56. "to" => ["https://example.com/blocked"]
  57. }
  58. assert MentionPolicy.filter(message) ==
  59. {:reject, "[MentionPolicy] Rejected for mention of https://example.com/blocked"}
  60. end
  61. test "cc" do
  62. Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
  63. message = %{
  64. "type" => "Create",
  65. "to" => ["https://example.com/ok"],
  66. "cc" => ["https://example.com/blocked"]
  67. }
  68. assert MentionPolicy.filter(message) ==
  69. {:reject, "[MentionPolicy] Rejected for mention of https://example.com/blocked"}
  70. end
  71. end
  72. end