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
8 alias Pleroma.Web.Metadata.Providers.OpenGraph
10 setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
12 test "it renders all supported types of attachments and skips unknown types" do
18 "actor" => user.ap_id,
20 "id" => "https://pleroma.gov/objects/whatever",
21 "content" => "pleroma in a nutshell",
26 "mediaType" => "image/png",
27 "href" => "https://pleroma.gov/tenshi.png",
36 "mediaType" => "application/octet-stream",
37 "href" => "https://pleroma.gov/fqa/badapple.sfc"
44 "mediaType" => "video/webm",
45 "href" => "https://pleroma.gov/about/juche.webm",
54 "mediaType" => "audio/basic",
55 "href" => "http://www.gnu.org/music/free-software-song.au"
63 result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
67 {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
68 {:meta, [property: "og:image:width", content: "1280"], []},
69 {:meta, [property: "og:image:height", content: "1024"], []},
71 [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
73 {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
75 {:meta, [property: "og:video:width", content: "800"], []},
76 {:meta, [property: "og:video:height", content: "600"], []}
78 fn element -> element in result end
82 test "it does not render attachments if post is nsfw" do
83 clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
84 user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
89 "actor" => user.ap_id,
90 "id" => "https://pleroma.gov/objects/whatever",
91 "content" => "#cuteposting #nsfw #hambaga",
92 "tag" => ["cuteposting", "nsfw", "hambaga"],
97 %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"}
104 result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
106 assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
108 refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result
111 test "video attachments have image thumbnail with WxH metadata with Preview Proxy enabled" do
112 clear_config([:media_proxy, :enabled], true)
113 clear_config([:media_preview_proxy, :enabled], true)
119 "actor" => user.ap_id,
120 "id" => "https://pleroma.gov/objects/whatever",
121 "content" => "test video post",
122 "sensitive" => false,
127 "mediaType" => "video/webm",
128 "href" => "https://pleroma.gov/about/juche.webm",
138 result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
140 assert {:meta, [property: "og:image:width", content: "800"], []} in result
141 assert {:meta, [property: "og:image:height", content: "600"], []} in result
145 property: "og:image",
147 "http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"
151 test "video attachments have no image thumbnail with Preview Proxy disabled" do
152 clear_config([:media_proxy, :enabled], true)
153 clear_config([:media_preview_proxy, :enabled], false)
159 "actor" => user.ap_id,
160 "id" => "https://pleroma.gov/objects/whatever",
161 "content" => "test video post",
162 "sensitive" => false,
167 "mediaType" => "video/webm",
168 "href" => "https://pleroma.gov/about/juche.webm",
178 result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
180 refute {:meta, [property: "og:image:width", content: "800"], []} in result
181 refute {:meta, [property: "og:image:height", content: "600"], []} in result
185 property: "og:image",
187 "http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"