1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
6 use Oban.Testing, repo: Pleroma.Repo
11 alias Pleroma.Object.Fetcher
12 alias Pleroma.Tests.ObanHelpers
14 alias Pleroma.Web.ActivityPub.ActivityPub
15 alias Pleroma.Web.ActivityPub.Transmogrifier
16 alias Pleroma.Web.AdminAPI.AccountView
17 alias Pleroma.Web.CommonAPI
20 import Pleroma.Factory
21 import ExUnit.CaptureLog
24 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
28 setup do: clear_config([:instance, :max_remote_account_fields])
30 describe "handle_incoming" do
31 test "it works for incoming notices with tag not being an array (kroeg)" do
32 data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Poison.decode!()
34 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
35 object = Object.normalize(data["object"])
37 assert object.data["emoji"] == %{
38 "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png"
41 data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Poison.decode!()
43 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
44 object = Object.normalize(data["object"])
46 assert "test" in object.data["tag"]
49 test "it works for incoming notices with url not being a string (prismo)" do
50 data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!()
52 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
53 object = Object.normalize(data["object"])
55 assert object.data["url"] == "https://prismo.news/posts/83"
58 test "it cleans up incoming notices which are not really DMs" do
60 other_user = insert(:user)
62 to = [user.ap_id, other_user.ap_id]
65 File.read!("test/fixtures/mastodon-post-activity.json")
75 data = Map.put(data, "object", object)
77 {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
79 assert data["to"] == []
80 assert data["cc"] == to
82 object_data = Object.normalize(activity).data
84 assert object_data["to"] == []
85 assert object_data["cc"] == to
88 test "it ignores an incoming notice if we already have it" do
89 activity = insert(:note_activity)
92 File.read!("test/fixtures/mastodon-post-activity.json")
94 |> Map.put("object", Object.normalize(activity).data)
96 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
98 assert activity == returned_activity
101 @tag capture_log: true
102 test "it fetches reply-to activities if we don't have them" do
104 File.read!("test/fixtures/mastodon-post-activity.json")
109 |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
111 data = Map.put(data, "object", object)
112 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
113 returned_object = Object.normalize(returned_activity, false)
116 Activity.get_create_by_object_ap_id(
117 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
120 assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
123 test "it does not fetch reply-to activities beyond max replies depth limit" do
125 File.read!("test/fixtures/mastodon-post-activity.json")
130 |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
132 data = Map.put(data, "object", object)
134 with_mock Pleroma.Web.Federator,
135 allowed_thread_distance?: fn _ -> false end do
136 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
138 returned_object = Object.normalize(returned_activity, false)
140 refute Activity.get_create_by_object_ap_id(
141 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
144 assert returned_object.data["inReplyToAtomUri"] ==
145 "https://shitposter.club/notice/2827873"
149 test "it does not crash if the object in inReplyTo can't be fetched" do
151 File.read!("test/fixtures/mastodon-post-activity.json")
156 |> Map.put("inReplyTo", "https://404.site/whatever")
160 |> Map.put("object", object)
162 assert capture_log(fn ->
163 {:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
164 end) =~ "[error] Couldn't fetch \"https://404.site/whatever\", error: nil"
167 test "it works for incoming notices" do
168 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
170 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
173 "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity"
175 assert data["context"] ==
176 "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
178 assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
180 assert data["cc"] == [
181 "http://mastodon.example.org/users/admin/followers",
182 "http://localtesting.pleroma.lol/users/lain"
185 assert data["actor"] == "http://mastodon.example.org/users/admin"
187 object_data = Object.normalize(data["object"]).data
189 assert object_data["id"] ==
190 "http://mastodon.example.org/users/admin/statuses/99512778738411822"
192 assert object_data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
194 assert object_data["cc"] == [
195 "http://mastodon.example.org/users/admin/followers",
196 "http://localtesting.pleroma.lol/users/lain"
199 assert object_data["actor"] == "http://mastodon.example.org/users/admin"
200 assert object_data["attributedTo"] == "http://mastodon.example.org/users/admin"
202 assert object_data["context"] ==
203 "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
205 assert object_data["sensitive"] == true
207 user = User.get_cached_by_ap_id(object_data["actor"])
209 assert user.note_count == 1
212 test "it works for incoming notices with hashtags" do
213 data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
215 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
216 object = Object.normalize(data["object"])
218 assert Enum.at(object.data["tag"], 2) == "moo"
221 test "it works for incoming questions" do
222 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
224 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
226 object = Object.normalize(activity)
228 assert Enum.all?(object.data["oneOf"], fn choice ->
231 "Everyone knows that!",
232 "25 char limit is dumb",
233 "I can't even fit a funny"
238 test "it works for incoming listens" do
240 "@context" => "https://www.w3.org/ns/activitystreams",
241 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
244 "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
245 "actor" => "http://mastodon.example.org/users/admin",
248 "id" => "http://mastodon.example.org/users/admin/listens/1234",
249 "attributedTo" => "http://mastodon.example.org/users/admin",
250 "title" => "lain radio episode 1",
252 "album" => "lain radio",
257 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
259 object = Object.normalize(activity)
261 assert object.data["title"] == "lain radio episode 1"
262 assert object.data["artist"] == "lain"
263 assert object.data["album"] == "lain radio"
264 assert object.data["length"] == 180_000
267 test "it rewrites Note votes to Answers and increments vote counters on question activities" do
271 CommonAPI.post(user, %{
273 poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
276 object = Object.normalize(activity)
279 File.read!("test/fixtures/mastodon-vote.json")
281 |> Kernel.put_in(["to"], user.ap_id)
282 |> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
283 |> Kernel.put_in(["object", "to"], user.ap_id)
285 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
286 answer_object = Object.normalize(activity)
287 assert answer_object.data["type"] == "Answer"
288 object = Object.get_by_ap_id(object.data["id"])
291 object.data["oneOf"],
293 %{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
299 test "it works for incoming notices with contentMap" do
301 File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
303 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
304 object = Object.normalize(data["object"])
306 assert object.data["content"] ==
307 "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
310 test "it works for incoming notices with to/cc not being an array (kroeg)" do
311 data = File.read!("test/fixtures/kroeg-post-activity.json") |> Poison.decode!()
313 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
314 object = Object.normalize(data["object"])
316 assert object.data["content"] ==
317 "<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>"
320 test "it ensures that as:Public activities make it to their followers collection" do
324 File.read!("test/fixtures/mastodon-post-activity.json")
326 |> Map.put("actor", user.ap_id)
327 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
332 |> Map.put("attributedTo", user.ap_id)
333 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
335 |> Map.put("id", user.ap_id <> "/activities/12345678")
337 data = Map.put(data, "object", object)
339 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
341 assert data["cc"] == [User.ap_followers(user)]
344 test "it ensures that address fields become lists" do
348 File.read!("test/fixtures/mastodon-post-activity.json")
350 |> Map.put("actor", user.ap_id)
351 |> Map.put("to", nil)
352 |> Map.put("cc", nil)
356 |> Map.put("attributedTo", user.ap_id)
357 |> Map.put("to", nil)
358 |> Map.put("cc", nil)
359 |> Map.put("id", user.ap_id <> "/activities/12345678")
361 data = Map.put(data, "object", object)
363 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
365 assert !is_nil(data["to"])
366 assert !is_nil(data["cc"])
369 test "it strips internal likes" do
371 File.read!("test/fixtures/mastodon-post-activity.json")
376 "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
377 "id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
379 "type" => "OrderedCollection"
382 object = Map.put(data["object"], "likes", likes)
383 data = Map.put(data, "object", object)
385 {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
387 refute Map.has_key?(object.data, "likes")
390 test "it strips internal reactions" do
392 {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
393 {:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "📢")
395 %{object: object} = Activity.get_by_id_with_object(activity.id)
396 assert Map.has_key?(object.data, "reactions")
397 assert Map.has_key?(object.data, "reaction_count")
399 object_data = Transmogrifier.strip_internal_fields(object.data)
400 refute Map.has_key?(object_data, "reactions")
401 refute Map.has_key?(object_data, "reaction_count")
404 test "it works for incomming unfollows with an existing follow" do
408 File.read!("test/fixtures/mastodon-follow-activity.json")
410 |> Map.put("object", user.ap_id)
412 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
415 File.read!("test/fixtures/mastodon-unfollow-activity.json")
417 |> Map.put("object", follow_data)
419 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
421 assert data["type"] == "Undo"
422 assert data["object"]["type"] == "Follow"
423 assert data["object"]["object"] == user.ap_id
424 assert data["actor"] == "http://mastodon.example.org/users/admin"
426 refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
429 test "it works for incoming follows to locked account" do
430 pending_follower = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
431 user = insert(:user, locked: true)
434 File.read!("test/fixtures/mastodon-follow-activity.json")
436 |> Map.put("object", user.ap_id)
438 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
440 assert data["type"] == "Follow"
441 assert data["object"] == user.ap_id
442 assert data["state"] == "pending"
443 assert data["actor"] == "http://mastodon.example.org/users/admin"
445 assert [^pending_follower] = User.get_follow_requests(user)
448 test "it works for incoming blocks" do
452 File.read!("test/fixtures/mastodon-block-activity.json")
454 |> Map.put("object", user.ap_id)
456 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
458 assert data["type"] == "Block"
459 assert data["object"] == user.ap_id
460 assert data["actor"] == "http://mastodon.example.org/users/admin"
462 blocker = User.get_cached_by_ap_id(data["actor"])
464 assert User.blocks?(blocker, user)
467 test "incoming blocks successfully tear down any follow relationship" do
468 blocker = insert(:user)
469 blocked = insert(:user)
472 File.read!("test/fixtures/mastodon-block-activity.json")
474 |> Map.put("object", blocked.ap_id)
475 |> Map.put("actor", blocker.ap_id)
477 {:ok, blocker} = User.follow(blocker, blocked)
478 {:ok, blocked} = User.follow(blocked, blocker)
480 assert User.following?(blocker, blocked)
481 assert User.following?(blocked, blocker)
483 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
485 assert data["type"] == "Block"
486 assert data["object"] == blocked.ap_id
487 assert data["actor"] == blocker.ap_id
489 blocker = User.get_cached_by_ap_id(data["actor"])
490 blocked = User.get_cached_by_ap_id(data["object"])
492 assert User.blocks?(blocker, blocked)
494 refute User.following?(blocker, blocked)
495 refute User.following?(blocked, blocker)
498 test "it works for incoming accepts which were pre-accepted" do
499 follower = insert(:user)
500 followed = insert(:user)
502 {:ok, follower} = User.follow(follower, followed)
503 assert User.following?(follower, followed) == true
505 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
508 File.read!("test/fixtures/mastodon-accept-activity.json")
510 |> Map.put("actor", followed.ap_id)
513 accept_data["object"]
514 |> Map.put("actor", follower.ap_id)
515 |> Map.put("id", follow_activity.data["id"])
517 accept_data = Map.put(accept_data, "object", object)
519 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
520 refute activity.local
522 assert activity.data["object"] == follow_activity.data["id"]
524 assert activity.data["id"] == accept_data["id"]
526 follower = User.get_cached_by_id(follower.id)
528 assert User.following?(follower, followed) == true
531 test "it works for incoming accepts which were orphaned" do
532 follower = insert(:user)
533 followed = insert(:user, locked: true)
535 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
538 File.read!("test/fixtures/mastodon-accept-activity.json")
540 |> Map.put("actor", followed.ap_id)
543 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
545 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
546 assert activity.data["object"] == follow_activity.data["id"]
548 follower = User.get_cached_by_id(follower.id)
550 assert User.following?(follower, followed) == true
553 test "it works for incoming accepts which are referenced by IRI only" do
554 follower = insert(:user)
555 followed = insert(:user, locked: true)
557 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
560 File.read!("test/fixtures/mastodon-accept-activity.json")
562 |> Map.put("actor", followed.ap_id)
563 |> Map.put("object", follow_activity.data["id"])
565 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
566 assert activity.data["object"] == follow_activity.data["id"]
568 follower = User.get_cached_by_id(follower.id)
570 assert User.following?(follower, followed) == true
572 follower = User.get_by_id(follower.id)
573 assert follower.following_count == 1
575 followed = User.get_by_id(followed.id)
576 assert followed.follower_count == 1
579 test "it fails for incoming accepts which cannot be correlated" do
580 follower = insert(:user)
581 followed = insert(:user, locked: true)
584 File.read!("test/fixtures/mastodon-accept-activity.json")
586 |> Map.put("actor", followed.ap_id)
589 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
591 :error = Transmogrifier.handle_incoming(accept_data)
593 follower = User.get_cached_by_id(follower.id)
595 refute User.following?(follower, followed) == true
598 test "it fails for incoming rejects which cannot be correlated" do
599 follower = insert(:user)
600 followed = insert(:user, locked: true)
603 File.read!("test/fixtures/mastodon-reject-activity.json")
605 |> Map.put("actor", followed.ap_id)
608 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
610 :error = Transmogrifier.handle_incoming(accept_data)
612 follower = User.get_cached_by_id(follower.id)
614 refute User.following?(follower, followed) == true
617 test "it works for incoming rejects which are orphaned" do
618 follower = insert(:user)
619 followed = insert(:user, locked: true)
621 {:ok, follower} = User.follow(follower, followed)
622 {:ok, _follow_activity} = ActivityPub.follow(follower, followed)
624 assert User.following?(follower, followed) == true
627 File.read!("test/fixtures/mastodon-reject-activity.json")
629 |> Map.put("actor", followed.ap_id)
632 Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
634 {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
635 refute activity.local
636 assert activity.data["id"] == reject_data["id"]
638 follower = User.get_cached_by_id(follower.id)
640 assert User.following?(follower, followed) == false
643 test "it works for incoming rejects which are referenced by IRI only" do
644 follower = insert(:user)
645 followed = insert(:user, locked: true)
647 {:ok, follower} = User.follow(follower, followed)
648 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
650 assert User.following?(follower, followed) == true
653 File.read!("test/fixtures/mastodon-reject-activity.json")
655 |> Map.put("actor", followed.ap_id)
656 |> Map.put("object", follow_activity.data["id"])
658 {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
660 follower = User.get_cached_by_id(follower.id)
662 assert User.following?(follower, followed) == false
665 test "it rejects activities without a valid ID" do
669 File.read!("test/fixtures/mastodon-follow-activity.json")
671 |> Map.put("object", user.ap_id)
674 :error = Transmogrifier.handle_incoming(data)
677 test "skip converting the content when it is nil" do
678 object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe"
680 {:ok, object} = Fetcher.fetch_and_contain_remote_object_from_id(object_id)
683 Pleroma.Web.ActivityPub.Transmogrifier.fix_object(Map.merge(object, %{"content" => nil}))
685 assert result["content"] == nil
688 test "it converts content of object to html" do
689 object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe"
691 {:ok, %{"content" => content_markdown}} =
692 Fetcher.fetch_and_contain_remote_object_from_id(object_id)
694 {:ok, %Pleroma.Object{data: %{"content" => content}} = object} =
695 Fetcher.fetch_object_from_id(object_id)
697 assert content_markdown ==
698 "Support this and our other Michigan!/usr/group videos and meetings. Learn more at http://mug.org/membership\n\nTwenty Years in Jail: FreeBSD's Jails, Then and Now\n\nJails started as a limited virtualization system, but over the last two years they've..."
701 "<p>Support this and our other Michigan!/usr/group videos and meetings. Learn more at <a href=\"http://mug.org/membership\">http://mug.org/membership</a></p><p>Twenty Years in Jail: FreeBSD’s Jails, Then and Now</p><p>Jails started as a limited virtualization system, but over the last two years they’ve…</p>"
703 assert object.data["mediaType"] == "text/html"
706 test "it remaps video URLs as attachments if necessary" do
708 Fetcher.fetch_object_from_id(
709 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
714 "mediaType" => "video/mp4",
718 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
719 "mediaType" => "video/mp4"
724 assert object.data["url"] ==
725 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
727 assert object.data["attachment"] == [attachment]
730 test "it accepts Flag activities" do
732 other_user = insert(:user)
734 {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
735 object = Object.normalize(activity)
739 "id" => activity.data["id"],
740 "content" => "test post",
741 "published" => object.data["published"],
742 "actor" => AccountView.render("show.json", %{user: user})
746 "@context" => "https://www.w3.org/ns/activitystreams",
747 "cc" => [user.ap_id],
748 "object" => [user.ap_id, activity.data["id"]],
750 "content" => "blocked AND reported!!!",
751 "actor" => other_user.ap_id
754 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
756 assert activity.data["object"] == [user.ap_id, note_obj]
757 assert activity.data["content"] == "blocked AND reported!!!"
758 assert activity.data["actor"] == other_user.ap_id
759 assert activity.data["cc"] == [user.ap_id]
762 test "it correctly processes messages with non-array to field" do
766 "@context" => "https://www.w3.org/ns/activitystreams",
767 "to" => "https://www.w3.org/ns/activitystreams#Public",
770 "content" => "blah blah blah",
772 "attributedTo" => user.ap_id,
775 "actor" => user.ap_id
778 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
780 assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["to"]
783 test "it correctly processes messages with non-array cc field" do
787 "@context" => "https://www.w3.org/ns/activitystreams",
788 "to" => user.follower_address,
789 "cc" => "https://www.w3.org/ns/activitystreams#Public",
792 "content" => "blah blah blah",
794 "attributedTo" => user.ap_id,
797 "actor" => user.ap_id
800 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
802 assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
803 assert [user.follower_address] == activity.data["to"]
806 test "it accepts Move activities" do
807 old_user = insert(:user)
808 new_user = insert(:user)
811 "@context" => "https://www.w3.org/ns/activitystreams",
813 "actor" => old_user.ap_id,
814 "object" => old_user.ap_id,
815 "target" => new_user.ap_id
818 assert :error = Transmogrifier.handle_incoming(message)
820 {:ok, _new_user} = User.update_and_set_cache(new_user, %{also_known_as: [old_user.ap_id]})
822 assert {:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(message)
823 assert activity.actor == old_user.ap_id
824 assert activity.data["actor"] == old_user.ap_id
825 assert activity.data["object"] == old_user.ap_id
826 assert activity.data["target"] == new_user.ap_id
827 assert activity.data["type"] == "Move"
831 describe "`handle_incoming/2`, Mastodon format `replies` handling" do
832 setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
833 setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
837 "test/fixtures/mastodon-post-activity.json"
841 items = get_in(data, ["object", "replies", "first", "items"])
842 assert length(items) > 0
844 %{data: data, items: items}
847 test "schedules background fetching of `replies` items if max thread depth limit allows", %{
851 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 10)
853 {:ok, _activity} = Transmogrifier.handle_incoming(data)
856 job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
857 assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
861 test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
863 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
865 {:ok, _activity} = Transmogrifier.handle_incoming(data)
867 assert all_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker) == []
871 describe "`handle_incoming/2`, Pleroma format `replies` handling" do
872 setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
873 setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
878 {:ok, activity} = CommonAPI.post(user, %{status: "post1"})
881 CommonAPI.post(user, %{status: "reply1", in_reply_to_status_id: activity.id})
884 CommonAPI.post(user, %{status: "reply2", in_reply_to_status_id: activity.id})
886 replies_uris = Enum.map([reply1, reply2], fn a -> a.object.data["id"] end)
888 {:ok, federation_output} = Transmogrifier.prepare_outgoing(activity.data)
890 Repo.delete(activity.object)
891 Repo.delete(activity)
893 %{federation_output: federation_output, replies_uris: replies_uris}
896 test "schedules background fetching of `replies` items if max thread depth limit allows", %{
897 federation_output: federation_output,
898 replies_uris: replies_uris
900 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 1)
902 {:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
904 for id <- replies_uris do
905 job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
906 assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
910 test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
911 %{federation_output: federation_output} do
912 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
914 {:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
916 assert all_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker) == []
920 describe "prepare outgoing" do
921 test "it inlines private announced objects" do
924 {:ok, activity} = CommonAPI.post(user, %{status: "hey", visibility: "private"})
926 {:ok, announce_activity} = CommonAPI.repeat(activity.id, user)
928 {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
930 assert modified["object"]["content"] == "hey"
931 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
934 test "it turns mentions into tags" do
936 other_user = insert(:user)
939 CommonAPI.post(user, %{status: "hey, @#{other_user.nickname}, how are ya? #2hu"})
941 with_mock Pleroma.Notification,
942 get_notified_from_activity: fn _, _ -> [] end do
943 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
945 object = modified["object"]
947 expected_mention = %{
948 "href" => other_user.ap_id,
949 "name" => "@#{other_user.nickname}",
954 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
959 refute called(Pleroma.Notification.get_notified_from_activity(:_, :_))
960 assert Enum.member?(object["tag"], expected_tag)
961 assert Enum.member?(object["tag"], expected_mention)
965 test "it adds the sensitive property" do
968 {:ok, activity} = CommonAPI.post(user, %{status: "#nsfw hey"})
969 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
971 assert modified["object"]["sensitive"]
974 test "it adds the json-ld context and the conversation property" do
977 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
978 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
980 assert modified["@context"] ==
981 Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
983 assert modified["object"]["conversation"] == modified["context"]
986 test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
989 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
990 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
992 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
995 test "it strips internal hashtag data" do
998 {:ok, activity} = CommonAPI.post(user, %{status: "#2hu"})
1001 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1002 "type" => "Hashtag",
1006 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1008 assert modified["object"]["tag"] == [expected_tag]
1011 test "it strips internal fields" do
1012 user = insert(:user)
1014 {:ok, activity} = CommonAPI.post(user, %{status: "#2hu :firefox:"})
1016 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1018 assert length(modified["object"]["tag"]) == 2
1020 assert is_nil(modified["object"]["emoji"])
1021 assert is_nil(modified["object"]["like_count"])
1022 assert is_nil(modified["object"]["announcements"])
1023 assert is_nil(modified["object"]["announcement_count"])
1024 assert is_nil(modified["object"]["context_id"])
1027 test "it strips internal fields of article" do
1028 activity = insert(:article_activity)
1030 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1032 assert length(modified["object"]["tag"]) == 2
1034 assert is_nil(modified["object"]["emoji"])
1035 assert is_nil(modified["object"]["like_count"])
1036 assert is_nil(modified["object"]["announcements"])
1037 assert is_nil(modified["object"]["announcement_count"])
1038 assert is_nil(modified["object"]["context_id"])
1039 assert is_nil(modified["object"]["likes"])
1042 test "the directMessage flag is present" do
1043 user = insert(:user)
1044 other_user = insert(:user)
1046 {:ok, activity} = CommonAPI.post(user, %{status: "2hu :moominmamma:"})
1048 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1050 assert modified["directMessage"] == false
1052 {:ok, activity} = CommonAPI.post(user, %{status: "@#{other_user.nickname} :moominmamma:"})
1054 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1056 assert modified["directMessage"] == false
1059 CommonAPI.post(user, %{
1060 status: "@#{other_user.nickname} :moominmamma:",
1061 visibility: "direct"
1064 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1066 assert modified["directMessage"] == true
1069 test "it strips BCC field" do
1070 user = insert(:user)
1071 {:ok, list} = Pleroma.List.create("foo", user)
1073 {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
1075 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1077 assert is_nil(modified["bcc"])
1080 test "it can handle Listen activities" do
1081 listen_activity = insert(:listen)
1083 {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
1085 assert modified["type"] == "Listen"
1087 user = insert(:user)
1089 {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
1091 {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
1095 describe "user upgrade" do
1096 test "it upgrades a user to activitypub" do
1099 nickname: "rye@niu.moe",
1101 ap_id: "https://niu.moe/users/rye",
1102 follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
1105 user_two = insert(:user)
1106 Pleroma.FollowingRelationship.follow(user_two, user, :follow_accept)
1108 {:ok, activity} = CommonAPI.post(user, %{status: "test"})
1109 {:ok, unrelated_activity} = CommonAPI.post(user_two, %{status: "test"})
1110 assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
1112 user = User.get_cached_by_id(user.id)
1113 assert user.note_count == 1
1115 {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
1116 ObanHelpers.perform_all()
1118 assert user.ap_enabled
1119 assert user.note_count == 1
1120 assert user.follower_address == "https://niu.moe/users/rye/followers"
1121 assert user.following_address == "https://niu.moe/users/rye/following"
1123 user = User.get_cached_by_id(user.id)
1124 assert user.note_count == 1
1126 activity = Activity.get_by_id(activity.id)
1127 assert user.follower_address in activity.recipients
1133 "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
1142 "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
1147 refute "..." in activity.recipients
1149 unrelated_activity = Activity.get_by_id(unrelated_activity.id)
1150 refute user.follower_address in unrelated_activity.recipients
1152 user_two = User.get_cached_by_id(user_two.id)
1153 assert User.following?(user_two, user)
1154 refute "..." in User.following(user_two)
1158 describe "actor rewriting" do
1159 test "it fixes the actor URL property to be a proper URI" do
1161 "url" => %{"href" => "http://example.com"}
1164 rewritten = Transmogrifier.maybe_fix_user_object(data)
1165 assert rewritten["url"] == "http://example.com"
1169 describe "actor origin containment" do
1170 test "it rejects activities which reference objects with bogus origins" do
1172 "@context" => "https://www.w3.org/ns/activitystreams",
1173 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1174 "actor" => "http://mastodon.example.org/users/admin",
1175 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1176 "object" => "https://info.pleroma.site/activity.json",
1177 "type" => "Announce"
1180 assert capture_log(fn ->
1181 {:error, _} = Transmogrifier.handle_incoming(data)
1182 end) =~ "Object containment failed"
1185 test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
1187 "@context" => "https://www.w3.org/ns/activitystreams",
1188 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1189 "actor" => "http://mastodon.example.org/users/admin",
1190 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1191 "object" => "https://info.pleroma.site/activity2.json",
1192 "type" => "Announce"
1195 assert capture_log(fn ->
1196 {:error, _} = Transmogrifier.handle_incoming(data)
1197 end) =~ "Object containment failed"
1200 test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
1202 "@context" => "https://www.w3.org/ns/activitystreams",
1203 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1204 "actor" => "http://mastodon.example.org/users/admin",
1205 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1206 "object" => "https://info.pleroma.site/activity3.json",
1207 "type" => "Announce"
1210 assert capture_log(fn ->
1211 {:error, _} = Transmogrifier.handle_incoming(data)
1212 end) =~ "Object containment failed"
1216 describe "reserialization" do
1217 test "successfully reserializes a message with inReplyTo == nil" do
1218 user = insert(:user)
1221 "@context" => "https://www.w3.org/ns/activitystreams",
1222 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1226 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1231 "attributedTo" => user.ap_id
1233 "actor" => user.ap_id
1236 {:ok, activity} = Transmogrifier.handle_incoming(message)
1238 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1241 test "successfully reserializes a message with AS2 objects in IR" do
1242 user = insert(:user)
1245 "@context" => "https://www.w3.org/ns/activitystreams",
1246 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1250 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1255 "attributedTo" => user.ap_id,
1257 %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
1258 %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
1261 "actor" => user.ap_id
1264 {:ok, activity} = Transmogrifier.handle_incoming(message)
1266 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1270 test "Rewrites Answers to Notes" do
1271 user = insert(:user)
1273 {:ok, poll_activity} =
1274 CommonAPI.post(user, %{
1276 poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
1279 poll_object = Object.normalize(poll_activity)
1280 # TODO: Replace with CommonAPI vote creation when implemented
1282 File.read!("test/fixtures/mastodon-vote.json")
1284 |> Kernel.put_in(["to"], user.ap_id)
1285 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
1286 |> Kernel.put_in(["object", "to"], user.ap_id)
1288 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
1289 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
1291 assert data["object"]["type"] == "Note"
1294 describe "fix_explicit_addressing" do
1296 user = insert(:user)
1300 test "moves non-explicitly mentioned actors to cc", %{user: user} do
1301 explicitly_mentioned_actors = [
1302 "https://pleroma.gold/users/user1",
1303 "https://pleroma.gold/user2"
1307 "actor" => user.ap_id,
1308 "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"],
1311 Enum.map(explicitly_mentioned_actors, fn href ->
1312 %{"type" => "Mention", "href" => href}
1316 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1317 assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
1318 refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
1319 assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
1322 test "does not move actor's follower collection to cc", %{user: user} do
1324 "actor" => user.ap_id,
1325 "to" => [user.follower_address],
1329 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1330 assert user.follower_address in fixed_object["to"]
1331 refute user.follower_address in fixed_object["cc"]
1334 test "removes recipient's follower collection from cc", %{user: user} do
1335 recipient = insert(:user)
1338 "actor" => user.ap_id,
1339 "to" => [recipient.ap_id, "https://www.w3.org/ns/activitystreams#Public"],
1340 "cc" => [user.follower_address, recipient.follower_address]
1343 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1345 assert user.follower_address in fixed_object["cc"]
1346 refute recipient.follower_address in fixed_object["cc"]
1347 refute recipient.follower_address in fixed_object["to"]
1351 describe "fix_summary/1" do
1352 test "returns fixed object" do
1353 assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
1354 assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
1355 assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
1359 describe "fix_in_reply_to/2" do
1360 setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
1363 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1367 test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
1368 assert Transmogrifier.fix_in_reply_to(data) == data
1371 test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
1372 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
1375 Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
1377 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1378 assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
1379 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1382 Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
1384 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1385 assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
1386 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1389 Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
1391 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1392 assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
1393 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1395 object_with_reply = Map.put(data["object"], "inReplyTo", [])
1396 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1397 assert modified_object["inReplyTo"] == []
1398 assert modified_object["inReplyToAtomUri"] == ""
1401 @tag capture_log: true
1402 test "returns modified object when allowed incoming reply", %{data: data} do
1407 "https://shitposter.club/notice/2827873"
1410 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
1411 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1413 assert modified_object["inReplyTo"] ==
1414 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
1416 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1418 assert modified_object["context"] ==
1419 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1423 describe "fix_url/1" do
1424 test "fixes data for object when url is map" do
1428 "mimeType" => "video/mp4",
1429 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1433 assert Transmogrifier.fix_url(object) == %{
1434 "url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1438 test "fixes data for video object" do
1444 "mimeType" => "video/mp4",
1445 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1449 "mimeType" => "video/mp4",
1450 "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
1454 "mimeType" => "text/html",
1455 "href" => "https://peertube.-2d4c2d1630e3"
1459 "mimeType" => "text/html",
1460 "href" => "https://peertube.-2d4c2d16377-42"
1465 assert Transmogrifier.fix_url(object) == %{
1468 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1469 "mimeType" => "video/mp4",
1474 "url" => "https://peertube.-2d4c2d1630e3"
1478 test "fixes url for not Video object" do
1484 "mimeType" => "text/html",
1485 "href" => "https://peertube.-2d4c2d1630e3"
1489 "mimeType" => "text/html",
1490 "href" => "https://peertube.-2d4c2d16377-42"
1495 assert Transmogrifier.fix_url(object) == %{
1497 "url" => "https://peertube.-2d4c2d1630e3"
1500 assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
1506 test "retunrs not modified object" do
1507 assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
1511 describe "get_obj_helper/2" do
1512 test "returns nil when cannot normalize object" do
1513 assert capture_log(fn ->
1514 refute Transmogrifier.get_obj_helper("test-obj-id")
1515 end) =~ "Unsupported URI scheme"
1518 @tag capture_log: true
1519 test "returns {:ok, %Object{}} for success case" do
1520 assert {:ok, %Object{}} =
1521 Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
1525 describe "fix_attachments/1" do
1526 test "returns not modified object" do
1527 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1528 assert Transmogrifier.fix_attachments(data) == data
1531 test "returns modified object when attachment is map" do
1532 assert Transmogrifier.fix_attachments(%{
1534 "mediaType" => "video/mp4",
1535 "url" => "https://peertube.moe/stat-480.mp4"
1540 "mediaType" => "video/mp4",
1542 %{"href" => "https://peertube.moe/stat-480.mp4", "mediaType" => "video/mp4"}
1549 test "returns modified object when attachment is list" do
1550 assert Transmogrifier.fix_attachments(%{
1552 %{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
1553 %{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
1558 "mediaType" => "video/mp4",
1560 %{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}
1564 "mediaType" => "video/mp4",
1566 %{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}
1574 describe "fix_emoji/1" do
1575 test "returns not modified object when object not contains tags" do
1576 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1577 assert Transmogrifier.fix_emoji(data) == data
1580 test "returns object with emoji when object contains list tags" do
1581 assert Transmogrifier.fix_emoji(%{
1583 %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
1584 %{"type" => "Hashtag"}
1587 "emoji" => %{"bib" => "/test"},
1589 %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
1590 %{"type" => "Hashtag"}
1595 test "returns object with emoji when object contains map tag" do
1596 assert Transmogrifier.fix_emoji(%{
1597 "tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
1599 "emoji" => %{"bib" => "/test"},
1600 "tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}
1605 describe "set_replies/1" do
1606 setup do: clear_config([:activitypub, :note_replies_output_limit], 2)
1608 test "returns unmodified object if activity doesn't have self-replies" do
1609 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1610 assert Transmogrifier.set_replies(data) == data
1613 test "sets `replies` collection with a limited number of self-replies" do
1614 [user, another_user] = insert_list(2, :user)
1616 {:ok, %{id: id1} = activity} = CommonAPI.post(user, %{status: "1"})
1618 {:ok, %{id: id2} = self_reply1} =
1619 CommonAPI.post(user, %{status: "self-reply 1", in_reply_to_status_id: id1})
1621 {:ok, self_reply2} =
1622 CommonAPI.post(user, %{status: "self-reply 2", in_reply_to_status_id: id1})
1624 # Assuming to _not_ be present in `replies` due to :note_replies_output_limit is set to 2
1625 {:ok, _} = CommonAPI.post(user, %{status: "self-reply 3", in_reply_to_status_id: id1})
1628 CommonAPI.post(user, %{
1629 status: "self-reply to self-reply",
1630 in_reply_to_status_id: id2
1634 CommonAPI.post(another_user, %{
1635 status: "another user's reply",
1636 in_reply_to_status_id: id1
1639 object = Object.normalize(activity)
1640 replies_uris = Enum.map([self_reply1, self_reply2], fn a -> a.object.data["id"] end)
1642 assert %{"type" => "Collection", "items" => ^replies_uris} =
1643 Transmogrifier.set_replies(object.data)["replies"]
1647 test "take_emoji_tags/1" do
1648 user = insert(:user, %{emoji: %{"firefox" => "https://example.org/firefox.png"}})
1650 assert Transmogrifier.take_emoji_tags(user) == [
1652 "icon" => %{"type" => "Image", "url" => "https://example.org/firefox.png"},
1653 "id" => "https://example.org/firefox.png",
1654 "name" => ":firefox:",
1656 "updated" => "1970-01-01T00:00:00Z"