logo

pleroma

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

vocabulary_policy_test.exs (2618B)


  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.VocabularyPolicyTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
  7. describe "accept" do
  8. setup do: clear_config([:mrf_vocabulary, :accept])
  9. test "it accepts based on parent activity type" do
  10. clear_config([:mrf_vocabulary, :accept], ["Like"])
  11. message = %{
  12. "type" => "Like",
  13. "object" => "whatever"
  14. }
  15. {:ok, ^message} = VocabularyPolicy.filter(message)
  16. end
  17. test "it accepts based on child object type" do
  18. clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
  19. message = %{
  20. "type" => "Create",
  21. "object" => %{
  22. "type" => "Note",
  23. "content" => "whatever"
  24. }
  25. }
  26. {:ok, ^message} = VocabularyPolicy.filter(message)
  27. end
  28. test "it does not accept disallowed child objects" do
  29. clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
  30. message = %{
  31. "type" => "Create",
  32. "object" => %{
  33. "type" => "Article",
  34. "content" => "whatever"
  35. }
  36. }
  37. {:reject, _} = VocabularyPolicy.filter(message)
  38. end
  39. test "it does not accept disallowed parent types" do
  40. clear_config([:mrf_vocabulary, :accept], ["Announce", "Note"])
  41. message = %{
  42. "type" => "Create",
  43. "object" => %{
  44. "type" => "Note",
  45. "content" => "whatever"
  46. }
  47. }
  48. {:reject, _} = VocabularyPolicy.filter(message)
  49. end
  50. end
  51. describe "reject" do
  52. setup do: clear_config([:mrf_vocabulary, :reject])
  53. test "it rejects based on parent activity type" do
  54. clear_config([:mrf_vocabulary, :reject], ["Like"])
  55. message = %{
  56. "type" => "Like",
  57. "object" => "whatever"
  58. }
  59. {:reject, _} = VocabularyPolicy.filter(message)
  60. end
  61. test "it rejects based on child object type" do
  62. clear_config([:mrf_vocabulary, :reject], ["Note"])
  63. message = %{
  64. "type" => "Create",
  65. "object" => %{
  66. "type" => "Note",
  67. "content" => "whatever"
  68. }
  69. }
  70. {:reject, _} = VocabularyPolicy.filter(message)
  71. end
  72. test "it passes through objects that aren't disallowed" do
  73. clear_config([:mrf_vocabulary, :reject], ["Like"])
  74. message = %{
  75. "type" => "Announce",
  76. "object" => "whatever"
  77. }
  78. {:ok, ^message} = VocabularyPolicy.filter(message)
  79. end
  80. end
  81. end