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