Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into revert-d6888e24
This commit is contained in:
commit
346014b897
224 changed files with 2531 additions and 1033 deletions
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.PleromaTest do
|
||||
use ExUnit.Case, async: true
|
||||
use ExUnit.Case, async: false
|
||||
import Mix.Pleroma
|
||||
|
||||
setup_all do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.AppTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
|
||||
setup_all do
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Activity
|
||||
|
|
|
|||
|
|
@ -261,23 +261,27 @@ defmodule Pleroma.ActivityTest do
|
|||
test "add_by_params_query/3" do
|
||||
user = insert(:user)
|
||||
|
||||
note = insert(:note_activity, user: user)
|
||||
note_activity = insert(:note_activity, user: user)
|
||||
|
||||
insert(:add_activity, user: user, note: note)
|
||||
insert(:add_activity, user: user, note: note)
|
||||
insert(:add_activity, user: user, note_activity: note_activity)
|
||||
insert(:add_activity, user: user, note_activity: note_activity)
|
||||
insert(:add_activity, user: user)
|
||||
|
||||
assert Repo.aggregate(Activity, :count, :id) == 4
|
||||
assert Repo.aggregate(Activity, :count, :id) == 5
|
||||
|
||||
add_query =
|
||||
Activity.add_by_params_query(note.data["object"], user.ap_id, user.featured_address)
|
||||
Activity.add_by_params_query(
|
||||
note_activity.data["object"],
|
||||
user.ap_id,
|
||||
user.featured_address
|
||||
)
|
||||
|
||||
assert Repo.aggregate(add_query, :count, :id) == 2
|
||||
|
||||
Repo.delete_all(add_query)
|
||||
assert Repo.aggregate(add_query, :count, :id) == 0
|
||||
|
||||
assert Repo.aggregate(Activity, :count, :id) == 2
|
||||
assert Repo.aggregate(Activity, :count, :id) == 3
|
||||
end
|
||||
|
||||
describe "associated_object_id() sql function" do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTTPTest do
|
||||
use ExUnit.Case, async: true
|
||||
use ExUnit.Case, async: false
|
||||
use Pleroma.Tests.Helpers
|
||||
|
||||
import Tesla.Mock
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
alias Pleroma.ConfigDB
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ defmodule Pleroma.Upload.Filter.Exiftool.StripLocationTest do
|
|||
|
||||
assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :filtered}
|
||||
|
||||
{exif_original, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010.#{type}"])
|
||||
{exif_filtered, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010_tmp.#{type}"])
|
||||
{exif_original, 0} = System.cmd("exiftool", ["-m", "test/fixtures/DSCN0010.#{type}"])
|
||||
{exif_filtered, 0} = System.cmd("exiftool", ["-m", "test/fixtures/DSCN0010_tmp.#{type}"])
|
||||
|
||||
assert String.match?(exif_original, ~r/GPS/)
|
||||
refute String.match?(exif_filtered, ~r/GPS/)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
defmodule Pleroma.Web.ActivityPub.MRF.RemoteReportPolicyTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF.RemoteReportPolicy
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,46 @@
|
|||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiTagBuildingTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
test "it encodes the id to be a valid url" do
|
||||
name = "hanapog"
|
||||
url = "https://misskey.local.live/emojis/hana pog.png"
|
||||
|
||||
tag = Transmogrifier.build_emoji_tag({name, url})
|
||||
tag = Pleroma.Emoji.build_emoji_tag({name, url})
|
||||
|
||||
assert tag["id"] == "https://misskey.local.live/emojis/hana%20pog.png"
|
||||
end
|
||||
|
||||
test "it does not double-encode already encoded urls" do
|
||||
name = "hanapog"
|
||||
url = "https://misskey.local.live/emojis/hana%20pog.png"
|
||||
|
||||
tag = Pleroma.Emoji.build_emoji_tag({name, url})
|
||||
|
||||
assert tag["id"] == url
|
||||
end
|
||||
|
||||
test "it encodes disallowed path characters" do
|
||||
name = "hanapog"
|
||||
url = "https://example.com/emojis/hana[pog].png"
|
||||
|
||||
tag = Pleroma.Emoji.build_emoji_tag({name, url})
|
||||
|
||||
assert tag["id"] == "https://example.com/emojis/hana%5Bpog%5D.png"
|
||||
end
|
||||
|
||||
test "local_url does not decode percent in filenames" do
|
||||
url = Pleroma.Emoji.local_url("/emoji/hana%20pog.png")
|
||||
|
||||
assert url == Pleroma.Web.Endpoint.url() <> "/emoji/hana%2520pog.png"
|
||||
|
||||
tag = Pleroma.Emoji.build_emoji_tag({"hanapog", url})
|
||||
|
||||
assert tag["id"] == url
|
||||
end
|
||||
|
||||
test "local_url encodes question marks in filenames" do
|
||||
url = Pleroma.Emoji.local_url("/emoji/file?name.png")
|
||||
|
||||
assert url == Pleroma.Web.Endpoint.url() <> "/emoji/file%3Fname.png"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -759,6 +759,22 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
)
|
||||
end
|
||||
|
||||
test "EmojiReact custom emoji urls are URI encoded" do
|
||||
user = insert(:user, local: true)
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
{:ok, react_activity} = CommonAPI.react_with_emoji(note_activity.id, user, ":dinosaur:")
|
||||
{:ok, data} = Transmogrifier.prepare_outgoing(react_activity.data)
|
||||
|
||||
assert length(data["tag"]) == 1
|
||||
|
||||
tag = List.first(data["tag"])
|
||||
url = tag["icon"]["url"]
|
||||
|
||||
assert url == "http://localhost:4001/emoji/dino%20walking.gif"
|
||||
assert tag["id"] == "http://localhost:4001/emoji/dino%20walking.gif"
|
||||
end
|
||||
|
||||
test "it prepares a quote post" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.User
|
||||
|
|
|
|||
|
|
@ -57,6 +57,28 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
|
|||
} = response
|
||||
end
|
||||
|
||||
test "success with redirect_uris array", %{conn: conn} do
|
||||
base_url = Endpoint.url()
|
||||
app_name = "Trusted app"
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/oauth_app", %{
|
||||
name: app_name,
|
||||
redirect_uris: [base_url]
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{
|
||||
"client_id" => _,
|
||||
"client_secret" => _,
|
||||
"name" => ^app_name,
|
||||
"redirect_uri" => ^base_url,
|
||||
"trusted" => false
|
||||
} = response
|
||||
end
|
||||
|
||||
test "with trusted", %{conn: conn} do
|
||||
base_url = Endpoint.url()
|
||||
app_name = "Trusted app"
|
||||
|
|
|
|||
|
|
@ -77,6 +77,10 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
assert redirected_to(get(conn, "/pleroma/admin")) =~ "/pleroma/admin/"
|
||||
end
|
||||
|
||||
test "GET /phoenix/live_dashboard -> /pleroma/live_dashboard", %{conn: conn} do
|
||||
assert redirected_to(get(conn, "/phoenix/live_dashboard")) =~ "/pleroma/live_dashboard"
|
||||
end
|
||||
|
||||
test "OPTIONS /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> options("/foo")
|
||||
|
|
|
|||
|
|
@ -61,6 +61,33 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
|
|||
assert app.user_id == nil
|
||||
end
|
||||
|
||||
test "creates an oauth app with redirect_uris array", %{conn: conn} do
|
||||
app_attrs = build(:oauth_app)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/apps", %{
|
||||
client_name: app_attrs.client_name,
|
||||
redirect_uris: [app_attrs.redirect_uris]
|
||||
})
|
||||
|
||||
[app] = Repo.all(App)
|
||||
|
||||
expected = %{
|
||||
"name" => app.client_name,
|
||||
"website" => app.website,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret,
|
||||
"id" => app.id |> to_string(),
|
||||
"redirect_uri" => app.redirect_uris,
|
||||
"vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
|
||||
}
|
||||
|
||||
assert expected == json_response_and_validate_schema(conn, 200)
|
||||
assert app.user_id == nil
|
||||
end
|
||||
|
||||
test "creates an oauth app with a user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
app_attrs = build(:oauth_app)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
defp extract_next_link_header(header) do
|
||||
[_, next_link] = Regex.run(~r{<(?<next_link>.*)>; rel="next"}, header)
|
||||
next_link
|
||||
end
|
||||
|
||||
describe "locked accounts" do
|
||||
setup do
|
||||
user = insert(:user, is_locked: true)
|
||||
|
|
@ -31,6 +36,23 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
|||
assert to_string(other_user.id) == relationship["id"]
|
||||
end
|
||||
|
||||
test "/api/v1/follow_requests paginates", %{user: user, conn: conn} do
|
||||
for _ <- 1..21 do
|
||||
other_user = insert(:user)
|
||||
{:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
|
||||
{:ok, _, _} = User.follow(other_user, user, :follow_pending)
|
||||
end
|
||||
|
||||
conn = get(conn, "/api/v1/follow_requests")
|
||||
assert length(json_response_and_validate_schema(conn, 200)) == 20
|
||||
assert [link_header] = get_resp_header(conn, "link")
|
||||
assert link_header =~ "rel=\"next\""
|
||||
next_link = extract_next_link_header(link_header)
|
||||
assert next_link =~ "/api/v1/follow_requests"
|
||||
conn = get(conn, next_link)
|
||||
assert length(json_response_and_validate_schema(conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do
|
||||
other_user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -153,6 +153,49 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
] = result["rules"]
|
||||
end
|
||||
|
||||
describe "instance domain blocks" do
|
||||
setup do
|
||||
clear_config([:mrf_simple, :reject], [{"fediverse.pl", "uses pl-fe"}])
|
||||
end
|
||||
|
||||
test "get instance domain blocks", %{conn: conn} do
|
||||
conn = get(conn, "/api/v1/instance/domain_blocks")
|
||||
|
||||
assert [
|
||||
%{
|
||||
"comment" => "uses pl-fe",
|
||||
"digest" => "55e3f44aefe7eb022d3b1daaf7396cabf7f181bf6093c8ea841e30c9fc7d8226",
|
||||
"domain" => "fediverse.pl",
|
||||
"severity" => "suspend"
|
||||
}
|
||||
] == json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "omits comment field if comment is empty", %{conn: conn} do
|
||||
clear_config([:mrf_simple, :reject], ["fediverse.pl"])
|
||||
|
||||
conn = get(conn, "/api/v1/instance/domain_blocks")
|
||||
|
||||
assert [
|
||||
%{
|
||||
"digest" => "55e3f44aefe7eb022d3b1daaf7396cabf7f181bf6093c8ea841e30c9fc7d8226",
|
||||
"domain" => "fediverse.pl",
|
||||
"severity" => "suspend"
|
||||
} = domain_block
|
||||
] = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
refute Map.has_key?(domain_block, "comment")
|
||||
end
|
||||
|
||||
test "returns empty array if mrf transparency is disabled", %{conn: conn} do
|
||||
clear_config([:mrf, :transparency], false)
|
||||
|
||||
conn = get(conn, "/api/v1/instance/domain_blocks")
|
||||
|
||||
assert [] == json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
test "translation languages matrix", %{conn: conn} do
|
||||
clear_config([Pleroma.Language.Translation, :provider], TranslationMock)
|
||||
|
||||
|
|
|
|||
|
|
@ -827,9 +827,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
end
|
||||
|
||||
defp local_and_remote_activities do
|
||||
remote_user = insert(:user, local: false, domain: "example.com")
|
||||
announce_user = insert(:user)
|
||||
local = insert(:note_activity)
|
||||
remote = insert(:note_activity, local: false)
|
||||
{:ok, local: local, remote: remote}
|
||||
remote = insert(:note_activity, local: false, object_local: false, user: remote_user)
|
||||
remote_note = insert(:note_activity, local: false, object_local: false)
|
||||
|
||||
local_activity_remote_object =
|
||||
insert(:announce_activity, note_activity: remote_note, user: announce_user)
|
||||
|
||||
{:ok,
|
||||
local: local, remote: remote, local_activity_remote_object: local_activity_remote_object}
|
||||
end
|
||||
|
||||
defp local_and_remote_context_activities do
|
||||
|
|
@ -872,7 +880,64 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
{:ok, job} = Pleroma.Web.Federator.incoming_ap_doc(params)
|
||||
{:ok, remote_activity} = ObanHelpers.perform(job)
|
||||
|
||||
%{locals: [id1, id2], remote: remote_activity.id, context: context}
|
||||
{:ok, %{id: local_to_local_react_id}} = CommonAPI.react_with_emoji(id1, local_user_2, "🦊")
|
||||
|
||||
{:ok, %{id: local_to_remote_react_id}} =
|
||||
CommonAPI.react_with_emoji(remote_activity.id, local_user_1, "🦊")
|
||||
|
||||
{:ok, %{id: remote_to_local_react_id}} = CommonAPI.react_with_emoji(id1, remote_user, "🦊")
|
||||
|
||||
{:ok, %{id: remote_to_remote_react_id}} =
|
||||
CommonAPI.react_with_emoji(remote_activity.id, remote_user, "🦊")
|
||||
|
||||
%{
|
||||
locals: [id1, id2],
|
||||
remote: remote_activity.id,
|
||||
local_interactions: [local_to_local_react_id, local_to_remote_react_id],
|
||||
remote_interactions: [remote_to_local_react_id, remote_to_remote_react_id],
|
||||
context: context
|
||||
}
|
||||
end
|
||||
|
||||
defp extract_activity_ids_from_response(list) when is_list(list) do
|
||||
list
|
||||
|> Enum.map(& &1["id"])
|
||||
end
|
||||
|
||||
defp all_ids_included?(checked, authority) when is_list(checked) and is_list(authority) do
|
||||
set1 = MapSet.new(checked)
|
||||
set2 = MapSet.new(authority)
|
||||
MapSet.equal?(set1, set2)
|
||||
end
|
||||
|
||||
defp local_interactions_to_remote do
|
||||
interacted_user = insert(:user, local: false, domain: "example.com")
|
||||
interacting_user = insert(:user)
|
||||
|
||||
announced_post =
|
||||
insert(:note_activity, local: false, object_local: false, user: interacted_user)
|
||||
|
||||
emoji_reacted_post =
|
||||
insert(:note_activity, local: false, object_local: false, user: interacted_user)
|
||||
|
||||
favorited_post =
|
||||
insert(:note_activity, local: false, object_local: false, user: interacted_user)
|
||||
|
||||
announce = insert(:announce_activity, note_activity: announced_post, user: interacting_user)
|
||||
|
||||
emoji_react =
|
||||
insert(:emoji_react_activity, note_activity: emoji_reacted_post, user: interacting_user)
|
||||
|
||||
{:ok, favorite} = CommonAPI.favorite(favorited_post.id, interacting_user)
|
||||
|
||||
{
|
||||
:ok,
|
||||
announce: announce,
|
||||
emoji_react: emoji_react,
|
||||
favorite: favorite,
|
||||
interacted: interacted_user,
|
||||
interacter: interacting_user
|
||||
}
|
||||
end
|
||||
|
||||
describe "status with restrict unauthenticated activities for local and remote" do
|
||||
|
|
@ -882,7 +947,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
test "if user is unauthenticated", %{
|
||||
conn: conn,
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, :not_found) == %{
|
||||
|
|
@ -891,18 +961,31 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_activity_remote_object.id}")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
test "if user is authenticated", %{
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_activity_remote_object.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -911,9 +994,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
test "if user is unauthenticated", %{
|
||||
conn: conn,
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_activity_remote_object.id}")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
|
|
@ -922,13 +1016,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
test "if user is authenticated", %{
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_activity_remote_object.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -937,24 +1038,177 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
test "if user is unauthenticated", %{
|
||||
conn: conn,
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_activity_remote_object.id}")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
test "if user is authenticated", %{
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_activity_remote_object.id}")
|
||||
assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
# Note: Activities of type Flag,Follow,Delete,Accept,Reject,Undo return 404
|
||||
describe "status has correct attribution when fetching as" do
|
||||
setup do: local_interactions_to_remote()
|
||||
|
||||
test "Add/Remove activity", %{conn: conn, interacter: user} do
|
||||
add = insert(:add_activity, user: user)
|
||||
add_id = add.id
|
||||
remove = insert(:remove_activity, user: user)
|
||||
remove_id = remove.id
|
||||
user_id = user.id
|
||||
|
||||
# Schema validation fails:
|
||||
# null value where integer expected at /pleroma/conversation_id
|
||||
result1 =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{add_id}")
|
||||
|> json_response(200)
|
||||
|
||||
assert match?(%{"id" => ^add_id, "account" => %{"id" => ^user_id}}, result1)
|
||||
|
||||
result2 =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{remove_id}")
|
||||
|> json_response(200)
|
||||
|
||||
assert match?(%{"id" => ^remove_id, "account" => %{"id" => ^user_id}}, result2)
|
||||
end
|
||||
|
||||
test "Announce activity", %{
|
||||
conn: conn,
|
||||
announce: activity,
|
||||
interacter: interacter,
|
||||
interacted: user
|
||||
} do
|
||||
announce_id = activity.id
|
||||
announced_activity = Pleroma.Activity.get_create_by_object_ap_id(activity.data["object"])
|
||||
announced_id = announced_activity.id
|
||||
interacter_ap_id = interacter.id
|
||||
user_id = user.id
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{activity.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert match?(
|
||||
%{
|
||||
"id" => ^announce_id,
|
||||
"account" => %{"id" => ^interacter_ap_id},
|
||||
"reblog" => %{"account" => %{"id" => ^user_id}, "id" => ^announced_id}
|
||||
},
|
||||
result
|
||||
)
|
||||
end
|
||||
|
||||
test "Create activity", %{conn: conn, interacted: user} do
|
||||
note_activity = insert(:note_activity, local: false, object_local: false, user: user)
|
||||
note_activity_id = note_activity.id
|
||||
user_id = user.id
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{note_activity_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert match?(%{"id" => ^note_activity_id, "account" => %{"id" => ^user_id}}, result)
|
||||
end
|
||||
|
||||
test "EmojiReact activity", %{conn: conn, emoji_react: activity, interacted: user} do
|
||||
emoji_react_id = activity.id
|
||||
user_id = user.id
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{emoji_react_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert match?(%{"id" => ^emoji_react_id, "account" => %{"id" => ^user_id}}, result)
|
||||
end
|
||||
|
||||
test "Like activity", %{conn: conn, favorite: activity, interacted: user} do
|
||||
like_id = activity.id
|
||||
user_id = user.id
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{like_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert match?(%{"id" => ^like_id, "account" => %{"id" => ^user_id}}, result)
|
||||
end
|
||||
|
||||
test "Update activity" do
|
||||
%{conn: conn, user: user} = oauth_access(["write:statuses"])
|
||||
user_id = user.id
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "This will be edited"})
|
||||
{:ok, updated_activity} = CommonAPI.update(activity, user, %{status: "edited"})
|
||||
|
||||
activity_id = activity.id
|
||||
updated_activity_id = updated_activity.id
|
||||
|
||||
result1 =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{activity_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
# Even though we ask for the original Create activity, updated post is served
|
||||
assert match?(
|
||||
%{
|
||||
"id" => ^activity_id,
|
||||
"account" => %{"id" => ^user_id},
|
||||
"content" => "edited"
|
||||
},
|
||||
result1
|
||||
)
|
||||
|
||||
# Schema validation fails:
|
||||
# null value where integer expected at /pleroma/conversation_id
|
||||
result2 =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{updated_activity_id}")
|
||||
|> json_response(200)
|
||||
|
||||
assert match?(
|
||||
%{
|
||||
"id" => ^updated_activity_id,
|
||||
"account" => %{"id" => ^user_id},
|
||||
"content" => "edited"
|
||||
},
|
||||
result2
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1014,18 +1268,35 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
|
||||
test "if user is unauthenticated", %{
|
||||
conn: conn,
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
res_conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}&id[]=#{local_activity_remote_object.id}"
|
||||
)
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, 200) == []
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
test "if user is authenticated", %{
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
|
||||
res_conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}&id[]=#{local_activity_remote_object.id}"
|
||||
)
|
||||
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 3
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1034,19 +1305,36 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
|
||||
test "if user is unauthenticated", %{
|
||||
conn: conn,
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
res_conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}&id[]=#{local_activity_remote_object.id}"
|
||||
)
|
||||
|
||||
remote_id = remote.id
|
||||
assert [%{"id" => ^remote_id}] = json_response_and_validate_schema(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
test "if user is authenticated", %{
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
|
||||
res_conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}&id[]=#{local_activity_remote_object.id}"
|
||||
)
|
||||
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 3
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1055,22 +1343,40 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
|
||||
test "if user is unauthenticated", %{
|
||||
conn: conn,
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
res_conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}&id[]=#{local_activity_remote_object.id}"
|
||||
)
|
||||
|
||||
local_id = local.id
|
||||
assert [%{"id" => ^local_id}] = json_response_and_validate_schema(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
test "if user is authenticated", %{
|
||||
local: local,
|
||||
remote: remote,
|
||||
local_activity_remote_object: local_activity_remote_object
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}")
|
||||
res_conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}&id[]=#{local_activity_remote_object.id}"
|
||||
)
|
||||
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 3
|
||||
end
|
||||
end
|
||||
|
||||
# Note: Context route on EmojiReact/Announce activities puts everything into the ancestors field
|
||||
describe "getting status contexts restricted unauthenticated for local and remote" do
|
||||
setup do: local_and_remote_context_activities()
|
||||
|
||||
|
|
@ -1096,6 +1402,40 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
}
|
||||
end
|
||||
|
||||
test "if user is unauthenticated Activity interactions", %{
|
||||
conn: conn,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, 200) == %{
|
||||
"ancestors" => [],
|
||||
"descendants" => []
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, 200) == %{
|
||||
"ancestors" => [],
|
||||
"descendants" => []
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, 200) == %{
|
||||
"ancestors" => [],
|
||||
"descendants" => []
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, 200) == %{
|
||||
"ancestors" => [],
|
||||
"descendants" => []
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{locals: [post_id, reply_id], remote: remote_reply_id} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{post_id}/context")
|
||||
|
|
@ -1129,6 +1469,47 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert post_id in ancestor_ids
|
||||
assert remote_reply_id in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is authenticated Activity interactions", %{
|
||||
locals: [post_id, reply_id],
|
||||
remote: remote_reply_id,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
all_ids = [post_id, reply_id, remote_reply_id]
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, all_ids)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting status contexts restricted unauthenticated for local" do
|
||||
|
|
@ -1178,6 +1559,45 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert remote_reply_id in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is unauthenticated Activity interactions", %{
|
||||
conn: conn,
|
||||
remote: remote_reply_id,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, [remote_reply_id])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, [remote_reply_id])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, [remote_reply_id])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, [remote_reply_id])
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{locals: [post_id, reply_id], remote: remote_reply_id} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{post_id}/context")
|
||||
|
|
@ -1211,6 +1631,47 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert post_id in ancestor_ids
|
||||
assert remote_reply_id in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is authenticated Activity interactions", %{
|
||||
locals: [post_id, reply_id],
|
||||
remote: remote_reply_id,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
all_ids = [post_id, reply_id, remote_reply_id]
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, all_ids)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting status contexts restricted unauthenticated for remote" do
|
||||
|
|
@ -1260,6 +1721,46 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert remote_reply_id not in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is unauthenticated Activity interactions", %{
|
||||
conn: conn,
|
||||
locals: [post_id, reply_id],
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
all_ids = [post_id, reply_id]
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, all_ids)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{locals: [post_id, reply_id], remote: remote_reply_id} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{post_id}/context")
|
||||
|
|
@ -1293,6 +1794,47 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert post_id in ancestor_ids
|
||||
assert remote_reply_id in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is authenticated Activity interactions", %{
|
||||
locals: [post_id, reply_id],
|
||||
remote: remote_reply_id,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
all_ids = [post_id, reply_id, remote_reply_id]
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, all_ids)
|
||||
end
|
||||
end
|
||||
|
||||
describe "deleting a status" do
|
||||
|
|
|
|||
|
|
@ -105,6 +105,25 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
end
|
||||
|
||||
test "encodes emoji urls in the emojis field" do
|
||||
user =
|
||||
insert(:user,
|
||||
name: ":brackets: :percent:",
|
||||
emoji: %{
|
||||
"brackets" => "/emoji/hana[pog].png",
|
||||
"percent" => "/emoji/hana%20pog.png"
|
||||
}
|
||||
)
|
||||
|
||||
%{emojis: emojis} =
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|
||||
emoji_urls = Map.new(emojis, &{&1.shortcode, &1.url})
|
||||
|
||||
assert emoji_urls["brackets"] == "/emoji/hana%5Bpog%5D.png"
|
||||
assert emoji_urls["percent"] == "/emoji/hana%2520pog.png"
|
||||
end
|
||||
|
||||
describe "roles and privileges" do
|
||||
setup do
|
||||
clear_config([:instance, :moderator_privileges], [:cofe, :only_moderator])
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
data: %{
|
||||
"reactions" => [
|
||||
["👍", [user.ap_id], nil],
|
||||
["dinosaur", [user.ap_id], "http://localhost:4001/emoji/dino walking.gif"]
|
||||
["dinosaur", [user.ap_id], "http://localhost:4001/emoji/dino%20walking.gif"]
|
||||
]
|
||||
}
|
||||
)
|
||||
|
|
@ -243,7 +243,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
account: AccountView.render("show.json", %{user: other_user, for: user}),
|
||||
status: StatusView.render("show.json", %{activity: activity, for: user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at),
|
||||
emoji_url: "http://localhost:4001/emoji/dino walking.gif"
|
||||
emoji_url: "http://localhost:4001/emoji/dino%20walking.gif"
|
||||
}
|
||||
|
||||
test_notifications_rendering([notification], user, [expected])
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
count: 2,
|
||||
me: false,
|
||||
name: "dinosaur",
|
||||
url: "http://localhost:4001/emoji/dino walking.gif",
|
||||
url: "http://localhost:4001/emoji/dino%20walking.gif",
|
||||
account_ids: [other_user.id, user.id]
|
||||
},
|
||||
%{name: "🍵", count: 1, me: false, url: nil, account_ids: [third_user.id]}
|
||||
|
|
@ -70,7 +70,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
count: 2,
|
||||
me: true,
|
||||
name: "dinosaur",
|
||||
url: "http://localhost:4001/emoji/dino walking.gif",
|
||||
url: "http://localhost:4001/emoji/dino%20walking.gif",
|
||||
account_ids: [other_user.id, user.id]
|
||||
},
|
||||
%{name: "🍵", count: 1, me: false, url: nil, account_ids: [third_user.id]}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
|||
"name" => "dinosaur",
|
||||
"count" => 1,
|
||||
"me" => true,
|
||||
"url" => "http://localhost:4001/emoji/dino walking.gif",
|
||||
"url" => "http://localhost:4001/emoji/dino%20walking.gif",
|
||||
"account_ids" => [other_user.id]
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
||||
alias Pleroma.NullCache
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
|
||||
alias Pleroma.Chat
|
||||
alias Pleroma.Chat.MessageReference
|
||||
|
|
@ -18,6 +18,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
|||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:rich_media, :enabled], true)
|
||||
|
||||
test "it displays a chat message" do
|
||||
|
|
|
|||
|
|
@ -106,7 +106,6 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
"manifest.json",
|
||||
"auth",
|
||||
"proxy",
|
||||
"phoenix",
|
||||
"test",
|
||||
"user_exists",
|
||||
"check_password"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Web.RichMedia.CardTest do
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
|
|
@ -19,6 +19,8 @@ defmodule Pleroma.Web.RichMedia.CardTest do
|
|||
setup do
|
||||
mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,12 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
|
||||
@moduletag needs_streamer: true, capture_log: true
|
||||
|
||||
setup do: clear_config([:instance, :skip_thread_containment])
|
||||
setup do
|
||||
clear_config([:instance, :skip_thread_containment])
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "get_topic/_ (unauthenticated)" do
|
||||
test "allows no stream" do
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.WebFingerTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
alias Pleroma.Web.WebFinger
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Workers.PublisherWorkerTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Workers.ReachabilityWorkerTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Mock
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Workers.ReceiverWorkerTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Mock
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Workers.RemoteFetcherWorkerTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase, async: false
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Workers.RemoteFetcherWorker
|
||||
|
|
|
|||
|
|
@ -102,11 +102,19 @@ defmodule Pleroma.Factory do
|
|||
|
||||
user = attrs[:user] || insert(:user)
|
||||
|
||||
object_id =
|
||||
if attrs[:object_local] == false do
|
||||
# Must not match our Endpoint URL in the test env
|
||||
"https://example.com/objects/#{Ecto.UUID.generate()}"
|
||||
else
|
||||
Pleroma.Web.ActivityPub.Utils.generate_object_id()
|
||||
end
|
||||
|
||||
data = %{
|
||||
"type" => "Note",
|
||||
"content" => text,
|
||||
"source" => text,
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
||||
"id" => object_id,
|
||||
"actor" => user.ap_id,
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||
|
|
@ -297,27 +305,27 @@ defmodule Pleroma.Factory do
|
|||
featured_collection_activity(attrs, "Add")
|
||||
end
|
||||
|
||||
def remove_activity_factor(attrs \\ %{}) do
|
||||
def remove_activity_factory(attrs \\ %{}) do
|
||||
featured_collection_activity(attrs, "Remove")
|
||||
end
|
||||
|
||||
defp featured_collection_activity(attrs, type) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
note = attrs[:note] || insert(:note, user: user)
|
||||
note_activity = attrs[:note_activity] || insert(:note_activity, user: user)
|
||||
|
||||
data_attrs =
|
||||
attrs
|
||||
|> Map.get(:data_attrs, %{})
|
||||
|> Map.put(:type, type)
|
||||
|
||||
attrs = Map.drop(attrs, [:user, :note, :data_attrs])
|
||||
attrs = Map.drop(attrs, [:user, :note_activity, :data_attrs])
|
||||
|
||||
data =
|
||||
%{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"target" => user.featured_address,
|
||||
"object" => note.data["object"],
|
||||
"actor" => note.data["actor"],
|
||||
"object" => note_activity.data["object"],
|
||||
"actor" => note_activity.data["actor"],
|
||||
"type" => "Add",
|
||||
"to" => [Pleroma.Constants.as_public()],
|
||||
"cc" => [user.follower_address]
|
||||
|
|
@ -361,14 +369,25 @@ defmodule Pleroma.Factory do
|
|||
|
||||
def note_activity_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
note = attrs[:note] || insert(:note, user: user)
|
||||
object_local = if attrs[:object_local] == false, do: false, else: true
|
||||
note = attrs[:note] || insert(:note, user: user, object_local: object_local)
|
||||
|
||||
activity_id =
|
||||
if attrs[:local] == false do
|
||||
# Same domain as in note Object factory, it doesn't make sense
|
||||
# to create mismatched Create Activities with an ID coming from
|
||||
# a different domain than the Object
|
||||
"https://example.com/activities/#{Ecto.UUID.generate()}"
|
||||
else
|
||||
Pleroma.Web.ActivityPub.Utils.generate_activity_id()
|
||||
end
|
||||
|
||||
data_attrs = attrs[:data_attrs] || %{}
|
||||
attrs = Map.drop(attrs, [:user, :note, :data_attrs])
|
||||
attrs = Map.drop(attrs, [:user, :note, :data_attrs, :object_local])
|
||||
|
||||
data =
|
||||
%{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"id" => activity_id,
|
||||
"type" => "Create",
|
||||
"actor" => note.data["actor"],
|
||||
"to" => note.data["to"],
|
||||
|
|
@ -408,15 +427,17 @@ defmodule Pleroma.Factory do
|
|||
|
||||
def announce_activity_factory(attrs \\ %{}) do
|
||||
note_activity = attrs[:note_activity] || insert(:note_activity)
|
||||
object = Object.normalize(note_activity, fetch: false)
|
||||
user = attrs[:user] || insert(:user)
|
||||
|
||||
data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"type" => "Announce",
|
||||
"actor" => note_activity.actor,
|
||||
"object" => note_activity.data["id"],
|
||||
"to" => [user.follower_address, note_activity.data["actor"]],
|
||||
"actor" => user.ap_id,
|
||||
"object" => object.data["id"],
|
||||
"to" => [user.follower_address, object.data["actor"]],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"context" => note_activity.data["context"]
|
||||
"context" => object.data["context"]
|
||||
}
|
||||
|
||||
%Pleroma.Activity{
|
||||
|
|
@ -426,6 +447,28 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def emoji_react_activity_factory(attrs \\ %{}) do
|
||||
note_activity = attrs[:note_activity] || insert(:note_activity)
|
||||
object = Object.normalize(note_activity, fetch: false)
|
||||
user = attrs[:user] || insert(:user)
|
||||
|
||||
data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"actor" => user.ap_id,
|
||||
"type" => "EmojiReact",
|
||||
"object" => object.data["id"],
|
||||
"to" => [user.follower_address, object.data["actor"]],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||
"context" => object.data["context"],
|
||||
"content" => "😀"
|
||||
}
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data
|
||||
}
|
||||
end
|
||||
|
||||
def like_activity_factory(attrs \\ %{}) do
|
||||
note_activity = attrs[:note_activity] || insert(:note_activity)
|
||||
object = Object.normalize(note_activity, fetch: false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue