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.info.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 announces" do
382 data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
384 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
386 assert data["actor"] == "http://mastodon.example.org/users/admin"
387 assert data["type"] == "Announce"
390 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
392 assert data["object"] ==
393 "http://mastodon.example.org/users/admin/statuses/99541947525187367"
395 assert Activity.get_create_by_object_ap_id(data["object"])
398 test "it works for incoming announces with an existing activity" do
400 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
403 File.read!("test/fixtures/mastodon-announce.json")
405 |> Map.put("object", activity.data["object"])
407 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
409 assert data["actor"] == "http://mastodon.example.org/users/admin"
410 assert data["type"] == "Announce"
413 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
415 assert data["object"] == activity.data["object"]
417 assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
420 test "it does not clobber the addressing on announce activities" do
422 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
425 File.read!("test/fixtures/mastodon-announce.json")
427 |> Map.put("object", Object.normalize(activity).data["id"])
428 |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
431 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
433 assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]
436 test "it ensures that as:Public activities make it to their followers collection" do
440 File.read!("test/fixtures/mastodon-post-activity.json")
442 |> Map.put("actor", user.ap_id)
443 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
448 |> Map.put("attributedTo", user.ap_id)
449 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
451 |> Map.put("id", user.ap_id <> "/activities/12345678")
453 data = Map.put(data, "object", object)
455 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
457 assert data["cc"] == [User.ap_followers(user)]
460 test "it ensures that address fields become lists" do
464 File.read!("test/fixtures/mastodon-post-activity.json")
466 |> Map.put("actor", user.ap_id)
467 |> Map.put("to", nil)
468 |> Map.put("cc", nil)
472 |> Map.put("attributedTo", user.ap_id)
473 |> Map.put("to", nil)
474 |> Map.put("cc", nil)
475 |> Map.put("id", user.ap_id <> "/activities/12345678")
477 data = Map.put(data, "object", object)
479 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
481 assert !is_nil(data["to"])
482 assert !is_nil(data["cc"])
485 test "it strips internal likes" do
487 File.read!("test/fixtures/mastodon-post-activity.json")
492 "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
493 "id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
495 "type" => "OrderedCollection"
498 object = Map.put(data["object"], "likes", likes)
499 data = Map.put(data, "object", object)
501 {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
503 refute Map.has_key?(object.data, "likes")
506 test "it works for incoming update activities" do
507 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
509 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
510 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
513 update_data["object"]
514 |> Map.put("actor", data["actor"])
515 |> Map.put("id", data["actor"])
519 |> Map.put("actor", data["actor"])
520 |> Map.put("object", object)
522 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
524 user = User.get_cached_by_ap_id(data["actor"])
525 assert user.name == "gargle"
527 assert user.avatar["url"] == [
530 "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
534 assert user.info.banner["url"] == [
537 "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
541 assert user.bio == "<p>Some bio</p>"
544 test "it works with custom profile fields" do
546 "test/fixtures/mastodon-post-activity.json"
549 |> Transmogrifier.handle_incoming()
551 user = User.get_cached_by_ap_id(activity.actor)
553 assert User.Info.fields(user.info) == [
554 %{"name" => "foo", "value" => "bar"},
555 %{"name" => "foo1", "value" => "bar1"}
558 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
561 update_data["object"]
562 |> Map.put("actor", user.ap_id)
563 |> Map.put("id", user.ap_id)
567 |> Map.put("actor", user.ap_id)
568 |> Map.put("object", object)
570 {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
572 user = User.get_cached_by_ap_id(user.ap_id)
574 assert User.Info.fields(user.info) == [
575 %{"name" => "foo", "value" => "updated"},
576 %{"name" => "foo1", "value" => "updated"}
579 Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
582 put_in(update_data, ["object", "attachment"], [
583 %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
584 %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
585 %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
588 {:ok, _} = Transmogrifier.handle_incoming(update_data)
590 user = User.get_cached_by_ap_id(user.ap_id)
592 assert User.Info.fields(user.info) == [
593 %{"name" => "foo", "value" => "updated"},
594 %{"name" => "foo1", "value" => "updated"}
597 update_data = put_in(update_data, ["object", "attachment"], [])
599 {:ok, _} = Transmogrifier.handle_incoming(update_data)
601 user = User.get_cached_by_ap_id(user.ap_id)
603 assert User.Info.fields(user.info) == []
606 test "it works for incoming update activities which lock the account" do
607 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
609 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
610 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
613 update_data["object"]
614 |> Map.put("actor", data["actor"])
615 |> Map.put("id", data["actor"])
616 |> Map.put("manuallyApprovesFollowers", true)
620 |> Map.put("actor", data["actor"])
621 |> Map.put("object", object)
623 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
625 user = User.get_cached_by_ap_id(data["actor"])
626 assert user.info.locked == true
629 test "it works for incoming deletes" do
630 activity = insert(:note_activity)
633 File.read!("test/fixtures/mastodon-delete.json")
638 |> Map.put("id", activity.data["object"])
642 |> Map.put("object", object)
643 |> Map.put("actor", activity.data["actor"])
645 {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
647 refute Activity.get_by_id(activity.id)
650 test "it fails for incoming deletes with spoofed origin" do
651 activity = insert(:note_activity)
654 File.read!("test/fixtures/mastodon-delete.json")
659 |> Map.put("id", activity.data["object"])
663 |> Map.put("object", object)
665 assert capture_log(fn ->
666 :error = Transmogrifier.handle_incoming(data)
668 "[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}"
670 assert Activity.get_by_id(activity.id)
673 test "it works for incoming user deletes" do
674 %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
677 File.read!("test/fixtures/mastodon-delete-user.json")
680 {:ok, _} = Transmogrifier.handle_incoming(data)
681 ObanHelpers.perform_all()
683 refute User.get_cached_by_ap_id(ap_id)
686 test "it fails for incoming user deletes with spoofed origin" do
687 %{ap_id: ap_id} = insert(:user)
690 File.read!("test/fixtures/mastodon-delete-user.json")
692 |> Map.put("actor", ap_id)
694 assert :error == Transmogrifier.handle_incoming(data)
695 assert User.get_cached_by_ap_id(ap_id)
698 test "it works for incoming unannounces with an existing notice" do
700 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
703 File.read!("test/fixtures/mastodon-announce.json")
705 |> Map.put("object", activity.data["object"])
707 {:ok, %Activity{data: announce_data, local: false}} =
708 Transmogrifier.handle_incoming(announce_data)
711 File.read!("test/fixtures/mastodon-undo-announce.json")
713 |> Map.put("object", announce_data)
714 |> Map.put("actor", announce_data["actor"])
716 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
718 assert data["type"] == "Undo"
719 assert object_data = data["object"]
720 assert object_data["type"] == "Announce"
721 assert object_data["object"] == activity.data["object"]
723 assert object_data["id"] ==
724 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
727 test "it works for incomming unfollows with an existing follow" do
731 File.read!("test/fixtures/mastodon-follow-activity.json")
733 |> Map.put("object", user.ap_id)
735 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
738 File.read!("test/fixtures/mastodon-unfollow-activity.json")
740 |> Map.put("object", follow_data)
742 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
744 assert data["type"] == "Undo"
745 assert data["object"]["type"] == "Follow"
746 assert data["object"]["object"] == user.ap_id
747 assert data["actor"] == "http://mastodon.example.org/users/admin"
749 refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
752 test "it works for incoming blocks" do
756 File.read!("test/fixtures/mastodon-block-activity.json")
758 |> Map.put("object", user.ap_id)
760 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
762 assert data["type"] == "Block"
763 assert data["object"] == user.ap_id
764 assert data["actor"] == "http://mastodon.example.org/users/admin"
766 blocker = User.get_cached_by_ap_id(data["actor"])
768 assert User.blocks?(blocker, user)
771 test "incoming blocks successfully tear down any follow relationship" do
772 blocker = insert(:user)
773 blocked = insert(:user)
776 File.read!("test/fixtures/mastodon-block-activity.json")
778 |> Map.put("object", blocked.ap_id)
779 |> Map.put("actor", blocker.ap_id)
781 {:ok, blocker} = User.follow(blocker, blocked)
782 {:ok, blocked} = User.follow(blocked, blocker)
784 assert User.following?(blocker, blocked)
785 assert User.following?(blocked, blocker)
787 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
789 assert data["type"] == "Block"
790 assert data["object"] == blocked.ap_id
791 assert data["actor"] == blocker.ap_id
793 blocker = User.get_cached_by_ap_id(data["actor"])
794 blocked = User.get_cached_by_ap_id(data["object"])
796 assert User.blocks?(blocker, blocked)
798 refute User.following?(blocker, blocked)
799 refute User.following?(blocked, blocker)
802 test "it works for incoming unblocks with an existing block" do
806 File.read!("test/fixtures/mastodon-block-activity.json")
808 |> Map.put("object", user.ap_id)
810 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
813 File.read!("test/fixtures/mastodon-unblock-activity.json")
815 |> Map.put("object", block_data)
817 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
818 assert data["type"] == "Undo"
819 assert data["object"]["type"] == "Block"
820 assert data["object"]["object"] == user.ap_id
821 assert data["actor"] == "http://mastodon.example.org/users/admin"
823 blocker = User.get_cached_by_ap_id(data["actor"])
825 refute User.blocks?(blocker, user)
828 test "it works for incoming accepts which were pre-accepted" do
829 follower = insert(:user)
830 followed = insert(:user)
832 {:ok, follower} = User.follow(follower, followed)
833 assert User.following?(follower, followed) == true
835 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
838 File.read!("test/fixtures/mastodon-accept-activity.json")
840 |> Map.put("actor", followed.ap_id)
843 accept_data["object"]
844 |> Map.put("actor", follower.ap_id)
845 |> Map.put("id", follow_activity.data["id"])
847 accept_data = Map.put(accept_data, "object", object)
849 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
850 refute activity.local
852 assert activity.data["object"] == follow_activity.data["id"]
854 follower = User.get_cached_by_id(follower.id)
856 assert User.following?(follower, followed) == true
859 test "it works for incoming accepts which were orphaned" do
860 follower = insert(:user)
861 followed = insert(:user, %{info: %User.Info{locked: true}})
863 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
866 File.read!("test/fixtures/mastodon-accept-activity.json")
868 |> Map.put("actor", followed.ap_id)
871 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
873 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
874 assert activity.data["object"] == follow_activity.data["id"]
876 follower = User.get_cached_by_id(follower.id)
878 assert User.following?(follower, followed) == true
881 test "it works for incoming accepts which are referenced by IRI only" do
882 follower = insert(:user)
883 followed = insert(:user, %{info: %User.Info{locked: true}})
885 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
888 File.read!("test/fixtures/mastodon-accept-activity.json")
890 |> Map.put("actor", followed.ap_id)
891 |> Map.put("object", follow_activity.data["id"])
893 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
894 assert activity.data["object"] == follow_activity.data["id"]
896 follower = User.get_cached_by_id(follower.id)
898 assert User.following?(follower, followed) == true
901 test "it fails for incoming accepts which cannot be correlated" do
902 follower = insert(:user)
903 followed = insert(:user, %{info: %User.Info{locked: true}})
906 File.read!("test/fixtures/mastodon-accept-activity.json")
908 |> Map.put("actor", followed.ap_id)
911 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
913 :error = Transmogrifier.handle_incoming(accept_data)
915 follower = User.get_cached_by_id(follower.id)
917 refute User.following?(follower, followed) == true
920 test "it fails for incoming rejects which cannot be correlated" do
921 follower = insert(:user)
922 followed = insert(:user, %{info: %User.Info{locked: true}})
925 File.read!("test/fixtures/mastodon-reject-activity.json")
927 |> Map.put("actor", followed.ap_id)
930 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
932 :error = Transmogrifier.handle_incoming(accept_data)
934 follower = User.get_cached_by_id(follower.id)
936 refute User.following?(follower, followed) == true
939 test "it works for incoming rejects which are orphaned" do
940 follower = insert(:user)
941 followed = insert(:user, %{info: %User.Info{locked: true}})
943 {:ok, follower} = User.follow(follower, followed)
944 {:ok, _follow_activity} = ActivityPub.follow(follower, followed)
946 assert User.following?(follower, followed) == true
949 File.read!("test/fixtures/mastodon-reject-activity.json")
951 |> Map.put("actor", followed.ap_id)
954 Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
956 {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
957 refute activity.local
959 follower = User.get_cached_by_id(follower.id)
961 assert User.following?(follower, followed) == false
964 test "it works for incoming rejects which are referenced by IRI only" do
965 follower = insert(:user)
966 followed = insert(:user, %{info: %User.Info{locked: true}})
968 {:ok, follower} = User.follow(follower, followed)
969 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
971 assert User.following?(follower, followed) == true
974 File.read!("test/fixtures/mastodon-reject-activity.json")
976 |> Map.put("actor", followed.ap_id)
977 |> Map.put("object", follow_activity.data["id"])
979 {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
981 follower = User.get_cached_by_id(follower.id)
983 assert User.following?(follower, followed) == false
986 test "it rejects activities without a valid ID" do
990 File.read!("test/fixtures/mastodon-follow-activity.json")
992 |> Map.put("object", user.ap_id)
995 :error = Transmogrifier.handle_incoming(data)
998 test "it remaps video URLs as attachments if necessary" do
1000 Fetcher.fetch_object_from_id(
1001 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1006 "mediaType" => "video/mp4",
1008 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1009 "mimeType" => "video/mp4",
1010 "size" => 5_015_880,
1014 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1015 "mediaType" => "video/mp4",
1022 assert object.data["url"] ==
1023 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1025 assert object.data["attachment"] == [attachment]
1028 test "it accepts Flag activities" do
1029 user = insert(:user)
1030 other_user = insert(:user)
1032 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
1033 object = Object.normalize(activity)
1036 "@context" => "https://www.w3.org/ns/activitystreams",
1037 "cc" => [user.ap_id],
1038 "object" => [user.ap_id, object.data["id"]],
1040 "content" => "blocked AND reported!!!",
1041 "actor" => other_user.ap_id
1044 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
1046 assert activity.data["object"] == [user.ap_id, object.data["id"]]
1047 assert activity.data["content"] == "blocked AND reported!!!"
1048 assert activity.data["actor"] == other_user.ap_id
1049 assert activity.data["cc"] == [user.ap_id]
1053 describe "prepare outgoing" do
1054 test "it turns mentions into tags" do
1055 user = insert(:user)
1056 other_user = insert(:user)
1059 CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
1061 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1062 object = modified["object"]
1064 expected_mention = %{
1065 "href" => other_user.ap_id,
1066 "name" => "@#{other_user.nickname}",
1071 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1072 "type" => "Hashtag",
1076 assert Enum.member?(object["tag"], expected_tag)
1077 assert Enum.member?(object["tag"], expected_mention)
1080 test "it adds the sensitive property" do
1081 user = insert(:user)
1083 {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
1084 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1086 assert modified["object"]["sensitive"]
1089 test "it adds the json-ld context and the conversation property" do
1090 user = insert(:user)
1092 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1093 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1095 assert modified["@context"] ==
1096 Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
1098 assert modified["object"]["conversation"] == modified["context"]
1101 test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
1102 user = insert(:user)
1104 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1105 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1107 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1110 test "it translates ostatus IDs to external URLs" do
1111 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1112 {:ok, [referent_activity]} = OStatus.handle_incoming(incoming)
1114 user = insert(:user)
1116 {:ok, activity, _} = CommonAPI.favorite(referent_activity.id, user)
1117 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1119 assert modified["object"] == "http://gs.example.org:4040/index.php/notice/29"
1122 test "it translates ostatus reply_to IDs to external URLs" do
1123 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1124 {:ok, [referred_activity]} = OStatus.handle_incoming(incoming)
1126 user = insert(:user)
1129 CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id})
1131 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1133 assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29"
1136 test "it strips internal hashtag data" do
1137 user = insert(:user)
1139 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu"})
1142 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1143 "type" => "Hashtag",
1147 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1149 assert modified["object"]["tag"] == [expected_tag]
1152 test "it strips internal fields" do
1153 user = insert(:user)
1155 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :firefox:"})
1157 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1159 assert length(modified["object"]["tag"]) == 2
1161 assert is_nil(modified["object"]["emoji"])
1162 assert is_nil(modified["object"]["like_count"])
1163 assert is_nil(modified["object"]["announcements"])
1164 assert is_nil(modified["object"]["announcement_count"])
1165 assert is_nil(modified["object"]["context_id"])
1168 test "it strips internal fields of article" do
1169 activity = insert(:article_activity)
1171 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1173 assert length(modified["object"]["tag"]) == 2
1175 assert is_nil(modified["object"]["emoji"])
1176 assert is_nil(modified["object"]["like_count"])
1177 assert is_nil(modified["object"]["announcements"])
1178 assert is_nil(modified["object"]["announcement_count"])
1179 assert is_nil(modified["object"]["context_id"])
1180 assert is_nil(modified["object"]["likes"])
1183 test "the directMessage flag is present" do
1184 user = insert(:user)
1185 other_user = insert(:user)
1187 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"})
1189 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1191 assert modified["directMessage"] == false
1194 CommonAPI.post(user, %{"status" => "@#{other_user.nickname} :moominmamma:"})
1196 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1198 assert modified["directMessage"] == false
1201 CommonAPI.post(user, %{
1202 "status" => "@#{other_user.nickname} :moominmamma:",
1203 "visibility" => "direct"
1206 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1208 assert modified["directMessage"] == true
1211 test "it strips BCC field" do
1212 user = insert(:user)
1213 {:ok, list} = Pleroma.List.create("foo", user)
1216 CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
1218 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1220 assert is_nil(modified["bcc"])
1224 describe "user upgrade" do
1225 test "it upgrades a user to activitypub" do
1228 nickname: "rye@niu.moe",
1230 ap_id: "https://niu.moe/users/rye",
1231 follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
1234 user_two = insert(:user, %{following: [user.follower_address]})
1236 {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
1237 {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
1238 assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
1240 user = User.get_cached_by_id(user.id)
1241 assert user.info.note_count == 1
1243 {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
1244 ObanHelpers.perform_all()
1246 assert user.info.ap_enabled
1247 assert user.info.note_count == 1
1248 assert user.follower_address == "https://niu.moe/users/rye/followers"
1249 assert user.following_address == "https://niu.moe/users/rye/following"
1251 user = User.get_cached_by_id(user.id)
1252 assert user.info.note_count == 1
1254 activity = Activity.get_by_id(activity.id)
1255 assert user.follower_address in activity.recipients
1261 "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
1270 "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
1273 } = user.info.banner
1275 refute "..." in activity.recipients
1277 unrelated_activity = Activity.get_by_id(unrelated_activity.id)
1278 refute user.follower_address in unrelated_activity.recipients
1280 user_two = User.get_cached_by_id(user_two.id)
1281 assert user.follower_address in user_two.following
1282 refute "..." in user_two.following
1286 describe "maybe_retire_websub" do
1287 test "it deletes all websub client subscripitions with the user as topic" do
1288 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/rye.atom"}
1289 {:ok, ws} = Repo.insert(subscription)
1291 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/pasty.atom"}
1292 {:ok, ws2} = Repo.insert(subscription)
1294 Transmogrifier.maybe_retire_websub("https://niu.moe/users/rye")
1296 refute Repo.get(WebsubClientSubscription, ws.id)
1297 assert Repo.get(WebsubClientSubscription, ws2.id)
1301 describe "actor rewriting" do
1302 test "it fixes the actor URL property to be a proper URI" do
1304 "url" => %{"href" => "http://example.com"}
1307 rewritten = Transmogrifier.maybe_fix_user_object(data)
1308 assert rewritten["url"] == "http://example.com"
1312 describe "actor origin containment" do
1313 test "it rejects activities which reference objects with bogus origins" do
1315 "@context" => "https://www.w3.org/ns/activitystreams",
1316 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1317 "actor" => "http://mastodon.example.org/users/admin",
1318 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1319 "object" => "https://info.pleroma.site/activity.json",
1320 "type" => "Announce"
1323 :error = Transmogrifier.handle_incoming(data)
1326 test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
1328 "@context" => "https://www.w3.org/ns/activitystreams",
1329 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1330 "actor" => "http://mastodon.example.org/users/admin",
1331 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1332 "object" => "https://info.pleroma.site/activity2.json",
1333 "type" => "Announce"
1336 :error = Transmogrifier.handle_incoming(data)
1339 test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
1341 "@context" => "https://www.w3.org/ns/activitystreams",
1342 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1343 "actor" => "http://mastodon.example.org/users/admin",
1344 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1345 "object" => "https://info.pleroma.site/activity3.json",
1346 "type" => "Announce"
1349 :error = Transmogrifier.handle_incoming(data)
1353 describe "reserialization" do
1354 test "successfully reserializes a message with inReplyTo == nil" do
1355 user = insert(:user)
1358 "@context" => "https://www.w3.org/ns/activitystreams",
1359 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1363 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1368 "attributedTo" => user.ap_id
1370 "actor" => user.ap_id
1373 {:ok, activity} = Transmogrifier.handle_incoming(message)
1375 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1378 test "successfully reserializes a message with AS2 objects in IR" do
1379 user = insert(:user)
1382 "@context" => "https://www.w3.org/ns/activitystreams",
1383 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1387 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1392 "attributedTo" => user.ap_id,
1394 %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
1395 %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
1398 "actor" => user.ap_id
1401 {:ok, activity} = Transmogrifier.handle_incoming(message)
1403 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1407 test "Rewrites Answers to Notes" do
1408 user = insert(:user)
1410 {:ok, poll_activity} =
1411 CommonAPI.post(user, %{
1412 "status" => "suya...",
1413 "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
1416 poll_object = Object.normalize(poll_activity)
1417 # TODO: Replace with CommonAPI vote creation when implemented
1419 File.read!("test/fixtures/mastodon-vote.json")
1421 |> Kernel.put_in(["to"], user.ap_id)
1422 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
1423 |> Kernel.put_in(["object", "to"], user.ap_id)
1425 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
1426 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
1428 assert data["object"]["type"] == "Note"
1431 describe "fix_explicit_addressing" do
1433 user = insert(:user)
1437 test "moves non-explicitly mentioned actors to cc", %{user: user} do
1438 explicitly_mentioned_actors = [
1439 "https://pleroma.gold/users/user1",
1440 "https://pleroma.gold/user2"
1444 "actor" => user.ap_id,
1445 "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"],
1448 Enum.map(explicitly_mentioned_actors, fn href ->
1449 %{"type" => "Mention", "href" => href}
1453 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1454 assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
1455 refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
1456 assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
1459 test "does not move actor's follower collection to cc", %{user: user} do
1461 "actor" => user.ap_id,
1462 "to" => [user.follower_address],
1466 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1467 assert user.follower_address in fixed_object["to"]
1468 refute user.follower_address in fixed_object["cc"]
1471 test "removes recipient's follower collection from cc", %{user: user} do
1472 recipient = insert(:user)
1475 "actor" => user.ap_id,
1476 "to" => [recipient.ap_id, "https://www.w3.org/ns/activitystreams#Public"],
1477 "cc" => [user.follower_address, recipient.follower_address]
1480 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1482 assert user.follower_address in fixed_object["cc"]
1483 refute recipient.follower_address in fixed_object["cc"]
1484 refute recipient.follower_address in fixed_object["to"]
1488 describe "fix_summary/1" do
1489 test "returns fixed object" do
1490 assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
1491 assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
1492 assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
1496 describe "fix_in_reply_to/2" do
1497 clear_config([:instance, :federation_incoming_replies_max_depth])
1500 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1504 test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
1505 assert Transmogrifier.fix_in_reply_to(data) == data
1508 test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
1509 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
1512 Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
1514 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1515 assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
1516 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1519 Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
1521 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1522 assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
1523 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1526 Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
1528 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1529 assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
1530 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1532 object_with_reply = Map.put(data["object"], "inReplyTo", [])
1533 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1534 assert modified_object["inReplyTo"] == []
1535 assert modified_object["inReplyToAtomUri"] == ""
1538 test "returns modified object when allowed incoming reply", %{data: data} do
1543 "https://shitposter.club/notice/2827873"
1546 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
1547 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1549 assert modified_object["inReplyTo"] ==
1550 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
1552 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1554 assert modified_object["conversation"] ==
1555 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1557 assert modified_object["context"] ==
1558 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1562 describe "fix_url/1" do
1563 test "fixes data for object when url is map" do
1567 "mimeType" => "video/mp4",
1568 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1572 assert Transmogrifier.fix_url(object) == %{
1573 "url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1577 test "fixes data for video object" do
1583 "mimeType" => "video/mp4",
1584 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1588 "mimeType" => "video/mp4",
1589 "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
1593 "mimeType" => "text/html",
1594 "href" => "https://peertube.-2d4c2d1630e3"
1598 "mimeType" => "text/html",
1599 "href" => "https://peertube.-2d4c2d16377-42"
1604 assert Transmogrifier.fix_url(object) == %{
1607 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1608 "mimeType" => "video/mp4",
1613 "url" => "https://peertube.-2d4c2d1630e3"
1617 test "fixes url for not Video object" do
1623 "mimeType" => "text/html",
1624 "href" => "https://peertube.-2d4c2d1630e3"
1628 "mimeType" => "text/html",
1629 "href" => "https://peertube.-2d4c2d16377-42"
1634 assert Transmogrifier.fix_url(object) == %{
1636 "url" => "https://peertube.-2d4c2d1630e3"
1639 assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
1645 test "retunrs not modified object" do
1646 assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
1650 describe "get_obj_helper/2" do
1651 test "returns nil when cannot normalize object" do
1652 refute Transmogrifier.get_obj_helper("test-obj-id")
1655 test "returns {:ok, %Object{}} for success case" do
1656 assert {:ok, %Object{}} =
1657 Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
1661 describe "fix_attachments/1" do
1662 test "returns not modified object" do
1663 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1664 assert Transmogrifier.fix_attachments(data) == data
1667 test "returns modified object when attachment is map" do
1668 assert Transmogrifier.fix_attachments(%{
1670 "mediaType" => "video/mp4",
1671 "url" => "https://peertube.moe/stat-480.mp4"
1676 "mediaType" => "video/mp4",
1679 "href" => "https://peertube.moe/stat-480.mp4",
1680 "mediaType" => "video/mp4",
1689 test "returns modified object when attachment is list" do
1690 assert Transmogrifier.fix_attachments(%{
1692 %{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
1693 %{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
1698 "mediaType" => "video/mp4",
1701 "href" => "https://pe.er/stat-480.mp4",
1702 "mediaType" => "video/mp4",
1708 "href" => "https://pe.er/stat-480.mp4",
1709 "mediaType" => "video/mp4",
1710 "mimeType" => "video/mp4",
1713 "href" => "https://pe.er/stat-480.mp4",
1714 "mediaType" => "video/mp4",
1724 describe "fix_emoji/1" do
1725 test "returns not modified object when object not contains tags" do
1726 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1727 assert Transmogrifier.fix_emoji(data) == data
1730 test "returns object with emoji when object contains list tags" do
1731 assert Transmogrifier.fix_emoji(%{
1733 %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
1734 %{"type" => "Hashtag"}
1737 "emoji" => %{"bib" => "/test"},
1739 %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
1740 %{"type" => "Hashtag"}
1745 test "returns object with emoji when object contains map tag" do
1746 assert Transmogrifier.fix_emoji(%{
1747 "tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
1749 "emoji" => %{"bib" => "/test"},
1750 "tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}