2019-01-16 07:15:13 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-01-16 07:15:13 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2019-01-17 23:32:52 -07:00
|
|
|
|
2019-01-16 07:15:13 -07:00
|
|
|
defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
import Pleroma.Factory
|
|
|
|
alias Pleroma.Web.Metadata.Providers.OpenGraph
|
|
|
|
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
2020-02-13 11:55:47 -07:00
|
|
|
|
2019-01-16 07:15:13 -07:00
|
|
|
test "it renders all supported types of attachments and skips unknown types" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"tag" => [],
|
2019-01-17 12:57:24 -07:00
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
2019-01-16 07:15:13 -07:00
|
|
|
"content" => "pleroma in a nutshell",
|
|
|
|
"attachment" => [
|
|
|
|
%{
|
|
|
|
"url" => [
|
2021-06-08 15:58:33 -06:00
|
|
|
%{
|
|
|
|
"mediaType" => "image/png",
|
|
|
|
"href" => "https://pleroma.gov/tenshi.png",
|
|
|
|
"height" => 1024,
|
|
|
|
"width" => 1280
|
|
|
|
}
|
2019-01-16 07:15:13 -07:00
|
|
|
]
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"mediaType" => "application/octet-stream",
|
|
|
|
"href" => "https://pleroma.gov/fqa/badapple.sfc"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"url" => [
|
2021-06-08 15:58:33 -06:00
|
|
|
%{
|
|
|
|
"mediaType" => "video/webm",
|
|
|
|
"href" => "https://pleroma.gov/about/juche.webm",
|
|
|
|
"height" => 600,
|
|
|
|
"width" => 800
|
|
|
|
}
|
2019-01-16 07:15:13 -07:00
|
|
|
]
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"mediaType" => "audio/basic",
|
|
|
|
"href" => "http://www.gnu.org/music/free-software-song.au"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-01-25 00:51:06 -07:00
|
|
|
result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
|
2019-01-16 07:15:13 -07:00
|
|
|
|
|
|
|
assert Enum.all?(
|
|
|
|
[
|
|
|
|
{:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
|
2021-06-08 15:58:33 -06:00
|
|
|
{:meta, [property: "og:image:width", content: "1280"], []},
|
|
|
|
{:meta, [property: "og:image:height", content: "1024"], []},
|
2019-01-16 07:15:13 -07:00
|
|
|
{:meta,
|
|
|
|
[property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
|
|
|
|
[]},
|
|
|
|
{:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
|
2021-06-08 15:58:33 -06:00
|
|
|
[]},
|
|
|
|
{:meta, [property: "og:video:width", content: "800"], []},
|
|
|
|
{:meta, [property: "og:video:height", content: "600"], []}
|
2019-01-16 07:15:13 -07:00
|
|
|
],
|
|
|
|
fn element -> element in result end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it does not render attachments if post is nsfw" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
|
2019-01-16 07:15:13 -07:00
|
|
|
user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
|
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
2019-01-17 12:57:24 -07:00
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
2019-01-16 07:15:13 -07:00
|
|
|
"content" => "#cuteposting #nsfw #hambaga",
|
|
|
|
"tag" => ["cuteposting", "nsfw", "hambaga"],
|
2019-01-17 23:32:52 -07:00
|
|
|
"sensitive" => true,
|
2019-01-16 07:15:13 -07:00
|
|
|
"attachment" => [
|
|
|
|
%{
|
|
|
|
"url" => [
|
|
|
|
%{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-01-25 00:51:06 -07:00
|
|
|
result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
|
2019-01-16 07:15:13 -07:00
|
|
|
|
|
|
|
assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
|
|
|
|
|
|
|
|
refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result
|
|
|
|
end
|
2021-06-09 10:46:31 -06:00
|
|
|
|
|
|
|
test "video attachments have image thumbnail with WxH metadata with Preview Proxy enabled" do
|
|
|
|
clear_config([:media_proxy, :enabled], true)
|
|
|
|
clear_config([:media_preview_proxy, :enabled], true)
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
|
|
|
"content" => "test video post",
|
|
|
|
"sensitive" => false,
|
|
|
|
"attachment" => [
|
|
|
|
%{
|
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"mediaType" => "video/webm",
|
|
|
|
"href" => "https://pleroma.gov/about/juche.webm",
|
|
|
|
"height" => 600,
|
|
|
|
"width" => 800
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
|
|
|
|
|
|
|
|
assert {:meta, [property: "og:image:width", content: "800"], []} in result
|
|
|
|
assert {:meta, [property: "og:image:height", content: "600"], []} in result
|
|
|
|
|
|
|
|
assert {:meta,
|
|
|
|
[
|
|
|
|
property: "og:image",
|
|
|
|
content:
|
|
|
|
"http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"
|
|
|
|
], []} in result
|
|
|
|
end
|
|
|
|
|
|
|
|
test "video attachments have no image thumbnail with Preview Proxy disabled" do
|
|
|
|
clear_config([:media_proxy, :enabled], true)
|
|
|
|
clear_config([:media_preview_proxy, :enabled], false)
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
|
|
|
"content" => "test video post",
|
|
|
|
"sensitive" => false,
|
|
|
|
"attachment" => [
|
|
|
|
%{
|
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"mediaType" => "video/webm",
|
|
|
|
"href" => "https://pleroma.gov/about/juche.webm",
|
|
|
|
"height" => 600,
|
|
|
|
"width" => 800
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
|
|
|
|
|
|
|
|
refute {:meta, [property: "og:image:width", content: "800"], []} in result
|
|
|
|
refute {:meta, [property: "og:image:height", content: "600"], []} in result
|
|
|
|
|
|
|
|
refute {:meta,
|
|
|
|
[
|
|
|
|
property: "og:image",
|
|
|
|
content:
|
|
|
|
"http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"
|
|
|
|
], []} in result
|
|
|
|
end
|
2019-01-16 07:15:13 -07:00
|
|
|
end
|