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.Transmogrifier
15 alias Pleroma.Web.AdminAPI.AccountView
16 alias Pleroma.Web.CommonAPI
19 import Pleroma.Factory
20 import ExUnit.CaptureLog
23 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
27 setup do: clear_config([:instance, :max_remote_account_fields])
29 describe "handle_incoming" do
30 test "it works for incoming notices with tag not being an array (kroeg)" do
31 data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Poison.decode!()
33 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
34 object = Object.normalize(data["object"])
36 assert object.data["emoji"] == %{
37 "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png"
40 data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Poison.decode!()
42 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
43 object = Object.normalize(data["object"])
45 assert "test" in object.data["tag"]
48 test "it works for incoming notices with url not being a string (prismo)" do
49 data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!()
51 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
52 object = Object.normalize(data["object"])
54 assert object.data["url"] == "https://prismo.news/posts/83"
57 test "it cleans up incoming notices which are not really DMs" do
59 other_user = insert(:user)
61 to = [user.ap_id, other_user.ap_id]
64 File.read!("test/fixtures/mastodon-post-activity.json")
74 data = Map.put(data, "object", object)
76 {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
78 assert data["to"] == []
79 assert data["cc"] == to
81 object_data = Object.normalize(activity).data
83 assert object_data["to"] == []
84 assert object_data["cc"] == to
87 test "it ignores an incoming notice if we already have it" do
88 activity = insert(:note_activity)
91 File.read!("test/fixtures/mastodon-post-activity.json")
93 |> Map.put("object", Object.normalize(activity).data)
95 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
97 assert activity == returned_activity
100 @tag capture_log: true
101 test "it fetches reply-to activities if we don't have them" do
103 File.read!("test/fixtures/mastodon-post-activity.json")
108 |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
110 data = Map.put(data, "object", object)
111 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
112 returned_object = Object.normalize(returned_activity, false)
115 Activity.get_create_by_object_ap_id(
116 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
119 assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
122 test "it does not fetch reply-to activities beyond max replies depth limit" do
124 File.read!("test/fixtures/mastodon-post-activity.json")
129 |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
131 data = Map.put(data, "object", object)
133 with_mock Pleroma.Web.Federator,
134 allowed_thread_distance?: fn _ -> false end do
135 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
137 returned_object = Object.normalize(returned_activity, false)
139 refute Activity.get_create_by_object_ap_id(
140 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
143 assert returned_object.data["inReplyToAtomUri"] ==
144 "https://shitposter.club/notice/2827873"
148 test "it does not crash if the object in inReplyTo can't be fetched" do
150 File.read!("test/fixtures/mastodon-post-activity.json")
155 |> Map.put("inReplyTo", "https://404.site/whatever")
159 |> Map.put("object", object)
161 assert capture_log(fn ->
162 {:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
163 end) =~ "[warn] Couldn't fetch \"https://404.site/whatever\", error: nil"
166 test "it works for incoming notices" do
167 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
169 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
172 "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity"
174 assert data["context"] ==
175 "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
177 assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
179 assert data["cc"] == [
180 "http://mastodon.example.org/users/admin/followers",
181 "http://localtesting.pleroma.lol/users/lain"
184 assert data["actor"] == "http://mastodon.example.org/users/admin"
186 object_data = Object.normalize(data["object"]).data
188 assert object_data["id"] ==
189 "http://mastodon.example.org/users/admin/statuses/99512778738411822"
191 assert object_data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
193 assert object_data["cc"] == [
194 "http://mastodon.example.org/users/admin/followers",
195 "http://localtesting.pleroma.lol/users/lain"
198 assert object_data["actor"] == "http://mastodon.example.org/users/admin"
199 assert object_data["attributedTo"] == "http://mastodon.example.org/users/admin"
201 assert object_data["context"] ==
202 "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
204 assert object_data["sensitive"] == true
206 user = User.get_cached_by_ap_id(object_data["actor"])
208 assert user.note_count == 1
211 test "it works for incoming notices with hashtags" do
212 data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
214 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
215 object = Object.normalize(data["object"])
217 assert Enum.at(object.data["tag"], 2) == "moo"
220 test "it works for incoming questions" do
221 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
223 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
225 object = Object.normalize(activity)
227 assert Enum.all?(object.data["oneOf"], fn choice ->
230 "Everyone knows that!",
231 "25 char limit is dumb",
232 "I can't even fit a funny"
237 test "it works for incoming listens" do
239 "@context" => "https://www.w3.org/ns/activitystreams",
240 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
243 "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
244 "actor" => "http://mastodon.example.org/users/admin",
247 "id" => "http://mastodon.example.org/users/admin/listens/1234",
248 "attributedTo" => "http://mastodon.example.org/users/admin",
249 "title" => "lain radio episode 1",
251 "album" => "lain radio",
256 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
258 object = Object.normalize(activity)
260 assert object.data["title"] == "lain radio episode 1"
261 assert object.data["artist"] == "lain"
262 assert object.data["album"] == "lain radio"
263 assert object.data["length"] == 180_000
266 test "it rewrites Note votes to Answers and increments vote counters on question activities" do
270 CommonAPI.post(user, %{
272 poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
275 object = Object.normalize(activity)
278 File.read!("test/fixtures/mastodon-vote.json")
280 |> Kernel.put_in(["to"], user.ap_id)
281 |> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
282 |> Kernel.put_in(["object", "to"], user.ap_id)
284 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
285 answer_object = Object.normalize(activity)
286 assert answer_object.data["type"] == "Answer"
287 object = Object.get_by_ap_id(object.data["id"])
290 object.data["oneOf"],
292 %{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
298 test "it works for incoming notices with contentMap" do
300 File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
302 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
303 object = Object.normalize(data["object"])
305 assert object.data["content"] ==
306 "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
309 test "it works for incoming notices with to/cc not being an array (kroeg)" do
310 data = File.read!("test/fixtures/kroeg-post-activity.json") |> Poison.decode!()
312 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
313 object = Object.normalize(data["object"])
315 assert object.data["content"] ==
316 "<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>"
319 test "it ensures that as:Public activities make it to their followers collection" do
323 File.read!("test/fixtures/mastodon-post-activity.json")
325 |> Map.put("actor", user.ap_id)
326 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
331 |> Map.put("attributedTo", user.ap_id)
332 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
334 |> Map.put("id", user.ap_id <> "/activities/12345678")
336 data = Map.put(data, "object", object)
338 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
340 assert data["cc"] == [User.ap_followers(user)]
343 test "it ensures that address fields become lists" do
347 File.read!("test/fixtures/mastodon-post-activity.json")
349 |> Map.put("actor", user.ap_id)
350 |> Map.put("to", nil)
351 |> Map.put("cc", nil)
355 |> Map.put("attributedTo", user.ap_id)
356 |> Map.put("to", nil)
357 |> Map.put("cc", nil)
358 |> Map.put("id", user.ap_id <> "/activities/12345678")
360 data = Map.put(data, "object", object)
362 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
364 assert !is_nil(data["to"])
365 assert !is_nil(data["cc"])
368 test "it strips internal likes" do
370 File.read!("test/fixtures/mastodon-post-activity.json")
375 "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
376 "id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
378 "type" => "OrderedCollection"
381 object = Map.put(data["object"], "likes", likes)
382 data = Map.put(data, "object", object)
384 {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
386 refute Map.has_key?(object.data, "likes")
389 test "it strips internal reactions" do
391 {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
392 {:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "📢")
394 %{object: object} = Activity.get_by_id_with_object(activity.id)
395 assert Map.has_key?(object.data, "reactions")
396 assert Map.has_key?(object.data, "reaction_count")
398 object_data = Transmogrifier.strip_internal_fields(object.data)
399 refute Map.has_key?(object_data, "reactions")
400 refute Map.has_key?(object_data, "reaction_count")
403 test "it works for incomming unfollows with an existing follow" do
407 File.read!("test/fixtures/mastodon-follow-activity.json")
409 |> Map.put("object", user.ap_id)
411 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
414 File.read!("test/fixtures/mastodon-unfollow-activity.json")
416 |> Map.put("object", follow_data)
418 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
420 assert data["type"] == "Undo"
421 assert data["object"]["type"] == "Follow"
422 assert data["object"]["object"] == user.ap_id
423 assert data["actor"] == "http://mastodon.example.org/users/admin"
425 refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
428 test "it works for incoming follows to locked account" do
429 pending_follower = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
430 user = insert(:user, locked: true)
433 File.read!("test/fixtures/mastodon-follow-activity.json")
435 |> Map.put("object", user.ap_id)
437 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
439 assert data["type"] == "Follow"
440 assert data["object"] == user.ap_id
441 assert data["state"] == "pending"
442 assert data["actor"] == "http://mastodon.example.org/users/admin"
444 assert [^pending_follower] = User.get_follow_requests(user)
447 test "it works for incoming accepts which were pre-accepted" do
448 follower = insert(:user)
449 followed = insert(:user)
451 {:ok, follower} = User.follow(follower, followed)
452 assert User.following?(follower, followed) == true
454 {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
457 File.read!("test/fixtures/mastodon-accept-activity.json")
459 |> Map.put("actor", followed.ap_id)
462 accept_data["object"]
463 |> Map.put("actor", follower.ap_id)
464 |> Map.put("id", follow_activity.data["id"])
466 accept_data = Map.put(accept_data, "object", object)
468 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
469 refute activity.local
471 assert activity.data["object"] == follow_activity.data["id"]
473 assert activity.data["id"] == accept_data["id"]
475 follower = User.get_cached_by_id(follower.id)
477 assert User.following?(follower, followed) == true
480 test "it works for incoming accepts which were orphaned" do
481 follower = insert(:user)
482 followed = insert(:user, locked: true)
484 {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
487 File.read!("test/fixtures/mastodon-accept-activity.json")
489 |> Map.put("actor", followed.ap_id)
492 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
494 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
495 assert activity.data["object"] == follow_activity.data["id"]
497 follower = User.get_cached_by_id(follower.id)
499 assert User.following?(follower, followed) == true
502 test "it works for incoming accepts which are referenced by IRI only" do
503 follower = insert(:user)
504 followed = insert(:user, locked: true)
506 {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
509 File.read!("test/fixtures/mastodon-accept-activity.json")
511 |> Map.put("actor", followed.ap_id)
512 |> Map.put("object", follow_activity.data["id"])
514 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
515 assert activity.data["object"] == follow_activity.data["id"]
517 follower = User.get_cached_by_id(follower.id)
519 assert User.following?(follower, followed) == true
521 follower = User.get_by_id(follower.id)
522 assert follower.following_count == 1
524 followed = User.get_by_id(followed.id)
525 assert followed.follower_count == 1
528 test "it fails for incoming accepts which cannot be correlated" do
529 follower = insert(:user)
530 followed = insert(:user, locked: true)
533 File.read!("test/fixtures/mastodon-accept-activity.json")
535 |> Map.put("actor", followed.ap_id)
538 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
540 :error = Transmogrifier.handle_incoming(accept_data)
542 follower = User.get_cached_by_id(follower.id)
544 refute User.following?(follower, followed) == true
547 test "it fails for incoming rejects which cannot be correlated" do
548 follower = insert(:user)
549 followed = insert(:user, locked: true)
552 File.read!("test/fixtures/mastodon-reject-activity.json")
554 |> Map.put("actor", followed.ap_id)
557 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
559 :error = Transmogrifier.handle_incoming(accept_data)
561 follower = User.get_cached_by_id(follower.id)
563 refute User.following?(follower, followed) == true
566 test "it works for incoming rejects which are orphaned" do
567 follower = insert(:user)
568 followed = insert(:user, locked: true)
570 {:ok, follower} = User.follow(follower, followed)
571 {:ok, _, _, _follow_activity} = CommonAPI.follow(follower, followed)
573 assert User.following?(follower, followed) == true
576 File.read!("test/fixtures/mastodon-reject-activity.json")
578 |> Map.put("actor", followed.ap_id)
581 Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
583 {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
584 refute activity.local
585 assert activity.data["id"] == reject_data["id"]
587 follower = User.get_cached_by_id(follower.id)
589 assert User.following?(follower, followed) == false
592 test "it works for incoming rejects which are referenced by IRI only" do
593 follower = insert(:user)
594 followed = insert(:user, locked: true)
596 {:ok, follower} = User.follow(follower, followed)
597 {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
599 assert User.following?(follower, followed) == true
602 File.read!("test/fixtures/mastodon-reject-activity.json")
604 |> Map.put("actor", followed.ap_id)
605 |> Map.put("object", follow_activity.data["id"])
607 {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
609 follower = User.get_cached_by_id(follower.id)
611 assert User.following?(follower, followed) == false
614 test "it rejects activities without a valid ID" do
618 File.read!("test/fixtures/mastodon-follow-activity.json")
620 |> Map.put("object", user.ap_id)
623 :error = Transmogrifier.handle_incoming(data)
626 test "skip converting the content when it is nil" do
627 object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe"
629 {:ok, object} = Fetcher.fetch_and_contain_remote_object_from_id(object_id)
632 Pleroma.Web.ActivityPub.Transmogrifier.fix_object(Map.merge(object, %{"content" => nil}))
634 assert result["content"] == nil
637 test "it converts content of object to html" do
638 object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe"
640 {:ok, %{"content" => content_markdown}} =
641 Fetcher.fetch_and_contain_remote_object_from_id(object_id)
643 {:ok, %Pleroma.Object{data: %{"content" => content}} = object} =
644 Fetcher.fetch_object_from_id(object_id)
646 assert content_markdown ==
647 "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..."
650 "<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>"
652 assert object.data["mediaType"] == "text/html"
655 test "it remaps video URLs as attachments if necessary" do
657 Fetcher.fetch_object_from_id(
658 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
661 assert object.data["url"] ==
662 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
664 assert object.data["attachment"] == [
667 "mediaType" => "video/mp4",
671 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
672 "mediaType" => "video/mp4"
679 Fetcher.fetch_object_from_id(
680 "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
683 assert object.data["attachment"] == [
686 "mediaType" => "video/mp4",
690 "https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
691 "mediaType" => "video/mp4"
697 assert object.data["url"] ==
698 "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
701 test "it accepts Flag activities" do
703 other_user = insert(:user)
705 {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
706 object = Object.normalize(activity)
710 "id" => activity.data["id"],
711 "content" => "test post",
712 "published" => object.data["published"],
713 "actor" => AccountView.render("show.json", %{user: user, skip_visibility_check: true})
717 "@context" => "https://www.w3.org/ns/activitystreams",
718 "cc" => [user.ap_id],
719 "object" => [user.ap_id, activity.data["id"]],
721 "content" => "blocked AND reported!!!",
722 "actor" => other_user.ap_id
725 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
727 assert activity.data["object"] == [user.ap_id, note_obj]
728 assert activity.data["content"] == "blocked AND reported!!!"
729 assert activity.data["actor"] == other_user.ap_id
730 assert activity.data["cc"] == [user.ap_id]
733 test "it correctly processes messages with non-array to field" do
737 "@context" => "https://www.w3.org/ns/activitystreams",
738 "to" => "https://www.w3.org/ns/activitystreams#Public",
741 "content" => "blah blah blah",
743 "attributedTo" => user.ap_id,
746 "actor" => user.ap_id
749 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
751 assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["to"]
754 test "it correctly processes messages with non-array cc field" do
758 "@context" => "https://www.w3.org/ns/activitystreams",
759 "to" => user.follower_address,
760 "cc" => "https://www.w3.org/ns/activitystreams#Public",
763 "content" => "blah blah blah",
765 "attributedTo" => user.ap_id,
768 "actor" => user.ap_id
771 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
773 assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
774 assert [user.follower_address] == activity.data["to"]
777 test "it correctly processes messages with weirdness in address fields" do
781 "@context" => "https://www.w3.org/ns/activitystreams",
782 "to" => [nil, user.follower_address],
783 "cc" => ["https://www.w3.org/ns/activitystreams#Public", ["¿"]],
788 "attributedTo" => user.ap_id,
791 "actor" => user.ap_id
794 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
796 assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
797 assert [user.follower_address] == activity.data["to"]
800 test "it accepts Move activities" do
801 old_user = insert(:user)
802 new_user = insert(:user)
805 "@context" => "https://www.w3.org/ns/activitystreams",
807 "actor" => old_user.ap_id,
808 "object" => old_user.ap_id,
809 "target" => new_user.ap_id
812 assert :error = Transmogrifier.handle_incoming(message)
814 {:ok, _new_user} = User.update_and_set_cache(new_user, %{also_known_as: [old_user.ap_id]})
816 assert {:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(message)
817 assert activity.actor == old_user.ap_id
818 assert activity.data["actor"] == old_user.ap_id
819 assert activity.data["object"] == old_user.ap_id
820 assert activity.data["target"] == new_user.ap_id
821 assert activity.data["type"] == "Move"
825 describe "`handle_incoming/2`, Mastodon format `replies` handling" do
826 setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
827 setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
831 "test/fixtures/mastodon-post-activity.json"
835 items = get_in(data, ["object", "replies", "first", "items"])
836 assert length(items) > 0
838 %{data: data, items: items}
841 test "schedules background fetching of `replies` items if max thread depth limit allows", %{
845 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 10)
847 {:ok, _activity} = Transmogrifier.handle_incoming(data)
850 job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
851 assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
855 test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
857 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
859 {:ok, _activity} = Transmogrifier.handle_incoming(data)
861 assert all_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker) == []
865 describe "`handle_incoming/2`, Pleroma format `replies` handling" do
866 setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
867 setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
872 {:ok, activity} = CommonAPI.post(user, %{status: "post1"})
875 CommonAPI.post(user, %{status: "reply1", in_reply_to_status_id: activity.id})
878 CommonAPI.post(user, %{status: "reply2", in_reply_to_status_id: activity.id})
880 replies_uris = Enum.map([reply1, reply2], fn a -> a.object.data["id"] end)
882 {:ok, federation_output} = Transmogrifier.prepare_outgoing(activity.data)
884 Repo.delete(activity.object)
885 Repo.delete(activity)
887 %{federation_output: federation_output, replies_uris: replies_uris}
890 test "schedules background fetching of `replies` items if max thread depth limit allows", %{
891 federation_output: federation_output,
892 replies_uris: replies_uris
894 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 1)
896 {:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
898 for id <- replies_uris do
899 job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
900 assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
904 test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
905 %{federation_output: federation_output} do
906 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
908 {:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
910 assert all_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker) == []
914 describe "prepare outgoing" do
915 test "it inlines private announced objects" do
918 {:ok, activity} = CommonAPI.post(user, %{status: "hey", visibility: "private"})
920 {:ok, announce_activity} = CommonAPI.repeat(activity.id, user)
922 {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
924 assert modified["object"]["content"] == "hey"
925 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
928 test "it turns mentions into tags" do
930 other_user = insert(:user)
933 CommonAPI.post(user, %{status: "hey, @#{other_user.nickname}, how are ya? #2hu"})
935 with_mock Pleroma.Notification,
936 get_notified_from_activity: fn _, _ -> [] end do
937 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
939 object = modified["object"]
941 expected_mention = %{
942 "href" => other_user.ap_id,
943 "name" => "@#{other_user.nickname}",
948 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
953 refute called(Pleroma.Notification.get_notified_from_activity(:_, :_))
954 assert Enum.member?(object["tag"], expected_tag)
955 assert Enum.member?(object["tag"], expected_mention)
959 test "it adds the sensitive property" do
962 {:ok, activity} = CommonAPI.post(user, %{status: "#nsfw hey"})
963 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
965 assert modified["object"]["sensitive"]
968 test "it adds the json-ld context and the conversation property" do
971 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
972 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
974 assert modified["@context"] ==
975 Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
977 assert modified["object"]["conversation"] == modified["context"]
980 test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
983 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
984 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
986 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
989 test "it strips internal hashtag data" do
992 {:ok, activity} = CommonAPI.post(user, %{status: "#2hu"})
995 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1000 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1002 assert modified["object"]["tag"] == [expected_tag]
1005 test "it strips internal fields" do
1006 user = insert(:user)
1008 {:ok, activity} = CommonAPI.post(user, %{status: "#2hu :firefox:"})
1010 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1012 assert length(modified["object"]["tag"]) == 2
1014 assert is_nil(modified["object"]["emoji"])
1015 assert is_nil(modified["object"]["like_count"])
1016 assert is_nil(modified["object"]["announcements"])
1017 assert is_nil(modified["object"]["announcement_count"])
1018 assert is_nil(modified["object"]["context_id"])
1021 test "it strips internal fields of article" do
1022 activity = insert(:article_activity)
1024 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1026 assert length(modified["object"]["tag"]) == 2
1028 assert is_nil(modified["object"]["emoji"])
1029 assert is_nil(modified["object"]["like_count"])
1030 assert is_nil(modified["object"]["announcements"])
1031 assert is_nil(modified["object"]["announcement_count"])
1032 assert is_nil(modified["object"]["context_id"])
1033 assert is_nil(modified["object"]["likes"])
1036 test "the directMessage flag is present" do
1037 user = insert(:user)
1038 other_user = insert(:user)
1040 {:ok, activity} = CommonAPI.post(user, %{status: "2hu :moominmamma:"})
1042 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1044 assert modified["directMessage"] == false
1046 {:ok, activity} = CommonAPI.post(user, %{status: "@#{other_user.nickname} :moominmamma:"})
1048 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1050 assert modified["directMessage"] == false
1053 CommonAPI.post(user, %{
1054 status: "@#{other_user.nickname} :moominmamma:",
1055 visibility: "direct"
1058 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1060 assert modified["directMessage"] == true
1063 test "it strips BCC field" do
1064 user = insert(:user)
1065 {:ok, list} = Pleroma.List.create("foo", user)
1067 {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
1069 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1071 assert is_nil(modified["bcc"])
1074 test "it can handle Listen activities" do
1075 listen_activity = insert(:listen)
1077 {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
1079 assert modified["type"] == "Listen"
1081 user = insert(:user)
1083 {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
1085 {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
1089 describe "user upgrade" do
1090 test "it upgrades a user to activitypub" do
1093 nickname: "rye@niu.moe",
1095 ap_id: "https://niu.moe/users/rye",
1096 follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
1099 user_two = insert(:user)
1100 Pleroma.FollowingRelationship.follow(user_two, user, :follow_accept)
1102 {:ok, activity} = CommonAPI.post(user, %{status: "test"})
1103 {:ok, unrelated_activity} = CommonAPI.post(user_two, %{status: "test"})
1104 assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
1106 user = User.get_cached_by_id(user.id)
1107 assert user.note_count == 1
1109 {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
1110 ObanHelpers.perform_all()
1112 assert user.ap_enabled
1113 assert user.note_count == 1
1114 assert user.follower_address == "https://niu.moe/users/rye/followers"
1115 assert user.following_address == "https://niu.moe/users/rye/following"
1117 user = User.get_cached_by_id(user.id)
1118 assert user.note_count == 1
1120 activity = Activity.get_by_id(activity.id)
1121 assert user.follower_address in activity.recipients
1127 "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
1136 "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
1141 refute "..." in activity.recipients
1143 unrelated_activity = Activity.get_by_id(unrelated_activity.id)
1144 refute user.follower_address in unrelated_activity.recipients
1146 user_two = User.get_cached_by_id(user_two.id)
1147 assert User.following?(user_two, user)
1148 refute "..." in User.following(user_two)
1152 describe "actor rewriting" do
1153 test "it fixes the actor URL property to be a proper URI" do
1155 "url" => %{"href" => "http://example.com"}
1158 rewritten = Transmogrifier.maybe_fix_user_object(data)
1159 assert rewritten["url"] == "http://example.com"
1163 describe "actor origin containment" do
1164 test "it rejects activities which reference objects with bogus origins" do
1166 "@context" => "https://www.w3.org/ns/activitystreams",
1167 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1168 "actor" => "http://mastodon.example.org/users/admin",
1169 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1170 "object" => "https://info.pleroma.site/activity.json",
1171 "type" => "Announce"
1174 assert capture_log(fn ->
1175 {:error, _} = Transmogrifier.handle_incoming(data)
1176 end) =~ "Object containment failed"
1179 test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
1181 "@context" => "https://www.w3.org/ns/activitystreams",
1182 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1183 "actor" => "http://mastodon.example.org/users/admin",
1184 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1185 "object" => "https://info.pleroma.site/activity2.json",
1186 "type" => "Announce"
1189 assert capture_log(fn ->
1190 {:error, _} = Transmogrifier.handle_incoming(data)
1191 end) =~ "Object containment failed"
1194 test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
1196 "@context" => "https://www.w3.org/ns/activitystreams",
1197 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1198 "actor" => "http://mastodon.example.org/users/admin",
1199 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1200 "object" => "https://info.pleroma.site/activity3.json",
1201 "type" => "Announce"
1204 assert capture_log(fn ->
1205 {:error, _} = Transmogrifier.handle_incoming(data)
1206 end) =~ "Object containment failed"
1210 describe "reserialization" do
1211 test "successfully reserializes a message with inReplyTo == nil" do
1212 user = insert(:user)
1215 "@context" => "https://www.w3.org/ns/activitystreams",
1216 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1220 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1225 "attributedTo" => user.ap_id
1227 "actor" => user.ap_id
1230 {:ok, activity} = Transmogrifier.handle_incoming(message)
1232 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1235 test "successfully reserializes a message with AS2 objects in IR" do
1236 user = insert(:user)
1239 "@context" => "https://www.w3.org/ns/activitystreams",
1240 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1244 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1249 "attributedTo" => user.ap_id,
1251 %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
1252 %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
1255 "actor" => user.ap_id
1258 {:ok, activity} = Transmogrifier.handle_incoming(message)
1260 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1264 test "Rewrites Answers to Notes" do
1265 user = insert(:user)
1267 {:ok, poll_activity} =
1268 CommonAPI.post(user, %{
1270 poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
1273 poll_object = Object.normalize(poll_activity)
1274 # TODO: Replace with CommonAPI vote creation when implemented
1276 File.read!("test/fixtures/mastodon-vote.json")
1278 |> Kernel.put_in(["to"], user.ap_id)
1279 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
1280 |> Kernel.put_in(["object", "to"], user.ap_id)
1282 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
1283 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
1285 assert data["object"]["type"] == "Note"
1288 describe "fix_explicit_addressing" do
1290 user = insert(:user)
1294 test "moves non-explicitly mentioned actors to cc", %{user: user} do
1295 explicitly_mentioned_actors = [
1296 "https://pleroma.gold/users/user1",
1297 "https://pleroma.gold/user2"
1301 "actor" => user.ap_id,
1302 "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"],
1305 Enum.map(explicitly_mentioned_actors, fn href ->
1306 %{"type" => "Mention", "href" => href}
1310 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1311 assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
1312 refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
1313 assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
1316 test "does not move actor's follower collection to cc", %{user: user} do
1318 "actor" => user.ap_id,
1319 "to" => [user.follower_address],
1323 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1324 assert user.follower_address in fixed_object["to"]
1325 refute user.follower_address in fixed_object["cc"]
1328 test "removes recipient's follower collection from cc", %{user: user} do
1329 recipient = insert(:user)
1332 "actor" => user.ap_id,
1333 "to" => [recipient.ap_id, "https://www.w3.org/ns/activitystreams#Public"],
1334 "cc" => [user.follower_address, recipient.follower_address]
1337 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1339 assert user.follower_address in fixed_object["cc"]
1340 refute recipient.follower_address in fixed_object["cc"]
1341 refute recipient.follower_address in fixed_object["to"]
1345 describe "fix_summary/1" do
1346 test "returns fixed object" do
1347 assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
1348 assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
1349 assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
1353 describe "fix_in_reply_to/2" do
1354 setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
1357 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1361 test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
1362 assert Transmogrifier.fix_in_reply_to(data) == data
1365 test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
1366 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
1369 Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
1371 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1372 assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
1373 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1376 Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
1378 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1379 assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
1380 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1383 Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
1385 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1386 assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
1387 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1389 object_with_reply = Map.put(data["object"], "inReplyTo", [])
1390 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1391 assert modified_object["inReplyTo"] == []
1392 assert modified_object["inReplyToAtomUri"] == ""
1395 @tag capture_log: true
1396 test "returns modified object when allowed incoming reply", %{data: data} do
1401 "https://shitposter.club/notice/2827873"
1404 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
1405 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1407 assert modified_object["inReplyTo"] ==
1408 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
1410 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1412 assert modified_object["context"] ==
1413 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1417 describe "fix_url/1" do
1418 test "fixes data for object when url is map" do
1422 "mimeType" => "video/mp4",
1423 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1427 assert Transmogrifier.fix_url(object) == %{
1428 "url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1432 test "fixes data for video object" do
1438 "mimeType" => "video/mp4",
1439 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1443 "mimeType" => "video/mp4",
1444 "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
1448 "mimeType" => "text/html",
1449 "href" => "https://peertube.-2d4c2d1630e3"
1453 "mimeType" => "text/html",
1454 "href" => "https://peertube.-2d4c2d16377-42"
1459 assert Transmogrifier.fix_url(object) == %{
1462 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1463 "mimeType" => "video/mp4",
1468 "url" => "https://peertube.-2d4c2d1630e3"
1472 test "fixes url for not Video object" do
1478 "mimeType" => "text/html",
1479 "href" => "https://peertube.-2d4c2d1630e3"
1483 "mimeType" => "text/html",
1484 "href" => "https://peertube.-2d4c2d16377-42"
1489 assert Transmogrifier.fix_url(object) == %{
1491 "url" => "https://peertube.-2d4c2d1630e3"
1494 assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
1500 test "retunrs not modified object" do
1501 assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
1505 describe "get_obj_helper/2" do
1506 test "returns nil when cannot normalize object" do
1507 assert capture_log(fn ->
1508 refute Transmogrifier.get_obj_helper("test-obj-id")
1509 end) =~ "Unsupported URI scheme"
1512 @tag capture_log: true
1513 test "returns {:ok, %Object{}} for success case" do
1514 assert {:ok, %Object{}} =
1515 Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
1519 describe "fix_attachments/1" do
1520 test "returns not modified object" do
1521 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1522 assert Transmogrifier.fix_attachments(data) == data
1525 test "returns modified object when attachment is map" do
1526 assert Transmogrifier.fix_attachments(%{
1528 "mediaType" => "video/mp4",
1529 "url" => "https://peertube.moe/stat-480.mp4"
1534 "mediaType" => "video/mp4",
1536 %{"href" => "https://peertube.moe/stat-480.mp4", "mediaType" => "video/mp4"}
1543 test "returns modified object when attachment is list" do
1544 assert Transmogrifier.fix_attachments(%{
1546 %{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
1547 %{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
1552 "mediaType" => "video/mp4",
1554 %{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}
1558 "mediaType" => "video/mp4",
1560 %{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}
1568 describe "fix_emoji/1" do
1569 test "returns not modified object when object not contains tags" do
1570 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1571 assert Transmogrifier.fix_emoji(data) == data
1574 test "returns object with emoji when object contains list tags" do
1575 assert Transmogrifier.fix_emoji(%{
1577 %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
1578 %{"type" => "Hashtag"}
1581 "emoji" => %{"bib" => "/test"},
1583 %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
1584 %{"type" => "Hashtag"}
1589 test "returns object with emoji when object contains map tag" do
1590 assert Transmogrifier.fix_emoji(%{
1591 "tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
1593 "emoji" => %{"bib" => "/test"},
1594 "tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}
1599 describe "set_replies/1" do
1600 setup do: clear_config([:activitypub, :note_replies_output_limit], 2)
1602 test "returns unmodified object if activity doesn't have self-replies" do
1603 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1604 assert Transmogrifier.set_replies(data) == data
1607 test "sets `replies` collection with a limited number of self-replies" do
1608 [user, another_user] = insert_list(2, :user)
1610 {:ok, %{id: id1} = activity} = CommonAPI.post(user, %{status: "1"})
1612 {:ok, %{id: id2} = self_reply1} =
1613 CommonAPI.post(user, %{status: "self-reply 1", in_reply_to_status_id: id1})
1615 {:ok, self_reply2} =
1616 CommonAPI.post(user, %{status: "self-reply 2", in_reply_to_status_id: id1})
1618 # Assuming to _not_ be present in `replies` due to :note_replies_output_limit is set to 2
1619 {:ok, _} = CommonAPI.post(user, %{status: "self-reply 3", in_reply_to_status_id: id1})
1622 CommonAPI.post(user, %{
1623 status: "self-reply to self-reply",
1624 in_reply_to_status_id: id2
1628 CommonAPI.post(another_user, %{
1629 status: "another user's reply",
1630 in_reply_to_status_id: id1
1633 object = Object.normalize(activity)
1634 replies_uris = Enum.map([self_reply1, self_reply2], fn a -> a.object.data["id"] end)
1636 assert %{"type" => "Collection", "items" => ^replies_uris} =
1637 Transmogrifier.set_replies(object.data)["replies"]
1641 test "take_emoji_tags/1" do
1642 user = insert(:user, %{emoji: %{"firefox" => "https://example.org/firefox.png"}})
1644 assert Transmogrifier.take_emoji_tags(user) == [
1646 "icon" => %{"type" => "Image", "url" => "https://example.org/firefox.png"},
1647 "id" => "https://example.org/firefox.png",
1648 "name" => ":firefox:",
1650 "updated" => "1970-01-01T00:00:00Z"