1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
9 alias Pleroma.Object.Fetcher
11 alias Pleroma.Tests.ObanHelpers
13 alias Pleroma.Web.ActivityPub.ActivityPub
14 alias Pleroma.Web.ActivityPub.Transmogrifier
15 alias Pleroma.Web.CommonAPI
16 alias Pleroma.Web.OStatus
17 alias Pleroma.Web.Websub.WebsubClientSubscription
20 import Pleroma.Factory
21 import ExUnit.CaptureLog
24 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
28 clear_config([:instance, :max_remote_account_fields])
30 describe "handle_incoming" do
31 test "it ignores an incoming notice if we already have it" do
32 activity = insert(:note_activity)
35 File.read!("test/fixtures/mastodon-post-activity.json")
37 |> Map.put("object", Object.normalize(activity).data)
39 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
41 assert activity == returned_activity
44 test "it fetches replied-to activities if we don't have them" do
46 File.read!("test/fixtures/mastodon-post-activity.json")
51 |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
53 data = Map.put(data, "object", object)
54 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
55 returned_object = Object.normalize(returned_activity, false)
58 Activity.get_create_by_object_ap_id(
59 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
62 assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
65 test "it does not fetch replied-to activities beyond max_replies_depth" do
67 File.read!("test/fixtures/mastodon-post-activity.json")
72 |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
74 data = Map.put(data, "object", object)
76 with_mock Pleroma.Web.Federator,
77 allowed_incoming_reply_depth?: fn _ -> false end do
78 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
80 returned_object = Object.normalize(returned_activity, false)
82 refute Activity.get_create_by_object_ap_id(
83 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
86 assert returned_object.data["inReplyToAtomUri"] ==
87 "https://shitposter.club/notice/2827873"
91 test "it does not crash if the object in inReplyTo can't be fetched" do
93 File.read!("test/fixtures/mastodon-post-activity.json")
98 |> Map.put("inReplyTo", "https://404.site/whatever")
102 |> Map.put("object", object)
104 assert capture_log(fn ->
105 {:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
106 end) =~ "[error] Couldn't fetch \"https://404.site/whatever\", error: nil"
109 test "it works for incoming notices" do
110 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
112 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
115 "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity"
117 assert data["context"] ==
118 "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
120 assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
122 assert data["cc"] == [
123 "http://mastodon.example.org/users/admin/followers",
124 "http://localtesting.pleroma.lol/users/lain"
127 assert data["actor"] == "http://mastodon.example.org/users/admin"
129 object_data = Object.normalize(data["object"]).data
131 assert object_data["id"] ==
132 "http://mastodon.example.org/users/admin/statuses/99512778738411822"
134 assert object_data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
136 assert object_data["cc"] == [
137 "http://mastodon.example.org/users/admin/followers",
138 "http://localtesting.pleroma.lol/users/lain"
141 assert object_data["actor"] == "http://mastodon.example.org/users/admin"
142 assert object_data["attributedTo"] == "http://mastodon.example.org/users/admin"
144 assert object_data["context"] ==
145 "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
147 assert object_data["sensitive"] == true
149 user = User.get_cached_by_ap_id(object_data["actor"])
151 assert user.note_count == 1
154 test "it works for incoming notices with hashtags" do
155 data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
157 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
158 object = Object.normalize(data["object"])
160 assert Enum.at(object.data["tag"], 2) == "moo"
163 test "it works for incoming questions" do
164 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
166 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
168 object = Object.normalize(activity)
170 assert Enum.all?(object.data["oneOf"], fn choice ->
173 "Everyone knows that!",
174 "25 char limit is dumb",
175 "I can't even fit a funny"
180 test "it works for incoming listens" do
182 "@context" => "https://www.w3.org/ns/activitystreams",
183 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
186 "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
187 "actor" => "http://mastodon.example.org/users/admin",
190 "id" => "http://mastodon.example.org/users/admin/listens/1234",
191 "attributedTo" => "http://mastodon.example.org/users/admin",
192 "title" => "lain radio episode 1",
194 "album" => "lain radio",
199 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
201 object = Object.normalize(activity)
203 assert object.data["title"] == "lain radio episode 1"
204 assert object.data["artist"] == "lain"
205 assert object.data["album"] == "lain radio"
206 assert object.data["length"] == 180_000
209 test "it rewrites Note votes to Answers and increments vote counters on question activities" do
213 CommonAPI.post(user, %{
214 "status" => "suya...",
215 "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
218 object = Object.normalize(activity)
221 File.read!("test/fixtures/mastodon-vote.json")
223 |> Kernel.put_in(["to"], user.ap_id)
224 |> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
225 |> Kernel.put_in(["object", "to"], user.ap_id)
227 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
228 answer_object = Object.normalize(activity)
229 assert answer_object.data["type"] == "Answer"
230 object = Object.get_by_ap_id(object.data["id"])
233 object.data["oneOf"],
235 %{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
241 test "it works for incoming notices with contentMap" do
243 File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
245 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
246 object = Object.normalize(data["object"])
248 assert object.data["content"] ==
249 "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
252 test "it works for incoming notices with to/cc not being an array (kroeg)" do
253 data = File.read!("test/fixtures/kroeg-post-activity.json") |> Poison.decode!()
255 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
256 object = Object.normalize(data["object"])
258 assert object.data["content"] ==
259 "<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>"
262 test "it works for incoming announces with actor being inlined (kroeg)" do
263 data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Poison.decode!()
265 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
267 assert data["actor"] == "https://puckipedia.com/"
270 test "it works for incoming notices with tag not being an array (kroeg)" do
271 data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Poison.decode!()
273 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
274 object = Object.normalize(data["object"])
276 assert object.data["emoji"] == %{
277 "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png"
280 data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Poison.decode!()
282 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
283 object = Object.normalize(data["object"])
285 assert "test" in object.data["tag"]
288 test "it works for incoming notices with url not being a string (prismo)" do
289 data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!()
291 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
292 object = Object.normalize(data["object"])
294 assert object.data["url"] == "https://prismo.news/posts/83"
297 test "it cleans up incoming notices which are not really DMs" do
299 other_user = insert(:user)
301 to = [user.ap_id, other_user.ap_id]
304 File.read!("test/fixtures/mastodon-post-activity.json")
314 data = Map.put(data, "object", object)
316 {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
318 assert data["to"] == []
319 assert data["cc"] == to
321 object_data = Object.normalize(activity).data
323 assert object_data["to"] == []
324 assert object_data["cc"] == to
327 test "it works for incoming likes" do
329 {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
332 File.read!("test/fixtures/mastodon-like.json")
334 |> Map.put("object", activity.data["object"])
336 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
338 assert data["actor"] == "http://mastodon.example.org/users/admin"
339 assert data["type"] == "Like"
340 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
341 assert data["object"] == activity.data["object"]
344 test "it returns an error for incoming unlikes wihout a like activity" do
346 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
349 File.read!("test/fixtures/mastodon-undo-like.json")
351 |> Map.put("object", activity.data["object"])
353 assert Transmogrifier.handle_incoming(data) == :error
356 test "it works for incoming unlikes with an existing like activity" do
358 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
361 File.read!("test/fixtures/mastodon-like.json")
363 |> Map.put("object", activity.data["object"])
365 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
368 File.read!("test/fixtures/mastodon-undo-like.json")
370 |> Map.put("object", like_data)
371 |> Map.put("actor", like_data["actor"])
373 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
375 assert data["actor"] == "http://mastodon.example.org/users/admin"
376 assert data["type"] == "Undo"
377 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
378 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
381 test "it works for incoming unlikes with an existing like activity and a compact object" do
383 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
386 File.read!("test/fixtures/mastodon-like.json")
388 |> Map.put("object", activity.data["object"])
390 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
393 File.read!("test/fixtures/mastodon-undo-like.json")
395 |> Map.put("object", like_data["id"])
396 |> Map.put("actor", like_data["actor"])
398 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
400 assert data["actor"] == "http://mastodon.example.org/users/admin"
401 assert data["type"] == "Undo"
402 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
403 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
406 test "it works for incoming announces" do
407 data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
409 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
411 assert data["actor"] == "http://mastodon.example.org/users/admin"
412 assert data["type"] == "Announce"
415 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
417 assert data["object"] ==
418 "http://mastodon.example.org/users/admin/statuses/99541947525187367"
420 assert Activity.get_create_by_object_ap_id(data["object"])
423 test "it works for incoming announces with an existing activity" do
425 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
428 File.read!("test/fixtures/mastodon-announce.json")
430 |> Map.put("object", activity.data["object"])
432 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
434 assert data["actor"] == "http://mastodon.example.org/users/admin"
435 assert data["type"] == "Announce"
438 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
440 assert data["object"] == activity.data["object"]
442 assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
445 test "it works for incoming announces with an inlined activity" do
447 File.read!("test/fixtures/mastodon-announce-private.json")
450 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
452 assert data["actor"] == "http://mastodon.example.org/users/admin"
453 assert data["type"] == "Announce"
456 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
458 object = Object.normalize(data["object"])
460 assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
461 assert object.data["content"] == "this is a private toot"
464 test "it rejects incoming announces with an inlined activity from another origin" do
466 File.read!("test/fixtures/bogus-mastodon-announce.json")
469 assert :error = Transmogrifier.handle_incoming(data)
472 test "it does not clobber the addressing on announce activities" do
474 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
477 File.read!("test/fixtures/mastodon-announce.json")
479 |> Map.put("object", Object.normalize(activity).data["id"])
480 |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
483 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
485 assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]
488 test "it ensures that as:Public activities make it to their followers collection" do
492 File.read!("test/fixtures/mastodon-post-activity.json")
494 |> Map.put("actor", user.ap_id)
495 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
500 |> Map.put("attributedTo", user.ap_id)
501 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
503 |> Map.put("id", user.ap_id <> "/activities/12345678")
505 data = Map.put(data, "object", object)
507 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
509 assert data["cc"] == [User.ap_followers(user)]
512 test "it ensures that address fields become lists" do
516 File.read!("test/fixtures/mastodon-post-activity.json")
518 |> Map.put("actor", user.ap_id)
519 |> Map.put("to", nil)
520 |> Map.put("cc", nil)
524 |> Map.put("attributedTo", user.ap_id)
525 |> Map.put("to", nil)
526 |> Map.put("cc", nil)
527 |> Map.put("id", user.ap_id <> "/activities/12345678")
529 data = Map.put(data, "object", object)
531 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
533 assert !is_nil(data["to"])
534 assert !is_nil(data["cc"])
537 test "it strips internal likes" do
539 File.read!("test/fixtures/mastodon-post-activity.json")
544 "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
545 "id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
547 "type" => "OrderedCollection"
550 object = Map.put(data["object"], "likes", likes)
551 data = Map.put(data, "object", object)
553 {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
555 refute Map.has_key?(object.data, "likes")
558 test "it works for incoming update activities" do
559 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
561 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
562 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
565 update_data["object"]
566 |> Map.put("actor", data["actor"])
567 |> Map.put("id", data["actor"])
571 |> Map.put("actor", data["actor"])
572 |> Map.put("object", object)
574 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
576 assert data["id"] == update_data["id"]
578 user = User.get_cached_by_ap_id(data["actor"])
579 assert user.name == "gargle"
581 assert user.avatar["url"] == [
584 "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
588 assert user.banner["url"] == [
591 "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
595 assert user.bio == "<p>Some bio</p>"
598 test "it works with custom profile fields" do
600 "test/fixtures/mastodon-post-activity.json"
603 |> Transmogrifier.handle_incoming()
605 user = User.get_cached_by_ap_id(activity.actor)
607 assert User.fields(user) == [
608 %{"name" => "foo", "value" => "bar"},
609 %{"name" => "foo1", "value" => "bar1"}
612 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
615 update_data["object"]
616 |> Map.put("actor", user.ap_id)
617 |> Map.put("id", user.ap_id)
621 |> Map.put("actor", user.ap_id)
622 |> Map.put("object", object)
624 {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
626 user = User.get_cached_by_ap_id(user.ap_id)
628 assert User.fields(user) == [
629 %{"name" => "foo", "value" => "updated"},
630 %{"name" => "foo1", "value" => "updated"}
633 Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
636 put_in(update_data, ["object", "attachment"], [
637 %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
638 %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
639 %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
642 {:ok, _} = Transmogrifier.handle_incoming(update_data)
644 user = User.get_cached_by_ap_id(user.ap_id)
646 assert User.fields(user) == [
647 %{"name" => "foo", "value" => "updated"},
648 %{"name" => "foo1", "value" => "updated"}
651 update_data = put_in(update_data, ["object", "attachment"], [])
653 {:ok, _} = Transmogrifier.handle_incoming(update_data)
655 user = User.get_cached_by_ap_id(user.ap_id)
657 assert User.fields(user) == []
660 test "it works for incoming update activities which lock the account" do
661 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
663 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
664 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
667 update_data["object"]
668 |> Map.put("actor", data["actor"])
669 |> Map.put("id", data["actor"])
670 |> Map.put("manuallyApprovesFollowers", true)
674 |> Map.put("actor", data["actor"])
675 |> Map.put("object", object)
677 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
679 user = User.get_cached_by_ap_id(data["actor"])
680 assert user.locked == true
683 test "it works for incoming deletes" do
684 activity = insert(:note_activity)
685 deleting_user = insert(:user)
688 File.read!("test/fixtures/mastodon-delete.json")
693 |> Map.put("id", activity.data["object"])
697 |> Map.put("object", object)
698 |> Map.put("actor", deleting_user.ap_id)
700 {:ok, %Activity{actor: actor, local: false, data: %{"id" => id}}} =
701 Transmogrifier.handle_incoming(data)
703 assert id == data["id"]
704 refute Activity.get_by_id(activity.id)
705 assert actor == deleting_user.ap_id
708 test "it fails for incoming deletes with spoofed origin" do
709 activity = insert(:note_activity)
712 File.read!("test/fixtures/mastodon-delete.json")
717 |> Map.put("id", activity.data["object"])
721 |> Map.put("object", object)
723 assert capture_log(fn ->
724 :error = Transmogrifier.handle_incoming(data)
726 "[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}"
728 assert Activity.get_by_id(activity.id)
731 test "it works for incoming user deletes" do
732 %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
735 File.read!("test/fixtures/mastodon-delete-user.json")
738 {:ok, _} = Transmogrifier.handle_incoming(data)
739 ObanHelpers.perform_all()
741 refute User.get_cached_by_ap_id(ap_id)
744 test "it fails for incoming user deletes with spoofed origin" do
745 %{ap_id: ap_id} = insert(:user)
748 File.read!("test/fixtures/mastodon-delete-user.json")
750 |> Map.put("actor", ap_id)
752 assert :error == Transmogrifier.handle_incoming(data)
753 assert User.get_cached_by_ap_id(ap_id)
756 test "it works for incoming unannounces with an existing notice" do
758 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
761 File.read!("test/fixtures/mastodon-announce.json")
763 |> Map.put("object", activity.data["object"])
765 {:ok, %Activity{data: announce_data, local: false}} =
766 Transmogrifier.handle_incoming(announce_data)
769 File.read!("test/fixtures/mastodon-undo-announce.json")
771 |> Map.put("object", announce_data)
772 |> Map.put("actor", announce_data["actor"])
774 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
776 assert data["type"] == "Undo"
777 assert object_data = data["object"]
778 assert object_data["type"] == "Announce"
779 assert object_data["object"] == activity.data["object"]
781 assert object_data["id"] ==
782 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
785 test "it works for incomming unfollows with an existing follow" do
789 File.read!("test/fixtures/mastodon-follow-activity.json")
791 |> Map.put("object", user.ap_id)
793 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
796 File.read!("test/fixtures/mastodon-unfollow-activity.json")
798 |> Map.put("object", follow_data)
800 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
802 assert data["type"] == "Undo"
803 assert data["object"]["type"] == "Follow"
804 assert data["object"]["object"] == user.ap_id
805 assert data["actor"] == "http://mastodon.example.org/users/admin"
807 refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
810 test "it works for incoming blocks" do
814 File.read!("test/fixtures/mastodon-block-activity.json")
816 |> Map.put("object", user.ap_id)
818 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
820 assert data["type"] == "Block"
821 assert data["object"] == user.ap_id
822 assert data["actor"] == "http://mastodon.example.org/users/admin"
824 blocker = User.get_cached_by_ap_id(data["actor"])
826 assert User.blocks?(blocker, user)
829 test "incoming blocks successfully tear down any follow relationship" do
830 blocker = insert(:user)
831 blocked = insert(:user)
834 File.read!("test/fixtures/mastodon-block-activity.json")
836 |> Map.put("object", blocked.ap_id)
837 |> Map.put("actor", blocker.ap_id)
839 {:ok, blocker} = User.follow(blocker, blocked)
840 {:ok, blocked} = User.follow(blocked, blocker)
842 assert User.following?(blocker, blocked)
843 assert User.following?(blocked, blocker)
845 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
847 assert data["type"] == "Block"
848 assert data["object"] == blocked.ap_id
849 assert data["actor"] == blocker.ap_id
851 blocker = User.get_cached_by_ap_id(data["actor"])
852 blocked = User.get_cached_by_ap_id(data["object"])
854 assert User.blocks?(blocker, blocked)
856 refute User.following?(blocker, blocked)
857 refute User.following?(blocked, blocker)
860 test "it works for incoming unblocks with an existing block" do
864 File.read!("test/fixtures/mastodon-block-activity.json")
866 |> Map.put("object", user.ap_id)
868 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
871 File.read!("test/fixtures/mastodon-unblock-activity.json")
873 |> Map.put("object", block_data)
875 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
876 assert data["type"] == "Undo"
877 assert data["object"]["type"] == "Block"
878 assert data["object"]["object"] == user.ap_id
879 assert data["actor"] == "http://mastodon.example.org/users/admin"
881 blocker = User.get_cached_by_ap_id(data["actor"])
883 refute User.blocks?(blocker, user)
886 test "it works for incoming accepts which were pre-accepted" do
887 follower = insert(:user)
888 followed = insert(:user)
890 {:ok, follower} = User.follow(follower, followed)
891 assert User.following?(follower, followed) == true
893 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
896 File.read!("test/fixtures/mastodon-accept-activity.json")
898 |> Map.put("actor", followed.ap_id)
901 accept_data["object"]
902 |> Map.put("actor", follower.ap_id)
903 |> Map.put("id", follow_activity.data["id"])
905 accept_data = Map.put(accept_data, "object", object)
907 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
908 refute activity.local
910 assert activity.data["object"] == follow_activity.data["id"]
912 assert activity.data["id"] == accept_data["id"]
914 follower = User.get_cached_by_id(follower.id)
916 assert User.following?(follower, followed) == true
919 test "it works for incoming accepts which were orphaned" do
920 follower = insert(:user)
921 followed = insert(:user, locked: true)
923 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
926 File.read!("test/fixtures/mastodon-accept-activity.json")
928 |> Map.put("actor", followed.ap_id)
931 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
933 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
934 assert activity.data["object"] == follow_activity.data["id"]
936 follower = User.get_cached_by_id(follower.id)
938 assert User.following?(follower, followed) == true
941 test "it works for incoming accepts which are referenced by IRI only" do
942 follower = insert(:user)
943 followed = insert(:user, locked: true)
945 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
948 File.read!("test/fixtures/mastodon-accept-activity.json")
950 |> Map.put("actor", followed.ap_id)
951 |> Map.put("object", follow_activity.data["id"])
953 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
954 assert activity.data["object"] == follow_activity.data["id"]
956 follower = User.get_cached_by_id(follower.id)
958 assert User.following?(follower, followed) == true
961 test "it fails for incoming accepts which cannot be correlated" do
962 follower = insert(:user)
963 followed = insert(:user, locked: true)
966 File.read!("test/fixtures/mastodon-accept-activity.json")
968 |> Map.put("actor", followed.ap_id)
971 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
973 :error = Transmogrifier.handle_incoming(accept_data)
975 follower = User.get_cached_by_id(follower.id)
977 refute User.following?(follower, followed) == true
980 test "it fails for incoming rejects which cannot be correlated" do
981 follower = insert(:user)
982 followed = insert(:user, locked: true)
985 File.read!("test/fixtures/mastodon-reject-activity.json")
987 |> Map.put("actor", followed.ap_id)
990 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
992 :error = Transmogrifier.handle_incoming(accept_data)
994 follower = User.get_cached_by_id(follower.id)
996 refute User.following?(follower, followed) == true
999 test "it works for incoming rejects which are orphaned" do
1000 follower = insert(:user)
1001 followed = insert(:user, locked: true)
1003 {:ok, follower} = User.follow(follower, followed)
1004 {:ok, _follow_activity} = ActivityPub.follow(follower, followed)
1006 assert User.following?(follower, followed) == true
1009 File.read!("test/fixtures/mastodon-reject-activity.json")
1011 |> Map.put("actor", followed.ap_id)
1014 Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
1016 {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
1017 refute activity.local
1018 assert activity.data["id"] == reject_data["id"]
1020 follower = User.get_cached_by_id(follower.id)
1022 assert User.following?(follower, followed) == false
1025 test "it works for incoming rejects which are referenced by IRI only" do
1026 follower = insert(:user)
1027 followed = insert(:user, locked: true)
1029 {:ok, follower} = User.follow(follower, followed)
1030 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
1032 assert User.following?(follower, followed) == true
1035 File.read!("test/fixtures/mastodon-reject-activity.json")
1037 |> Map.put("actor", followed.ap_id)
1038 |> Map.put("object", follow_activity.data["id"])
1040 {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
1042 follower = User.get_cached_by_id(follower.id)
1044 assert User.following?(follower, followed) == false
1047 test "it rejects activities without a valid ID" do
1048 user = insert(:user)
1051 File.read!("test/fixtures/mastodon-follow-activity.json")
1053 |> Map.put("object", user.ap_id)
1054 |> Map.put("id", "")
1056 :error = Transmogrifier.handle_incoming(data)
1059 test "it remaps video URLs as attachments if necessary" do
1061 Fetcher.fetch_object_from_id(
1062 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1067 "mediaType" => "video/mp4",
1069 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1070 "mimeType" => "video/mp4",
1071 "size" => 5_015_880,
1075 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1076 "mediaType" => "video/mp4",
1083 assert object.data["url"] ==
1084 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1086 assert object.data["attachment"] == [attachment]
1089 test "it accepts Flag activities" do
1090 user = insert(:user)
1091 other_user = insert(:user)
1093 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
1094 object = Object.normalize(activity)
1097 "@context" => "https://www.w3.org/ns/activitystreams",
1098 "cc" => [user.ap_id],
1099 "object" => [user.ap_id, object.data["id"]],
1101 "content" => "blocked AND reported!!!",
1102 "actor" => other_user.ap_id
1105 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
1107 assert activity.data["object"] == [user.ap_id, object.data["id"]]
1108 assert activity.data["content"] == "blocked AND reported!!!"
1109 assert activity.data["actor"] == other_user.ap_id
1110 assert activity.data["cc"] == [user.ap_id]
1114 describe "prepare outgoing" do
1115 test "it inlines private announced objects" do
1116 user = insert(:user)
1118 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey", "visibility" => "private"})
1120 {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
1122 {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
1124 assert modified["object"]["content"] == "hey"
1125 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1128 test "it turns mentions into tags" do
1129 user = insert(:user)
1130 other_user = insert(:user)
1133 CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
1135 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1136 object = modified["object"]
1138 expected_mention = %{
1139 "href" => other_user.ap_id,
1140 "name" => "@#{other_user.nickname}",
1145 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1146 "type" => "Hashtag",
1150 assert Enum.member?(object["tag"], expected_tag)
1151 assert Enum.member?(object["tag"], expected_mention)
1154 test "it adds the sensitive property" do
1155 user = insert(:user)
1157 {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
1158 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1160 assert modified["object"]["sensitive"]
1163 test "it adds the json-ld context and the conversation property" do
1164 user = insert(:user)
1166 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1167 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1169 assert modified["@context"] ==
1170 Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
1172 assert modified["object"]["conversation"] == modified["context"]
1175 test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
1176 user = insert(:user)
1178 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1179 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1181 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1184 test "it translates ostatus IDs to external URLs" do
1185 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1186 {:ok, [referent_activity]} = OStatus.handle_incoming(incoming)
1188 user = insert(:user)
1190 {:ok, activity, _} = CommonAPI.favorite(referent_activity.id, user)
1191 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1193 assert modified["object"] == "http://gs.example.org:4040/index.php/notice/29"
1196 test "it translates ostatus reply_to IDs to external URLs" do
1197 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1198 {:ok, [referred_activity]} = OStatus.handle_incoming(incoming)
1200 user = insert(:user)
1203 CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id})
1205 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1207 assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29"
1210 test "it strips internal hashtag data" do
1211 user = insert(:user)
1213 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu"})
1216 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1217 "type" => "Hashtag",
1221 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1223 assert modified["object"]["tag"] == [expected_tag]
1226 test "it strips internal fields" do
1227 user = insert(:user)
1229 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :firefox:"})
1231 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1233 assert length(modified["object"]["tag"]) == 2
1235 assert is_nil(modified["object"]["emoji"])
1236 assert is_nil(modified["object"]["like_count"])
1237 assert is_nil(modified["object"]["announcements"])
1238 assert is_nil(modified["object"]["announcement_count"])
1239 assert is_nil(modified["object"]["context_id"])
1242 test "it strips internal fields of article" do
1243 activity = insert(:article_activity)
1245 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1247 assert length(modified["object"]["tag"]) == 2
1249 assert is_nil(modified["object"]["emoji"])
1250 assert is_nil(modified["object"]["like_count"])
1251 assert is_nil(modified["object"]["announcements"])
1252 assert is_nil(modified["object"]["announcement_count"])
1253 assert is_nil(modified["object"]["context_id"])
1254 assert is_nil(modified["object"]["likes"])
1257 test "the directMessage flag is present" do
1258 user = insert(:user)
1259 other_user = insert(:user)
1261 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"})
1263 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1265 assert modified["directMessage"] == false
1268 CommonAPI.post(user, %{"status" => "@#{other_user.nickname} :moominmamma:"})
1270 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1272 assert modified["directMessage"] == false
1275 CommonAPI.post(user, %{
1276 "status" => "@#{other_user.nickname} :moominmamma:",
1277 "visibility" => "direct"
1280 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1282 assert modified["directMessage"] == true
1285 test "it strips BCC field" do
1286 user = insert(:user)
1287 {:ok, list} = Pleroma.List.create("foo", user)
1290 CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
1292 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1294 assert is_nil(modified["bcc"])
1297 test "it can handle Listen activities" do
1298 listen_activity = insert(:listen)
1300 {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
1302 assert modified["type"] == "Listen"
1304 user = insert(:user)
1306 {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
1308 {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
1312 describe "user upgrade" do
1313 test "it upgrades a user to activitypub" do
1316 nickname: "rye@niu.moe",
1318 ap_id: "https://niu.moe/users/rye",
1319 follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
1322 user_two = insert(:user, %{following: [user.follower_address]})
1324 {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
1325 {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
1326 assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
1328 user = User.get_cached_by_id(user.id)
1329 assert user.note_count == 1
1331 {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
1332 ObanHelpers.perform_all()
1334 assert user.ap_enabled
1335 assert user.note_count == 1
1336 assert user.follower_address == "https://niu.moe/users/rye/followers"
1337 assert user.following_address == "https://niu.moe/users/rye/following"
1339 user = User.get_cached_by_id(user.id)
1340 assert user.note_count == 1
1342 activity = Activity.get_by_id(activity.id)
1343 assert user.follower_address in activity.recipients
1349 "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
1358 "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
1363 refute "..." in activity.recipients
1365 unrelated_activity = Activity.get_by_id(unrelated_activity.id)
1366 refute user.follower_address in unrelated_activity.recipients
1368 user_two = User.get_cached_by_id(user_two.id)
1369 assert user.follower_address in user_two.following
1370 refute "..." in user_two.following
1374 describe "maybe_retire_websub" do
1375 test "it deletes all websub client subscripitions with the user as topic" do
1376 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/rye.atom"}
1377 {:ok, ws} = Repo.insert(subscription)
1379 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/pasty.atom"}
1380 {:ok, ws2} = Repo.insert(subscription)
1382 Transmogrifier.maybe_retire_websub("https://niu.moe/users/rye")
1384 refute Repo.get(WebsubClientSubscription, ws.id)
1385 assert Repo.get(WebsubClientSubscription, ws2.id)
1389 describe "actor rewriting" do
1390 test "it fixes the actor URL property to be a proper URI" do
1392 "url" => %{"href" => "http://example.com"}
1395 rewritten = Transmogrifier.maybe_fix_user_object(data)
1396 assert rewritten["url"] == "http://example.com"
1400 describe "actor origin containment" do
1401 test "it rejects activities which reference objects with bogus origins" do
1403 "@context" => "https://www.w3.org/ns/activitystreams",
1404 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1405 "actor" => "http://mastodon.example.org/users/admin",
1406 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1407 "object" => "https://info.pleroma.site/activity.json",
1408 "type" => "Announce"
1411 :error = Transmogrifier.handle_incoming(data)
1414 test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
1416 "@context" => "https://www.w3.org/ns/activitystreams",
1417 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1418 "actor" => "http://mastodon.example.org/users/admin",
1419 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1420 "object" => "https://info.pleroma.site/activity2.json",
1421 "type" => "Announce"
1424 :error = Transmogrifier.handle_incoming(data)
1427 test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
1429 "@context" => "https://www.w3.org/ns/activitystreams",
1430 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1431 "actor" => "http://mastodon.example.org/users/admin",
1432 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1433 "object" => "https://info.pleroma.site/activity3.json",
1434 "type" => "Announce"
1437 :error = Transmogrifier.handle_incoming(data)
1441 describe "reserialization" do
1442 test "successfully reserializes a message with inReplyTo == nil" do
1443 user = insert(:user)
1446 "@context" => "https://www.w3.org/ns/activitystreams",
1447 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1451 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1456 "attributedTo" => user.ap_id
1458 "actor" => user.ap_id
1461 {:ok, activity} = Transmogrifier.handle_incoming(message)
1463 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1466 test "successfully reserializes a message with AS2 objects in IR" do
1467 user = insert(:user)
1470 "@context" => "https://www.w3.org/ns/activitystreams",
1471 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1475 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1480 "attributedTo" => user.ap_id,
1482 %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
1483 %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
1486 "actor" => user.ap_id
1489 {:ok, activity} = Transmogrifier.handle_incoming(message)
1491 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1495 test "Rewrites Answers to Notes" do
1496 user = insert(:user)
1498 {:ok, poll_activity} =
1499 CommonAPI.post(user, %{
1500 "status" => "suya...",
1501 "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
1504 poll_object = Object.normalize(poll_activity)
1505 # TODO: Replace with CommonAPI vote creation when implemented
1507 File.read!("test/fixtures/mastodon-vote.json")
1509 |> Kernel.put_in(["to"], user.ap_id)
1510 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
1511 |> Kernel.put_in(["object", "to"], user.ap_id)
1513 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
1514 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
1516 assert data["object"]["type"] == "Note"
1519 describe "fix_explicit_addressing" do
1521 user = insert(:user)
1525 test "moves non-explicitly mentioned actors to cc", %{user: user} do
1526 explicitly_mentioned_actors = [
1527 "https://pleroma.gold/users/user1",
1528 "https://pleroma.gold/user2"
1532 "actor" => user.ap_id,
1533 "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"],
1536 Enum.map(explicitly_mentioned_actors, fn href ->
1537 %{"type" => "Mention", "href" => href}
1541 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1542 assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
1543 refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
1544 assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
1547 test "does not move actor's follower collection to cc", %{user: user} do
1549 "actor" => user.ap_id,
1550 "to" => [user.follower_address],
1554 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1555 assert user.follower_address in fixed_object["to"]
1556 refute user.follower_address in fixed_object["cc"]
1559 test "removes recipient's follower collection from cc", %{user: user} do
1560 recipient = insert(:user)
1563 "actor" => user.ap_id,
1564 "to" => [recipient.ap_id, "https://www.w3.org/ns/activitystreams#Public"],
1565 "cc" => [user.follower_address, recipient.follower_address]
1568 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1570 assert user.follower_address in fixed_object["cc"]
1571 refute recipient.follower_address in fixed_object["cc"]
1572 refute recipient.follower_address in fixed_object["to"]
1576 describe "fix_summary/1" do
1577 test "returns fixed object" do
1578 assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
1579 assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
1580 assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
1584 describe "fix_in_reply_to/2" do
1585 clear_config([:instance, :federation_incoming_replies_max_depth])
1588 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1592 test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
1593 assert Transmogrifier.fix_in_reply_to(data) == data
1596 test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
1597 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
1600 Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
1602 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1603 assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
1604 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1607 Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
1609 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1610 assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
1611 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1614 Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
1616 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1617 assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
1618 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1620 object_with_reply = Map.put(data["object"], "inReplyTo", [])
1621 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1622 assert modified_object["inReplyTo"] == []
1623 assert modified_object["inReplyToAtomUri"] == ""
1626 test "returns modified object when allowed incoming reply", %{data: data} do
1631 "https://shitposter.club/notice/2827873"
1634 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
1635 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1637 assert modified_object["inReplyTo"] ==
1638 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
1640 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1642 assert modified_object["conversation"] ==
1643 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1645 assert modified_object["context"] ==
1646 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1650 describe "fix_url/1" do
1651 test "fixes data for object when url is map" do
1655 "mimeType" => "video/mp4",
1656 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1660 assert Transmogrifier.fix_url(object) == %{
1661 "url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1665 test "fixes data for video object" do
1671 "mimeType" => "video/mp4",
1672 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1676 "mimeType" => "video/mp4",
1677 "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
1681 "mimeType" => "text/html",
1682 "href" => "https://peertube.-2d4c2d1630e3"
1686 "mimeType" => "text/html",
1687 "href" => "https://peertube.-2d4c2d16377-42"
1692 assert Transmogrifier.fix_url(object) == %{
1695 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1696 "mimeType" => "video/mp4",
1701 "url" => "https://peertube.-2d4c2d1630e3"
1705 test "fixes url for not Video object" do
1711 "mimeType" => "text/html",
1712 "href" => "https://peertube.-2d4c2d1630e3"
1716 "mimeType" => "text/html",
1717 "href" => "https://peertube.-2d4c2d16377-42"
1722 assert Transmogrifier.fix_url(object) == %{
1724 "url" => "https://peertube.-2d4c2d1630e3"
1727 assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
1733 test "retunrs not modified object" do
1734 assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
1738 describe "get_obj_helper/2" do
1739 test "returns nil when cannot normalize object" do
1740 refute Transmogrifier.get_obj_helper("test-obj-id")
1743 test "returns {:ok, %Object{}} for success case" do
1744 assert {:ok, %Object{}} =
1745 Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
1749 describe "fix_attachments/1" do
1750 test "returns not modified object" do
1751 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1752 assert Transmogrifier.fix_attachments(data) == data
1755 test "returns modified object when attachment is map" do
1756 assert Transmogrifier.fix_attachments(%{
1758 "mediaType" => "video/mp4",
1759 "url" => "https://peertube.moe/stat-480.mp4"
1764 "mediaType" => "video/mp4",
1767 "href" => "https://peertube.moe/stat-480.mp4",
1768 "mediaType" => "video/mp4",
1777 test "returns modified object when attachment is list" do
1778 assert Transmogrifier.fix_attachments(%{
1780 %{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
1781 %{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
1786 "mediaType" => "video/mp4",
1789 "href" => "https://pe.er/stat-480.mp4",
1790 "mediaType" => "video/mp4",
1796 "href" => "https://pe.er/stat-480.mp4",
1797 "mediaType" => "video/mp4",
1798 "mimeType" => "video/mp4",
1801 "href" => "https://pe.er/stat-480.mp4",
1802 "mediaType" => "video/mp4",
1812 describe "fix_emoji/1" do
1813 test "returns not modified object when object not contains tags" do
1814 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1815 assert Transmogrifier.fix_emoji(data) == data
1818 test "returns object with emoji when object contains list tags" do
1819 assert Transmogrifier.fix_emoji(%{
1821 %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
1822 %{"type" => "Hashtag"}
1825 "emoji" => %{"bib" => "/test"},
1827 %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
1828 %{"type" => "Hashtag"}
1833 test "returns object with emoji when object contains map tag" do
1834 assert Transmogrifier.fix_emoji(%{
1835 "tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
1837 "emoji" => %{"bib" => "/test"},
1838 "tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}