1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
10 alias Pleroma.UnstubbedConfigMock, as: ConfigMock
11 alias Pleroma.Web.Metadata.Providers.OpenGraph
15 |> stub_with(Pleroma.Test.StaticConfig)
20 setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
22 test "it renders all supported types of attachments and skips unknown types" do
28 "actor" => user.ap_id,
30 "id" => "https://pleroma.gov/objects/whatever",
31 "content" => "pleroma in a nutshell",
36 "mediaType" => "image/png",
37 "href" => "https://pleroma.gov/tenshi.png",
46 "mediaType" => "application/octet-stream",
47 "href" => "https://pleroma.gov/fqa/badapple.sfc"
54 "mediaType" => "video/webm",
55 "href" => "https://pleroma.gov/about/juche.webm",
64 "mediaType" => "audio/basic",
65 "href" => "http://www.gnu.org/music/free-software-song.au"
73 result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
77 {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
78 {:meta, [property: "og:image:width", content: "1280"], []},
79 {:meta, [property: "og:image:height", content: "1024"], []},
81 [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
83 {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
85 {:meta, [property: "og:video:width", content: "800"], []},
86 {:meta, [property: "og:video:height", content: "600"], []}
88 fn element -> element in result end
92 test "it does not render attachments if post is nsfw" do
93 clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
94 user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
99 "actor" => user.ap_id,
100 "id" => "https://pleroma.gov/objects/whatever",
101 "content" => "#cuteposting #nsfw #hambaga",
102 "tag" => ["cuteposting", "nsfw", "hambaga"],
107 %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"}
114 result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
116 assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
118 refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result
121 test "video attachments have image thumbnail with WxH metadata with Preview Proxy enabled" do
122 clear_config([:media_proxy, :enabled], true)
123 clear_config([:media_preview_proxy, :enabled], true)
129 "actor" => user.ap_id,
130 "id" => "https://pleroma.gov/objects/whatever",
131 "content" => "test video post",
132 "sensitive" => false,
137 "mediaType" => "video/webm",
138 "href" => "https://pleroma.gov/about/juche.webm",
148 result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
150 assert {:meta, [property: "og:image:width", content: "800"], []} in result
151 assert {:meta, [property: "og:image:height", content: "600"], []} in result
155 property: "og:image",
157 "http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"
161 test "video attachments have no image thumbnail with Preview Proxy disabled" do
162 clear_config([:media_proxy, :enabled], true)
163 clear_config([:media_preview_proxy, :enabled], false)
169 "actor" => user.ap_id,
170 "id" => "https://pleroma.gov/objects/whatever",
171 "content" => "test video post",
172 "sensitive" => false,
177 "mediaType" => "video/webm",
178 "href" => "https://pleroma.gov/about/juche.webm",
188 result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
190 refute {:meta, [property: "og:image:width", content: "800"], []} in result
191 refute {:meta, [property: "og:image:height", content: "600"], []} in result
195 property: "og:image",
197 "http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"