Merge branch 'develop' into media-preview-proxy
This commit is contained in:
commit
4ee99dafcc
123 changed files with 1809 additions and 308 deletions
|
|
@ -4,12 +4,15 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Config.DeprecationWarnings
|
||||
|
||||
test "check_old_mrf_config/0" do
|
||||
clear_config([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.NoOpPolicy)
|
||||
clear_config([:instance, :mrf_transparency], true)
|
||||
clear_config([:instance, :mrf_transparency_exclusions], [])
|
||||
|
||||
assert capture_log(fn -> Pleroma.Config.DeprecationWarnings.check_old_mrf_config() end) =~
|
||||
assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
|
||||
"""
|
||||
!!!DEPRECATION WARNING!!!
|
||||
Your config is using old namespaces for MRF configuration. They should work for now, but you are advised to change to new namespaces to prevent possible issues later:
|
||||
|
|
@ -44,22 +47,66 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
]
|
||||
|
||||
assert capture_log(fn ->
|
||||
Pleroma.Config.DeprecationWarnings.move_namespace_and_warn(
|
||||
DeprecationWarnings.move_namespace_and_warn(
|
||||
config_map,
|
||||
"Warning preface"
|
||||
)
|
||||
end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
|
||||
|
||||
assert Pleroma.Config.get(new_group1) == 1
|
||||
assert Pleroma.Config.get(new_group2) == 2
|
||||
assert Pleroma.Config.get(new_group3) == 3
|
||||
assert Config.get(new_group1) == 1
|
||||
assert Config.get(new_group2) == 2
|
||||
assert Config.get(new_group3) == 3
|
||||
end
|
||||
|
||||
test "check_media_proxy_whitelist_config/0" do
|
||||
clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
|
||||
|
||||
assert capture_log(fn ->
|
||||
Pleroma.Config.DeprecationWarnings.check_media_proxy_whitelist_config()
|
||||
DeprecationWarnings.check_media_proxy_whitelist_config()
|
||||
end) =~ "Your config is using old format (only domain) for MediaProxy whitelist option"
|
||||
end
|
||||
|
||||
describe "check_gun_pool_options/0" do
|
||||
test "await_up_timeout" do
|
||||
config = Config.get(:connections_pool)
|
||||
clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_gun_pool_options()
|
||||
end) =~
|
||||
"Your config is using old setting name `await_up_timeout` instead of `connect_timeout`"
|
||||
end
|
||||
|
||||
test "pool timeout" do
|
||||
old_config = [
|
||||
federation: [
|
||||
size: 50,
|
||||
max_waiting: 10,
|
||||
timeout: 10_000
|
||||
],
|
||||
media: [
|
||||
size: 50,
|
||||
max_waiting: 10,
|
||||
timeout: 10_000
|
||||
],
|
||||
upload: [
|
||||
size: 25,
|
||||
max_waiting: 5,
|
||||
timeout: 15_000
|
||||
],
|
||||
default: [
|
||||
size: 10,
|
||||
max_waiting: 2,
|
||||
timeout: 5_000
|
||||
]
|
||||
]
|
||||
|
||||
clear_config(:pools, old_config)
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_gun_pool_options()
|
||||
end) =~
|
||||
"Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ defmodule Pleroma.HTMLTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "extract_first_external_url" do
|
||||
describe "extract_first_external_url_from_object" do
|
||||
test "extracts the url" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ defmodule Pleroma.HTMLTest do
|
|||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
{:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
|
||||
{:ok, url} = HTML.extract_first_external_url_from_object(object)
|
||||
assert url == "https://github.com/komeiji-satori/Dress"
|
||||
end
|
||||
|
||||
|
|
@ -191,7 +191,7 @@ defmodule Pleroma.HTMLTest do
|
|||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
{:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
|
||||
{:ok, url} = HTML.extract_first_external_url_from_object(object)
|
||||
|
||||
assert url == "https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md"
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ defmodule Pleroma.HTMLTest do
|
|||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
{:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
|
||||
{:ok, url} = HTML.extract_first_external_url_from_object(object)
|
||||
|
||||
assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
|
||||
end
|
||||
|
|
@ -223,7 +223,7 @@ defmodule Pleroma.HTMLTest do
|
|||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
{:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
|
||||
{:ok, url} = HTML.extract_first_external_url_from_object(object)
|
||||
|
||||
assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
|
||||
end
|
||||
|
|
@ -235,7 +235,7 @@ defmodule Pleroma.HTMLTest do
|
|||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
|
||||
assert {:ok, nil} = HTML.extract_first_external_url_from_object(object)
|
||||
end
|
||||
|
||||
test "skips attachment links" do
|
||||
|
|
@ -249,7 +249,7 @@ defmodule Pleroma.HTMLTest do
|
|||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
|
||||
assert {:ok, nil} = HTML.extract_first_external_url_from_object(object)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.AdminSecretAuthenticationPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.OAuthScopesPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Plugs.OAuthScopesPlug
|
||||
alias Pleroma.Repo
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
defmodule Pleroma.StatsTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Stats
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
describe "user count" do
|
||||
|
|
@ -13,7 +16,7 @@ defmodule Pleroma.StatsTest do
|
|||
_internal = insert(:user, local: true, nickname: nil)
|
||||
_internal = Pleroma.Web.ActivityPub.Relay.get_actor()
|
||||
|
||||
assert match?(%{stats: %{user_count: 1}}, Pleroma.Stats.calculate_stat_data())
|
||||
assert match?(%{stats: %{user_count: 1}}, Stats.calculate_stat_data())
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -47,23 +50,23 @@ defmodule Pleroma.StatsTest do
|
|||
end)
|
||||
|
||||
assert %{"direct" => 3, "private" => 4, "public" => 1, "unlisted" => 2} =
|
||||
Pleroma.Stats.get_status_visibility_count()
|
||||
Stats.get_status_visibility_count()
|
||||
end
|
||||
|
||||
test "on status delete" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
|
||||
assert %{"public" => 1} = Pleroma.Stats.get_status_visibility_count()
|
||||
assert %{"public" => 1} = Stats.get_status_visibility_count()
|
||||
CommonAPI.delete(activity.id, user)
|
||||
assert %{"public" => 0} = Pleroma.Stats.get_status_visibility_count()
|
||||
assert %{"public" => 0} = Stats.get_status_visibility_count()
|
||||
end
|
||||
|
||||
test "on status visibility update" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
|
||||
assert %{"public" => 1, "private" => 0} = Pleroma.Stats.get_status_visibility_count()
|
||||
assert %{"public" => 1, "private" => 0} = Stats.get_status_visibility_count()
|
||||
{:ok, _} = CommonAPI.update_activity_scope(activity.id, %{visibility: "private"})
|
||||
assert %{"public" => 0, "private" => 1} = Pleroma.Stats.get_status_visibility_count()
|
||||
assert %{"public" => 0, "private" => 1} = Stats.get_status_visibility_count()
|
||||
end
|
||||
|
||||
test "doesn't count unrelated activities" do
|
||||
|
|
@ -75,7 +78,7 @@ defmodule Pleroma.StatsTest do
|
|||
CommonAPI.repeat(activity.id, other_user)
|
||||
|
||||
assert %{"direct" => 0, "private" => 0, "public" => 1, "unlisted" => 0} =
|
||||
Pleroma.Stats.get_status_visibility_count()
|
||||
Stats.get_status_visibility_count()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -110,10 +113,10 @@ defmodule Pleroma.StatsTest do
|
|||
end)
|
||||
|
||||
assert %{"direct" => 10, "private" => 0, "public" => 1, "unlisted" => 5} =
|
||||
Pleroma.Stats.get_status_visibility_count(local_instance)
|
||||
Stats.get_status_visibility_count(local_instance)
|
||||
|
||||
assert %{"direct" => 0, "private" => 20, "public" => 0, "unlisted" => 0} =
|
||||
Pleroma.Stats.get_status_visibility_count(instance2)
|
||||
Stats.get_status_visibility_count(instance2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,18 +24,18 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
|
|||
|
||||
test "it replaces filename on pre-defined text", %{upload_file: upload_file} do
|
||||
Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
|
||||
{:ok, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
|
||||
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
|
||||
assert name == "custom-file.png"
|
||||
end
|
||||
|
||||
test "it replaces filename on pre-defined text expression", %{upload_file: upload_file} do
|
||||
Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.{extension}")
|
||||
{:ok, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
|
||||
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
|
||||
assert name == "custom-file.jpg"
|
||||
end
|
||||
|
||||
test "it replaces filename on random text", %{upload_file: upload_file} do
|
||||
{:ok, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
|
||||
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
|
||||
assert <<_::bytes-size(14)>> <> ".jpg" = name
|
||||
refute name == "an… image.jpg"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ defmodule Pleroma.Upload.Filter.DedupeTest do
|
|||
|
||||
assert {
|
||||
:ok,
|
||||
:filtered,
|
||||
%Pleroma.Upload{id: @shasum, path: @shasum <> ".jpg"}
|
||||
} = Dedupe.filter(upload)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ defmodule Pleroma.Upload.Filter.ExiftoolTest do
|
|||
tempfile: Path.absname("test/fixtures/DSCN0010_tmp.jpg")
|
||||
}
|
||||
|
||||
assert Filter.Exiftool.filter(upload) == :ok
|
||||
assert Filter.Exiftool.filter(upload) == {:ok, :filtered}
|
||||
|
||||
{exif_original, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010.jpg"])
|
||||
{exif_filtered, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010_tmp.jpg"])
|
||||
|
|
@ -30,4 +30,13 @@ defmodule Pleroma.Upload.Filter.ExiftoolTest do
|
|||
assert String.match?(exif_original, ~r/GPS/)
|
||||
refute String.match?(exif_filtered, ~r/GPS/)
|
||||
end
|
||||
|
||||
test "verify webp files are skipped" do
|
||||
upload = %Pleroma.Upload{
|
||||
name: "sample.webp",
|
||||
content_type: "image/webp"
|
||||
}
|
||||
|
||||
assert Filter.Exiftool.filter(upload) == {:ok, :noop}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ defmodule Pleroma.Upload.Filter.MogrifunTest do
|
|||
save: fn _f, _o -> :ok end
|
||||
]}
|
||||
]) do
|
||||
assert Filter.Mogrifun.filter(upload) == :ok
|
||||
assert Filter.Mogrifun.filter(upload) == {:ok, :filtered}
|
||||
end
|
||||
|
||||
Task.await(task)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ defmodule Pleroma.Upload.Filter.MogrifyTest do
|
|||
custom: fn _m, _a -> :ok end,
|
||||
custom: fn m, a, o -> send(task.pid, {:apply_filter, {m, a, o}}) end,
|
||||
save: fn _f, _o -> :ok end do
|
||||
assert Filter.Mogrify.filter(upload) == :ok
|
||||
assert Filter.Mogrify.filter(upload) == {:ok, :filtered}
|
||||
end
|
||||
|
||||
Task.await(task)
|
||||
|
|
|
|||
|
|
@ -905,6 +905,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
describe "POST /users/:nickname/outbox (C2S)" do
|
||||
setup do: clear_config([:instance, :limit])
|
||||
|
||||
setup do
|
||||
[
|
||||
activity: %{
|
||||
|
|
@ -1121,6 +1123,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert cirno_object.data["actor"] == cirno.ap_id
|
||||
assert cirno_object.data["attributedTo"] == cirno.ap_id
|
||||
end
|
||||
|
||||
test "Character limitation", %{conn: conn, activity: activity} do
|
||||
Pleroma.Config.put([:instance, :limit], 5)
|
||||
user = insert(:user)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(400)
|
||||
|
||||
assert result == "Note is over the character limit"
|
||||
end
|
||||
end
|
||||
|
||||
describe "/relay/followers" do
|
||||
|
|
|
|||
60
test/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs
Normal file
60
test/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicyTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy
|
||||
@public "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
||||
defp generate_messages(actor) do
|
||||
{%{
|
||||
"actor" => actor.ap_id,
|
||||
"type" => "Create",
|
||||
"object" => %{},
|
||||
"to" => [@public, "f"],
|
||||
"cc" => [actor.follower_address, "d"]
|
||||
},
|
||||
%{
|
||||
"actor" => actor.ap_id,
|
||||
"type" => "Create",
|
||||
"object" => %{"to" => ["f", actor.follower_address], "cc" => ["d", @public]},
|
||||
"to" => ["f", actor.follower_address],
|
||||
"cc" => ["d", @public]
|
||||
}}
|
||||
end
|
||||
|
||||
test "removes from the federated timeline by nickname heuristics 1" do
|
||||
actor = insert(:user, %{nickname: "annoying_ebooks@example.com"})
|
||||
|
||||
{message, except_message} = generate_messages(actor)
|
||||
|
||||
assert ForceBotUnlistedPolicy.filter(message) == {:ok, except_message}
|
||||
end
|
||||
|
||||
test "removes from the federated timeline by nickname heuristics 2" do
|
||||
actor = insert(:user, %{nickname: "cirnonewsnetworkbot@meow.cat"})
|
||||
|
||||
{message, except_message} = generate_messages(actor)
|
||||
|
||||
assert ForceBotUnlistedPolicy.filter(message) == {:ok, except_message}
|
||||
end
|
||||
|
||||
test "removes from the federated timeline by actor type Application" do
|
||||
actor = insert(:user, %{actor_type: "Application"})
|
||||
|
||||
{message, except_message} = generate_messages(actor)
|
||||
|
||||
assert ForceBotUnlistedPolicy.filter(message) == {:ok, except_message}
|
||||
end
|
||||
|
||||
test "removes from the federated timeline by actor type Service" do
|
||||
actor = insert(:user, %{actor_type: "Service"})
|
||||
|
||||
{message, except_message} = generate_messages(actor)
|
||||
|
||||
assert ForceBotUnlistedPolicy.filter(message) == {:ok, except_message}
|
||||
end
|
||||
end
|
||||
|
|
@ -181,4 +181,17 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
'yeah #PleromaArt'
|
||||
]
|
||||
end
|
||||
|
||||
describe "private instance" do
|
||||
setup do: clear_config([:instance, :public])
|
||||
|
||||
test "returns 404 for tags feed", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart"))
|
||||
|> response(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -246,4 +246,20 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
assert response == ~S({"error":"Not found"})
|
||||
end
|
||||
end
|
||||
|
||||
describe "private instance" do
|
||||
setup do: clear_config([:instance, :public])
|
||||
|
||||
test "returns 404 for user feed", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
||||
|
||||
assert conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get(user_feed_path(conn, :feed, user.nickname))
|
||||
|> response(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Instances.InstanceTest do
|
|||
|
||||
use Pleroma.DataCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do: clear_config([:instance, :federation_reachability_timeout_days], 1)
|
||||
|
|
@ -97,4 +98,36 @@ defmodule Pleroma.Instances.InstanceTest do
|
|||
assert initial_value == instance.unreachable_since
|
||||
end
|
||||
end
|
||||
|
||||
test "Scrapes favicon URLs" do
|
||||
Tesla.Mock.mock(fn %{url: "https://favicon.example.org/"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: ~s[<html><head><link rel="icon" href="/favicon.png"></head></html>]
|
||||
}
|
||||
end)
|
||||
|
||||
assert "https://favicon.example.org/favicon.png" ==
|
||||
Instance.get_or_update_favicon(URI.parse("https://favicon.example.org/"))
|
||||
end
|
||||
|
||||
test "Returns nil on too long favicon URLs" do
|
||||
long_favicon_url =
|
||||
"https://Lorem.ipsum.dolor.sit.amet/consecteturadipiscingelit/Praesentpharetrapurusutaliquamtempus/Mauriseulaoreetarcu/atfacilisisorci/Nullamporttitor/nequesedfeugiatmollis/dolormagnaefficiturlorem/nonpretiumsapienorcieurisus/Nullamveleratsem/Maecenassedaccumsanexnam/favicon.png"
|
||||
|
||||
Tesla.Mock.mock(fn %{url: "https://long-favicon.example.org/"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: ~s[<html><head><link rel="icon" href="] <> long_favicon_url <> ~s["></head></html>]
|
||||
}
|
||||
end)
|
||||
|
||||
assert capture_log(fn ->
|
||||
assert nil ==
|
||||
Instance.get_or_update_favicon(
|
||||
URI.parse("https://long-favicon.example.org/")
|
||||
)
|
||||
end) =~
|
||||
"Instance.get_or_update_favicon(\"long-favicon.example.org\") error: %Postgrex.Error{"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -296,9 +296,45 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert real_status == fake_status
|
||||
end
|
||||
|
||||
test "fake statuses' preview card is not cached", %{conn: conn} do
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://example.com/twitter-card"
|
||||
} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
|
||||
|
||||
env ->
|
||||
apply(HttpRequestMock, :request, [env])
|
||||
end)
|
||||
|
||||
conn1 =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "https://example.com/ogp",
|
||||
"preview" => true
|
||||
})
|
||||
|
||||
conn2 =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "https://example.com/twitter-card",
|
||||
"preview" => true
|
||||
})
|
||||
|
||||
assert %{"card" => %{"title" => "The Rock"}} = json_response_and_validate_schema(conn1, 200)
|
||||
|
||||
assert %{"card" => %{"title" => "Small Island Developing States Photo Submission"}} =
|
||||
json_response_and_validate_schema(conn2, 200)
|
||||
end
|
||||
|
||||
test "posting a status with OGP link preview", %{conn: conn} do
|
||||
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
Config.put([:rich_media, :enabled], true)
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -19,8 +18,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:instances_favicons, :enabled])
|
||||
|
||||
test "Represent a user account" do
|
||||
background_image = %{
|
||||
"url" => [%{"href" => "https://example.com/images/asuka_hospital.png"}]
|
||||
|
|
@ -78,8 +75,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
background_image: "https://example.com/images/asuka_hospital.png",
|
||||
favicon:
|
||||
"https://shitposter.club/plugins/Qvitter/img/gnusocial-favicons/favicon-16x16.png",
|
||||
favicon: nil,
|
||||
confirmation_pending: false,
|
||||
tags: [],
|
||||
is_admin: false,
|
||||
|
|
@ -98,22 +94,26 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
end
|
||||
|
||||
test "Favicon is nil when :instances_favicons is disabled" do
|
||||
user = insert(:user)
|
||||
describe "favicon" do
|
||||
setup do
|
||||
[user: insert(:user)]
|
||||
end
|
||||
|
||||
Config.put([:instances_favicons, :enabled], true)
|
||||
test "is parsed when :instance_favicons is enabled", %{user: user} do
|
||||
clear_config([:instances_favicons, :enabled], true)
|
||||
|
||||
assert %{
|
||||
pleroma: %{
|
||||
favicon:
|
||||
"https://shitposter.club/plugins/Qvitter/img/gnusocial-favicons/favicon-16x16.png"
|
||||
}
|
||||
} = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
assert %{
|
||||
pleroma: %{
|
||||
favicon:
|
||||
"https://shitposter.club/plugins/Qvitter/img/gnusocial-favicons/favicon-16x16.png"
|
||||
}
|
||||
} = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
end
|
||||
|
||||
Config.put([:instances_favicons, :enabled], false)
|
||||
|
||||
assert %{pleroma: %{favicon: nil}} =
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
test "is nil when :instances_favicons is disabled", %{user: user} do
|
||||
assert %{pleroma: %{favicon: nil}} =
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
end
|
||||
end
|
||||
|
||||
test "Represent the user account for the account owner" do
|
||||
|
|
@ -173,8 +173,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
background_image: nil,
|
||||
favicon:
|
||||
"https://shitposter.club/plugins/Qvitter/img/gnusocial-favicons/favicon-16x16.png",
|
||||
favicon: nil,
|
||||
confirmation_pending: false,
|
||||
tags: [],
|
||||
is_admin: false,
|
||||
|
|
|
|||
|
|
@ -22,4 +22,13 @@ defmodule Pleroma.Web.MetadataTest do
|
|||
"<meta content=\"noindex, noarchive\" name=\"robots\">"
|
||||
end
|
||||
end
|
||||
|
||||
describe "no metadata for private instances" do
|
||||
test "for local user" do
|
||||
clear_config([:instance, :public], false)
|
||||
user = insert(:user, bio: "This is my secret fedi account bio")
|
||||
|
||||
assert "" = Pleroma.Web.Metadata.build_tags(%{user: user})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -66,9 +66,7 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
|
|||
end
|
||||
|
||||
test "doesn't just add a title" do
|
||||
assert Parser.parse("http://example.com/non-ogp") ==
|
||||
{:error,
|
||||
"Found metadata was invalid or incomplete: %{\"url\" => \"http://example.com/non-ogp\"}"}
|
||||
assert {:error, {:invalid_metadata, _}} = Parser.parse("http://example.com/non-ogp")
|
||||
end
|
||||
|
||||
test "parses ogp" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue