logo

pleroma

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

reject_non_public_test.exs (3223B)


  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.RejectNonPublicTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Web.ActivityPub.MRF.RejectNonPublic
  8. setup do: clear_config([:mrf_rejectnonpublic])
  9. describe "public message" do
  10. test "it's allowed when address is public" do
  11. actor = insert(:user, follower_address: "test-address")
  12. message = %{
  13. "actor" => actor.ap_id,
  14. "to" => ["https://www.w3.org/ns/activitystreams#Public"],
  15. "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
  16. "type" => "Create"
  17. }
  18. assert {:ok, message} = RejectNonPublic.filter(message)
  19. end
  20. test "it's allowed when cc address contain public address" do
  21. actor = insert(:user, follower_address: "test-address")
  22. message = %{
  23. "actor" => actor.ap_id,
  24. "to" => ["https://www.w3.org/ns/activitystreams#Public"],
  25. "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
  26. "type" => "Create"
  27. }
  28. assert {:ok, message} = RejectNonPublic.filter(message)
  29. end
  30. end
  31. describe "followers message" do
  32. test "it's allowed when addrer of message in the follower addresses of user and it enabled in config" do
  33. actor = insert(:user, follower_address: "test-address")
  34. message = %{
  35. "actor" => actor.ap_id,
  36. "to" => ["test-address"],
  37. "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
  38. "type" => "Create"
  39. }
  40. Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
  41. assert {:ok, message} = RejectNonPublic.filter(message)
  42. end
  43. test "it's rejected when addrer of message in the follower addresses of user and it disabled in config" do
  44. actor = insert(:user, follower_address: "test-address")
  45. message = %{
  46. "actor" => actor.ap_id,
  47. "to" => ["test-address"],
  48. "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
  49. "type" => "Create"
  50. }
  51. Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], false)
  52. assert {:reject, _} = RejectNonPublic.filter(message)
  53. end
  54. end
  55. describe "direct message" do
  56. test "it's allows when direct messages are allow" do
  57. actor = insert(:user)
  58. message = %{
  59. "actor" => actor.ap_id,
  60. "to" => ["https://www.w3.org/ns/activitystreams#Publid"],
  61. "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
  62. "type" => "Create"
  63. }
  64. Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
  65. assert {:ok, message} = RejectNonPublic.filter(message)
  66. end
  67. test "it's reject when direct messages aren't allow" do
  68. actor = insert(:user)
  69. message = %{
  70. "actor" => actor.ap_id,
  71. "to" => ["https://www.w3.org/ns/activitystreams#Publid~~~"],
  72. "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
  73. "type" => "Create"
  74. }
  75. Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], false)
  76. assert {:reject, _} = RejectNonPublic.filter(message)
  77. end
  78. end
  79. end