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} = activity} = Transmogrifier.handle_incoming(data)
338 refute Enum.empty?(activity.recipients)
340 assert data["actor"] == "http://mastodon.example.org/users/admin"
341 assert data["type"] == "Like"
342 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
343 assert data["object"] == activity.data["object"]
346 test "it returns an error for incoming unlikes wihout a like activity" do
348 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
351 File.read!("test/fixtures/mastodon-undo-like.json")
353 |> Map.put("object", activity.data["object"])
355 assert Transmogrifier.handle_incoming(data) == :error
358 test "it works for incoming unlikes with an existing like activity" do
360 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
363 File.read!("test/fixtures/mastodon-like.json")
365 |> Map.put("object", activity.data["object"])
367 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
370 File.read!("test/fixtures/mastodon-undo-like.json")
372 |> Map.put("object", like_data)
373 |> Map.put("actor", like_data["actor"])
375 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
377 assert data["actor"] == "http://mastodon.example.org/users/admin"
378 assert data["type"] == "Undo"
379 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
380 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
383 test "it works for incoming unlikes with an existing like activity and a compact object" do
385 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
388 File.read!("test/fixtures/mastodon-like.json")
390 |> Map.put("object", activity.data["object"])
392 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
395 File.read!("test/fixtures/mastodon-undo-like.json")
397 |> Map.put("object", like_data["id"])
398 |> Map.put("actor", like_data["actor"])
400 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
402 assert data["actor"] == "http://mastodon.example.org/users/admin"
403 assert data["type"] == "Undo"
404 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
405 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
408 test "it works for incoming announces" do
409 data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
411 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
413 assert data["actor"] == "http://mastodon.example.org/users/admin"
414 assert data["type"] == "Announce"
417 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
419 assert data["object"] ==
420 "http://mastodon.example.org/users/admin/statuses/99541947525187367"
422 assert Activity.get_create_by_object_ap_id(data["object"])
425 test "it works for incoming announces with an existing activity" do
427 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
430 File.read!("test/fixtures/mastodon-announce.json")
432 |> Map.put("object", activity.data["object"])
434 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
436 assert data["actor"] == "http://mastodon.example.org/users/admin"
437 assert data["type"] == "Announce"
440 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
442 assert data["object"] == activity.data["object"]
444 assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
447 test "it works for incoming announces with an inlined activity" do
449 File.read!("test/fixtures/mastodon-announce-private.json")
452 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
454 assert data["actor"] == "http://mastodon.example.org/users/admin"
455 assert data["type"] == "Announce"
458 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
460 object = Object.normalize(data["object"])
462 assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
463 assert object.data["content"] == "this is a private toot"
466 test "it rejects incoming announces with an inlined activity from another origin" do
468 File.read!("test/fixtures/bogus-mastodon-announce.json")
471 assert :error = Transmogrifier.handle_incoming(data)
474 test "it does not clobber the addressing on announce activities" do
476 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
479 File.read!("test/fixtures/mastodon-announce.json")
481 |> Map.put("object", Object.normalize(activity).data["id"])
482 |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
485 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
487 assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]
490 test "it ensures that as:Public activities make it to their followers collection" do
494 File.read!("test/fixtures/mastodon-post-activity.json")
496 |> Map.put("actor", user.ap_id)
497 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
502 |> Map.put("attributedTo", user.ap_id)
503 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
505 |> Map.put("id", user.ap_id <> "/activities/12345678")
507 data = Map.put(data, "object", object)
509 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
511 assert data["cc"] == [User.ap_followers(user)]
514 test "it ensures that address fields become lists" do
518 File.read!("test/fixtures/mastodon-post-activity.json")
520 |> Map.put("actor", user.ap_id)
521 |> Map.put("to", nil)
522 |> Map.put("cc", nil)
526 |> Map.put("attributedTo", user.ap_id)
527 |> Map.put("to", nil)
528 |> Map.put("cc", nil)
529 |> Map.put("id", user.ap_id <> "/activities/12345678")
531 data = Map.put(data, "object", object)
533 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
535 assert !is_nil(data["to"])
536 assert !is_nil(data["cc"])
539 test "it strips internal likes" do
541 File.read!("test/fixtures/mastodon-post-activity.json")
546 "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
547 "id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
549 "type" => "OrderedCollection"
552 object = Map.put(data["object"], "likes", likes)
553 data = Map.put(data, "object", object)
555 {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
557 refute Map.has_key?(object.data, "likes")
560 test "it works for incoming update activities" do
561 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
563 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
564 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
567 update_data["object"]
568 |> Map.put("actor", data["actor"])
569 |> Map.put("id", data["actor"])
573 |> Map.put("actor", data["actor"])
574 |> Map.put("object", object)
576 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
578 assert data["id"] == update_data["id"]
580 user = User.get_cached_by_ap_id(data["actor"])
581 assert user.name == "gargle"
583 assert user.avatar["url"] == [
586 "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
590 assert user.info.banner["url"] == [
593 "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
597 assert user.bio == "<p>Some bio</p>"
600 test "it works with custom profile fields" do
602 "test/fixtures/mastodon-post-activity.json"
605 |> Transmogrifier.handle_incoming()
607 user = User.get_cached_by_ap_id(activity.actor)
609 assert User.Info.fields(user.info) == [
610 %{"name" => "foo", "value" => "bar"},
611 %{"name" => "foo1", "value" => "bar1"}
614 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
617 update_data["object"]
618 |> Map.put("actor", user.ap_id)
619 |> Map.put("id", user.ap_id)
623 |> Map.put("actor", user.ap_id)
624 |> Map.put("object", object)
626 {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
628 user = User.get_cached_by_ap_id(user.ap_id)
630 assert User.Info.fields(user.info) == [
631 %{"name" => "foo", "value" => "updated"},
632 %{"name" => "foo1", "value" => "updated"}
635 Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
638 put_in(update_data, ["object", "attachment"], [
639 %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
640 %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
641 %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
644 {:ok, _} = Transmogrifier.handle_incoming(update_data)
646 user = User.get_cached_by_ap_id(user.ap_id)
648 assert User.Info.fields(user.info) == [
649 %{"name" => "foo", "value" => "updated"},
650 %{"name" => "foo1", "value" => "updated"}
653 update_data = put_in(update_data, ["object", "attachment"], [])
655 {:ok, _} = Transmogrifier.handle_incoming(update_data)
657 user = User.get_cached_by_ap_id(user.ap_id)
659 assert User.Info.fields(user.info) == []
662 test "it works for incoming update activities which lock the account" do
663 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
665 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
666 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
669 update_data["object"]
670 |> Map.put("actor", data["actor"])
671 |> Map.put("id", data["actor"])
672 |> Map.put("manuallyApprovesFollowers", true)
676 |> Map.put("actor", data["actor"])
677 |> Map.put("object", object)
679 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
681 user = User.get_cached_by_ap_id(data["actor"])
682 assert user.info.locked == true
685 test "it works for incoming deletes" do
686 activity = insert(:note_activity)
687 deleting_user = insert(:user)
690 File.read!("test/fixtures/mastodon-delete.json")
695 |> Map.put("id", activity.data["object"])
699 |> Map.put("object", object)
700 |> Map.put("actor", deleting_user.ap_id)
702 {:ok, %Activity{actor: actor, local: false, data: %{"id" => id}}} =
703 Transmogrifier.handle_incoming(data)
705 assert id == data["id"]
706 refute Activity.get_by_id(activity.id)
707 assert actor == deleting_user.ap_id
710 test "it fails for incoming deletes with spoofed origin" do
711 activity = insert(:note_activity)
714 File.read!("test/fixtures/mastodon-delete.json")
719 |> Map.put("id", activity.data["object"])
723 |> Map.put("object", object)
725 assert capture_log(fn ->
726 :error = Transmogrifier.handle_incoming(data)
728 "[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}"
730 assert Activity.get_by_id(activity.id)
733 test "it works for incoming user deletes" do
734 %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
737 File.read!("test/fixtures/mastodon-delete-user.json")
740 {:ok, _} = Transmogrifier.handle_incoming(data)
741 ObanHelpers.perform_all()
743 refute User.get_cached_by_ap_id(ap_id)
746 test "it fails for incoming user deletes with spoofed origin" do
747 %{ap_id: ap_id} = insert(:user)
750 File.read!("test/fixtures/mastodon-delete-user.json")
752 |> Map.put("actor", ap_id)
754 assert :error == Transmogrifier.handle_incoming(data)
755 assert User.get_cached_by_ap_id(ap_id)
758 test "it works for incoming unannounces with an existing notice" do
760 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
763 File.read!("test/fixtures/mastodon-announce.json")
765 |> Map.put("object", activity.data["object"])
767 {:ok, %Activity{data: announce_data, local: false}} =
768 Transmogrifier.handle_incoming(announce_data)
771 File.read!("test/fixtures/mastodon-undo-announce.json")
773 |> Map.put("object", announce_data)
774 |> Map.put("actor", announce_data["actor"])
776 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
778 assert data["type"] == "Undo"
779 assert object_data = data["object"]
780 assert object_data["type"] == "Announce"
781 assert object_data["object"] == activity.data["object"]
783 assert object_data["id"] ==
784 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
787 test "it works for incomming unfollows with an existing follow" do
791 File.read!("test/fixtures/mastodon-follow-activity.json")
793 |> Map.put("object", user.ap_id)
795 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
798 File.read!("test/fixtures/mastodon-unfollow-activity.json")
800 |> Map.put("object", follow_data)
802 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
804 assert data["type"] == "Undo"
805 assert data["object"]["type"] == "Follow"
806 assert data["object"]["object"] == user.ap_id
807 assert data["actor"] == "http://mastodon.example.org/users/admin"
809 refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
812 test "it works for incoming blocks" do
816 File.read!("test/fixtures/mastodon-block-activity.json")
818 |> Map.put("object", user.ap_id)
820 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
822 assert data["type"] == "Block"
823 assert data["object"] == user.ap_id
824 assert data["actor"] == "http://mastodon.example.org/users/admin"
826 blocker = User.get_cached_by_ap_id(data["actor"])
828 assert User.blocks?(blocker, user)
831 test "incoming blocks successfully tear down any follow relationship" do
832 blocker = insert(:user)
833 blocked = insert(:user)
836 File.read!("test/fixtures/mastodon-block-activity.json")
838 |> Map.put("object", blocked.ap_id)
839 |> Map.put("actor", blocker.ap_id)
841 {:ok, blocker} = User.follow(blocker, blocked)
842 {:ok, blocked} = User.follow(blocked, blocker)
844 assert User.following?(blocker, blocked)
845 assert User.following?(blocked, blocker)
847 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
849 assert data["type"] == "Block"
850 assert data["object"] == blocked.ap_id
851 assert data["actor"] == blocker.ap_id
853 blocker = User.get_cached_by_ap_id(data["actor"])
854 blocked = User.get_cached_by_ap_id(data["object"])
856 assert User.blocks?(blocker, blocked)
858 refute User.following?(blocker, blocked)
859 refute User.following?(blocked, blocker)
862 test "it works for incoming unblocks with an existing block" do
866 File.read!("test/fixtures/mastodon-block-activity.json")
868 |> Map.put("object", user.ap_id)
870 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
873 File.read!("test/fixtures/mastodon-unblock-activity.json")
875 |> Map.put("object", block_data)
877 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
878 assert data["type"] == "Undo"
879 assert data["object"]["type"] == "Block"
880 assert data["object"]["object"] == user.ap_id
881 assert data["actor"] == "http://mastodon.example.org/users/admin"
883 blocker = User.get_cached_by_ap_id(data["actor"])
885 refute User.blocks?(blocker, user)
888 test "it works for incoming accepts which were pre-accepted" do
889 follower = insert(:user)
890 followed = insert(:user)
892 {:ok, follower} = User.follow(follower, followed)
893 assert User.following?(follower, followed) == true
895 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
898 File.read!("test/fixtures/mastodon-accept-activity.json")
900 |> Map.put("actor", followed.ap_id)
903 accept_data["object"]
904 |> Map.put("actor", follower.ap_id)
905 |> Map.put("id", follow_activity.data["id"])
907 accept_data = Map.put(accept_data, "object", object)
909 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
910 refute activity.local
912 assert activity.data["object"] == follow_activity.data["id"]
914 assert activity.data["id"] == accept_data["id"]
916 follower = User.get_cached_by_id(follower.id)
918 assert User.following?(follower, followed) == true
921 test "it works for incoming accepts which were orphaned" do
922 follower = insert(:user)
923 followed = insert(:user, %{info: %User.Info{locked: true}})
925 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
928 File.read!("test/fixtures/mastodon-accept-activity.json")
930 |> Map.put("actor", followed.ap_id)
933 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
935 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
936 assert activity.data["object"] == follow_activity.data["id"]
938 follower = User.get_cached_by_id(follower.id)
940 assert User.following?(follower, followed) == true
943 test "it works for incoming accepts which are referenced by IRI only" do
944 follower = insert(:user)
945 followed = insert(:user, %{info: %User.Info{locked: true}})
947 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
950 File.read!("test/fixtures/mastodon-accept-activity.json")
952 |> Map.put("actor", followed.ap_id)
953 |> Map.put("object", follow_activity.data["id"])
955 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
956 assert activity.data["object"] == follow_activity.data["id"]
958 follower = User.get_cached_by_id(follower.id)
960 assert User.following?(follower, followed) == true
963 test "it fails for incoming accepts which cannot be correlated" do
964 follower = insert(:user)
965 followed = insert(:user, %{info: %User.Info{locked: true}})
968 File.read!("test/fixtures/mastodon-accept-activity.json")
970 |> Map.put("actor", followed.ap_id)
973 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
975 :error = Transmogrifier.handle_incoming(accept_data)
977 follower = User.get_cached_by_id(follower.id)
979 refute User.following?(follower, followed) == true
982 test "it fails for incoming rejects which cannot be correlated" do
983 follower = insert(:user)
984 followed = insert(:user, %{info: %User.Info{locked: true}})
987 File.read!("test/fixtures/mastodon-reject-activity.json")
989 |> Map.put("actor", followed.ap_id)
992 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
994 :error = Transmogrifier.handle_incoming(accept_data)
996 follower = User.get_cached_by_id(follower.id)
998 refute User.following?(follower, followed) == true
1001 test "it works for incoming rejects which are orphaned" do
1002 follower = insert(:user)
1003 followed = insert(:user, %{info: %User.Info{locked: true}})
1005 {:ok, follower} = User.follow(follower, followed)
1006 {:ok, _follow_activity} = ActivityPub.follow(follower, followed)
1008 assert User.following?(follower, followed) == true
1011 File.read!("test/fixtures/mastodon-reject-activity.json")
1013 |> Map.put("actor", followed.ap_id)
1016 Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
1018 {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
1019 refute activity.local
1020 assert activity.data["id"] == reject_data["id"]
1022 follower = User.get_cached_by_id(follower.id)
1024 assert User.following?(follower, followed) == false
1027 test "it works for incoming rejects which are referenced by IRI only" do
1028 follower = insert(:user)
1029 followed = insert(:user, %{info: %User.Info{locked: true}})
1031 {:ok, follower} = User.follow(follower, followed)
1032 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
1034 assert User.following?(follower, followed) == true
1037 File.read!("test/fixtures/mastodon-reject-activity.json")
1039 |> Map.put("actor", followed.ap_id)
1040 |> Map.put("object", follow_activity.data["id"])
1042 {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
1044 follower = User.get_cached_by_id(follower.id)
1046 assert User.following?(follower, followed) == false
1049 test "it rejects activities without a valid ID" do
1050 user = insert(:user)
1053 File.read!("test/fixtures/mastodon-follow-activity.json")
1055 |> Map.put("object", user.ap_id)
1056 |> Map.put("id", "")
1058 :error = Transmogrifier.handle_incoming(data)
1061 test "it remaps video URLs as attachments if necessary" do
1063 Fetcher.fetch_object_from_id(
1064 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1069 "mediaType" => "video/mp4",
1071 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1072 "mimeType" => "video/mp4",
1073 "size" => 5_015_880,
1077 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1078 "mediaType" => "video/mp4",
1085 assert object.data["url"] ==
1086 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1088 assert object.data["attachment"] == [attachment]
1091 test "it accepts Flag activities" do
1092 user = insert(:user)
1093 other_user = insert(:user)
1095 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
1096 object = Object.normalize(activity)
1099 "@context" => "https://www.w3.org/ns/activitystreams",
1100 "cc" => [user.ap_id],
1101 "object" => [user.ap_id, object.data["id"]],
1103 "content" => "blocked AND reported!!!",
1104 "actor" => other_user.ap_id
1107 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
1109 assert activity.data["object"] == [user.ap_id, object.data["id"]]
1110 assert activity.data["content"] == "blocked AND reported!!!"
1111 assert activity.data["actor"] == other_user.ap_id
1112 assert activity.data["cc"] == [user.ap_id]
1116 describe "prepare outgoing" do
1117 test "it inlines private announced objects" do
1118 user = insert(:user)
1120 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey", "visibility" => "private"})
1122 {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
1124 {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
1126 assert modified["object"]["content"] == "hey"
1127 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1130 test "it turns mentions into tags" do
1131 user = insert(:user)
1132 other_user = insert(:user)
1135 CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
1137 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1138 object = modified["object"]
1140 expected_mention = %{
1141 "href" => other_user.ap_id,
1142 "name" => "@#{other_user.nickname}",
1147 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1148 "type" => "Hashtag",
1152 assert Enum.member?(object["tag"], expected_tag)
1153 assert Enum.member?(object["tag"], expected_mention)
1156 test "it adds the sensitive property" do
1157 user = insert(:user)
1159 {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
1160 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1162 assert modified["object"]["sensitive"]
1165 test "it adds the json-ld context and the conversation property" do
1166 user = insert(:user)
1168 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1169 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1171 assert modified["@context"] ==
1172 Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
1174 assert modified["object"]["conversation"] == modified["context"]
1177 test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
1178 user = insert(:user)
1180 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1181 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1183 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1186 test "it translates ostatus IDs to external URLs" do
1187 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1188 {:ok, [referent_activity]} = OStatus.handle_incoming(incoming)
1190 user = insert(:user)
1192 {:ok, activity} = CommonAPI.favorite(user, referent_activity.id)
1193 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1195 assert modified["object"] == "http://gs.example.org:4040/index.php/notice/29"
1198 test "it translates ostatus reply_to IDs to external URLs" do
1199 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1200 {:ok, [referred_activity]} = OStatus.handle_incoming(incoming)
1202 user = insert(:user)
1205 CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id})
1207 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1209 assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29"
1212 test "it strips internal hashtag data" do
1213 user = insert(:user)
1215 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu"})
1218 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1219 "type" => "Hashtag",
1223 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1225 assert modified["object"]["tag"] == [expected_tag]
1228 test "it strips internal fields" do
1229 user = insert(:user)
1231 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :firefox:"})
1233 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1235 assert length(modified["object"]["tag"]) == 2
1237 assert is_nil(modified["object"]["emoji"])
1238 assert is_nil(modified["object"]["like_count"])
1239 assert is_nil(modified["object"]["announcements"])
1240 assert is_nil(modified["object"]["announcement_count"])
1241 assert is_nil(modified["object"]["context_id"])
1244 test "it strips internal fields of article" do
1245 activity = insert(:article_activity)
1247 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1249 assert length(modified["object"]["tag"]) == 2
1251 assert is_nil(modified["object"]["emoji"])
1252 assert is_nil(modified["object"]["like_count"])
1253 assert is_nil(modified["object"]["announcements"])
1254 assert is_nil(modified["object"]["announcement_count"])
1255 assert is_nil(modified["object"]["context_id"])
1256 assert is_nil(modified["object"]["likes"])
1259 test "the directMessage flag is present" do
1260 user = insert(:user)
1261 other_user = insert(:user)
1263 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"})
1265 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1267 assert modified["directMessage"] == false
1270 CommonAPI.post(user, %{"status" => "@#{other_user.nickname} :moominmamma:"})
1272 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1274 assert modified["directMessage"] == false
1277 CommonAPI.post(user, %{
1278 "status" => "@#{other_user.nickname} :moominmamma:",
1279 "visibility" => "direct"
1282 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1284 assert modified["directMessage"] == true
1287 test "it strips BCC field" do
1288 user = insert(:user)
1289 {:ok, list} = Pleroma.List.create("foo", user)
1292 CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
1294 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1296 assert is_nil(modified["bcc"])
1299 test "it can handle Listen activities" do
1300 listen_activity = insert(:listen)
1302 {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
1304 assert modified["type"] == "Listen"
1306 user = insert(:user)
1308 {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
1310 {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
1314 describe "user upgrade" do
1315 test "it upgrades a user to activitypub" do
1318 nickname: "rye@niu.moe",
1320 ap_id: "https://niu.moe/users/rye",
1321 follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
1324 user_two = insert(:user, %{following: [user.follower_address]})
1326 {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
1327 {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
1328 assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
1330 user = User.get_cached_by_id(user.id)
1331 assert user.info.note_count == 1
1333 {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
1334 ObanHelpers.perform_all()
1336 assert user.info.ap_enabled
1337 assert user.info.note_count == 1
1338 assert user.follower_address == "https://niu.moe/users/rye/followers"
1339 assert user.following_address == "https://niu.moe/users/rye/following"
1341 user = User.get_cached_by_id(user.id)
1342 assert user.info.note_count == 1
1344 activity = Activity.get_by_id(activity.id)
1345 assert user.follower_address in activity.recipients
1351 "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
1360 "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
1363 } = user.info.banner
1365 refute "..." in activity.recipients
1367 unrelated_activity = Activity.get_by_id(unrelated_activity.id)
1368 refute user.follower_address in unrelated_activity.recipients
1370 user_two = User.get_cached_by_id(user_two.id)
1371 assert user.follower_address in user_two.following
1372 refute "..." in user_two.following
1376 describe "maybe_retire_websub" do
1377 test "it deletes all websub client subscripitions with the user as topic" do
1378 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/rye.atom"}
1379 {:ok, ws} = Repo.insert(subscription)
1381 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/pasty.atom"}
1382 {:ok, ws2} = Repo.insert(subscription)
1384 Transmogrifier.maybe_retire_websub("https://niu.moe/users/rye")
1386 refute Repo.get(WebsubClientSubscription, ws.id)
1387 assert Repo.get(WebsubClientSubscription, ws2.id)
1391 describe "actor rewriting" do
1392 test "it fixes the actor URL property to be a proper URI" do
1394 "url" => %{"href" => "http://example.com"}
1397 rewritten = Transmogrifier.maybe_fix_user_object(data)
1398 assert rewritten["url"] == "http://example.com"
1402 describe "actor origin containment" do
1403 test "it rejects activities which reference objects with bogus origins" do
1405 "@context" => "https://www.w3.org/ns/activitystreams",
1406 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1407 "actor" => "http://mastodon.example.org/users/admin",
1408 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1409 "object" => "https://info.pleroma.site/activity.json",
1410 "type" => "Announce"
1413 :error = Transmogrifier.handle_incoming(data)
1416 test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" 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/activity2.json",
1423 "type" => "Announce"
1426 :error = Transmogrifier.handle_incoming(data)
1429 test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" 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/activity3.json",
1436 "type" => "Announce"
1439 :error = Transmogrifier.handle_incoming(data)
1443 describe "reserialization" do
1444 test "successfully reserializes a message with inReplyTo == nil" do
1445 user = insert(:user)
1448 "@context" => "https://www.w3.org/ns/activitystreams",
1449 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1453 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1458 "attributedTo" => user.ap_id
1460 "actor" => user.ap_id
1463 {:ok, activity} = Transmogrifier.handle_incoming(message)
1465 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1468 test "successfully reserializes a message with AS2 objects in IR" do
1469 user = insert(:user)
1472 "@context" => "https://www.w3.org/ns/activitystreams",
1473 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1477 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1482 "attributedTo" => user.ap_id,
1484 %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
1485 %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
1488 "actor" => user.ap_id
1491 {:ok, activity} = Transmogrifier.handle_incoming(message)
1493 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1497 test "Rewrites Answers to Notes" do
1498 user = insert(:user)
1500 {:ok, poll_activity} =
1501 CommonAPI.post(user, %{
1502 "status" => "suya...",
1503 "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
1506 poll_object = Object.normalize(poll_activity)
1507 # TODO: Replace with CommonAPI vote creation when implemented
1509 File.read!("test/fixtures/mastodon-vote.json")
1511 |> Kernel.put_in(["to"], user.ap_id)
1512 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
1513 |> Kernel.put_in(["object", "to"], user.ap_id)
1515 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
1516 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
1518 assert data["object"]["type"] == "Note"
1521 describe "fix_explicit_addressing" do
1523 user = insert(:user)
1527 test "moves non-explicitly mentioned actors to cc", %{user: user} do
1528 explicitly_mentioned_actors = [
1529 "https://pleroma.gold/users/user1",
1530 "https://pleroma.gold/user2"
1534 "actor" => user.ap_id,
1535 "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"],
1538 Enum.map(explicitly_mentioned_actors, fn href ->
1539 %{"type" => "Mention", "href" => href}
1543 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1544 assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
1545 refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
1546 assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
1549 test "does not move actor's follower collection to cc", %{user: user} do
1551 "actor" => user.ap_id,
1552 "to" => [user.follower_address],
1556 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1557 assert user.follower_address in fixed_object["to"]
1558 refute user.follower_address in fixed_object["cc"]
1561 test "removes recipient's follower collection from cc", %{user: user} do
1562 recipient = insert(:user)
1565 "actor" => user.ap_id,
1566 "to" => [recipient.ap_id, "https://www.w3.org/ns/activitystreams#Public"],
1567 "cc" => [user.follower_address, recipient.follower_address]
1570 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1572 assert user.follower_address in fixed_object["cc"]
1573 refute recipient.follower_address in fixed_object["cc"]
1574 refute recipient.follower_address in fixed_object["to"]
1578 describe "fix_summary/1" do
1579 test "returns fixed object" do
1580 assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
1581 assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
1582 assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
1586 describe "fix_in_reply_to/2" do
1587 clear_config([:instance, :federation_incoming_replies_max_depth])
1590 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1594 test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
1595 assert Transmogrifier.fix_in_reply_to(data) == data
1598 test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
1599 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
1602 Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
1604 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1605 assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
1606 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1609 Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
1611 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1612 assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
1613 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1616 Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
1618 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1619 assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
1620 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1622 object_with_reply = Map.put(data["object"], "inReplyTo", [])
1623 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1624 assert modified_object["inReplyTo"] == []
1625 assert modified_object["inReplyToAtomUri"] == ""
1628 test "returns modified object when allowed incoming reply", %{data: data} do
1633 "https://shitposter.club/notice/2827873"
1636 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
1637 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1639 assert modified_object["inReplyTo"] ==
1640 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
1642 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1644 assert modified_object["conversation"] ==
1645 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1647 assert modified_object["context"] ==
1648 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1652 describe "fix_url/1" do
1653 test "fixes data for object when url is map" do
1657 "mimeType" => "video/mp4",
1658 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1662 assert Transmogrifier.fix_url(object) == %{
1663 "url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1667 test "fixes data for video object" do
1673 "mimeType" => "video/mp4",
1674 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1678 "mimeType" => "video/mp4",
1679 "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
1683 "mimeType" => "text/html",
1684 "href" => "https://peertube.-2d4c2d1630e3"
1688 "mimeType" => "text/html",
1689 "href" => "https://peertube.-2d4c2d16377-42"
1694 assert Transmogrifier.fix_url(object) == %{
1697 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1698 "mimeType" => "video/mp4",
1703 "url" => "https://peertube.-2d4c2d1630e3"
1707 test "fixes url for not Video object" do
1713 "mimeType" => "text/html",
1714 "href" => "https://peertube.-2d4c2d1630e3"
1718 "mimeType" => "text/html",
1719 "href" => "https://peertube.-2d4c2d16377-42"
1724 assert Transmogrifier.fix_url(object) == %{
1726 "url" => "https://peertube.-2d4c2d1630e3"
1729 assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
1735 test "retunrs not modified object" do
1736 assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
1740 describe "get_obj_helper/2" do
1741 test "returns nil when cannot normalize object" do
1742 refute Transmogrifier.get_obj_helper("test-obj-id")
1745 test "returns {:ok, %Object{}} for success case" do
1746 assert {:ok, %Object{}} =
1747 Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
1751 describe "fix_attachments/1" do
1752 test "returns not modified object" do
1753 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1754 assert Transmogrifier.fix_attachments(data) == data
1757 test "returns modified object when attachment is map" do
1758 assert Transmogrifier.fix_attachments(%{
1760 "mediaType" => "video/mp4",
1761 "url" => "https://peertube.moe/stat-480.mp4"
1766 "mediaType" => "video/mp4",
1769 "href" => "https://peertube.moe/stat-480.mp4",
1770 "mediaType" => "video/mp4",
1779 test "returns modified object when attachment is list" do
1780 assert Transmogrifier.fix_attachments(%{
1782 %{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
1783 %{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
1788 "mediaType" => "video/mp4",
1791 "href" => "https://pe.er/stat-480.mp4",
1792 "mediaType" => "video/mp4",
1798 "href" => "https://pe.er/stat-480.mp4",
1799 "mediaType" => "video/mp4",
1800 "mimeType" => "video/mp4",
1803 "href" => "https://pe.er/stat-480.mp4",
1804 "mediaType" => "video/mp4",
1814 describe "fix_emoji/1" do
1815 test "returns not modified object when object not contains tags" do
1816 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1817 assert Transmogrifier.fix_emoji(data) == data
1820 test "returns object with emoji when object contains list tags" do
1821 assert Transmogrifier.fix_emoji(%{
1823 %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
1824 %{"type" => "Hashtag"}
1827 "emoji" => %{"bib" => "/test"},
1829 %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
1830 %{"type" => "Hashtag"}
1835 test "returns object with emoji when object contains map tag" do
1836 assert Transmogrifier.fix_emoji(%{
1837 "tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
1839 "emoji" => %{"bib" => "/test"},
1840 "tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}