logo

pleroma

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

hashtag_policy_test.exs (2585B)


  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.HashtagPolicyTest do
  5. use Oban.Testing, repo: Pleroma.Repo
  6. use Pleroma.DataCase
  7. alias Pleroma.Web.ActivityPub.Transmogrifier
  8. alias Pleroma.Web.CommonAPI
  9. import Pleroma.Factory
  10. test "it sets the sensitive property with relevant hashtags" do
  11. user = insert(:user)
  12. {:ok, activity} = CommonAPI.post(user, %{status: "#nsfw hey"})
  13. {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
  14. assert modified["object"]["sensitive"]
  15. end
  16. test "it is history-aware" do
  17. activity = %{
  18. "type" => "Create",
  19. "object" => %{
  20. "content" => "hey",
  21. "tag" => []
  22. }
  23. }
  24. activity_data =
  25. activity
  26. |> put_in(
  27. ["object", "formerRepresentations"],
  28. %{
  29. "type" => "OrderedCollection",
  30. "orderedItems" => [
  31. Map.put(
  32. activity["object"],
  33. "tag",
  34. [%{"type" => "Hashtag", "name" => "#nsfw"}]
  35. )
  36. ]
  37. }
  38. )
  39. {:ok, modified} =
  40. Pleroma.Web.ActivityPub.MRF.filter_one(
  41. Pleroma.Web.ActivityPub.MRF.HashtagPolicy,
  42. activity_data
  43. )
  44. refute modified["object"]["sensitive"]
  45. assert Enum.at(modified["object"]["formerRepresentations"]["orderedItems"], 0)["sensitive"]
  46. end
  47. test "it works with Update" do
  48. activity = %{
  49. "type" => "Update",
  50. "object" => %{
  51. "content" => "hey",
  52. "tag" => []
  53. }
  54. }
  55. activity_data =
  56. activity
  57. |> put_in(
  58. ["object", "formerRepresentations"],
  59. %{
  60. "type" => "OrderedCollection",
  61. "orderedItems" => [
  62. Map.put(
  63. activity["object"],
  64. "tag",
  65. [%{"type" => "Hashtag", "name" => "#nsfw"}]
  66. )
  67. ]
  68. }
  69. )
  70. {:ok, modified} =
  71. Pleroma.Web.ActivityPub.MRF.filter_one(
  72. Pleroma.Web.ActivityPub.MRF.HashtagPolicy,
  73. activity_data
  74. )
  75. refute modified["object"]["sensitive"]
  76. assert Enum.at(modified["object"]["formerRepresentations"]["orderedItems"], 0)["sensitive"]
  77. end
  78. test "it doesn't sets the sensitive property with irrelevant hashtags" do
  79. user = insert(:user)
  80. {:ok, activity} = CommonAPI.post(user, %{status: "#cofe hey"})
  81. {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
  82. refute modified["object"]["sensitive"]
  83. end
  84. end