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 works for incoming emoji reactions" do
346 {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
349 File.read!("test/fixtures/emoji-reaction.json")
351 |> Map.put("object", activity.data["object"])
353 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
355 assert data["actor"] == "http://mastodon.example.org/users/admin"
356 assert data["type"] == "EmojiReaction"
357 assert data["id"] == "http://mastodon.example.org/users/admin#reactions/2"
358 assert data["object"] == activity.data["object"]
359 assert data["content"] == "👌"
362 test "it works for incoming emoji reaction undos" do
365 {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
366 {:ok, reaction_activity, _object} = CommonAPI.react_with_emoji(activity.id, user, "👌")
369 File.read!("test/fixtures/mastodon-undo-like.json")
371 |> Map.put("object", reaction_activity.data["id"])
372 |> Map.put("actor", user.ap_id)
374 {:ok, activity} = Transmogrifier.handle_incoming(data)
376 assert activity.actor == user.ap_id
377 assert activity.data["id"] == data["id"]
378 assert activity.data["type"] == "Undo"
381 test "it returns an error for incoming unlikes wihout a like activity" do
383 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
386 File.read!("test/fixtures/mastodon-undo-like.json")
388 |> Map.put("object", activity.data["object"])
390 assert Transmogrifier.handle_incoming(data) == :error
393 test "it works for incoming unlikes with an existing like activity" do
395 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
398 File.read!("test/fixtures/mastodon-like.json")
400 |> Map.put("object", activity.data["object"])
402 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
405 File.read!("test/fixtures/mastodon-undo-like.json")
407 |> Map.put("object", like_data)
408 |> Map.put("actor", like_data["actor"])
410 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
412 assert data["actor"] == "http://mastodon.example.org/users/admin"
413 assert data["type"] == "Undo"
414 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
415 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
418 test "it works for incoming unlikes with an existing like activity and a compact object" do
420 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
423 File.read!("test/fixtures/mastodon-like.json")
425 |> Map.put("object", activity.data["object"])
427 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
430 File.read!("test/fixtures/mastodon-undo-like.json")
432 |> Map.put("object", like_data["id"])
433 |> Map.put("actor", like_data["actor"])
435 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
437 assert data["actor"] == "http://mastodon.example.org/users/admin"
438 assert data["type"] == "Undo"
439 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
440 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
443 test "it works for incoming announces" do
444 data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
446 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
448 assert data["actor"] == "http://mastodon.example.org/users/admin"
449 assert data["type"] == "Announce"
452 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
454 assert data["object"] ==
455 "http://mastodon.example.org/users/admin/statuses/99541947525187367"
457 assert Activity.get_create_by_object_ap_id(data["object"])
460 test "it works for incoming announces with an existing activity" do
462 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
465 File.read!("test/fixtures/mastodon-announce.json")
467 |> Map.put("object", activity.data["object"])
469 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
471 assert data["actor"] == "http://mastodon.example.org/users/admin"
472 assert data["type"] == "Announce"
475 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
477 assert data["object"] == activity.data["object"]
479 assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
482 test "it does not clobber the addressing on announce activities" do
484 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
487 File.read!("test/fixtures/mastodon-announce.json")
489 |> Map.put("object", Object.normalize(activity).data["id"])
490 |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
493 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
495 assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]
498 test "it ensures that as:Public activities make it to their followers collection" do
502 File.read!("test/fixtures/mastodon-post-activity.json")
504 |> Map.put("actor", user.ap_id)
505 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
510 |> Map.put("attributedTo", user.ap_id)
511 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
513 |> Map.put("id", user.ap_id <> "/activities/12345678")
515 data = Map.put(data, "object", object)
517 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
519 assert data["cc"] == [User.ap_followers(user)]
522 test "it ensures that address fields become lists" do
526 File.read!("test/fixtures/mastodon-post-activity.json")
528 |> Map.put("actor", user.ap_id)
529 |> Map.put("to", nil)
530 |> Map.put("cc", nil)
534 |> Map.put("attributedTo", user.ap_id)
535 |> Map.put("to", nil)
536 |> Map.put("cc", nil)
537 |> Map.put("id", user.ap_id <> "/activities/12345678")
539 data = Map.put(data, "object", object)
541 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
543 assert !is_nil(data["to"])
544 assert !is_nil(data["cc"])
547 test "it strips internal likes" do
549 File.read!("test/fixtures/mastodon-post-activity.json")
554 "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
555 "id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
557 "type" => "OrderedCollection"
560 object = Map.put(data["object"], "likes", likes)
561 data = Map.put(data, "object", object)
563 {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
565 refute Map.has_key?(object.data, "likes")
568 test "it strips internal reactions" do
570 {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
571 {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, user, "📢")
573 %{object: object} = Activity.get_by_id_with_object(activity.id)
574 assert Map.has_key?(object.data, "reactions")
575 assert Map.has_key?(object.data, "reaction_count")
577 object_data = Transmogrifier.strip_internal_fields(object.data)
578 refute Map.has_key?(object_data, "reactions")
579 refute Map.has_key?(object_data, "reaction_count")
582 test "it works for incoming update activities" do
583 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
585 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
586 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
589 update_data["object"]
590 |> Map.put("actor", data["actor"])
591 |> Map.put("id", data["actor"])
595 |> Map.put("actor", data["actor"])
596 |> Map.put("object", object)
598 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
600 user = User.get_cached_by_ap_id(data["actor"])
601 assert user.name == "gargle"
603 assert user.avatar["url"] == [
606 "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
610 assert user.info.banner["url"] == [
613 "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
617 assert user.bio == "<p>Some bio</p>"
620 test "it works with custom profile fields" do
622 "test/fixtures/mastodon-post-activity.json"
625 |> Transmogrifier.handle_incoming()
627 user = User.get_cached_by_ap_id(activity.actor)
629 assert User.Info.fields(user.info) == [
630 %{"name" => "foo", "value" => "bar"},
631 %{"name" => "foo1", "value" => "bar1"}
634 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
637 update_data["object"]
638 |> Map.put("actor", user.ap_id)
639 |> Map.put("id", user.ap_id)
643 |> Map.put("actor", user.ap_id)
644 |> Map.put("object", object)
646 {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
648 user = User.get_cached_by_ap_id(user.ap_id)
650 assert User.Info.fields(user.info) == [
651 %{"name" => "foo", "value" => "updated"},
652 %{"name" => "foo1", "value" => "updated"}
655 Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
658 put_in(update_data, ["object", "attachment"], [
659 %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
660 %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
661 %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
664 {:ok, _} = Transmogrifier.handle_incoming(update_data)
666 user = User.get_cached_by_ap_id(user.ap_id)
668 assert User.Info.fields(user.info) == [
669 %{"name" => "foo", "value" => "updated"},
670 %{"name" => "foo1", "value" => "updated"}
673 update_data = put_in(update_data, ["object", "attachment"], [])
675 {:ok, _} = Transmogrifier.handle_incoming(update_data)
677 user = User.get_cached_by_ap_id(user.ap_id)
679 assert User.Info.fields(user.info) == []
682 test "it works for incoming update activities which lock the account" do
683 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
685 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
686 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
689 update_data["object"]
690 |> Map.put("actor", data["actor"])
691 |> Map.put("id", data["actor"])
692 |> Map.put("manuallyApprovesFollowers", true)
696 |> Map.put("actor", data["actor"])
697 |> Map.put("object", object)
699 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
701 user = User.get_cached_by_ap_id(data["actor"])
702 assert user.info.locked == true
705 test "it works for incoming deletes" do
706 activity = insert(:note_activity)
709 File.read!("test/fixtures/mastodon-delete.json")
714 |> Map.put("id", activity.data["object"])
718 |> Map.put("object", object)
719 |> Map.put("actor", activity.data["actor"])
721 {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
723 refute Activity.get_by_id(activity.id)
726 test "it fails for incoming deletes with spoofed origin" do
727 activity = insert(:note_activity)
730 File.read!("test/fixtures/mastodon-delete.json")
735 |> Map.put("id", activity.data["object"])
739 |> Map.put("object", object)
741 assert capture_log(fn ->
742 :error = Transmogrifier.handle_incoming(data)
744 "[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}"
746 assert Activity.get_by_id(activity.id)
749 test "it works for incoming user deletes" do
750 %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
753 File.read!("test/fixtures/mastodon-delete-user.json")
756 {:ok, _} = Transmogrifier.handle_incoming(data)
757 ObanHelpers.perform_all()
759 refute User.get_cached_by_ap_id(ap_id)
762 test "it fails for incoming user deletes with spoofed origin" do
763 %{ap_id: ap_id} = insert(:user)
766 File.read!("test/fixtures/mastodon-delete-user.json")
768 |> Map.put("actor", ap_id)
770 assert :error == Transmogrifier.handle_incoming(data)
771 assert User.get_cached_by_ap_id(ap_id)
774 test "it works for incoming unannounces with an existing notice" do
776 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
779 File.read!("test/fixtures/mastodon-announce.json")
781 |> Map.put("object", activity.data["object"])
783 {:ok, %Activity{data: announce_data, local: false}} =
784 Transmogrifier.handle_incoming(announce_data)
787 File.read!("test/fixtures/mastodon-undo-announce.json")
789 |> Map.put("object", announce_data)
790 |> Map.put("actor", announce_data["actor"])
792 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
794 assert data["type"] == "Undo"
795 assert object_data = data["object"]
796 assert object_data["type"] == "Announce"
797 assert object_data["object"] == activity.data["object"]
799 assert object_data["id"] ==
800 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
803 test "it works for incomming unfollows with an existing follow" do
807 File.read!("test/fixtures/mastodon-follow-activity.json")
809 |> Map.put("object", user.ap_id)
811 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
814 File.read!("test/fixtures/mastodon-unfollow-activity.json")
816 |> Map.put("object", follow_data)
818 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
820 assert data["type"] == "Undo"
821 assert data["object"]["type"] == "Follow"
822 assert data["object"]["object"] == user.ap_id
823 assert data["actor"] == "http://mastodon.example.org/users/admin"
825 refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
828 test "it works for incoming blocks" do
832 File.read!("test/fixtures/mastodon-block-activity.json")
834 |> Map.put("object", user.ap_id)
836 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
838 assert data["type"] == "Block"
839 assert data["object"] == user.ap_id
840 assert data["actor"] == "http://mastodon.example.org/users/admin"
842 blocker = User.get_cached_by_ap_id(data["actor"])
844 assert User.blocks?(blocker, user)
847 test "incoming blocks successfully tear down any follow relationship" do
848 blocker = insert(:user)
849 blocked = insert(:user)
852 File.read!("test/fixtures/mastodon-block-activity.json")
854 |> Map.put("object", blocked.ap_id)
855 |> Map.put("actor", blocker.ap_id)
857 {:ok, blocker} = User.follow(blocker, blocked)
858 {:ok, blocked} = User.follow(blocked, blocker)
860 assert User.following?(blocker, blocked)
861 assert User.following?(blocked, blocker)
863 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
865 assert data["type"] == "Block"
866 assert data["object"] == blocked.ap_id
867 assert data["actor"] == blocker.ap_id
869 blocker = User.get_cached_by_ap_id(data["actor"])
870 blocked = User.get_cached_by_ap_id(data["object"])
872 assert User.blocks?(blocker, blocked)
874 refute User.following?(blocker, blocked)
875 refute User.following?(blocked, blocker)
878 test "it works for incoming unblocks with an existing block" do
882 File.read!("test/fixtures/mastodon-block-activity.json")
884 |> Map.put("object", user.ap_id)
886 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
889 File.read!("test/fixtures/mastodon-unblock-activity.json")
891 |> Map.put("object", block_data)
893 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
894 assert data["type"] == "Undo"
895 assert data["object"]["type"] == "Block"
896 assert data["object"]["object"] == user.ap_id
897 assert data["actor"] == "http://mastodon.example.org/users/admin"
899 blocker = User.get_cached_by_ap_id(data["actor"])
901 refute User.blocks?(blocker, user)
904 test "it works for incoming accepts which were pre-accepted" do
905 follower = insert(:user)
906 followed = insert(:user)
908 {:ok, follower} = User.follow(follower, followed)
909 assert User.following?(follower, followed) == true
911 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
914 File.read!("test/fixtures/mastodon-accept-activity.json")
916 |> Map.put("actor", followed.ap_id)
919 accept_data["object"]
920 |> Map.put("actor", follower.ap_id)
921 |> Map.put("id", follow_activity.data["id"])
923 accept_data = Map.put(accept_data, "object", object)
925 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
926 refute activity.local
928 assert activity.data["object"] == follow_activity.data["id"]
930 follower = User.get_cached_by_id(follower.id)
932 assert User.following?(follower, followed) == true
935 test "it works for incoming accepts which were orphaned" do
936 follower = insert(:user)
937 followed = insert(:user, %{info: %User.Info{locked: true}})
939 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
942 File.read!("test/fixtures/mastodon-accept-activity.json")
944 |> Map.put("actor", followed.ap_id)
947 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
949 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
950 assert activity.data["object"] == follow_activity.data["id"]
952 follower = User.get_cached_by_id(follower.id)
954 assert User.following?(follower, followed) == true
957 test "it works for incoming accepts which are referenced by IRI only" do
958 follower = insert(:user)
959 followed = insert(:user, %{info: %User.Info{locked: true}})
961 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
964 File.read!("test/fixtures/mastodon-accept-activity.json")
966 |> Map.put("actor", followed.ap_id)
967 |> Map.put("object", follow_activity.data["id"])
969 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
970 assert activity.data["object"] == follow_activity.data["id"]
972 follower = User.get_cached_by_id(follower.id)
974 assert User.following?(follower, followed) == true
977 test "it fails for incoming accepts which cannot be correlated" do
978 follower = insert(:user)
979 followed = insert(:user, %{info: %User.Info{locked: true}})
982 File.read!("test/fixtures/mastodon-accept-activity.json")
984 |> Map.put("actor", followed.ap_id)
987 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
989 :error = Transmogrifier.handle_incoming(accept_data)
991 follower = User.get_cached_by_id(follower.id)
993 refute User.following?(follower, followed) == true
996 test "it fails for incoming rejects which cannot be correlated" do
997 follower = insert(:user)
998 followed = insert(:user, %{info: %User.Info{locked: true}})
1001 File.read!("test/fixtures/mastodon-reject-activity.json")
1003 |> Map.put("actor", followed.ap_id)
1006 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
1008 :error = Transmogrifier.handle_incoming(accept_data)
1010 follower = User.get_cached_by_id(follower.id)
1012 refute User.following?(follower, followed) == true
1015 test "it works for incoming rejects which are orphaned" do
1016 follower = insert(:user)
1017 followed = insert(:user, %{info: %User.Info{locked: true}})
1019 {:ok, follower} = User.follow(follower, followed)
1020 {:ok, _follow_activity} = ActivityPub.follow(follower, followed)
1022 assert User.following?(follower, followed) == true
1025 File.read!("test/fixtures/mastodon-reject-activity.json")
1027 |> Map.put("actor", followed.ap_id)
1030 Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
1032 {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
1033 refute activity.local
1035 follower = User.get_cached_by_id(follower.id)
1037 assert User.following?(follower, followed) == false
1040 test "it works for incoming rejects which are referenced by IRI only" do
1041 follower = insert(:user)
1042 followed = insert(:user, %{info: %User.Info{locked: true}})
1044 {:ok, follower} = User.follow(follower, followed)
1045 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
1047 assert User.following?(follower, followed) == true
1050 File.read!("test/fixtures/mastodon-reject-activity.json")
1052 |> Map.put("actor", followed.ap_id)
1053 |> Map.put("object", follow_activity.data["id"])
1055 {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
1057 follower = User.get_cached_by_id(follower.id)
1059 assert User.following?(follower, followed) == false
1062 test "it rejects activities without a valid ID" do
1063 user = insert(:user)
1066 File.read!("test/fixtures/mastodon-follow-activity.json")
1068 |> Map.put("object", user.ap_id)
1069 |> Map.put("id", "")
1071 :error = Transmogrifier.handle_incoming(data)
1074 test "it remaps video URLs as attachments if necessary" do
1076 Fetcher.fetch_object_from_id(
1077 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1082 "mediaType" => "video/mp4",
1084 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1085 "mimeType" => "video/mp4",
1086 "size" => 5_015_880,
1090 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1091 "mediaType" => "video/mp4",
1098 assert object.data["url"] ==
1099 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1101 assert object.data["attachment"] == [attachment]
1104 test "it accepts Flag activities" do
1105 user = insert(:user)
1106 other_user = insert(:user)
1108 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
1109 object = Object.normalize(activity)
1112 "@context" => "https://www.w3.org/ns/activitystreams",
1113 "cc" => [user.ap_id],
1114 "object" => [user.ap_id, object.data["id"]],
1116 "content" => "blocked AND reported!!!",
1117 "actor" => other_user.ap_id
1120 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
1122 assert activity.data["object"] == [user.ap_id, object.data["id"]]
1123 assert activity.data["content"] == "blocked AND reported!!!"
1124 assert activity.data["actor"] == other_user.ap_id
1125 assert activity.data["cc"] == [user.ap_id]
1129 describe "prepare outgoing" do
1130 test "it inlines private announced objects" do
1131 user = insert(:user)
1133 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey", "visibility" => "private"})
1135 {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
1137 {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
1139 assert modified["object"]["content"] == "hey"
1140 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1143 test "it turns mentions into tags" do
1144 user = insert(:user)
1145 other_user = insert(:user)
1148 CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
1150 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1151 object = modified["object"]
1153 expected_mention = %{
1154 "href" => other_user.ap_id,
1155 "name" => "@#{other_user.nickname}",
1160 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1161 "type" => "Hashtag",
1165 assert Enum.member?(object["tag"], expected_tag)
1166 assert Enum.member?(object["tag"], expected_mention)
1169 test "it adds the sensitive property" do
1170 user = insert(:user)
1172 {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
1173 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1175 assert modified["object"]["sensitive"]
1178 test "it adds the json-ld context and the conversation property" do
1179 user = insert(:user)
1181 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1182 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1184 assert modified["@context"] ==
1185 Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
1187 assert modified["object"]["conversation"] == modified["context"]
1190 test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
1191 user = insert(:user)
1193 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1194 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1196 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1199 test "it translates ostatus IDs to external URLs" do
1200 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1201 {:ok, [referent_activity]} = OStatus.handle_incoming(incoming)
1203 user = insert(:user)
1205 {:ok, activity, _} = CommonAPI.favorite(referent_activity.id, user)
1206 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1208 assert modified["object"] == "http://gs.example.org:4040/index.php/notice/29"
1211 test "it translates ostatus reply_to IDs to external URLs" do
1212 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1213 {:ok, [referred_activity]} = OStatus.handle_incoming(incoming)
1215 user = insert(:user)
1218 CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id})
1220 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1222 assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29"
1225 test "it strips internal hashtag data" do
1226 user = insert(:user)
1228 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu"})
1231 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1232 "type" => "Hashtag",
1236 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1238 assert modified["object"]["tag"] == [expected_tag]
1241 test "it strips internal fields" do
1242 user = insert(:user)
1244 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :firefox:"})
1246 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1248 assert length(modified["object"]["tag"]) == 2
1250 assert is_nil(modified["object"]["emoji"])
1251 assert is_nil(modified["object"]["like_count"])
1252 assert is_nil(modified["object"]["announcements"])
1253 assert is_nil(modified["object"]["announcement_count"])
1254 assert is_nil(modified["object"]["context_id"])
1257 test "it strips internal fields of article" do
1258 activity = insert(:article_activity)
1260 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1262 assert length(modified["object"]["tag"]) == 2
1264 assert is_nil(modified["object"]["emoji"])
1265 assert is_nil(modified["object"]["like_count"])
1266 assert is_nil(modified["object"]["announcements"])
1267 assert is_nil(modified["object"]["announcement_count"])
1268 assert is_nil(modified["object"]["context_id"])
1269 assert is_nil(modified["object"]["likes"])
1272 test "the directMessage flag is present" do
1273 user = insert(:user)
1274 other_user = insert(:user)
1276 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"})
1278 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1280 assert modified["directMessage"] == false
1283 CommonAPI.post(user, %{"status" => "@#{other_user.nickname} :moominmamma:"})
1285 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1287 assert modified["directMessage"] == false
1290 CommonAPI.post(user, %{
1291 "status" => "@#{other_user.nickname} :moominmamma:",
1292 "visibility" => "direct"
1295 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1297 assert modified["directMessage"] == true
1300 test "it strips BCC field" do
1301 user = insert(:user)
1302 {:ok, list} = Pleroma.List.create("foo", user)
1305 CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
1307 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1309 assert is_nil(modified["bcc"])
1312 test "it can handle Listen activities" do
1313 listen_activity = insert(:listen)
1315 {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
1317 assert modified["type"] == "Listen"
1319 user = insert(:user)
1321 {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
1323 {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
1327 describe "user upgrade" do
1328 test "it upgrades a user to activitypub" do
1331 nickname: "rye@niu.moe",
1333 ap_id: "https://niu.moe/users/rye",
1334 follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
1337 user_two = insert(:user, %{following: [user.follower_address]})
1339 {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
1340 {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
1341 assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
1343 user = User.get_cached_by_id(user.id)
1344 assert user.info.note_count == 1
1346 {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
1347 ObanHelpers.perform_all()
1349 assert user.info.ap_enabled
1350 assert user.info.note_count == 1
1351 assert user.follower_address == "https://niu.moe/users/rye/followers"
1352 assert user.following_address == "https://niu.moe/users/rye/following"
1354 user = User.get_cached_by_id(user.id)
1355 assert user.info.note_count == 1
1357 activity = Activity.get_by_id(activity.id)
1358 assert user.follower_address in activity.recipients
1364 "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
1373 "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
1376 } = user.info.banner
1378 refute "..." in activity.recipients
1380 unrelated_activity = Activity.get_by_id(unrelated_activity.id)
1381 refute user.follower_address in unrelated_activity.recipients
1383 user_two = User.get_cached_by_id(user_two.id)
1384 assert user.follower_address in user_two.following
1385 refute "..." in user_two.following
1389 describe "maybe_retire_websub" do
1390 test "it deletes all websub client subscripitions with the user as topic" do
1391 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/rye.atom"}
1392 {:ok, ws} = Repo.insert(subscription)
1394 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/pasty.atom"}
1395 {:ok, ws2} = Repo.insert(subscription)
1397 Transmogrifier.maybe_retire_websub("https://niu.moe/users/rye")
1399 refute Repo.get(WebsubClientSubscription, ws.id)
1400 assert Repo.get(WebsubClientSubscription, ws2.id)
1404 describe "actor rewriting" do
1405 test "it fixes the actor URL property to be a proper URI" do
1407 "url" => %{"href" => "http://example.com"}
1410 rewritten = Transmogrifier.maybe_fix_user_object(data)
1411 assert rewritten["url"] == "http://example.com"
1415 describe "actor origin containment" do
1416 test "it rejects activities which reference objects with bogus origins" do
1418 "@context" => "https://www.w3.org/ns/activitystreams",
1419 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1420 "actor" => "http://mastodon.example.org/users/admin",
1421 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1422 "object" => "https://info.pleroma.site/activity.json",
1423 "type" => "Announce"
1426 :error = Transmogrifier.handle_incoming(data)
1429 test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
1431 "@context" => "https://www.w3.org/ns/activitystreams",
1432 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1433 "actor" => "http://mastodon.example.org/users/admin",
1434 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1435 "object" => "https://info.pleroma.site/activity2.json",
1436 "type" => "Announce"
1439 :error = Transmogrifier.handle_incoming(data)
1442 test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
1444 "@context" => "https://www.w3.org/ns/activitystreams",
1445 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1446 "actor" => "http://mastodon.example.org/users/admin",
1447 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1448 "object" => "https://info.pleroma.site/activity3.json",
1449 "type" => "Announce"
1452 :error = Transmogrifier.handle_incoming(data)
1456 describe "reserialization" do
1457 test "successfully reserializes a message with inReplyTo == nil" do
1458 user = insert(:user)
1461 "@context" => "https://www.w3.org/ns/activitystreams",
1462 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1466 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1471 "attributedTo" => user.ap_id
1473 "actor" => user.ap_id
1476 {:ok, activity} = Transmogrifier.handle_incoming(message)
1478 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1481 test "successfully reserializes a message with AS2 objects in IR" do
1482 user = insert(:user)
1485 "@context" => "https://www.w3.org/ns/activitystreams",
1486 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1490 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1495 "attributedTo" => user.ap_id,
1497 %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
1498 %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
1501 "actor" => user.ap_id
1504 {:ok, activity} = Transmogrifier.handle_incoming(message)
1506 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1510 test "Rewrites Answers to Notes" do
1511 user = insert(:user)
1513 {:ok, poll_activity} =
1514 CommonAPI.post(user, %{
1515 "status" => "suya...",
1516 "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
1519 poll_object = Object.normalize(poll_activity)
1520 # TODO: Replace with CommonAPI vote creation when implemented
1522 File.read!("test/fixtures/mastodon-vote.json")
1524 |> Kernel.put_in(["to"], user.ap_id)
1525 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
1526 |> Kernel.put_in(["object", "to"], user.ap_id)
1528 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
1529 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
1531 assert data["object"]["type"] == "Note"
1534 describe "fix_explicit_addressing" do
1536 user = insert(:user)
1540 test "moves non-explicitly mentioned actors to cc", %{user: user} do
1541 explicitly_mentioned_actors = [
1542 "https://pleroma.gold/users/user1",
1543 "https://pleroma.gold/user2"
1547 "actor" => user.ap_id,
1548 "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"],
1551 Enum.map(explicitly_mentioned_actors, fn href ->
1552 %{"type" => "Mention", "href" => href}
1556 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1557 assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
1558 refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
1559 assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
1562 test "does not move actor's follower collection to cc", %{user: user} do
1564 "actor" => user.ap_id,
1565 "to" => [user.follower_address],
1569 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1570 assert user.follower_address in fixed_object["to"]
1571 refute user.follower_address in fixed_object["cc"]
1574 test "removes recipient's follower collection from cc", %{user: user} do
1575 recipient = insert(:user)
1578 "actor" => user.ap_id,
1579 "to" => [recipient.ap_id, "https://www.w3.org/ns/activitystreams#Public"],
1580 "cc" => [user.follower_address, recipient.follower_address]
1583 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1585 assert user.follower_address in fixed_object["cc"]
1586 refute recipient.follower_address in fixed_object["cc"]
1587 refute recipient.follower_address in fixed_object["to"]
1591 describe "fix_summary/1" do
1592 test "returns fixed object" do
1593 assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
1594 assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
1595 assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
1599 describe "fix_in_reply_to/2" do
1600 clear_config([:instance, :federation_incoming_replies_max_depth])
1603 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1607 test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
1608 assert Transmogrifier.fix_in_reply_to(data) == data
1611 test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
1612 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
1615 Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
1617 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1618 assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
1619 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1622 Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
1624 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1625 assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
1626 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1629 Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
1631 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1632 assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
1633 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1635 object_with_reply = Map.put(data["object"], "inReplyTo", [])
1636 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1637 assert modified_object["inReplyTo"] == []
1638 assert modified_object["inReplyToAtomUri"] == ""
1641 test "returns modified object when allowed incoming reply", %{data: data} do
1646 "https://shitposter.club/notice/2827873"
1649 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
1650 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1652 assert modified_object["inReplyTo"] ==
1653 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
1655 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1657 assert modified_object["conversation"] ==
1658 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1660 assert modified_object["context"] ==
1661 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1665 describe "fix_url/1" do
1666 test "fixes data for object when url is map" do
1670 "mimeType" => "video/mp4",
1671 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1675 assert Transmogrifier.fix_url(object) == %{
1676 "url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1680 test "fixes data for video object" do
1686 "mimeType" => "video/mp4",
1687 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1691 "mimeType" => "video/mp4",
1692 "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
1696 "mimeType" => "text/html",
1697 "href" => "https://peertube.-2d4c2d1630e3"
1701 "mimeType" => "text/html",
1702 "href" => "https://peertube.-2d4c2d16377-42"
1707 assert Transmogrifier.fix_url(object) == %{
1710 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1711 "mimeType" => "video/mp4",
1716 "url" => "https://peertube.-2d4c2d1630e3"
1720 test "fixes url for not Video object" do
1726 "mimeType" => "text/html",
1727 "href" => "https://peertube.-2d4c2d1630e3"
1731 "mimeType" => "text/html",
1732 "href" => "https://peertube.-2d4c2d16377-42"
1737 assert Transmogrifier.fix_url(object) == %{
1739 "url" => "https://peertube.-2d4c2d1630e3"
1742 assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
1748 test "retunrs not modified object" do
1749 assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
1753 describe "get_obj_helper/2" do
1754 test "returns nil when cannot normalize object" do
1755 refute Transmogrifier.get_obj_helper("test-obj-id")
1758 test "returns {:ok, %Object{}} for success case" do
1759 assert {:ok, %Object{}} =
1760 Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
1764 describe "fix_attachments/1" do
1765 test "returns not modified object" do
1766 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1767 assert Transmogrifier.fix_attachments(data) == data
1770 test "returns modified object when attachment is map" do
1771 assert Transmogrifier.fix_attachments(%{
1773 "mediaType" => "video/mp4",
1774 "url" => "https://peertube.moe/stat-480.mp4"
1779 "mediaType" => "video/mp4",
1782 "href" => "https://peertube.moe/stat-480.mp4",
1783 "mediaType" => "video/mp4",
1792 test "returns modified object when attachment is list" do
1793 assert Transmogrifier.fix_attachments(%{
1795 %{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
1796 %{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
1801 "mediaType" => "video/mp4",
1804 "href" => "https://pe.er/stat-480.mp4",
1805 "mediaType" => "video/mp4",
1811 "href" => "https://pe.er/stat-480.mp4",
1812 "mediaType" => "video/mp4",
1813 "mimeType" => "video/mp4",
1816 "href" => "https://pe.er/stat-480.mp4",
1817 "mediaType" => "video/mp4",
1827 describe "fix_emoji/1" do
1828 test "returns not modified object when object not contains tags" do
1829 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1830 assert Transmogrifier.fix_emoji(data) == data
1833 test "returns object with emoji when object contains list tags" do
1834 assert Transmogrifier.fix_emoji(%{
1836 %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
1837 %{"type" => "Hashtag"}
1840 "emoji" => %{"bib" => "/test"},
1842 %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
1843 %{"type" => "Hashtag"}
1848 test "returns object with emoji when object contains map tag" do
1849 assert Transmogrifier.fix_emoji(%{
1850 "tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
1852 "emoji" => %{"bib" => "/test"},
1853 "tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}