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
10 alias Pleroma.Tests.ObanHelpers
12 alias Pleroma.Web.ActivityPub.ActivityPub
13 alias Pleroma.Web.ActivityPub.Transmogrifier
14 alias Pleroma.Web.CommonAPI
17 import Pleroma.Factory
18 import ExUnit.CaptureLog
21 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
25 clear_config([:instance, :max_remote_account_fields])
27 describe "handle_incoming" do
28 test "it ignores an incoming notice if we already have it" do
29 activity = insert(:note_activity)
32 File.read!("test/fixtures/mastodon-post-activity.json")
34 |> Map.put("object", Object.normalize(activity).data)
36 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
38 assert activity == returned_activity
41 test "it fetches replied-to activities if we don't have them" do
43 File.read!("test/fixtures/mastodon-post-activity.json")
48 |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
50 data = Map.put(data, "object", object)
51 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
52 returned_object = Object.normalize(returned_activity, false)
55 Activity.get_create_by_object_ap_id(
56 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
59 assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
62 test "it does not fetch replied-to activities beyond max_replies_depth" do
64 File.read!("test/fixtures/mastodon-post-activity.json")
69 |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
71 data = Map.put(data, "object", object)
73 with_mock Pleroma.Web.Federator,
74 allowed_incoming_reply_depth?: fn _ -> false end do
75 {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
77 returned_object = Object.normalize(returned_activity, false)
79 refute Activity.get_create_by_object_ap_id(
80 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
83 assert returned_object.data["inReplyToAtomUri"] ==
84 "https://shitposter.club/notice/2827873"
88 test "it does not crash if the object in inReplyTo can't be fetched" do
90 File.read!("test/fixtures/mastodon-post-activity.json")
95 |> Map.put("inReplyTo", "https://404.site/whatever")
99 |> Map.put("object", object)
101 assert capture_log(fn ->
102 {:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
103 end) =~ "[error] Couldn't fetch \"https://404.site/whatever\", error: nil"
106 test "it works for incoming notices" do
107 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
109 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
112 "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity"
114 assert data["context"] ==
115 "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
117 assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
119 assert data["cc"] == [
120 "http://mastodon.example.org/users/admin/followers",
121 "http://localtesting.pleroma.lol/users/lain"
124 assert data["actor"] == "http://mastodon.example.org/users/admin"
126 object_data = Object.normalize(data["object"]).data
128 assert object_data["id"] ==
129 "http://mastodon.example.org/users/admin/statuses/99512778738411822"
131 assert object_data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
133 assert object_data["cc"] == [
134 "http://mastodon.example.org/users/admin/followers",
135 "http://localtesting.pleroma.lol/users/lain"
138 assert object_data["actor"] == "http://mastodon.example.org/users/admin"
139 assert object_data["attributedTo"] == "http://mastodon.example.org/users/admin"
141 assert object_data["context"] ==
142 "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
144 assert object_data["sensitive"] == true
146 user = User.get_cached_by_ap_id(object_data["actor"])
148 assert user.info.note_count == 1
151 test "it works for incoming notices with hashtags" do
152 data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
154 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
155 object = Object.normalize(data["object"])
157 assert Enum.at(object.data["tag"], 2) == "moo"
160 test "it works for incoming questions" do
161 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
163 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
165 object = Object.normalize(activity)
167 assert Enum.all?(object.data["oneOf"], fn choice ->
170 "Everyone knows that!",
171 "25 char limit is dumb",
172 "I can't even fit a funny"
177 test "it works for incoming listens" do
179 "@context" => "https://www.w3.org/ns/activitystreams",
180 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
183 "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
184 "actor" => "http://mastodon.example.org/users/admin",
187 "id" => "http://mastodon.example.org/users/admin/listens/1234",
188 "attributedTo" => "http://mastodon.example.org/users/admin",
189 "title" => "lain radio episode 1",
191 "album" => "lain radio",
196 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
198 object = Object.normalize(activity)
200 assert object.data["title"] == "lain radio episode 1"
201 assert object.data["artist"] == "lain"
202 assert object.data["album"] == "lain radio"
203 assert object.data["length"] == 180_000
206 test "it rewrites Note votes to Answers and increments vote counters on question activities" do
210 CommonAPI.post(user, %{
211 "status" => "suya...",
212 "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
215 object = Object.normalize(activity)
218 File.read!("test/fixtures/mastodon-vote.json")
220 |> Kernel.put_in(["to"], user.ap_id)
221 |> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
222 |> Kernel.put_in(["object", "to"], user.ap_id)
224 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
225 answer_object = Object.normalize(activity)
226 assert answer_object.data["type"] == "Answer"
227 object = Object.get_by_ap_id(object.data["id"])
230 object.data["oneOf"],
232 %{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
238 test "it works for incoming notices with contentMap" do
240 File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
242 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
243 object = Object.normalize(data["object"])
245 assert object.data["content"] ==
246 "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
249 test "it works for incoming notices with to/cc not being an array (kroeg)" do
250 data = File.read!("test/fixtures/kroeg-post-activity.json") |> Poison.decode!()
252 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
253 object = Object.normalize(data["object"])
255 assert object.data["content"] ==
256 "<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>"
259 test "it works for incoming announces with actor being inlined (kroeg)" do
260 data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Poison.decode!()
262 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
264 assert data["actor"] == "https://puckipedia.com/"
267 test "it works for incoming notices with tag not being an array (kroeg)" do
268 data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Poison.decode!()
270 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
271 object = Object.normalize(data["object"])
273 assert object.data["emoji"] == %{
274 "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png"
277 data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Poison.decode!()
279 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
280 object = Object.normalize(data["object"])
282 assert "test" in object.data["tag"]
285 test "it works for incoming notices with url not being a string (prismo)" do
286 data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!()
288 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
289 object = Object.normalize(data["object"])
291 assert object.data["url"] == "https://prismo.news/posts/83"
294 test "it cleans up incoming notices which are not really DMs" do
296 other_user = insert(:user)
298 to = [user.ap_id, other_user.ap_id]
301 File.read!("test/fixtures/mastodon-post-activity.json")
311 data = Map.put(data, "object", object)
313 {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
315 assert data["to"] == []
316 assert data["cc"] == to
318 object_data = Object.normalize(activity).data
320 assert object_data["to"] == []
321 assert object_data["cc"] == to
324 test "it works for incoming likes" do
326 {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
329 File.read!("test/fixtures/mastodon-like.json")
331 |> Map.put("object", activity.data["object"])
333 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
335 assert data["actor"] == "http://mastodon.example.org/users/admin"
336 assert data["type"] == "Like"
337 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
338 assert data["object"] == activity.data["object"]
341 test "it returns an error for incoming unlikes wihout a like activity" do
343 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
346 File.read!("test/fixtures/mastodon-undo-like.json")
348 |> Map.put("object", activity.data["object"])
350 assert Transmogrifier.handle_incoming(data) == :error
353 test "it works for incoming unlikes with an existing like activity" do
355 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
358 File.read!("test/fixtures/mastodon-like.json")
360 |> Map.put("object", activity.data["object"])
362 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
365 File.read!("test/fixtures/mastodon-undo-like.json")
367 |> Map.put("object", like_data)
368 |> Map.put("actor", like_data["actor"])
370 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
372 assert data["actor"] == "http://mastodon.example.org/users/admin"
373 assert data["type"] == "Undo"
374 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
375 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
378 test "it works for incoming unlikes with an existing like activity and a compact object" do
380 {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
383 File.read!("test/fixtures/mastodon-like.json")
385 |> Map.put("object", activity.data["object"])
387 {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
390 File.read!("test/fixtures/mastodon-undo-like.json")
392 |> Map.put("object", like_data["id"])
393 |> Map.put("actor", like_data["actor"])
395 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
397 assert data["actor"] == "http://mastodon.example.org/users/admin"
398 assert data["type"] == "Undo"
399 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
400 assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
403 test "it works for incoming announces" do
404 data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
406 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
408 assert data["actor"] == "http://mastodon.example.org/users/admin"
409 assert data["type"] == "Announce"
412 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
414 assert data["object"] ==
415 "http://mastodon.example.org/users/admin/statuses/99541947525187367"
417 assert Activity.get_create_by_object_ap_id(data["object"])
420 test "it works for incoming announces with an existing activity" do
422 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
425 File.read!("test/fixtures/mastodon-announce.json")
427 |> Map.put("object", activity.data["object"])
429 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
431 assert data["actor"] == "http://mastodon.example.org/users/admin"
432 assert data["type"] == "Announce"
435 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
437 assert data["object"] == activity.data["object"]
439 assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
442 test "it works for incoming announces with an inlined activity" do
444 File.read!("test/fixtures/mastodon-announce-private.json")
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"] == "Announce"
453 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
455 object = Object.normalize(data["object"])
457 assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
458 assert object.data["content"] == "this is a private toot"
461 test "it rejects incoming announces with an inlined activity from another origin" do
463 File.read!("test/fixtures/bogus-mastodon-announce.json")
466 assert :error = Transmogrifier.handle_incoming(data)
469 test "it does not clobber the addressing on announce activities" do
471 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
474 File.read!("test/fixtures/mastodon-announce.json")
476 |> Map.put("object", Object.normalize(activity).data["id"])
477 |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
480 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
482 assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]
485 test "it ensures that as:Public activities make it to their followers collection" do
489 File.read!("test/fixtures/mastodon-post-activity.json")
491 |> Map.put("actor", user.ap_id)
492 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
497 |> Map.put("attributedTo", user.ap_id)
498 |> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
500 |> Map.put("id", user.ap_id <> "/activities/12345678")
502 data = Map.put(data, "object", object)
504 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
506 assert data["cc"] == [User.ap_followers(user)]
509 test "it ensures that address fields become lists" do
513 File.read!("test/fixtures/mastodon-post-activity.json")
515 |> Map.put("actor", user.ap_id)
516 |> Map.put("to", nil)
517 |> Map.put("cc", nil)
521 |> Map.put("attributedTo", user.ap_id)
522 |> Map.put("to", nil)
523 |> Map.put("cc", nil)
524 |> Map.put("id", user.ap_id <> "/activities/12345678")
526 data = Map.put(data, "object", object)
528 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
530 assert !is_nil(data["to"])
531 assert !is_nil(data["cc"])
534 test "it strips internal likes" do
536 File.read!("test/fixtures/mastodon-post-activity.json")
541 "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
542 "id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
544 "type" => "OrderedCollection"
547 object = Map.put(data["object"], "likes", likes)
548 data = Map.put(data, "object", object)
550 {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
552 refute Map.has_key?(object.data, "likes")
555 test "it works for incoming update activities" do
556 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
558 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
559 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
562 update_data["object"]
563 |> Map.put("actor", data["actor"])
564 |> Map.put("id", data["actor"])
568 |> Map.put("actor", data["actor"])
569 |> Map.put("object", object)
571 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
573 assert data["id"] == update_data["id"]
575 user = User.get_cached_by_ap_id(data["actor"])
576 assert user.name == "gargle"
578 assert user.avatar["url"] == [
581 "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
585 assert user.info.banner["url"] == [
588 "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
592 assert user.bio == "<p>Some bio</p>"
595 test "it works with custom profile fields" do
597 "test/fixtures/mastodon-post-activity.json"
600 |> Transmogrifier.handle_incoming()
602 user = User.get_cached_by_ap_id(activity.actor)
604 assert User.Info.fields(user.info) == [
605 %{"name" => "foo", "value" => "bar"},
606 %{"name" => "foo1", "value" => "bar1"}
609 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
612 update_data["object"]
613 |> Map.put("actor", user.ap_id)
614 |> Map.put("id", user.ap_id)
618 |> Map.put("actor", user.ap_id)
619 |> Map.put("object", object)
621 {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
623 user = User.get_cached_by_ap_id(user.ap_id)
625 assert User.Info.fields(user.info) == [
626 %{"name" => "foo", "value" => "updated"},
627 %{"name" => "foo1", "value" => "updated"}
630 Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
633 put_in(update_data, ["object", "attachment"], [
634 %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
635 %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
636 %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
639 {:ok, _} = Transmogrifier.handle_incoming(update_data)
641 user = User.get_cached_by_ap_id(user.ap_id)
643 assert User.Info.fields(user.info) == [
644 %{"name" => "foo", "value" => "updated"},
645 %{"name" => "foo1", "value" => "updated"}
648 update_data = put_in(update_data, ["object", "attachment"], [])
650 {:ok, _} = Transmogrifier.handle_incoming(update_data)
652 user = User.get_cached_by_ap_id(user.ap_id)
654 assert User.Info.fields(user.info) == []
657 test "it works for incoming update activities which lock the account" do
658 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
660 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
661 update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
664 update_data["object"]
665 |> Map.put("actor", data["actor"])
666 |> Map.put("id", data["actor"])
667 |> Map.put("manuallyApprovesFollowers", true)
671 |> Map.put("actor", data["actor"])
672 |> Map.put("object", object)
674 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
676 user = User.get_cached_by_ap_id(data["actor"])
677 assert user.info.locked == true
680 test "it works for incoming deletes" do
681 activity = insert(:note_activity)
682 deleting_user = insert(:user)
685 File.read!("test/fixtures/mastodon-delete.json")
690 |> Map.put("id", activity.data["object"])
694 |> Map.put("object", object)
695 |> Map.put("actor", deleting_user.ap_id)
697 {:ok, %Activity{actor: actor, local: false, data: %{"id" => id}}} =
698 Transmogrifier.handle_incoming(data)
700 assert id == data["id"]
701 refute Activity.get_by_id(activity.id)
702 assert actor == deleting_user.ap_id
705 test "it fails for incoming deletes with spoofed origin" do
706 activity = insert(:note_activity)
709 File.read!("test/fixtures/mastodon-delete.json")
714 |> Map.put("id", activity.data["object"])
718 |> Map.put("object", object)
720 assert capture_log(fn ->
721 :error = Transmogrifier.handle_incoming(data)
723 "[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}"
725 assert Activity.get_by_id(activity.id)
728 test "it works for incoming user deletes" do
729 %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
732 File.read!("test/fixtures/mastodon-delete-user.json")
735 {:ok, _} = Transmogrifier.handle_incoming(data)
736 ObanHelpers.perform_all()
738 refute User.get_cached_by_ap_id(ap_id)
741 test "it fails for incoming user deletes with spoofed origin" do
742 %{ap_id: ap_id} = insert(:user)
745 File.read!("test/fixtures/mastodon-delete-user.json")
747 |> Map.put("actor", ap_id)
749 assert :error == Transmogrifier.handle_incoming(data)
750 assert User.get_cached_by_ap_id(ap_id)
753 test "it works for incoming unannounces with an existing notice" do
755 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
758 File.read!("test/fixtures/mastodon-announce.json")
760 |> Map.put("object", activity.data["object"])
762 {:ok, %Activity{data: announce_data, local: false}} =
763 Transmogrifier.handle_incoming(announce_data)
766 File.read!("test/fixtures/mastodon-undo-announce.json")
768 |> Map.put("object", announce_data)
769 |> Map.put("actor", announce_data["actor"])
771 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
773 assert data["type"] == "Undo"
774 assert object_data = data["object"]
775 assert object_data["type"] == "Announce"
776 assert object_data["object"] == activity.data["object"]
778 assert object_data["id"] ==
779 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
782 test "it works for incomming unfollows with an existing follow" do
786 File.read!("test/fixtures/mastodon-follow-activity.json")
788 |> Map.put("object", user.ap_id)
790 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data)
793 File.read!("test/fixtures/mastodon-unfollow-activity.json")
795 |> Map.put("object", follow_data)
797 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
799 assert data["type"] == "Undo"
800 assert data["object"]["type"] == "Follow"
801 assert data["object"]["object"] == user.ap_id
802 assert data["actor"] == "http://mastodon.example.org/users/admin"
804 refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
807 test "it works for incoming blocks" do
811 File.read!("test/fixtures/mastodon-block-activity.json")
813 |> Map.put("object", user.ap_id)
815 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
817 assert data["type"] == "Block"
818 assert data["object"] == user.ap_id
819 assert data["actor"] == "http://mastodon.example.org/users/admin"
821 blocker = User.get_cached_by_ap_id(data["actor"])
823 assert User.blocks?(blocker, user)
826 test "incoming blocks successfully tear down any follow relationship" do
827 blocker = insert(:user)
828 blocked = insert(:user)
831 File.read!("test/fixtures/mastodon-block-activity.json")
833 |> Map.put("object", blocked.ap_id)
834 |> Map.put("actor", blocker.ap_id)
836 {:ok, blocker} = User.follow(blocker, blocked)
837 {:ok, blocked} = User.follow(blocked, blocker)
839 assert User.following?(blocker, blocked)
840 assert User.following?(blocked, blocker)
842 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
844 assert data["type"] == "Block"
845 assert data["object"] == blocked.ap_id
846 assert data["actor"] == blocker.ap_id
848 blocker = User.get_cached_by_ap_id(data["actor"])
849 blocked = User.get_cached_by_ap_id(data["object"])
851 assert User.blocks?(blocker, blocked)
853 refute User.following?(blocker, blocked)
854 refute User.following?(blocked, blocker)
857 test "it works for incoming unblocks with an existing block" do
861 File.read!("test/fixtures/mastodon-block-activity.json")
863 |> Map.put("object", user.ap_id)
865 {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
868 File.read!("test/fixtures/mastodon-unblock-activity.json")
870 |> Map.put("object", block_data)
872 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
873 assert data["type"] == "Undo"
874 assert data["object"]["type"] == "Block"
875 assert data["object"]["object"] == user.ap_id
876 assert data["actor"] == "http://mastodon.example.org/users/admin"
878 blocker = User.get_cached_by_ap_id(data["actor"])
880 refute User.blocks?(blocker, user)
883 test "it works for incoming accepts which were pre-accepted" do
884 follower = insert(:user)
885 followed = insert(:user)
887 {:ok, follower} = User.follow(follower, followed)
888 assert User.following?(follower, followed) == true
890 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
893 File.read!("test/fixtures/mastodon-accept-activity.json")
895 |> Map.put("actor", followed.ap_id)
898 accept_data["object"]
899 |> Map.put("actor", follower.ap_id)
900 |> Map.put("id", follow_activity.data["id"])
902 accept_data = Map.put(accept_data, "object", object)
904 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
905 refute activity.local
907 assert activity.data["object"] == follow_activity.data["id"]
909 assert activity.data["id"] == accept_data["id"]
911 follower = User.get_cached_by_id(follower.id)
913 assert User.following?(follower, followed) == true
916 test "it works for incoming accepts which were orphaned" do
917 follower = insert(:user)
918 followed = insert(:user, %{info: %User.Info{locked: true}})
920 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
923 File.read!("test/fixtures/mastodon-accept-activity.json")
925 |> Map.put("actor", followed.ap_id)
928 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
930 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
931 assert activity.data["object"] == follow_activity.data["id"]
933 follower = User.get_cached_by_id(follower.id)
935 assert User.following?(follower, followed) == true
938 test "it works for incoming accepts which are referenced by IRI only" do
939 follower = insert(:user)
940 followed = insert(:user, %{info: %User.Info{locked: true}})
942 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
945 File.read!("test/fixtures/mastodon-accept-activity.json")
947 |> Map.put("actor", followed.ap_id)
948 |> Map.put("object", follow_activity.data["id"])
950 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
951 assert activity.data["object"] == follow_activity.data["id"]
953 follower = User.get_cached_by_id(follower.id)
955 assert User.following?(follower, followed) == true
958 test "it fails for incoming accepts which cannot be correlated" do
959 follower = insert(:user)
960 followed = insert(:user, %{info: %User.Info{locked: true}})
963 File.read!("test/fixtures/mastodon-accept-activity.json")
965 |> Map.put("actor", followed.ap_id)
968 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
970 :error = Transmogrifier.handle_incoming(accept_data)
972 follower = User.get_cached_by_id(follower.id)
974 refute User.following?(follower, followed) == true
977 test "it fails for incoming rejects which cannot be correlated" do
978 follower = insert(:user)
979 followed = insert(:user, %{info: %User.Info{locked: true}})
982 File.read!("test/fixtures/mastodon-reject-activity.json")
984 |> Map.put("actor", followed.ap_id)
987 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
989 :error = Transmogrifier.handle_incoming(accept_data)
991 follower = User.get_cached_by_id(follower.id)
993 refute User.following?(follower, followed) == true
996 test "it works for incoming rejects which are orphaned" do
997 follower = insert(:user)
998 followed = insert(:user, %{info: %User.Info{locked: true}})
1000 {:ok, follower} = User.follow(follower, followed)
1001 {:ok, _follow_activity} = ActivityPub.follow(follower, followed)
1003 assert User.following?(follower, followed) == true
1006 File.read!("test/fixtures/mastodon-reject-activity.json")
1008 |> Map.put("actor", followed.ap_id)
1011 Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
1013 {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
1014 refute activity.local
1015 assert activity.data["id"] == reject_data["id"]
1017 follower = User.get_cached_by_id(follower.id)
1019 assert User.following?(follower, followed) == false
1022 test "it works for incoming rejects which are referenced by IRI only" do
1023 follower = insert(:user)
1024 followed = insert(:user, %{info: %User.Info{locked: true}})
1026 {:ok, follower} = User.follow(follower, followed)
1027 {:ok, follow_activity} = ActivityPub.follow(follower, followed)
1029 assert User.following?(follower, followed) == true
1032 File.read!("test/fixtures/mastodon-reject-activity.json")
1034 |> Map.put("actor", followed.ap_id)
1035 |> Map.put("object", follow_activity.data["id"])
1037 {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
1039 follower = User.get_cached_by_id(follower.id)
1041 assert User.following?(follower, followed) == false
1044 test "it rejects activities without a valid ID" do
1045 user = insert(:user)
1048 File.read!("test/fixtures/mastodon-follow-activity.json")
1050 |> Map.put("object", user.ap_id)
1051 |> Map.put("id", "")
1053 :error = Transmogrifier.handle_incoming(data)
1056 test "it remaps video URLs as attachments if necessary" do
1058 Fetcher.fetch_object_from_id(
1059 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1064 "mediaType" => "video/mp4",
1066 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1067 "mimeType" => "video/mp4",
1068 "size" => 5_015_880,
1072 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1073 "mediaType" => "video/mp4",
1080 assert object.data["url"] ==
1081 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
1083 assert object.data["attachment"] == [attachment]
1086 test "it accepts Flag activities" do
1087 user = insert(:user)
1088 other_user = insert(:user)
1090 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
1091 object = Object.normalize(activity)
1094 "@context" => "https://www.w3.org/ns/activitystreams",
1095 "cc" => [user.ap_id],
1096 "object" => [user.ap_id, object.data["id"]],
1098 "content" => "blocked AND reported!!!",
1099 "actor" => other_user.ap_id
1102 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
1104 assert activity.data["object"] == [user.ap_id, object.data["id"]]
1105 assert activity.data["content"] == "blocked AND reported!!!"
1106 assert activity.data["actor"] == other_user.ap_id
1107 assert activity.data["cc"] == [user.ap_id]
1111 describe "prepare outgoing" do
1112 test "it inlines private announced objects" do
1113 user = insert(:user)
1115 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey", "visibility" => "private"})
1117 {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
1119 {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
1121 assert modified["object"]["content"] == "hey"
1122 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1125 test "it turns mentions into tags" do
1126 user = insert(:user)
1127 other_user = insert(:user)
1130 CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
1132 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1133 object = modified["object"]
1135 expected_mention = %{
1136 "href" => other_user.ap_id,
1137 "name" => "@#{other_user.nickname}",
1142 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1143 "type" => "Hashtag",
1147 assert Enum.member?(object["tag"], expected_tag)
1148 assert Enum.member?(object["tag"], expected_mention)
1151 test "it adds the sensitive property" do
1152 user = insert(:user)
1154 {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
1155 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1157 assert modified["object"]["sensitive"]
1160 test "it adds the json-ld context and the conversation property" do
1161 user = insert(:user)
1163 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1164 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1166 assert modified["@context"] ==
1167 Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
1169 assert modified["object"]["conversation"] == modified["context"]
1172 test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
1173 user = insert(:user)
1175 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
1176 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1178 assert modified["object"]["actor"] == modified["object"]["attributedTo"]
1181 test "it strips internal hashtag data" do
1182 user = insert(:user)
1184 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu"})
1187 "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
1188 "type" => "Hashtag",
1192 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1194 assert modified["object"]["tag"] == [expected_tag]
1197 test "it strips internal fields" do
1198 user = insert(:user)
1200 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :firefox:"})
1202 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1204 assert length(modified["object"]["tag"]) == 2
1206 assert is_nil(modified["object"]["emoji"])
1207 assert is_nil(modified["object"]["like_count"])
1208 assert is_nil(modified["object"]["announcements"])
1209 assert is_nil(modified["object"]["announcement_count"])
1210 assert is_nil(modified["object"]["context_id"])
1213 test "it strips internal fields of article" do
1214 activity = insert(:article_activity)
1216 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1218 assert length(modified["object"]["tag"]) == 2
1220 assert is_nil(modified["object"]["emoji"])
1221 assert is_nil(modified["object"]["like_count"])
1222 assert is_nil(modified["object"]["announcements"])
1223 assert is_nil(modified["object"]["announcement_count"])
1224 assert is_nil(modified["object"]["context_id"])
1225 assert is_nil(modified["object"]["likes"])
1228 test "the directMessage flag is present" do
1229 user = insert(:user)
1230 other_user = insert(:user)
1232 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"})
1234 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1236 assert modified["directMessage"] == false
1239 CommonAPI.post(user, %{"status" => "@#{other_user.nickname} :moominmamma:"})
1241 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1243 assert modified["directMessage"] == false
1246 CommonAPI.post(user, %{
1247 "status" => "@#{other_user.nickname} :moominmamma:",
1248 "visibility" => "direct"
1251 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1253 assert modified["directMessage"] == true
1256 test "it strips BCC field" do
1257 user = insert(:user)
1258 {:ok, list} = Pleroma.List.create("foo", user)
1261 CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
1263 {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
1265 assert is_nil(modified["bcc"])
1268 test "it can handle Listen activities" do
1269 listen_activity = insert(:listen)
1271 {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
1273 assert modified["type"] == "Listen"
1275 user = insert(:user)
1277 {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
1279 {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
1283 describe "user upgrade" do
1284 test "it upgrades a user to activitypub" do
1287 nickname: "rye@niu.moe",
1289 ap_id: "https://niu.moe/users/rye",
1290 follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
1293 user_two = insert(:user)
1294 Pleroma.FollowingRelationship.follow(user_two, user, "accept")
1296 {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
1297 {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
1298 assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
1300 user = User.get_cached_by_id(user.id)
1301 assert user.info.note_count == 1
1303 {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
1304 ObanHelpers.perform_all()
1306 assert user.info.ap_enabled
1307 assert user.info.note_count == 1
1308 assert user.follower_address == "https://niu.moe/users/rye/followers"
1309 assert user.following_address == "https://niu.moe/users/rye/following"
1311 user = User.get_cached_by_id(user.id)
1312 assert user.info.note_count == 1
1314 activity = Activity.get_by_id(activity.id)
1315 assert user.follower_address in activity.recipients
1321 "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
1330 "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
1333 } = user.info.banner
1335 refute "..." in activity.recipients
1337 unrelated_activity = Activity.get_by_id(unrelated_activity.id)
1338 refute user.follower_address in unrelated_activity.recipients
1340 user_two = User.get_cached_by_id(user_two.id)
1341 assert User.following?(user_two, user)
1342 refute "..." in User.following(user_two)
1346 describe "actor rewriting" do
1347 test "it fixes the actor URL property to be a proper URI" do
1349 "url" => %{"href" => "http://example.com"}
1352 rewritten = Transmogrifier.maybe_fix_user_object(data)
1353 assert rewritten["url"] == "http://example.com"
1357 describe "actor origin containment" do
1358 test "it rejects activities which reference objects with bogus origins" do
1360 "@context" => "https://www.w3.org/ns/activitystreams",
1361 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1362 "actor" => "http://mastodon.example.org/users/admin",
1363 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1364 "object" => "https://info.pleroma.site/activity.json",
1365 "type" => "Announce"
1368 :error = Transmogrifier.handle_incoming(data)
1371 test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
1373 "@context" => "https://www.w3.org/ns/activitystreams",
1374 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1375 "actor" => "http://mastodon.example.org/users/admin",
1376 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1377 "object" => "https://info.pleroma.site/activity2.json",
1378 "type" => "Announce"
1381 :error = Transmogrifier.handle_incoming(data)
1384 test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
1386 "@context" => "https://www.w3.org/ns/activitystreams",
1387 "id" => "http://mastodon.example.org/users/admin/activities/1234",
1388 "actor" => "http://mastodon.example.org/users/admin",
1389 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1390 "object" => "https://info.pleroma.site/activity3.json",
1391 "type" => "Announce"
1394 :error = Transmogrifier.handle_incoming(data)
1398 describe "reserialization" do
1399 test "successfully reserializes a message with inReplyTo == nil" do
1400 user = insert(:user)
1403 "@context" => "https://www.w3.org/ns/activitystreams",
1404 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1408 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1413 "attributedTo" => user.ap_id
1415 "actor" => user.ap_id
1418 {:ok, activity} = Transmogrifier.handle_incoming(message)
1420 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1423 test "successfully reserializes a message with AS2 objects in IR" do
1424 user = insert(:user)
1427 "@context" => "https://www.w3.org/ns/activitystreams",
1428 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1432 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
1437 "attributedTo" => user.ap_id,
1439 %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
1440 %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
1443 "actor" => user.ap_id
1446 {:ok, activity} = Transmogrifier.handle_incoming(message)
1448 {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
1452 test "Rewrites Answers to Notes" do
1453 user = insert(:user)
1455 {:ok, poll_activity} =
1456 CommonAPI.post(user, %{
1457 "status" => "suya...",
1458 "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
1461 poll_object = Object.normalize(poll_activity)
1462 # TODO: Replace with CommonAPI vote creation when implemented
1464 File.read!("test/fixtures/mastodon-vote.json")
1466 |> Kernel.put_in(["to"], user.ap_id)
1467 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
1468 |> Kernel.put_in(["object", "to"], user.ap_id)
1470 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
1471 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
1473 assert data["object"]["type"] == "Note"
1476 describe "fix_explicit_addressing" do
1478 user = insert(:user)
1482 test "moves non-explicitly mentioned actors to cc", %{user: user} do
1483 explicitly_mentioned_actors = [
1484 "https://pleroma.gold/users/user1",
1485 "https://pleroma.gold/user2"
1489 "actor" => user.ap_id,
1490 "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"],
1493 Enum.map(explicitly_mentioned_actors, fn href ->
1494 %{"type" => "Mention", "href" => href}
1498 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1499 assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
1500 refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
1501 assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
1504 test "does not move actor's follower collection to cc", %{user: user} do
1506 "actor" => user.ap_id,
1507 "to" => [user.follower_address],
1511 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1512 assert user.follower_address in fixed_object["to"]
1513 refute user.follower_address in fixed_object["cc"]
1516 test "removes recipient's follower collection from cc", %{user: user} do
1517 recipient = insert(:user)
1520 "actor" => user.ap_id,
1521 "to" => [recipient.ap_id, "https://www.w3.org/ns/activitystreams#Public"],
1522 "cc" => [user.follower_address, recipient.follower_address]
1525 fixed_object = Transmogrifier.fix_explicit_addressing(object)
1527 assert user.follower_address in fixed_object["cc"]
1528 refute recipient.follower_address in fixed_object["cc"]
1529 refute recipient.follower_address in fixed_object["to"]
1533 describe "fix_summary/1" do
1534 test "returns fixed object" do
1535 assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
1536 assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
1537 assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
1541 describe "fix_in_reply_to/2" do
1542 clear_config([:instance, :federation_incoming_replies_max_depth])
1545 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1549 test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
1550 assert Transmogrifier.fix_in_reply_to(data) == data
1553 test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
1554 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
1557 Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
1559 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1560 assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
1561 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1564 Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
1566 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1567 assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
1568 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1571 Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
1573 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1574 assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
1575 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1577 object_with_reply = Map.put(data["object"], "inReplyTo", [])
1578 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1579 assert modified_object["inReplyTo"] == []
1580 assert modified_object["inReplyToAtomUri"] == ""
1583 test "returns modified object when allowed incoming reply", %{data: data} do
1588 "https://shitposter.club/notice/2827873"
1591 Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
1592 modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
1594 assert modified_object["inReplyTo"] ==
1595 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
1597 assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
1599 assert modified_object["conversation"] ==
1600 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1602 assert modified_object["context"] ==
1603 "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
1607 describe "fix_url/1" do
1608 test "fixes data for object when url is map" do
1612 "mimeType" => "video/mp4",
1613 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1617 assert Transmogrifier.fix_url(object) == %{
1618 "url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1622 test "fixes data for video object" do
1628 "mimeType" => "video/mp4",
1629 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
1633 "mimeType" => "video/mp4",
1634 "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
1638 "mimeType" => "text/html",
1639 "href" => "https://peertube.-2d4c2d1630e3"
1643 "mimeType" => "text/html",
1644 "href" => "https://peertube.-2d4c2d16377-42"
1649 assert Transmogrifier.fix_url(object) == %{
1652 "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
1653 "mimeType" => "video/mp4",
1658 "url" => "https://peertube.-2d4c2d1630e3"
1662 test "fixes url for not Video object" do
1668 "mimeType" => "text/html",
1669 "href" => "https://peertube.-2d4c2d1630e3"
1673 "mimeType" => "text/html",
1674 "href" => "https://peertube.-2d4c2d16377-42"
1679 assert Transmogrifier.fix_url(object) == %{
1681 "url" => "https://peertube.-2d4c2d1630e3"
1684 assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
1690 test "retunrs not modified object" do
1691 assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
1695 describe "get_obj_helper/2" do
1696 test "returns nil when cannot normalize object" do
1697 refute Transmogrifier.get_obj_helper("test-obj-id")
1700 test "returns {:ok, %Object{}} for success case" do
1701 assert {:ok, %Object{}} =
1702 Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
1706 describe "fix_attachments/1" do
1707 test "returns not modified object" do
1708 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1709 assert Transmogrifier.fix_attachments(data) == data
1712 test "returns modified object when attachment is map" do
1713 assert Transmogrifier.fix_attachments(%{
1715 "mediaType" => "video/mp4",
1716 "url" => "https://peertube.moe/stat-480.mp4"
1721 "mediaType" => "video/mp4",
1724 "href" => "https://peertube.moe/stat-480.mp4",
1725 "mediaType" => "video/mp4",
1734 test "returns modified object when attachment is list" do
1735 assert Transmogrifier.fix_attachments(%{
1737 %{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
1738 %{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
1743 "mediaType" => "video/mp4",
1746 "href" => "https://pe.er/stat-480.mp4",
1747 "mediaType" => "video/mp4",
1753 "href" => "https://pe.er/stat-480.mp4",
1754 "mediaType" => "video/mp4",
1755 "mimeType" => "video/mp4",
1758 "href" => "https://pe.er/stat-480.mp4",
1759 "mediaType" => "video/mp4",
1769 describe "fix_emoji/1" do
1770 test "returns not modified object when object not contains tags" do
1771 data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
1772 assert Transmogrifier.fix_emoji(data) == data
1775 test "returns object with emoji when object contains list tags" do
1776 assert Transmogrifier.fix_emoji(%{
1778 %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
1779 %{"type" => "Hashtag"}
1782 "emoji" => %{"bib" => "/test"},
1784 %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
1785 %{"type" => "Hashtag"}
1790 test "returns object with emoji when object contains map tag" do
1791 assert Transmogrifier.fix_emoji(%{
1792 "tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
1794 "emoji" => %{"bib" => "/test"},
1795 "tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}