Merge branch 'develop' into feature/addressable-lists
This commit is contained in:
commit
182f7bbb11
826 changed files with 14251 additions and 3303 deletions
|
|
@ -11,12 +11,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.CommonAPI
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -30,7 +31,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|> Map.put("object", Object.normalize(activity).data)
|
||||
|
||||
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
|
|
@ -46,12 +47,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
data["object"]
|
||||
|> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("object", object)
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
returned_object = Object.normalize(returned_activity.data["object"])
|
||||
returned_object = Object.normalize(returned_activity, false)
|
||||
|
||||
assert activity =
|
||||
Activity.get_create_by_object_ap_id(
|
||||
|
|
@ -61,6 +59,50 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
end
|
||||
|
||||
test "it does not fetch replied-to activities beyond max_replies_depth" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
allowed_incoming_reply_depth?: fn _ -> false end do
|
||||
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
returned_object = Object.normalize(returned_activity, false)
|
||||
|
||||
refute Activity.get_create_by_object_ap_id(
|
||||
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
)
|
||||
|
||||
assert returned_object.data["inReplyToAtomUri"] ==
|
||||
"https://shitposter.club/notice/2827873"
|
||||
end
|
||||
end
|
||||
|
||||
test "it does not crash if the object in inReplyTo can't be fetched" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("inReplyTo", "https://404.site/whatever")
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("object", object)
|
||||
|
||||
assert capture_log(fn ->
|
||||
{:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "[error] Couldn't fetch \"\"https://404.site/whatever\"\", error: nil"
|
||||
end
|
||||
|
||||
test "it works for incoming notices" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
|
|
@ -81,25 +123,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
object = Object.normalize(data["object"]).data
|
||||
assert object["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822"
|
||||
object_data = Object.normalize(data["object"]).data
|
||||
|
||||
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
assert object_data["id"] ==
|
||||
"http://mastodon.example.org/users/admin/statuses/99512778738411822"
|
||||
|
||||
assert object["cc"] == [
|
||||
assert object_data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert object_data["cc"] == [
|
||||
"http://mastodon.example.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
]
|
||||
|
||||
assert object["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert object["attributedTo"] == "http://mastodon.example.org/users/admin"
|
||||
assert object_data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert object_data["attributedTo"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
assert object["context"] ==
|
||||
assert object_data["context"] ==
|
||||
"tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
|
||||
|
||||
assert object["sensitive"] == true
|
||||
assert object_data["sensitive"] == true
|
||||
|
||||
user = User.get_cached_by_ap_id(object["actor"])
|
||||
user = User.get_cached_by_ap_id(object_data["actor"])
|
||||
|
||||
assert user.info.note_count == 1
|
||||
end
|
||||
|
|
@ -248,59 +292,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert object_data["cc"] == to
|
||||
end
|
||||
|
||||
test "it works for incoming follow requests" do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert data["type"] == "Follow"
|
||||
assert data["id"] == "http://mastodon.example.org/users/admin#follows/2"
|
||||
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||
end
|
||||
|
||||
test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do
|
||||
Pleroma.Config.put([:user, :deny_follow_blocked], true)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
|
||||
|
||||
{:ok, user} = User.block(user, target)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: %{"id" => id}}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
%Activity{} = activity = Activity.get_by_ap_id(id)
|
||||
|
||||
assert activity.data["state"] == "reject"
|
||||
end
|
||||
|
||||
test "it works for incoming follow requests from hubzilla" do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/hubzilla-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|> Utils.normalize_params()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"
|
||||
assert data["type"] == "Follow"
|
||||
assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
|
||||
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||
end
|
||||
|
||||
test "it works for incoming likes" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
|
@ -554,11 +545,38 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
data
|
||||
|> Map.put("object", object)
|
||||
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
assert capture_log(fn ->
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
end) =~
|
||||
"[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}"
|
||||
|
||||
assert Activity.get_by_id(activity.id)
|
||||
end
|
||||
|
||||
test "it works for incoming user deletes" do
|
||||
%{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete-user.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
{:ok, _} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
refute User.get_cached_by_ap_id(ap_id)
|
||||
end
|
||||
|
||||
test "it fails for incoming user deletes with spoofed origin" do
|
||||
%{ap_id: ap_id} = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete-user.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", ap_id)
|
||||
|
||||
assert :error == Transmogrifier.handle_incoming(data)
|
||||
assert User.get_cached_by_ap_id(ap_id)
|
||||
end
|
||||
|
||||
test "it works for incoming unannounces with an existing notice" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
|
|
@ -580,10 +598,11 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Undo"
|
||||
assert data["object"]["type"] == "Announce"
|
||||
assert data["object"]["object"] == activity.data["object"]
|
||||
assert object_data = data["object"]
|
||||
assert object_data["type"] == "Announce"
|
||||
assert object_data["object"] == activity.data["object"]
|
||||
|
||||
assert data["object"]["id"] ==
|
||||
assert object_data["id"] ==
|
||||
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
||||
end
|
||||
|
||||
|
|
@ -893,7 +912,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
|
||||
object = Object.normalize(activity.data["object"])
|
||||
object = Object.normalize(activity)
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue