X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Factivity_pub%2Ftransmogrifier_test.exs;h=efbca82f620b177bd9691ef19d612afd8369bac7;hb=0e07c5ef5717460d37336129cb657ba11091f09d;hp=3720dda2a5de10c28da9dac2b693f1d8f8dc5a3b;hpb=4e6bbdc7b549e630141cb10d383a42055f06dc16;p=akkoma
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 3720dda2a..efbca82f6 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
@@ -42,7 +42,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
@tag capture_log: true
- test "it fetches replied-to activities if we don't have them" do
+ test "it fetches reply-to activities if we don't have them" do
data =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Poison.decode!()
@@ -63,7 +63,7 @@ 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
+ test "it does not fetch reply-to activities beyond max replies depth limit" do
data =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Poison.decode!()
@@ -75,7 +75,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = Map.put(data, "object", object)
with_mock Pleroma.Web.Federator,
- allowed_incoming_reply_depth?: fn _ -> false end do
+ allowed_thread_distance?: fn _ -> false end do
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
returned_object = Object.normalize(returned_activity, false)
@@ -1350,50 +1350,99 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
end
- describe "`replies` handling in handle_incoming/2" do
+ describe "`handle_incoming/2`, Mastodon format `replies` handling" do
+ clear_config([:activitypub, :note_replies_output_limit]) do
+ Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
+ end
+
+ clear_config([:instance, :federation_incoming_replies_max_depth])
+
setup do
data =
- File.read!("test/fixtures/mastodon-post-activity.json")
+ "test/fixtures/mastodon-post-activity.json"
+ |> File.read!()
|> Poison.decode!()
- items = ["https://shitposter.club/notice/2827873", "https://shitposter.club/notice/7387606"]
- collection = %{"items" => items}
- %{data: data, items: items, collection: collection}
+ items = get_in(data, ["object", "replies", "first", "items"])
+ assert length(items) > 0
+
+ %{data: data, items: items}
end
- test "with wrapped `replies` collection, it schedules background fetching of items", %{
+ test "schedules background fetching of `replies` items if max thread depth limit allows", %{
data: data,
- items: items,
- collection: collection
+ items: items
} do
- replies = %{"first" => collection}
+ Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 10)
- object = Map.put(data["object"], "replies", replies)
- data = Map.put(data, "object", object)
{:ok, _activity} = Transmogrifier.handle_incoming(data)
for id <- items do
- job_args = %{"op" => "fetch_remote", "id" => id}
+ job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
end
end
- test "it schedules background fetching of unwrapped `replies` collection items", %{
- data: data,
- items: items,
- collection: collection
- } do
- replies = collection
+ test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
+ %{data: data} do
+ Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
- object = Map.put(data["object"], "replies", replies)
- data = Map.put(data, "object", object)
{:ok, _activity} = Transmogrifier.handle_incoming(data)
- for id <- items do
- job_args = %{"op" => "fetch_remote", "id" => id}
+ assert all_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker) == []
+ end
+ end
+
+ describe "`handle_incoming/2`, Pleroma format `replies` handling" do
+ clear_config([:activitypub, :note_replies_output_limit]) do
+ Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
+ end
+
+ clear_config([:instance, :federation_incoming_replies_max_depth])
+
+ setup do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "post1"})
+
+ {:ok, reply1} =
+ CommonAPI.post(user, %{"status" => "reply1", "in_reply_to_status_id" => activity.id})
+
+ {:ok, reply2} =
+ CommonAPI.post(user, %{"status" => "reply2", "in_reply_to_status_id" => activity.id})
+
+ replies_uris = Enum.map([reply1, reply2], fn a -> a.object.data["id"] end)
+
+ {:ok, federation_output} = Transmogrifier.prepare_outgoing(activity.data)
+
+ Repo.delete(activity.object)
+ Repo.delete(activity)
+
+ %{federation_output: federation_output, replies_uris: replies_uris}
+ end
+
+ test "schedules background fetching of `replies` items if max thread depth limit allows", %{
+ federation_output: federation_output,
+ replies_uris: replies_uris
+ } do
+ Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 1)
+
+ {:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
+
+ for id <- replies_uris do
+ job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
end
end
+
+ test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
+ %{federation_output: federation_output} do
+ Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+
+ {:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
+
+ assert all_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker) == []
+ end
end
describe "prepare outgoing" do
@@ -2133,12 +2182,10 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
})
object = Object.normalize(activity)
- replies_uris = Enum.map([self_reply1, self_reply2], fn a -> a.data["id"] end)
+ replies_uris = Enum.map([self_reply1, self_reply2], fn a -> a.object.data["id"] end)
- assert %{
- "type" => "Collection",
- "first" => %{"type" => "Collection", "items" => ^replies_uris}
- } = Transmogrifier.set_replies(object.data)["replies"]
+ assert %{"type" => "Collection", "items" => ^replies_uris} =
+ Transmogrifier.set_replies(object.data)["replies"]
end
end
end