logo

pleroma

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

inline_quote_policy_test.exs (3668B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicyTest do
  5. alias Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy
  6. use Pleroma.DataCase
  7. test "adds quote URL to post content" do
  8. quote_url = "https://gleasonator.com/objects/1234"
  9. activity = %{
  10. "type" => "Create",
  11. "actor" => "https://gleasonator.com/users/alex",
  12. "object" => %{
  13. "type" => "Note",
  14. "content" => "Nice post",
  15. "quoteUrl" => quote_url
  16. }
  17. }
  18. {:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
  19. assert filtered ==
  20. "Nice post<span class=\"quote-inline\"><br/><br/><bdi>RT:</bdi> <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span>"
  21. end
  22. test "adds quote URL to post content, custom template" do
  23. clear_config([:mrf_inline_quote, :template], "{url}'s quoting")
  24. quote_url = "https://gleasonator.com/objects/1234"
  25. activity = %{
  26. "type" => "Create",
  27. "actor" => "https://gleasonator.com/users/alex",
  28. "object" => %{
  29. "type" => "Note",
  30. "content" => "Nice post",
  31. "quoteUrl" => quote_url
  32. }
  33. }
  34. {:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
  35. assert filtered ==
  36. "Nice post<span class=\"quote-inline\"><br/><br/><a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a>'s quoting</span>"
  37. end
  38. test "doesn't add line breaks to markdown posts" do
  39. quote_url = "https://gleasonator.com/objects/1234"
  40. activity = %{
  41. "type" => "Create",
  42. "actor" => "https://gleasonator.com/users/alex",
  43. "object" => %{
  44. "type" => "Note",
  45. "content" => "<p>Nice post</p>",
  46. "quoteUrl" => quote_url
  47. }
  48. }
  49. {:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
  50. assert filtered ==
  51. "<p>Nice post<span class=\"quote-inline\"><br/><br/><bdi>RT:</bdi> <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span></p>"
  52. end
  53. test "ignores Misskey quote posts" do
  54. object = File.read!("test/fixtures/quote_post/misskey_quote_post.json") |> Jason.decode!()
  55. activity = %{
  56. "type" => "Create",
  57. "actor" => "https://misskey.io/users/7rkrarq81i",
  58. "object" => object
  59. }
  60. {:ok, filtered} = InlineQuotePolicy.filter(activity)
  61. assert filtered == activity
  62. end
  63. test "ignores Fedibird quote posts" do
  64. object = File.read!("test/fixtures/quote_post/fedibird_quote_post.json") |> Jason.decode!()
  65. # Normally the ObjectValidator will fix this before it reaches MRF
  66. object = Map.put(object, "quoteUrl", object["quoteURL"])
  67. activity = %{
  68. "type" => "Create",
  69. "actor" => "https://fedibird.com/users/noellabo",
  70. "object" => object
  71. }
  72. {:ok, filtered} = InlineQuotePolicy.filter(activity)
  73. assert filtered == activity
  74. end
  75. test "skips objects which already have an .inline-quote span" do
  76. object =
  77. File.read!("test/fixtures/quote_post/fedibird_quote_mismatched.json") |> Jason.decode!()
  78. # Normally the ObjectValidator will fix this before it reaches MRF
  79. object = Map.put(object, "quoteUrl", object["quoteUri"])
  80. activity = %{
  81. "type" => "Create",
  82. "actor" => "https://fedibird.com/users/noellabo",
  83. "object" => object
  84. }
  85. {:ok, filtered} = InlineQuotePolicy.filter(activity)
  86. assert filtered == activity
  87. end
  88. end