Merge remote-tracking branch 'upstream/develop' into earmark
This commit is contained in:
commit
52fc59f125
1199 changed files with 16799 additions and 6871 deletions
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.CommonAPITest do
|
||||
|
|
@ -25,6 +25,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
require Pleroma.Constants
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :safe_dm_mentions])
|
||||
setup do: clear_config([:instance, :limit])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
|
@ -39,7 +44,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
poll: %{expires_in: 600, options: ["reimu", "marisa"]}
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["type"] == "Question"
|
||||
assert object.data["oneOf"] |> length() == 2
|
||||
|
|
@ -174,7 +179,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
assert other_user.ap_id not in activity.recipients
|
||||
|
||||
object = Object.normalize(activity, false)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["content"] == "uguu<br/>uguuu"
|
||||
end
|
||||
|
|
@ -194,7 +199,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
assert other_user.ap_id not in activity.recipients
|
||||
|
||||
object = Object.normalize(activity, false)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["content"] ==
|
||||
"<a href=\"https://example.org\" rel=\"ugc\">https://example.org</a> is the site of <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{
|
||||
|
|
@ -215,7 +220,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
assert activity.data["type"] == "Create"
|
||||
assert activity.local
|
||||
object = Object.normalize(activity)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["type"] == "ChatMessage"
|
||||
assert object.data["to"] == [recipient.ap_id]
|
||||
|
|
@ -234,7 +239,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
test "it reject messages over the local limit" do
|
||||
Pleroma.Config.put([:instance, :chat_limit], 2)
|
||||
clear_config([:instance, :chat_limit], 2)
|
||||
|
||||
author = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
|
@ -281,7 +286,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
clear_config([:instance, :federating], true)
|
||||
|
||||
Object.normalize(post, false)
|
||||
Object.normalize(post, fetch: false)
|
||||
|> Object.prune()
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
|
|
@ -475,7 +480,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
jafnhar = insert(:user)
|
||||
tridi = insert(:user)
|
||||
|
||||
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
|
||||
clear_config([:instance, :safe_dm_mentions], true)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(har, %{
|
||||
|
|
@ -491,21 +496,55 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["tag"] == ["2hu"]
|
||||
assert Object.tags(object) == ["2hu"]
|
||||
end
|
||||
|
||||
test "it adds emoji in the object" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"})
|
||||
|
||||
assert Object.normalize(activity).data["emoji"]["firefox"]
|
||||
assert Object.normalize(activity, fetch: false).data["emoji"]["firefox"]
|
||||
end
|
||||
|
||||
describe "posting" do
|
||||
test "it adds an emoji on an external site" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hey :external_emoji:"})
|
||||
|
||||
assert %{"external_emoji" => url} = Object.normalize(activity).data["emoji"]
|
||||
assert url == "https://example.com/emoji.png"
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"})
|
||||
|
||||
assert %{"blank" => url} = Object.normalize(activity).data["emoji"]
|
||||
assert url == "#{Pleroma.Web.base_url()}/emoji/blank.png"
|
||||
end
|
||||
|
||||
test "it copies emoji from the subject of the parent post" do
|
||||
%Object{} =
|
||||
object =
|
||||
Object.normalize("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f",
|
||||
fetch: true
|
||||
)
|
||||
|
||||
activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, reply_activity} =
|
||||
CommonAPI.post(user, %{
|
||||
in_reply_to_id: activity.id,
|
||||
status: ":joker_disapprove:",
|
||||
spoiler_text: ":joker_smile:"
|
||||
})
|
||||
|
||||
assert Object.normalize(reply_activity).data["emoji"][":joker_smile:"]
|
||||
refute Object.normalize(reply_activity).data["emoji"][":joker_disapprove:"]
|
||||
end
|
||||
|
||||
test "deactivated users can't post" do
|
||||
user = insert(:user, deactivated: true)
|
||||
user = insert(:user, is_active: false)
|
||||
assert {:error, _} = CommonAPI.post(user, %{status: "ye"})
|
||||
end
|
||||
|
||||
|
|
@ -539,7 +578,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
content_type: "text/html"
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
assert object.data["source"] == post
|
||||
|
|
@ -556,7 +595,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>"
|
||||
assert object.data["source"] == post
|
||||
|
|
@ -629,7 +668,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
test "it validates character limits are correctly enforced" do
|
||||
Pleroma.Config.put([:instance, :limit], 5)
|
||||
clear_config([:instance, :limit], 5)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -731,6 +770,22 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
refute Visibility.visible_for_user?(announce_activity, nil)
|
||||
end
|
||||
|
||||
test "author can repeat own private statuses" do
|
||||
author = insert(:user)
|
||||
follower = insert(:user)
|
||||
CommonAPI.follow(follower, author)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(author, %{status: "cofe", visibility: "private"})
|
||||
|
||||
{:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, author)
|
||||
|
||||
assert Visibility.is_private?(announce_activity)
|
||||
refute Visibility.visible_for_user?(announce_activity, nil)
|
||||
|
||||
assert Visibility.visible_for_user?(activity, follower)
|
||||
assert {:error, :not_found} = CommonAPI.repeat(activity.id, follower)
|
||||
end
|
||||
|
||||
test "favoriting a status" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
@ -764,7 +819,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
describe "pinned statuses" do
|
||||
setup do
|
||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||
clear_config([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
|
||||
|
|
@ -772,13 +827,17 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
[user: user, activity: activity]
|
||||
end
|
||||
|
||||
test "activity not found error", %{user: user} do
|
||||
assert {:error, :not_found} = CommonAPI.pin("id", user)
|
||||
end
|
||||
|
||||
test "pin status", %{user: user, activity: activity} do
|
||||
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
id = activity.id
|
||||
%{data: %{"id" => object_id}} = Object.normalize(activity)
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: [^id]} = user
|
||||
assert user.pinned_objects |> Map.keys() == [object_id]
|
||||
end
|
||||
|
||||
test "pin poll", %{user: user} do
|
||||
|
|
@ -790,10 +849,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
id = activity.id
|
||||
%{data: %{"id" => object_id}} = Object.normalize(activity)
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: [^id]} = user
|
||||
assert user.pinned_objects |> Map.keys() == [object_id]
|
||||
end
|
||||
|
||||
test "unlisted statuses can be pinned", %{user: user} do
|
||||
|
|
@ -804,7 +864,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
test "only self-authored can be pinned", %{activity: activity} do
|
||||
user = insert(:user)
|
||||
|
||||
assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
|
||||
assert {:error, :ownership_error} = CommonAPI.pin(activity.id, user)
|
||||
end
|
||||
|
||||
test "max pinned statuses", %{user: user, activity: activity_one} do
|
||||
|
|
@ -814,8 +874,12 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert {:error, "You have already pinned the maximum number of statuses"} =
|
||||
CommonAPI.pin(activity_two.id, user)
|
||||
assert {:error, :pinned_statuses_limit_reached} = CommonAPI.pin(activity_two.id, user)
|
||||
end
|
||||
|
||||
test "only public can be pinned", %{user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "private status", visibility: "private"})
|
||||
{:error, :visibility_error} = CommonAPI.pin(activity.id, user)
|
||||
end
|
||||
|
||||
test "unpin status", %{user: user, activity: activity} do
|
||||
|
|
@ -829,7 +893,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: []} = user
|
||||
assert user.pinned_objects == %{}
|
||||
end
|
||||
|
||||
test "should unpin when deleting a status", %{user: user, activity: activity} do
|
||||
|
|
@ -841,7 +905,40 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: []} = user
|
||||
assert user.pinned_objects == %{}
|
||||
end
|
||||
|
||||
test "ephemeral activity won't be deleted if was pinned", %{user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "Hello!", expires_in: 601})
|
||||
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
|
||||
{:ok, _activity} = CommonAPI.pin(activity.id, user)
|
||||
refute Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
|
||||
user = refresh_record(user)
|
||||
{:ok, _} = CommonAPI.unpin(activity.id, user)
|
||||
|
||||
# recreates expiration job on unpin
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
end
|
||||
|
||||
test "ephemeral activity deletion job won't be deleted on pinning error", %{
|
||||
user: user,
|
||||
activity: activity
|
||||
} do
|
||||
clear_config([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
{:ok, _activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
{:ok, activity2} = CommonAPI.post(user, %{status: "another status", expires_in: 601})
|
||||
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity2.id)
|
||||
|
||||
user = refresh_record(user)
|
||||
{:error, :pinned_statuses_limit_reached} = CommonAPI.pin(activity2.id, user)
|
||||
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity2.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1211,7 +1308,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
poll: %{options: ["Yes", "No"], expires_in: 20}
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
{:ok, _, object} = CommonAPI.vote(other_user, object, [0])
|
||||
|
||||
|
|
@ -1231,7 +1328,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
length: 180_000
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["title"] == "lain radio episode 1"
|
||||
|
||||
|
|
@ -1250,7 +1347,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
visibility: "private"
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["title"] == "lain radio episode 1"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue