2019-02-24 14:39:27 -05:00
|
|
|
defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
2019-05-17 14:49:43 -04:00
|
|
|
alias Pleroma.Object
|
2019-02-24 14:39:27 -05:00
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
import Tesla.Mock
|
|
|
|
|
|
|
|
setup do
|
|
|
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
test "refuses to crawl incomplete URLs" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(user, %{
|
|
|
|
"status" => "[test](example.com/ogp)",
|
|
|
|
"content_type" => "text/markdown"
|
|
|
|
})
|
|
|
|
|
2019-03-02 07:22:02 -05:00
|
|
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
|
|
|
|
|
|
|
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
|
|
|
|
|
|
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "refuses to crawl malformed URLs" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(user, %{
|
|
|
|
"status" => "[test](example.com[]/ogp)",
|
|
|
|
"content_type" => "text/markdown"
|
|
|
|
})
|
|
|
|
|
|
|
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
|
|
|
|
2019-02-24 14:39:27 -05:00
|
|
|
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
2019-03-02 07:22:02 -05:00
|
|
|
|
|
|
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
2019-02-24 14:39:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "crawls valid, complete URLs" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(user, %{
|
|
|
|
"status" => "[test](http://example.com/ogp)",
|
|
|
|
"content_type" => "text/markdown"
|
|
|
|
})
|
|
|
|
|
|
|
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
|
|
|
|
|
|
|
assert %{page_url: "http://example.com/ogp", rich_media: _} =
|
|
|
|
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
|
|
|
|
|
|
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
|
|
|
end
|
2019-05-17 14:49:43 -04:00
|
|
|
|
|
|
|
test "refuses to crawl URLs from posts marked sensitive" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(user, %{
|
|
|
|
"status" => "http://example.com/ogp",
|
2019-05-17 16:42:51 -04:00
|
|
|
"sensitive" => true
|
|
|
|
})
|
|
|
|
|
|
|
|
%Object{} = object = Object.normalize(activity)
|
|
|
|
|
|
|
|
assert object.data["sensitive"]
|
|
|
|
|
|
|
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
|
|
|
|
|
|
|
assert %{} = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
|
|
|
|
|
|
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "refuses to crawl URLs from posts tagged NSFW" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(user, %{
|
|
|
|
"status" => "http://example.com/ogp #nsfw"
|
2019-05-17 14:49:43 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
%Object{} = object = Object.normalize(activity)
|
|
|
|
|
|
|
|
assert object.data["sensitive"]
|
|
|
|
|
|
|
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
|
|
|
|
|
|
|
assert %{} = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
|
|
|
|
|
|
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
|
|
|
end
|
2019-02-24 14:39:27 -05:00
|
|
|
end
|