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.ActivityPubControllerTest do
6 use Pleroma.Web.ConnCase
7 use Oban.Testing, repo: Pleroma.Repo
10 alias Pleroma.Activity
11 alias Pleroma.Delivery
12 alias Pleroma.Instances
14 alias Pleroma.Tests.ObanHelpers
16 alias Pleroma.Web.ActivityPub.ObjectView
17 alias Pleroma.Web.ActivityPub.Relay
18 alias Pleroma.Web.ActivityPub.UserView
19 alias Pleroma.Web.ActivityPub.Utils
20 alias Pleroma.Web.CommonAPI
21 alias Pleroma.Workers.ReceiverWorker
24 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
28 clear_config_all([:instance, :federating],
29 do: Pleroma.Config.put([:instance, :federating], true)
33 clear_config([:instance, :allow_relay])
35 test "with the relay active, it returns the relay user", %{conn: conn} do
38 |> get(activity_pub_path(conn, :relay))
41 assert res["id"] =~ "/relay"
44 test "with the relay disabled, it returns 404", %{conn: conn} do
45 Pleroma.Config.put([:instance, :allow_relay], false)
48 |> get(activity_pub_path(conn, :relay))
54 describe "/internal/fetch" do
55 test "it returns the internal fetch user", %{conn: conn} do
58 |> get(activity_pub_path(conn, :internal_fetch))
61 assert res["id"] =~ "/fetch"
65 describe "/users/:nickname" do
66 test "it returns a json representation of the user with accept application/json", %{
73 |> put_req_header("accept", "application/json")
74 |> get("/users/#{user.nickname}")
76 user = User.get_cached_by_id(user.id)
78 assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
81 test "it returns a json representation of the user with accept application/activity+json", %{
88 |> put_req_header("accept", "application/activity+json")
89 |> get("/users/#{user.nickname}")
91 user = User.get_cached_by_id(user.id)
93 assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
96 test "it returns a json representation of the user with accept application/ld+json", %{
105 "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
107 |> get("/users/#{user.nickname}")
109 user = User.get_cached_by_id(user.id)
111 assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
114 test "it returns 404 for remote users", %{
117 user = insert(:user, local: false, nickname: "remoteuser@example.com")
121 |> put_req_header("accept", "application/json")
122 |> get("/users/#{user.nickname}.json")
124 assert json_response(conn, 404)
128 describe "/object/:uuid" do
129 test "it returns a json representation of the object with accept application/json", %{
133 uuid = String.split(note.data["id"], "/") |> List.last()
137 |> put_req_header("accept", "application/json")
138 |> get("/objects/#{uuid}")
140 assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
143 test "it returns a json representation of the object with accept application/activity+json",
146 uuid = String.split(note.data["id"], "/") |> List.last()
150 |> put_req_header("accept", "application/activity+json")
151 |> get("/objects/#{uuid}")
153 assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
156 test "it returns a json representation of the object with accept application/ld+json", %{
160 uuid = String.split(note.data["id"], "/") |> List.last()
166 "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
168 |> get("/objects/#{uuid}")
170 assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
173 test "it returns 404 for non-public messages", %{conn: conn} do
174 note = insert(:direct_note)
175 uuid = String.split(note.data["id"], "/") |> List.last()
179 |> put_req_header("accept", "application/activity+json")
180 |> get("/objects/#{uuid}")
182 assert json_response(conn, 404)
185 test "it returns 404 for tombstone objects", %{conn: conn} do
186 tombstone = insert(:tombstone)
187 uuid = String.split(tombstone.data["id"], "/") |> List.last()
191 |> put_req_header("accept", "application/activity+json")
192 |> get("/objects/#{uuid}")
194 assert json_response(conn, 404)
197 test "it caches a response", %{conn: conn} do
199 uuid = String.split(note.data["id"], "/") |> List.last()
203 |> put_req_header("accept", "application/activity+json")
204 |> get("/objects/#{uuid}")
206 assert json_response(conn1, :ok)
207 assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
211 |> put_req_header("accept", "application/activity+json")
212 |> get("/objects/#{uuid}")
214 assert json_response(conn1, :ok) == json_response(conn2, :ok)
215 assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"}))
218 test "cached purged after object deletion", %{conn: conn} do
220 uuid = String.split(note.data["id"], "/") |> List.last()
224 |> put_req_header("accept", "application/activity+json")
225 |> get("/objects/#{uuid}")
227 assert json_response(conn1, :ok)
228 assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
234 |> put_req_header("accept", "application/activity+json")
235 |> get("/objects/#{uuid}")
237 assert "Not found" == json_response(conn2, :not_found)
241 describe "/activities/:uuid" do
242 test "it returns a json representation of the activity", %{conn: conn} do
243 activity = insert(:note_activity)
244 uuid = String.split(activity.data["id"], "/") |> List.last()
248 |> put_req_header("accept", "application/activity+json")
249 |> get("/activities/#{uuid}")
251 assert json_response(conn, 200) == ObjectView.render("object.json", %{object: activity})
254 test "it returns 404 for non-public activities", %{conn: conn} do
255 activity = insert(:direct_note_activity)
256 uuid = String.split(activity.data["id"], "/") |> List.last()
260 |> put_req_header("accept", "application/activity+json")
261 |> get("/activities/#{uuid}")
263 assert json_response(conn, 404)
266 test "it caches a response", %{conn: conn} do
267 activity = insert(:note_activity)
268 uuid = String.split(activity.data["id"], "/") |> List.last()
272 |> put_req_header("accept", "application/activity+json")
273 |> get("/activities/#{uuid}")
275 assert json_response(conn1, :ok)
276 assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
280 |> put_req_header("accept", "application/activity+json")
281 |> get("/activities/#{uuid}")
283 assert json_response(conn1, :ok) == json_response(conn2, :ok)
284 assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"}))
287 test "cached purged after activity deletion", %{conn: conn} do
289 {:ok, activity} = CommonAPI.post(user, %{"status" => "cofe"})
291 uuid = String.split(activity.data["id"], "/") |> List.last()
295 |> put_req_header("accept", "application/activity+json")
296 |> get("/activities/#{uuid}")
298 assert json_response(conn1, :ok)
299 assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
301 Activity.delete_all_by_object_ap_id(activity.object.data["id"])
305 |> put_req_header("accept", "application/activity+json")
306 |> get("/activities/#{uuid}")
308 assert "Not found" == json_response(conn2, :not_found)
313 test "it inserts an incoming activity into the database", %{conn: conn} do
314 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
318 |> assign(:valid_signature, true)
319 |> put_req_header("content-type", "application/activity+json")
320 |> post("/inbox", data)
322 assert "ok" == json_response(conn, 200)
324 ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
325 assert Activity.get_by_ap_id(data["id"])
328 test "it clears `unreachable` federation status of the sender", %{conn: conn} do
329 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
331 sender_url = data["actor"]
332 Instances.set_consistently_unreachable(sender_url)
333 refute Instances.reachable?(sender_url)
337 |> assign(:valid_signature, true)
338 |> put_req_header("content-type", "application/activity+json")
339 |> post("/inbox", data)
341 assert "ok" == json_response(conn, 200)
342 assert Instances.reachable?(sender_url)
346 describe "/users/:nickname/inbox" do
349 File.read!("test/fixtures/mastodon-post-activity.json")
355 test "it inserts an incoming activity into the database", %{conn: conn, data: data} do
357 data = Map.put(data, "bcc", [user.ap_id])
361 |> assign(:valid_signature, true)
362 |> put_req_header("content-type", "application/activity+json")
363 |> post("/users/#{user.nickname}/inbox", data)
365 assert "ok" == json_response(conn, 200)
366 ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
367 assert Activity.get_by_ap_id(data["id"])
370 test "it accepts messages with to as string instead of array", %{conn: conn, data: data} do
374 Map.put(data, "to", user.ap_id)
379 |> assign(:valid_signature, true)
380 |> put_req_header("content-type", "application/activity+json")
381 |> post("/users/#{user.nickname}/inbox", data)
383 assert "ok" == json_response(conn, 200)
384 ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
385 assert Activity.get_by_ap_id(data["id"])
388 test "it accepts messages with cc as string instead of array", %{conn: conn, data: data} do
392 Map.put(data, "cc", user.ap_id)
397 |> assign(:valid_signature, true)
398 |> put_req_header("content-type", "application/activity+json")
399 |> post("/users/#{user.nickname}/inbox", data)
401 assert "ok" == json_response(conn, 200)
402 ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
403 %Activity{} = activity = Activity.get_by_ap_id(data["id"])
404 assert user.ap_id in activity.recipients
407 test "it accepts messages with bcc as string instead of array", %{conn: conn, data: data} do
411 Map.put(data, "bcc", user.ap_id)
417 |> assign(:valid_signature, true)
418 |> put_req_header("content-type", "application/activity+json")
419 |> post("/users/#{user.nickname}/inbox", data)
421 assert "ok" == json_response(conn, 200)
422 ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
423 assert Activity.get_by_ap_id(data["id"])
426 test "it accepts announces with to as string instead of array", %{conn: conn} do
430 "@context" => "https://www.w3.org/ns/activitystreams",
431 "actor" => "http://mastodon.example.org/users/admin",
432 "id" => "http://mastodon.example.org/users/admin/statuses/19512778738411822/activity",
433 "object" => "https://mastodon.social/users/emelie/statuses/101849165031453009",
434 "to" => "https://www.w3.org/ns/activitystreams#Public",
435 "cc" => [user.ap_id],
441 |> assign(:valid_signature, true)
442 |> put_req_header("content-type", "application/activity+json")
443 |> post("/users/#{user.nickname}/inbox", data)
445 assert "ok" == json_response(conn, 200)
446 ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
447 %Activity{} = activity = Activity.get_by_ap_id(data["id"])
448 assert "https://www.w3.org/ns/activitystreams#Public" in activity.recipients
451 test "it accepts messages from actors that are followed by the user", %{
455 recipient = insert(:user)
456 actor = insert(:user, %{ap_id: "http://mastodon.example.org/users/actor"})
458 {:ok, recipient} = User.follow(recipient, actor)
462 |> Map.put("attributedTo", actor.ap_id)
466 |> Map.put("actor", actor.ap_id)
467 |> Map.put("object", object)
471 |> assign(:valid_signature, true)
472 |> put_req_header("content-type", "application/activity+json")
473 |> post("/users/#{recipient.nickname}/inbox", data)
475 assert "ok" == json_response(conn, 200)
476 ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
477 assert Activity.get_by_ap_id(data["id"])
480 test "it rejects reads from other users", %{conn: conn} do
482 otheruser = insert(:user)
486 |> assign(:user, otheruser)
487 |> put_req_header("accept", "application/activity+json")
488 |> get("/users/#{user.nickname}/inbox")
490 assert json_response(conn, 403)
493 test "it doesn't crash without an authenticated user", %{conn: conn} do
498 |> put_req_header("accept", "application/activity+json")
499 |> get("/users/#{user.nickname}/inbox")
501 assert json_response(conn, 403)
504 test "it returns a note activity in a collection", %{conn: conn} do
505 note_activity = insert(:direct_note_activity)
506 note_object = Object.normalize(note_activity)
507 user = User.get_cached_by_ap_id(hd(note_activity.data["to"]))
511 |> assign(:user, user)
512 |> put_req_header("accept", "application/activity+json")
513 |> get("/users/#{user.nickname}/inbox?page=true")
515 assert response(conn, 200) =~ note_object.data["content"]
518 test "it clears `unreachable` federation status of the sender", %{conn: conn, data: data} do
520 data = Map.put(data, "bcc", [user.ap_id])
522 sender_host = URI.parse(data["actor"]).host
523 Instances.set_consistently_unreachable(sender_host)
524 refute Instances.reachable?(sender_host)
528 |> assign(:valid_signature, true)
529 |> put_req_header("content-type", "application/activity+json")
530 |> post("/users/#{user.nickname}/inbox", data)
532 assert "ok" == json_response(conn, 200)
533 assert Instances.reachable?(sender_host)
536 test "it removes all follower collections but actor's", %{conn: conn} do
537 [actor, recipient] = insert_pair(:user)
540 File.read!("test/fixtures/activitypub-client-post-activity.json")
543 object = Map.put(data["object"], "attributedTo", actor.ap_id)
547 |> Map.put("id", Utils.generate_object_id())
548 |> Map.put("actor", actor.ap_id)
549 |> Map.put("object", object)
551 recipient.follower_address,
552 actor.follower_address
556 recipient.follower_address,
557 "https://www.w3.org/ns/activitystreams#Public"
561 |> assign(:valid_signature, true)
562 |> put_req_header("content-type", "application/activity+json")
563 |> post("/users/#{recipient.nickname}/inbox", data)
564 |> json_response(200)
566 ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
568 activity = Activity.get_by_ap_id(data["id"])
571 assert actor.follower_address in activity.recipients
572 assert actor.follower_address in activity.data["cc"]
574 refute recipient.follower_address in activity.recipients
575 refute recipient.follower_address in activity.data["cc"]
576 refute recipient.follower_address in activity.data["to"]
580 describe "/users/:nickname/outbox" do
581 test "it will not bomb when there is no activity", %{conn: conn} do
586 |> put_req_header("accept", "application/activity+json")
587 |> get("/users/#{user.nickname}/outbox")
589 result = json_response(conn, 200)
590 assert user.ap_id <> "/outbox" == result["id"]
593 test "it returns a note activity in a collection", %{conn: conn} do
594 note_activity = insert(:note_activity)
595 note_object = Object.normalize(note_activity)
596 user = User.get_cached_by_ap_id(note_activity.data["actor"])
600 |> put_req_header("accept", "application/activity+json")
601 |> get("/users/#{user.nickname}/outbox?page=true")
603 assert response(conn, 200) =~ note_object.data["content"]
606 test "it returns an announce activity in a collection", %{conn: conn} do
607 announce_activity = insert(:announce_activity)
608 user = User.get_cached_by_ap_id(announce_activity.data["actor"])
612 |> put_req_header("accept", "application/activity+json")
613 |> get("/users/#{user.nickname}/outbox?page=true")
615 assert response(conn, 200) =~ announce_activity.data["object"]
618 test "it rejects posts from other users", %{conn: conn} do
619 data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
621 otheruser = insert(:user)
625 |> assign(:user, otheruser)
626 |> put_req_header("content-type", "application/activity+json")
627 |> post("/users/#{user.nickname}/outbox", data)
629 assert json_response(conn, 403)
632 test "it inserts an incoming create activity into the database", %{conn: conn} do
633 data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
638 |> assign(:user, user)
639 |> put_req_header("content-type", "application/activity+json")
640 |> post("/users/#{user.nickname}/outbox", data)
642 result = json_response(conn, 201)
644 assert Activity.get_by_ap_id(result["id"])
647 test "it rejects an incoming activity with bogus type", %{conn: conn} do
648 data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
653 |> Map.put("type", "BadType")
657 |> assign(:user, user)
658 |> put_req_header("content-type", "application/activity+json")
659 |> post("/users/#{user.nickname}/outbox", data)
661 assert json_response(conn, 400)
664 test "it erects a tombstone when receiving a delete activity", %{conn: conn} do
665 note_activity = insert(:note_activity)
666 note_object = Object.normalize(note_activity)
667 user = User.get_cached_by_ap_id(note_activity.data["actor"])
672 id: note_object.data["id"]
678 |> assign(:user, user)
679 |> put_req_header("content-type", "application/activity+json")
680 |> post("/users/#{user.nickname}/outbox", data)
682 result = json_response(conn, 201)
683 assert Activity.get_by_ap_id(result["id"])
685 assert object = Object.get_by_ap_id(note_object.data["id"])
686 assert object.data["type"] == "Tombstone"
689 test "it rejects delete activity of object from other actor", %{conn: conn} do
690 note_activity = insert(:note_activity)
691 note_object = Object.normalize(note_activity)
697 id: note_object.data["id"]
703 |> assign(:user, user)
704 |> put_req_header("content-type", "application/activity+json")
705 |> post("/users/#{user.nickname}/outbox", data)
707 assert json_response(conn, 400)
710 test "it increases like count when receiving a like action", %{conn: conn} do
711 note_activity = insert(:note_activity)
712 note_object = Object.normalize(note_activity)
713 user = User.get_cached_by_ap_id(note_activity.data["actor"])
718 id: note_object.data["id"]
724 |> assign(:user, user)
725 |> put_req_header("content-type", "application/activity+json")
726 |> post("/users/#{user.nickname}/outbox", data)
728 result = json_response(conn, 201)
729 assert Activity.get_by_ap_id(result["id"])
731 assert object = Object.get_by_ap_id(note_object.data["id"])
732 assert object.data["like_count"] == 1
736 describe "/relay/followers" do
737 test "it returns relay followers", %{conn: conn} do
738 relay_actor = Relay.get_actor()
740 User.follow(user, relay_actor)
744 |> assign(:relay, true)
745 |> get("/relay/followers")
746 |> json_response(200)
748 assert result["first"]["orderedItems"] == [user.ap_id]
752 describe "/relay/following" do
753 test "it returns relay following", %{conn: conn} do
756 |> assign(:relay, true)
757 |> get("/relay/following")
758 |> json_response(200)
760 assert result["first"]["orderedItems"] == []
764 describe "/users/:nickname/followers" do
765 test "it returns the followers in a collection", %{conn: conn} do
767 user_two = insert(:user)
768 User.follow(user, user_two)
772 |> get("/users/#{user_two.nickname}/followers")
773 |> json_response(200)
775 assert result["first"]["orderedItems"] == [user.ap_id]
778 test "it returns returns a uri if the user has 'hide_followers' set", %{conn: conn} do
780 user_two = insert(:user, hide_followers: true)
781 User.follow(user, user_two)
785 |> get("/users/#{user_two.nickname}/followers")
786 |> json_response(200)
788 assert is_binary(result["first"])
791 test "it returns a 403 error on pages, if the user has 'hide_followers' set and the request is not authenticated",
793 user = insert(:user, hide_followers: true)
797 |> get("/users/#{user.nickname}/followers?page=1")
799 assert result.status == 403
800 assert result.resp_body == ""
803 test "it renders the page, if the user has 'hide_followers' set and the request is authenticated with the same user",
805 user = insert(:user, hide_followers: true)
806 other_user = insert(:user)
807 {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
811 |> assign(:user, user)
812 |> get("/users/#{user.nickname}/followers?page=1")
813 |> json_response(200)
815 assert result["totalItems"] == 1
816 assert result["orderedItems"] == [other_user.ap_id]
819 test "it works for more than 10 users", %{conn: conn} do
822 Enum.each(1..15, fn _ ->
823 other_user = insert(:user)
824 User.follow(other_user, user)
829 |> get("/users/#{user.nickname}/followers")
830 |> json_response(200)
832 assert length(result["first"]["orderedItems"]) == 10
833 assert result["first"]["totalItems"] == 15
834 assert result["totalItems"] == 15
838 |> get("/users/#{user.nickname}/followers?page=2")
839 |> json_response(200)
841 assert length(result["orderedItems"]) == 5
842 assert result["totalItems"] == 15
846 describe "/users/:nickname/following" do
847 test "it returns the following in a collection", %{conn: conn} do
849 user_two = insert(:user)
850 User.follow(user, user_two)
854 |> get("/users/#{user.nickname}/following")
855 |> json_response(200)
857 assert result["first"]["orderedItems"] == [user_two.ap_id]
860 test "it returns a uri if the user has 'hide_follows' set", %{conn: conn} do
861 user = insert(:user, hide_follows: true)
862 user_two = insert(:user)
863 User.follow(user, user_two)
867 |> get("/users/#{user.nickname}/following")
868 |> json_response(200)
870 assert is_binary(result["first"])
873 test "it returns a 403 error on pages, if the user has 'hide_follows' set and the request is not authenticated",
875 user = insert(:user, hide_follows: true)
879 |> get("/users/#{user.nickname}/following?page=1")
881 assert result.status == 403
882 assert result.resp_body == ""
885 test "it renders the page, if the user has 'hide_follows' set and the request is authenticated with the same user",
887 user = insert(:user, hide_follows: true)
888 other_user = insert(:user)
889 {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
893 |> assign(:user, user)
894 |> get("/users/#{user.nickname}/following?page=1")
895 |> json_response(200)
897 assert result["totalItems"] == 1
898 assert result["orderedItems"] == [other_user.ap_id]
901 test "it works for more than 10 users", %{conn: conn} do
904 Enum.each(1..15, fn _ ->
905 user = User.get_cached_by_id(user.id)
906 other_user = insert(:user)
907 User.follow(user, other_user)
912 |> get("/users/#{user.nickname}/following")
913 |> json_response(200)
915 assert length(result["first"]["orderedItems"]) == 10
916 assert result["first"]["totalItems"] == 15
917 assert result["totalItems"] == 15
921 |> get("/users/#{user.nickname}/following?page=2")
922 |> json_response(200)
924 assert length(result["orderedItems"]) == 5
925 assert result["totalItems"] == 15
929 describe "delivery tracking" do
930 test "it tracks a signed object fetch", %{conn: conn} do
931 user = insert(:user, local: false)
932 activity = insert(:note_activity)
933 object = Object.normalize(activity)
935 object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
938 |> put_req_header("accept", "application/activity+json")
939 |> assign(:user, user)
941 |> json_response(200)
943 assert Delivery.get(object.id, user.id)
946 test "it tracks a signed activity fetch", %{conn: conn} do
947 user = insert(:user, local: false)
948 activity = insert(:note_activity)
949 object = Object.normalize(activity)
951 activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
954 |> put_req_header("accept", "application/activity+json")
955 |> assign(:user, user)
956 |> get(activity_path)
957 |> json_response(200)
959 assert Delivery.get(object.id, user.id)
962 test "it tracks a signed object fetch when the json is cached", %{conn: conn} do
963 user = insert(:user, local: false)
964 other_user = insert(:user, local: false)
965 activity = insert(:note_activity)
966 object = Object.normalize(activity)
968 object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
971 |> put_req_header("accept", "application/activity+json")
972 |> assign(:user, user)
974 |> json_response(200)
977 |> put_req_header("accept", "application/activity+json")
978 |> assign(:user, other_user)
980 |> json_response(200)
982 assert Delivery.get(object.id, user.id)
983 assert Delivery.get(object.id, other_user.id)
986 test "it tracks a signed activity fetch when the json is cached", %{conn: conn} do
987 user = insert(:user, local: false)
988 other_user = insert(:user, local: false)
989 activity = insert(:note_activity)
990 object = Object.normalize(activity)
992 activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
995 |> put_req_header("accept", "application/activity+json")
996 |> assign(:user, user)
997 |> get(activity_path)
998 |> json_response(200)
1001 |> put_req_header("accept", "application/activity+json")
1002 |> assign(:user, other_user)
1003 |> get(activity_path)
1004 |> json_response(200)
1006 assert Delivery.get(object.id, user.id)
1007 assert Delivery.get(object.id, other_user.id)
1011 describe "Additionnal ActivityPub C2S endpoints" do
1012 test "/api/ap/whoami", %{conn: conn} do
1013 user = insert(:user)
1017 |> assign(:user, user)
1018 |> get("/api/ap/whoami")
1020 user = User.get_cached_by_id(user.id)
1022 assert UserView.render("user.json", %{user: user}) == json_response(conn, 200)
1025 clear_config([:media_proxy])
1026 clear_config([Pleroma.Upload])
1028 test "uploadMedia", %{conn: conn} do
1029 user = insert(:user)
1031 desc = "Description of the image"
1033 image = %Plug.Upload{
1034 content_type: "image/jpg",
1035 path: Path.absname("test/fixtures/image.jpg"),
1036 filename: "an_image.jpg"
1041 |> assign(:user, user)
1042 |> post("/api/ap/upload_media", %{"file" => image, "description" => desc})
1044 assert object = json_response(conn, :created)
1045 assert object["name"] == desc
1046 assert object["type"] == "Document"
1047 assert object["actor"] == user.ap_id