logo

pleroma

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

opengraph_test.exs (3154B)


  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.Metadata.Providers.OpenGraphTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Web.Metadata.Providers.OpenGraph
  8. setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
  9. test "it renders all supported types of attachments and skips unknown types" do
  10. user = insert(:user)
  11. note =
  12. insert(:note, %{
  13. data: %{
  14. "actor" => user.ap_id,
  15. "tag" => [],
  16. "id" => "https://pleroma.gov/objects/whatever",
  17. "content" => "pleroma in a nutshell",
  18. "attachment" => [
  19. %{
  20. "url" => [
  21. %{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}
  22. ]
  23. },
  24. %{
  25. "url" => [
  26. %{
  27. "mediaType" => "application/octet-stream",
  28. "href" => "https://pleroma.gov/fqa/badapple.sfc"
  29. }
  30. ]
  31. },
  32. %{
  33. "url" => [
  34. %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
  35. ]
  36. },
  37. %{
  38. "url" => [
  39. %{
  40. "mediaType" => "audio/basic",
  41. "href" => "http://www.gnu.org/music/free-software-song.au"
  42. }
  43. ]
  44. }
  45. ]
  46. }
  47. })
  48. result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
  49. assert Enum.all?(
  50. [
  51. {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
  52. {:meta,
  53. [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
  54. []},
  55. {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
  56. []}
  57. ],
  58. fn element -> element in result end
  59. )
  60. end
  61. test "it does not render attachments if post is nsfw" do
  62. Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
  63. user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
  64. note =
  65. insert(:note, %{
  66. data: %{
  67. "actor" => user.ap_id,
  68. "id" => "https://pleroma.gov/objects/whatever",
  69. "content" => "#cuteposting #nsfw #hambaga",
  70. "tag" => ["cuteposting", "nsfw", "hambaga"],
  71. "sensitive" => true,
  72. "attachment" => [
  73. %{
  74. "url" => [
  75. %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"}
  76. ]
  77. }
  78. ]
  79. }
  80. })
  81. result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
  82. assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
  83. refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result
  84. end
  85. end