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 misskey likes, turning them into EmojiReactions" do
346 {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
349 File.read!("test/fixtures/misskey-like.json")
351 |> Map.put("object", activity.data["object"])
353 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
355 assert data["actor"] == data["actor"]
356 assert data["type"] == "EmojiReaction"
357 assert data["id"] == data["id"]
358 assert data["object"] == activity.data["object"]
359 assert data["content"] == "🍮"
362 test "it works for incoming misskey likes that contain unicode emojis, turning them into EmojiReactions" do
364 {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
367 File.read!("test/fixtures/misskey-like.json")
369 |> Map.put("object", activity.data["object"])
370 |> Map.put("_misskey_reaction", "⭐")
372 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
374 assert data["actor"] == data["actor"]
375 assert data["type"] == "EmojiReaction"
376 assert data["id"] == data["id"]
377 assert data["object"] == activity.data["object"]
378 assert data["content"] == "⭐"
381 test "it works for incoming emoji reactions" do
383 {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
386 File.read!("test/fixtures/emoji-reaction.json")
388 |> Map.put("object", activity.data["object"])
390 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
392 assert data["actor"] == "http://mastodon.example.org/users/admin"
393 assert data["type"] == "EmojiReaction"
394 assert data["id"] == "http://mastodon.example.org/users/admin#reactions/2"
395 assert data["object"] == activity.data["object"]
396 assert data["content"] == "👌"
399 test "it works for incoming emoji reaction undos" do
402 {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
403 {:ok, reaction_activity, _object} = CommonAPI.react_with_emoji(activity.id, user, "👌")
406 File.read!("test/fixtures/mastodon-undo-like.json")
408 |> Map.put("object", reaction_activity.data["id"])
409 |> Map.put("actor", user.ap_id)
411 {:ok, activity} = Transmogrifier.handle_incoming(data)
413 assert activity.actor == user.ap_id
414 assert activity.data["id"] == data["id"]
415 assert activity.data["type"] == "Undo"
418 test "it returns an error for incoming unlikes wihout a like activity" do
420 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
423 File.read!("test/fixtures/mastodon-undo-like.json")
425 |> Map.put("object", activity.data["object"])
427 assert Transmogrifier.handle_incoming(data) == :error
430 test "it works for incoming unlikes with an existing like activity" do
432 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
435 File.read!("test/fixtures/mastodon-like.json")
437 |> Map.put("object", activity.data["object"])
439 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
442 File.read!("test/fixtures/mastodon-undo-like.json")
444 |> Map.put("object", like_data)
445 |> Map.put("actor", like_data["actor"])
447 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
449 assert data["actor"] == "http://mastodon.example.org/users/admin"
450 assert data["type"] == "Undo"
451 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
452 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
455 test "it works for incoming unlikes with an existing like activity and a compact object" do
457 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
460 File.read!("test/fixtures/mastodon-like.json")
462 |> Map.put("object", activity.data["object"])
464 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
467 File.read!("test/fixtures/mastodon-undo-like.json")
469 |> Map.put("object", like_data["id"])
470 |> Map.put("actor", like_data["actor"])
472 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
474 assert data["actor"] == "http://mastodon.example.org/users/admin"
475 assert data["type"] == "Undo"
476 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
477 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
480 test "it works for incoming announces" do
481 data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
483 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
485 assert data["actor"] == "http://mastodon.example.org/users/admin"
486 assert data["type"] == "Announce"
489 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
491 assert data["object"] ==
492 "http://mastodon.example.org/users/admin/statuses/99541947525187367"
494 assert Activity.get_create_by_object_ap_id(data["object"])
497 test "it works for incoming announces with an existing activity" do
499 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
502 File.read!("test/fixtures/mastodon-announce.json")
504 |> Map.put("object", activity.data["object"])
506 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
508 assert data["actor"] == "http://mastodon.example.org/users/admin"
509 assert data["type"] == "Announce"
512 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
514 assert data["object"] == activity.data["object"]
516 assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
519 test "it does not clobber the addressing on announce activities" do
521 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
524 File.read!("test/fixtures/mastodon-announce.json")
526 |> Map.put("object", Object.normalize(activity).data["id"])
527 |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
530 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
532 assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]
535 test "it ensures that as:Public activities make it to their followers collection" do
539 File.read!("test/fixtures/mastodon-post-activity.json")
541 |> Map.put("actor", user.ap_id)
542 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
547 |> Map.put("attributedTo", user.ap_id)
548 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
550 |> Map.put("id", user.ap_id <> "/activities/12345678")
552 data = Map.put(data, "object", object)
554 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
556 assert data["cc"] == [User.ap_followers(user)]
559 test "it ensures that address fields become lists" do
563 File.read!("test/fixtures/mastodon-post-activity.json")
565 |> Map.put("actor", user.ap_id)
566 |> Map.put("to", nil)
567 |> Map.put("cc", nil)
571 |> Map.put("attributedTo", user.ap_id)
572 |> Map.put("to", nil)
573 |> Map.put("cc", nil)
574 |> Map.put("id", user.ap_id <> "/activities/12345678")
576 data = Map.put(data, "object", object)
578 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
580 assert !is_nil(data["to"])
581 assert !is_nil(data["cc"])
584 test "it strips internal likes" do
586 File.read!("test/fixtures/mastodon-post-activity.json")
591 "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
592 "id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
594 "type" => "OrderedCollection"
597 object = Map.put(data["object"], "likes", likes)
598 data = Map.put(data, "object", object)
600 {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
602 refute Map.has_key?(object.data, "likes")
605 test "it strips internal reactions" do
607 {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
608 {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, user, "📢")
610 %{object: object} = Activity.get_by_id_with_object(activity.id)
611 assert Map.has_key?(object.data, "reactions")
612 assert Map.has_key?(object.data, "reaction_count")
614 object_data = Transmogrifier.strip_internal_fields(object.data)
615 refute Map.has_key?(object_data, "reactions")
616 refute Map.has_key?(object_data, "reaction_count")
619 test "it works for incoming update activities" do
620 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
622 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
623 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
626 update_data["object"]
627 |> Map.put("actor", data["actor"])
628 |> Map.put("id", data["actor"])
632 |> Map.put("actor", data["actor"])
633 |> Map.put("object", object)
635 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
637 user = User.get_cached_by_ap_id(data["actor"])
638 assert user.name == "gargle"
640 assert user.avatar["url"] == [
643 "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
647 assert user.info.banner["url"] == [
650 "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
654 assert user.bio == "<p>Some bio</p>"
657 test "it works with custom profile fields" do
659 "test/fixtures/mastodon-post-activity.json"
662 |> Transmogrifier.handle_incoming()
664 user = User.get_cached_by_ap_id(activity.actor)
666 assert User.Info.fields(user.info) == [
667 %{"name" => "foo", "value" => "bar"},
668 %{"name" => "foo1", "value" => "bar1"}
671 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
674 update_data["object"]
675 |> Map.put("actor", user.ap_id)
676 |> Map.put("id", user.ap_id)
680 |> Map.put("actor", user.ap_id)
681 |> Map.put("object", object)
683 {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
685 user = User.get_cached_by_ap_id(user.ap_id)
687 assert User.Info.fields(user.info) == [
688 %{"name" => "foo", "value" => "updated"},
689 %{"name" => "foo1", "value" => "updated"}
692 Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
695 put_in(update_data, ["object", "attachment"], [
696 %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
697 %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
698 %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
701 {:ok, _} = Transmogrifier.handle_incoming(update_data)
703 user = User.get_cached_by_ap_id(user.ap_id)
705 assert User.Info.fields(user.info) == [
706 %{"name" => "foo", "value" => "updated"},
707 %{"name" => "foo1", "value" => "updated"}
710 update_data = put_in(update_data, ["object", "attachment"], [])
712 {:ok, _} = Transmogrifier.handle_incoming(update_data)
714 user = User.get_cached_by_ap_id(user.ap_id)
716 assert User.Info.fields(user.info) == []
719 test "it works for incoming update activities which lock the account" do
720 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
722 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
723 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
726 update_data["object"]
727 |> Map.put("actor", data["actor"])
728 |> Map.put("id", data["actor"])
729 |> Map.put("manuallyApprovesFollowers", true)
733 |> Map.put("actor", data["actor"])
734 |> Map.put("object", object)
736 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
738 user = User.get_cached_by_ap_id(data["actor"])
739 assert user.info.locked == true
742 test "it works for incoming deletes" do
743 activity = insert(:note_activity)
746 File.read!("test/fixtures/mastodon-delete.json")
751 |> Map.put("id", activity.data["object"])
755 |> Map.put("object", object)
756 |> Map.put("actor", activity.data["actor"])
758 {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
760 refute Activity.get_by_id(activity.id)
763 test "it fails for incoming deletes with spoofed origin" do
764 activity = insert(:note_activity)
767 File.read!("test/fixtures/mastodon-delete.json")
772 |> Map.put("id", activity.data["object"])
776 |> Map.put("object", object)
778 assert capture_log(fn ->
779 :error = Transmogrifier.handle_incoming(data)
781 "[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}"
783 assert Activity.get_by_id(activity.id)
786 test "it works for incoming user deletes" do
787 %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
790 File.read!("test/fixtures/mastodon-delete-user.json")
793 {:ok, _} = Transmogrifier.handle_incoming(data)
794 ObanHelpers.perform_all()
796 refute User.get_cached_by_ap_id(ap_id)
799 test "it fails for incoming user deletes with spoofed origin" do
800 %{ap_id: ap_id} = insert(:user)
803 File.read!("test/fixtures/mastodon-delete-user.json")
805 |> Map.put("actor", ap_id)
807 assert :error == Transmogrifier.handle_incoming(data)
808 assert User.get_cached_by_ap_id(ap_id)
811 test "it works for incoming unannounces with an existing notice" do
813 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
816 File.read!("test/fixtures/mastodon-announce.json")
818 |> Map.put("object", activity.data["object"])
820 {:ok, %Activity{data: announce_data, local: false}} =
821 Transmogrifier.handle_incoming(announce_data)
824 File.read!("test/fixtures/mastodon-undo-announce.json")
826 |> Map.put("object", announce_data)
827 |> Map.put("actor", announce_data["actor"])
829 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
831 assert data["type"] == "Undo"
832 assert object_data = data["object"]
833 assert object_data["type"] == "Announce"
834 assert object_data["object"] == activity.data["object"]
836 assert object_data["id"] ==
837 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
840 test "it works for incomming unfollows with an existing follow" do
844 File.read!("test/fixtures/mastodon-follow-activity.json")
846 |> Map.put("object", user.ap_id)
848 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
851 File.read!("test/fixtures/mastodon-unfollow-activity.json")
853 |> Map.put("object", follow_data)
855 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
857 assert data["type"] == "Undo"
858 assert data["object"]["type"] == "Follow"
859 assert data["object"]["object"] == user.ap_id
860 assert data["actor"] == "http://mastodon.example.org/users/admin"
862 refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
865 test "it works for incoming blocks" do
869 File.read!("test/fixtures/mastodon-block-activity.json")
871 |> Map.put("object", user.ap_id)
873 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
875 assert data["type"] == "Block"
876 assert data["object"] == user.ap_id
877 assert data["actor"] == "http://mastodon.example.org/users/admin"
879 blocker = User.get_cached_by_ap_id(data["actor"])
881 assert User.blocks?(blocker, user)
884 test "incoming blocks successfully tear down any follow relationship" do
885 blocker = insert(:user)
886 blocked = insert(:user)
889 File.read!("test/fixtures/mastodon-block-activity.json")
891 |> Map.put("object", blocked.ap_id)
892 |> Map.put("actor", blocker.ap_id)
894 {:ok, blocker} = User.follow(blocker, blocked)
895 {:ok, blocked} = User.follow(blocked, blocker)
897 assert User.following?(blocker, blocked)
898 assert User.following?(blocked, blocker)
900 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
902 assert data["type"] == "Block"
903 assert data["object"] == blocked.ap_id
904 assert data["actor"] == blocker.ap_id
906 blocker = User.get_cached_by_ap_id(data["actor"])
907 blocked = User.get_cached_by_ap_id(data["object"])
909 assert User.blocks?(blocker, blocked)
911 refute User.following?(blocker, blocked)
912 refute User.following?(blocked, blocker)
915 test "it works for incoming unblocks with an existing block" do
919 File.read!("test/fixtures/mastodon-block-activity.json")
921 |> Map.put("object", user.ap_id)
923 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
926 File.read!("test/fixtures/mastodon-unblock-activity.json")
928 |> Map.put("object", block_data)
930 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
931 assert data["type"] == "Undo"
932 assert data["object"]["type"] == "Block"
933 assert data["object"]["object"] == user.ap_id
934 assert data["actor"] == "http://mastodon.example.org/users/admin"
936 blocker = User.get_cached_by_ap_id(data["actor"])
938 refute User.blocks?(blocker, user)
941 test "it works for incoming accepts which were pre-accepted" do
942 follower = insert(:user)
943 followed = insert(:user)
945 {:ok, follower} = User.follow(follower, followed)
946 assert User.following?(follower, followed) == true
948 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
951 File.read!("test/fixtures/mastodon-accept-activity.json")
953 |> Map.put("actor", followed.ap_id)
956 accept_data["object"]
957 |> Map.put("actor", follower.ap_id)
958 |> Map.put("id", follow_activity.data["id"])
960 accept_data = Map.put(accept_data, "object", object)
962 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
963 refute activity.local
965 assert activity.data["object"] == follow_activity.data["id"]
967 follower = User.get_cached_by_id(follower.id)
969 assert User.following?(follower, followed) == true
972 test "it works for incoming accepts which were orphaned" do
973 follower = insert(:user)
974 followed = insert(:user, %{info: %User.Info{locked: true}})
976 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
979 File.read!("test/fixtures/mastodon-accept-activity.json")
981 |> Map.put("actor", followed.ap_id)
984 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
986 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
987 assert activity.data["object"] == follow_activity.data["id"]
989 follower = User.get_cached_by_id(follower.id)
991 assert User.following?(follower, followed) == true
994 test "it works for incoming accepts which are referenced by IRI only" do
995 follower = insert(:user)
996 followed = insert(:user, %{info: %User.Info{locked: true}})
998 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
1001 File.read!("test/fixtures/mastodon-accept-activity.json")
1003 |> Map.put("actor", followed.ap_id)
1004 |> Map.put("object", follow_activity.data["id"])
1006 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
1007 assert activity.data["object"] == follow_activity.data["id"]
1009 follower = User.get_cached_by_id(follower.id)
1011 assert User.following?(follower, followed) == true
1014 test "it fails for incoming accepts which cannot be correlated" do
1015 follower = insert(:user)
1016 followed = insert(:user, %{info: %User.Info{locked: true}})
1019 File.read!("test/fixtures/mastodon-accept-activity.json")
1021 |> Map.put("actor", followed.ap_id)
1024 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
1026 :error = Transmogrifier.handle_incoming(accept_data)
1028 follower = User.get_cached_by_id(follower.id)
1030 refute User.following?(follower, followed) == true
1033 test "it fails for incoming rejects which cannot be correlated" do
1034 follower = insert(:user)
1035 followed = insert(:user, %{info: %User.Info{locked: true}})
1038 File.read!("test/fixtures/mastodon-reject-activity.json")
1040 |> Map.put("actor", followed.ap_id)
1043 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
1045 :error = Transmogrifier.handle_incoming(accept_data)
1047 follower = User.get_cached_by_id(follower.id)
1049 refute User.following?(follower, followed) == true
1052 test "it works for incoming rejects which are orphaned" do
1053 follower = insert(:user)
1054 followed = insert(:user, %{info: %User.Info{locked: true}})
1056 {:ok, follower} = User.follow(follower, followed)
1057 {:ok, _follow_activity} = ActivityPub.follow(follower, followed)
1059 assert User.following?(follower, followed) == true
1062 File.read!("test/fixtures/mastodon-reject-activity.json")
1064 |> Map.put("actor", followed.ap_id)
1067 Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
1069 {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
1070 refute activity.local
1072 follower = User.get_cached_by_id(follower.id)
1074 assert User.following?(follower, followed) == false
1077 test "it works for incoming rejects which are referenced by IRI only" do
1078 follower = insert(:user)
1079 followed = insert(:user, %{info: %User.Info{locked: true}})
1081 {:ok, follower} = User.follow(follower, followed)
1082 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
1084 assert User.following?(follower, followed) == true
1087 File.read!("test/fixtures/mastodon-reject-activity.json")
1089 |> Map.put("actor", followed.ap_id)
1090 |> Map.put("object", follow_activity.data["id"])
1092 {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
1094 follower = User.get_cached_by_id(follower.id)
1096 assert User.following?(follower, followed) == false
1099 test "it rejects activities without a valid ID" do
1100 user = insert(:user)
1103 File.read!("test/fixtures/mastodon-follow-activity.json")
1105 |> Map.put("object", user.ap_id)
1106 |> Map.put("id", "")
1108 :error = Transmogrifier.handle_incoming(data)
1111 test "it remaps video URLs as attachments if necessary" do
1113 Fetcher.fetch_object_from_id(
1114 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1119 "mediaType" => "video/mp4",
1121 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1122 "mimeType" => "video/mp4",
1123 "size" => 5_015_880,
1127 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1128 "mediaType" => "video/mp4",
1135 assert object.data["url"] ==
1136 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1138 assert object.data["attachment"] == [attachment]
1141 test "it accepts Flag activities" do
1142 user = insert(:user)
1143 other_user = insert(:user)
1145 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
1146 object = Object.normalize(activity)
1149 "@context" => "https://www.w3.org/ns/activitystreams",
1150 "cc" => [user.ap_id],
1151 "object" => [user.ap_id, object.data["id"]],
1153 "content" => "blocked AND reported!!!",
1154 "actor" => other_user.ap_id
1157 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
1159 assert activity.data["object"] == [user.ap_id, object.data["id"]]
1160 assert activity.data["content"] == "blocked AND reported!!!"
1161 assert activity.data["actor"] == other_user.ap_id
1162 assert activity.data["cc"] == [user.ap_id]
1166 describe "prepare outgoing" do
1167 test "it inlines private announced objects" do
1168 user = insert(:user)
1170 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey", "visibility" => "private"})
1172 {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
1174 {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
1176 assert modified["object"]["content"] == "hey"
1177 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1180 test "it turns mentions into tags" do
1181 user = insert(:user)
1182 other_user = insert(:user)
1185 CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
1187 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1188 object = modified["object"]
1190 expected_mention = %{
1191 "href" => other_user.ap_id,
1192 "name" => "@#{other_user.nickname}",
1197 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1198 "type" => "Hashtag",
1202 assert Enum.member?(object["tag"], expected_tag)
1203 assert Enum.member?(object["tag"], expected_mention)
1206 test "it adds the sensitive property" do
1207 user = insert(:user)
1209 {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
1210 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1212 assert modified["object"]["sensitive"]
1215 test "it adds the json-ld context and the conversation property" do
1216 user = insert(:user)
1218 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1219 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1221 assert modified["@context"] ==
1222 Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
1224 assert modified["object"]["conversation"] == modified["context"]
1227 test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
1228 user = insert(:user)
1230 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1231 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1233 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1236 test "it translates ostatus IDs to external URLs" do
1237 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1238 {:ok, [referent_activity]} = OStatus.handle_incoming(incoming)
1240 user = insert(:user)
1242 {:ok, activity, _} = CommonAPI.favorite(referent_activity.id, user)
1243 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1245 assert modified["object"] == "http://gs.example.org:4040/index.php/notice/29"
1248 test "it translates ostatus reply_to IDs to external URLs" do
1249 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
1250 {:ok, [referred_activity]} = OStatus.handle_incoming(incoming)
1252 user = insert(:user)
1255 CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id})
1257 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1259 assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29"
1262 test "it strips internal hashtag data" do
1263 user = insert(:user)
1265 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu"})
1268 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1269 "type" => "Hashtag",
1273 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1275 assert modified["object"]["tag"] == [expected_tag]
1278 test "it strips internal fields" do
1279 user = insert(:user)
1281 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :firefox:"})
1283 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1285 assert length(modified["object"]["tag"]) == 2
1287 assert is_nil(modified["object"]["emoji"])
1288 assert is_nil(modified["object"]["like_count"])
1289 assert is_nil(modified["object"]["announcements"])
1290 assert is_nil(modified["object"]["announcement_count"])
1291 assert is_nil(modified["object"]["context_id"])
1294 test "it strips internal fields of article" do
1295 activity = insert(:article_activity)
1297 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1299 assert length(modified["object"]["tag"]) == 2
1301 assert is_nil(modified["object"]["emoji"])
1302 assert is_nil(modified["object"]["like_count"])
1303 assert is_nil(modified["object"]["announcements"])
1304 assert is_nil(modified["object"]["announcement_count"])
1305 assert is_nil(modified["object"]["context_id"])
1306 assert is_nil(modified["object"]["likes"])
1309 test "the directMessage flag is present" do
1310 user = insert(:user)
1311 other_user = insert(:user)
1313 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"})
1315 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1317 assert modified["directMessage"] == false
1320 CommonAPI.post(user, %{"status" => "@#{other_user.nickname} :moominmamma:"})
1322 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1324 assert modified["directMessage"] == false
1327 CommonAPI.post(user, %{
1328 "status" => "@#{other_user.nickname} :moominmamma:",
1329 "visibility" => "direct"
1332 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1334 assert modified["directMessage"] == true
1337 test "it strips BCC field" do
1338 user = insert(:user)
1339 {:ok, list} = Pleroma.List.create("foo", user)
1342 CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
1344 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1346 assert is_nil(modified["bcc"])
1349 test "it can handle Listen activities" do
1350 listen_activity = insert(:listen)
1352 {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
1354 assert modified["type"] == "Listen"
1356 user = insert(:user)
1358 {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
1360 {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
1364 describe "user upgrade" do
1365 test "it upgrades a user to activitypub" do
1368 nickname: "rye@niu.moe",
1370 ap_id: "https://niu.moe/users/rye",
1371 follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
1374 user_two = insert(:user, %{following: [user.follower_address]})
1376 {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
1377 {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
1378 assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
1380 user = User.get_cached_by_id(user.id)
1381 assert user.info.note_count == 1
1383 {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
1384 ObanHelpers.perform_all()
1386 assert user.info.ap_enabled
1387 assert user.info.note_count == 1
1388 assert user.follower_address == "https://niu.moe/users/rye/followers"
1389 assert user.following_address == "https://niu.moe/users/rye/following"
1391 user = User.get_cached_by_id(user.id)
1392 assert user.info.note_count == 1
1394 activity = Activity.get_by_id(activity.id)
1395 assert user.follower_address in activity.recipients
1401 "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
1410 "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
1413 } = user.info.banner
1415 refute "..." in activity.recipients
1417 unrelated_activity = Activity.get_by_id(unrelated_activity.id)
1418 refute user.follower_address in unrelated_activity.recipients
1420 user_two = User.get_cached_by_id(user_two.id)
1421 assert user.follower_address in user_two.following
1422 refute "..." in user_two.following
1426 describe "maybe_retire_websub" do
1427 test "it deletes all websub client subscripitions with the user as topic" do
1428 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/rye.atom"}
1429 {:ok, ws} = Repo.insert(subscription)
1431 subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/pasty.atom"}
1432 {:ok, ws2} = Repo.insert(subscription)
1434 Transmogrifier.maybe_retire_websub("https://niu.moe/users/rye")
1436 refute Repo.get(WebsubClientSubscription, ws.id)
1437 assert Repo.get(WebsubClientSubscription, ws2.id)
1441 describe "actor rewriting" do
1442 test "it fixes the actor URL property to be a proper URI" do
1444 "url" => %{"href" => "http://example.com"}
1447 rewritten = Transmogrifier.maybe_fix_user_object(data)
1448 assert rewritten["url"] == "http://example.com"
1452 describe "actor origin containment" do
1453 test "it rejects activities which reference objects with bogus origins" do
1455 "@context" => "https://www.w3.org/ns/activitystreams",
1456 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1457 "actor" => "http://mastodon.example.org/users/admin",
1458 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1459 "object" => "https://info.pleroma.site/activity.json",
1460 "type" => "Announce"
1463 :error = Transmogrifier.handle_incoming(data)
1466 test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
1468 "@context" => "https://www.w3.org/ns/activitystreams",
1469 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1470 "actor" => "http://mastodon.example.org/users/admin",
1471 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1472 "object" => "https://info.pleroma.site/activity2.json",
1473 "type" => "Announce"
1476 :error = Transmogrifier.handle_incoming(data)
1479 test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
1481 "@context" => "https://www.w3.org/ns/activitystreams",
1482 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1483 "actor" => "http://mastodon.example.org/users/admin",
1484 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1485 "object" => "https://info.pleroma.site/activity3.json",
1486 "type" => "Announce"
1489 :error = Transmogrifier.handle_incoming(data)
1493 describe "reserialization" do
1494 test "successfully reserializes a message with inReplyTo == nil" do
1495 user = insert(:user)
1498 "@context" => "https://www.w3.org/ns/activitystreams",
1499 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1503 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1508 "attributedTo" => user.ap_id
1510 "actor" => user.ap_id
1513 {:ok, activity} = Transmogrifier.handle_incoming(message)
1515 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1518 test "successfully reserializes a message with AS2 objects in IR" do
1519 user = insert(:user)
1522 "@context" => "https://www.w3.org/ns/activitystreams",
1523 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1527 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1532 "attributedTo" => user.ap_id,
1534 %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
1535 %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
1538 "actor" => user.ap_id
1541 {:ok, activity} = Transmogrifier.handle_incoming(message)
1543 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1547 test "Rewrites Answers to Notes" do
1548 user = insert(:user)
1550 {:ok, poll_activity} =
1551 CommonAPI.post(user, %{
1552 "status" => "suya...",
1553 "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
1556 poll_object = Object.normalize(poll_activity)
1557 # TODO: Replace with CommonAPI vote creation when implemented
1559 File.read!("test/fixtures/mastodon-vote.json")
1561 |> Kernel.put_in(["to"], user.ap_id)
1562 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
1563 |> Kernel.put_in(["object", "to"], user.ap_id)
1565 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
1566 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
1568 assert data["object"]["type"] == "Note"
1571 describe "fix_explicit_addressing" do
1573 user = insert(:user)
1577 test "moves non-explicitly mentioned actors to cc", %{user: user} do
1578 explicitly_mentioned_actors = [
1579 "https://pleroma.gold/users/user1",
1580 "https://pleroma.gold/user2"
1584 "actor" => user.ap_id,
1585 "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"],
1588 Enum.map(explicitly_mentioned_actors, fn href ->
1589 %{"type" => "Mention", "href" => href}
1593 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1594 assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
1595 refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
1596 assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
1599 test "does not move actor's follower collection to cc", %{user: user} do
1601 "actor" => user.ap_id,
1602 "to" => [user.follower_address],
1606 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1607 assert user.follower_address in fixed_object["to"]
1608 refute user.follower_address in fixed_object["cc"]
1611 test "removes recipient's follower collection from cc", %{user: user} do
1612 recipient = insert(:user)
1615 "actor" => user.ap_id,
1616 "to" => [recipient.ap_id, "https://www.w3.org/ns/activitystreams#Public"],
1617 "cc" => [user.follower_address, recipient.follower_address]
1620 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1622 assert user.follower_address in fixed_object["cc"]
1623 refute recipient.follower_address in fixed_object["cc"]
1624 refute recipient.follower_address in fixed_object["to"]
1628 describe "fix_summary/1" do
1629 test "returns fixed object" do
1630 assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
1631 assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
1632 assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
1636 describe "fix_in_reply_to/2" do
1637 clear_config([:instance, :federation_incoming_replies_max_depth])
1640 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1644 test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
1645 assert Transmogrifier.fix_in_reply_to(data) == data
1648 test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
1649 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
1652 Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
1654 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1655 assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
1656 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1659 Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
1661 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1662 assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
1663 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1666 Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
1668 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1669 assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
1670 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1672 object_with_reply = Map.put(data["object"], "inReplyTo", [])
1673 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1674 assert modified_object["inReplyTo"] == []
1675 assert modified_object["inReplyToAtomUri"] == ""
1678 test "returns modified object when allowed incoming reply", %{data: data} do
1683 "https://shitposter.club/notice/2827873"
1686 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
1687 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1689 assert modified_object["inReplyTo"] ==
1690 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
1692 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1694 assert modified_object["conversation"] ==
1695 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1697 assert modified_object["context"] ==
1698 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1702 describe "fix_url/1" do
1703 test "fixes data for object when url is map" do
1707 "mimeType" => "video/mp4",
1708 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1712 assert Transmogrifier.fix_url(object) == %{
1713 "url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1717 test "fixes data for video object" do
1723 "mimeType" => "video/mp4",
1724 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1728 "mimeType" => "video/mp4",
1729 "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
1733 "mimeType" => "text/html",
1734 "href" => "https://peertube.-2d4c2d1630e3"
1738 "mimeType" => "text/html",
1739 "href" => "https://peertube.-2d4c2d16377-42"
1744 assert Transmogrifier.fix_url(object) == %{
1747 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1748 "mimeType" => "video/mp4",
1753 "url" => "https://peertube.-2d4c2d1630e3"
1757 test "fixes url for not Video object" do
1763 "mimeType" => "text/html",
1764 "href" => "https://peertube.-2d4c2d1630e3"
1768 "mimeType" => "text/html",
1769 "href" => "https://peertube.-2d4c2d16377-42"
1774 assert Transmogrifier.fix_url(object) == %{
1776 "url" => "https://peertube.-2d4c2d1630e3"
1779 assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
1785 test "retunrs not modified object" do
1786 assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
1790 describe "get_obj_helper/2" do
1791 test "returns nil when cannot normalize object" do
1792 refute Transmogrifier.get_obj_helper("test-obj-id")
1795 test "returns {:ok, %Object{}} for success case" do
1796 assert {:ok, %Object{}} =
1797 Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
1801 describe "fix_attachments/1" do
1802 test "returns not modified object" do
1803 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1804 assert Transmogrifier.fix_attachments(data) == data
1807 test "returns modified object when attachment is map" do
1808 assert Transmogrifier.fix_attachments(%{
1810 "mediaType" => "video/mp4",
1811 "url" => "https://peertube.moe/stat-480.mp4"
1816 "mediaType" => "video/mp4",
1819 "href" => "https://peertube.moe/stat-480.mp4",
1820 "mediaType" => "video/mp4",
1829 test "returns modified object when attachment is list" do
1830 assert Transmogrifier.fix_attachments(%{
1832 %{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
1833 %{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
1838 "mediaType" => "video/mp4",
1841 "href" => "https://pe.er/stat-480.mp4",
1842 "mediaType" => "video/mp4",
1848 "href" => "https://pe.er/stat-480.mp4",
1849 "mediaType" => "video/mp4",
1850 "mimeType" => "video/mp4",
1853 "href" => "https://pe.er/stat-480.mp4",
1854 "mediaType" => "video/mp4",
1864 describe "fix_emoji/1" do
1865 test "returns not modified object when object not contains tags" do
1866 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1867 assert Transmogrifier.fix_emoji(data) == data
1870 test "returns object with emoji when object contains list tags" do
1871 assert Transmogrifier.fix_emoji(%{
1873 %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
1874 %{"type" => "Hashtag"}
1877 "emoji" => %{"bib" => "/test"},
1879 %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
1880 %{"type" => "Hashtag"}
1885 test "returns object with emoji when object contains map tag" do
1886 assert Transmogrifier.fix_emoji(%{
1887 "tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
1889 "emoji" => %{"bib" => "/test"},
1890 "tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}