1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
6 use Pleroma.Web.ConnCase
12 alias Pleroma.Web.CommonAPI
15 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
20 setup do: oauth_access(["read:statuses"])
22 test "does NOT embed account/pleroma/relationship in statuses", %{
26 other_user = insert(:user)
28 {:ok, _} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
32 |> assign(:user, user)
33 |> get("/api/v1/timelines/home")
34 |> json_response_and_validate_schema(200)
36 assert Enum.all?(response, fn n ->
37 get_in(n, ["account", "pleroma", "relationship"]) == %{}
41 test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
42 {:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
43 {:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
45 {:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
47 {:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
49 conn = get(conn, "/api/v1/timelines/home?exclude_visibilities[]=direct")
51 assert status_ids = json_response_and_validate_schema(conn, :ok) |> Enum.map(& &1["id"])
52 assert public_activity.id in status_ids
53 assert unlisted_activity.id in status_ids
54 assert private_activity.id in status_ids
55 refute direct_activity.id in status_ids
58 test "muted emotions", %{user: user, conn: conn} do
59 other_user = insert(:user)
60 {:ok, activity} = CommonAPI.post(user, %{status: "."})
62 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
63 User.mute(user, other_user)
67 |> assign(:user, user)
68 |> get("/api/v1/timelines/home")
69 |> json_response_and_validate_schema(200)
74 "emoji_reactions" => []
81 |> assign(:user, user)
82 |> get("/api/v1/timelines/home?with_muted=true")
83 |> json_response_and_validate_schema(200)
88 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
94 test "filtering", %{conn: conn, user: user} do
95 local_user = insert(:user)
96 {:ok, user, local_user} = User.follow(user, local_user)
97 {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"})
98 with_media = create_with_media_activity(local_user)
100 remote_user = insert(:user, local: false)
101 {:ok, _user, remote_user} = User.follow(user, remote_user)
102 remote_activity = create_remote_activity(remote_user)
106 |> get("/api/v1/timelines/home")
107 |> json_response_and_validate_schema(200)
108 |> Enum.map(& &1["id"])
110 assert local_activity.id in without_filter_ids
111 assert remote_activity.id in without_filter_ids
112 assert with_media.id in without_filter_ids
116 |> get("/api/v1/timelines/home?local=true")
117 |> json_response_and_validate_schema(200)
118 |> Enum.map(& &1["id"])
120 assert local_activity.id in only_local_ids
121 refute remote_activity.id in only_local_ids
122 assert with_media.id in only_local_ids
124 only_local_media_ids =
126 |> get("/api/v1/timelines/home?local=true&only_media=true")
127 |> json_response_and_validate_schema(200)
128 |> Enum.map(& &1["id"])
130 refute local_activity.id in only_local_media_ids
131 refute remote_activity.id in only_local_media_ids
132 assert with_media.id in only_local_media_ids
136 |> get("/api/v1/timelines/home?remote=true")
137 |> json_response_and_validate_schema(200)
138 |> Enum.map(& &1["id"])
140 refute local_activity.id in remote_ids
141 assert remote_activity.id in remote_ids
142 refute with_media.id in remote_ids
145 |> get("/api/v1/timelines/home?remote=true&only_media=true")
146 |> json_response_and_validate_schema(200) == []
149 |> get("/api/v1/timelines/home?remote=true&local=true")
150 |> json_response_and_validate_schema(200) == []
155 @tag capture_log: true
156 test "the public timeline", %{conn: conn} do
159 {:ok, activity} = CommonAPI.post(user, %{status: "test"})
160 with_media = create_with_media_activity(user)
162 remote = insert(:note_activity, local: false)
165 |> get("/api/v1/timelines/public?local=False")
166 |> json_response_and_validate_schema(:ok)
171 |> get("/api/v1/timelines/public?local=True")
172 |> json_response_and_validate_schema(:ok)
173 |> Enum.map(& &1["id"])
175 assert activity.id in local_ids
176 assert with_media.id in local_ids
177 refute remote.id in local_ids
181 |> get("/api/v1/timelines/public?local=True")
182 |> json_response_and_validate_schema(:ok)
183 |> Enum.map(& &1["id"])
185 assert activity.id in local_ids
186 assert with_media.id in local_ids
187 refute remote.id in local_ids
191 |> get("/api/v1/timelines/public?local=True&only_media=true")
192 |> json_response_and_validate_schema(:ok)
193 |> Enum.map(& &1["id"])
195 refute activity.id in local_ids
196 assert with_media.id in local_ids
197 refute remote.id in local_ids
201 |> get("/api/v1/timelines/public?local=1")
202 |> json_response_and_validate_schema(:ok)
203 |> Enum.map(& &1["id"])
205 assert activity.id in local_ids
206 assert with_media.id in local_ids
207 refute remote.id in local_ids
209 remote_id = remote.id
211 assert [%{"id" => ^remote_id}] =
213 |> get("/api/v1/timelines/public?remote=true")
214 |> json_response_and_validate_schema(:ok)
216 with_media_id = with_media.id
218 assert [%{"id" => ^with_media_id}] =
220 |> get("/api/v1/timelines/public?only_media=true")
221 |> json_response_and_validate_schema(:ok)
224 |> get("/api/v1/timelines/public?remote=true&only_media=true")
225 |> json_response_and_validate_schema(:ok) == []
227 # does not contain repeats
228 {:ok, _} = CommonAPI.repeat(activity.id, user)
232 |> get("/api/v1/timelines/public?local=true")
233 |> json_response_and_validate_schema(:ok)
236 test "the public timeline includes only public statuses for an authenticated user" do
237 %{user: user, conn: conn} = oauth_access(["read:statuses"])
239 {:ok, _activity} = CommonAPI.post(user, %{status: "test"})
240 {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "private"})
241 {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "unlisted"})
242 {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
244 res_conn = get(conn, "/api/v1/timelines/public")
245 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
248 test "doesn't return replies if follower is posting with blocked user" do
249 %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
250 [blockee, friend] = insert_list(2, :user)
251 {:ok, blocker, friend} = User.follow(blocker, friend)
252 {:ok, _} = User.block(blocker, blockee)
254 conn = assign(conn, :user, blocker)
256 {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
258 {:ok, reply_from_blockee} =
259 CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
261 {:ok, _reply_from_friend} =
262 CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
264 # Still shows replies from yourself
265 {:ok, %{id: reply_from_me}} =
266 CommonAPI.post(blocker, %{status: "status", in_reply_to_status_id: reply_from_blockee})
269 get(conn, "/api/v1/timelines/public")
270 |> json_response_and_validate_schema(200)
272 assert length(response) == 2
273 [%{"id" => ^reply_from_me}, %{"id" => ^activity_id}] = response
276 test "doesn't return posts from users who blocked you when :blockers_visible is disabled" do
277 clear_config([:activitypub, :blockers_visible], false)
279 %{conn: conn, user: blockee} = oauth_access(["read:statuses"])
280 blocker = insert(:user)
281 {:ok, _} = User.block(blocker, blockee)
283 conn = assign(conn, :user, blockee)
285 {:ok, _} = CommonAPI.post(blocker, %{status: "hey!"})
288 get(conn, "/api/v1/timelines/public")
289 |> json_response_and_validate_schema(200)
291 assert length(response) == 0
294 test "doesn't return replies if follow is posting with users from blocked domain" do
295 %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
296 friend = insert(:user)
297 blockee = insert(:user, ap_id: "https://example.com/users/blocked")
298 {:ok, blocker, friend} = User.follow(blocker, friend)
299 {:ok, blocker} = User.block_domain(blocker, "example.com")
301 conn = assign(conn, :user, blocker)
303 {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
305 {:ok, reply_from_blockee} =
306 CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
308 {:ok, _reply_from_friend} =
309 CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
311 res_conn = get(conn, "/api/v1/timelines/public")
313 activities = json_response_and_validate_schema(res_conn, 200)
314 [%{"id" => ^activity_id}] = activities
317 test "can be filtered by instance", %{conn: conn} do
318 user = insert(:user, ap_id: "https://lain.com/users/lain")
319 insert(:note_activity, local: false)
320 insert(:note_activity, local: false)
322 {:ok, _} = CommonAPI.post(user, %{status: "test"})
324 conn = get(conn, "/api/v1/timelines/public?instance=lain.com")
326 assert length(json_response_and_validate_schema(conn, :ok)) == 1
329 test "muted emotions", %{conn: conn} do
331 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
335 |> assign(:user, user)
336 |> assign(:token, token)
338 other_user = insert(:user)
339 {:ok, activity} = CommonAPI.post(user, %{status: "."})
341 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
342 User.mute(user, other_user)
346 |> get("/api/v1/timelines/public")
347 |> json_response_and_validate_schema(200)
352 "emoji_reactions" => []
359 |> get("/api/v1/timelines/public?with_muted=true")
360 |> json_response_and_validate_schema(200)
365 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
372 defp local_and_remote_activities do
373 insert(:note_activity)
374 insert(:note_activity, local: false)
378 describe "public with restrict unauthenticated timeline for local and federated timelines" do
379 setup do: local_and_remote_activities()
381 setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
383 setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
385 test "if user is unauthenticated", %{conn: conn} do
386 res_conn = get(conn, "/api/v1/timelines/public?local=true")
388 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
389 "error" => "authorization required for timeline view"
392 res_conn = get(conn, "/api/v1/timelines/public?local=false")
394 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
395 "error" => "authorization required for timeline view"
399 test "if user is authenticated" do
400 %{conn: conn} = oauth_access(["read:statuses"])
402 res_conn = get(conn, "/api/v1/timelines/public?local=true")
403 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
405 res_conn = get(conn, "/api/v1/timelines/public?local=false")
406 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
410 describe "public with restrict unauthenticated timeline for local" do
411 setup do: local_and_remote_activities()
413 setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
415 test "if user is unauthenticated", %{conn: conn} do
416 res_conn = get(conn, "/api/v1/timelines/public?local=true")
418 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
419 "error" => "authorization required for timeline view"
422 res_conn = get(conn, "/api/v1/timelines/public?local=false")
423 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
426 test "if user is authenticated", %{conn: _conn} do
427 %{conn: conn} = oauth_access(["read:statuses"])
429 res_conn = get(conn, "/api/v1/timelines/public?local=true")
430 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
432 res_conn = get(conn, "/api/v1/timelines/public?local=false")
433 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
437 describe "public with restrict unauthenticated timeline for remote" do
438 setup do: local_and_remote_activities()
440 setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
442 test "if user is unauthenticated", %{conn: conn} do
443 res_conn = get(conn, "/api/v1/timelines/public?local=true")
444 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
446 res_conn = get(conn, "/api/v1/timelines/public?local=false")
448 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
449 "error" => "authorization required for timeline view"
453 test "if user is authenticated", %{conn: _conn} do
454 %{conn: conn} = oauth_access(["read:statuses"])
456 res_conn = get(conn, "/api/v1/timelines/public?local=true")
457 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
459 res_conn = get(conn, "/api/v1/timelines/public?local=false")
460 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
465 test "direct timeline", %{conn: conn} do
466 user_one = insert(:user)
467 user_two = insert(:user)
469 {:ok, user_two, user_one} = User.follow(user_two, user_one)
472 CommonAPI.post(user_one, %{
473 status: "Hi @#{user_two.nickname}!",
477 {:ok, _follower_only} =
478 CommonAPI.post(user_one, %{
479 status: "Hi @#{user_two.nickname}!",
480 visibility: "private"
485 |> assign(:user, user_two)
486 |> assign(:token, insert(:oauth_token, user: user_two, scopes: ["read:statuses"]))
488 # Only direct should be visible here
489 res_conn = get(conn_user_two, "api/v1/timelines/direct")
491 assert [status] = json_response_and_validate_schema(res_conn, :ok)
493 assert %{"visibility" => "direct"} = status
494 assert status["url"] != direct.data["id"]
496 # User should be able to see their own direct message
499 |> assign(:user, user_one)
500 |> assign(:token, insert(:oauth_token, user: user_one, scopes: ["read:statuses"]))
501 |> get("api/v1/timelines/direct")
503 [status] = json_response_and_validate_schema(res_conn, :ok)
505 assert %{"visibility" => "direct"} = status
507 # Both should be visible here
508 res_conn = get(conn_user_two, "api/v1/timelines/home")
510 [_s1, _s2] = json_response_and_validate_schema(res_conn, :ok)
513 Enum.each(1..20, fn _ ->
515 CommonAPI.post(user_one, %{
516 status: "Hi @#{user_two.nickname}!",
521 res_conn = get(conn_user_two, "api/v1/timelines/direct")
523 statuses = json_response_and_validate_schema(res_conn, :ok)
524 assert length(statuses) == 20
526 max_id = List.last(statuses)["id"]
528 res_conn = get(conn_user_two, "api/v1/timelines/direct?max_id=#{max_id}")
530 assert [status] = json_response_and_validate_schema(res_conn, :ok)
532 assert status["url"] != direct.data["id"]
535 test "doesn't include DMs from blocked users" do
536 %{user: blocker, conn: conn} = oauth_access(["read:statuses"])
537 blocked = insert(:user)
538 other_user = insert(:user)
539 {:ok, _user_relationship} = User.block(blocker, blocked)
541 {:ok, _blocked_direct} =
542 CommonAPI.post(blocked, %{
543 status: "Hi @#{blocker.nickname}!",
548 CommonAPI.post(other_user, %{
549 status: "Hi @#{blocker.nickname}!",
553 res_conn = get(conn, "api/v1/timelines/direct")
555 [status] = json_response_and_validate_schema(res_conn, :ok)
556 assert status["id"] == direct.id
561 setup do: oauth_access(["read:lists"])
563 test "does not contain retoots", %{user: user, conn: conn} do
564 other_user = insert(:user)
565 {:ok, activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
566 {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is stupid."})
567 {:ok, _} = CommonAPI.repeat(activity_one.id, other_user)
569 {:ok, list} = Pleroma.List.create("name", user)
570 {:ok, list} = Pleroma.List.follow(list, other_user)
572 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
574 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
576 assert id == to_string(activity_two.id)
579 test "works with pagination", %{user: user, conn: conn} do
580 other_user = insert(:user)
581 {:ok, list} = Pleroma.List.create("name", user)
582 {:ok, list} = Pleroma.List.follow(list, other_user)
584 Enum.each(1..30, fn i ->
585 CommonAPI.post(other_user, %{status: "post number #{i}"})
589 get(conn, "/api/v1/timelines/list/#{list.id}?limit=1")
590 |> json_response_and_validate_schema(:ok)
592 assert length(res) == 1
597 get(conn, "/api/v1/timelines/list/#{list.id}?max_id=#{first["id"]}&limit=30")
598 |> json_response_and_validate_schema(:ok)
600 assert length(res) == 29
603 test "list timeline", %{user: user, conn: conn} do
604 other_user = insert(:user)
605 {:ok, _activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
606 {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
607 {:ok, list} = Pleroma.List.create("name", user)
608 {:ok, list} = Pleroma.List.follow(list, other_user)
610 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
612 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
614 assert id == to_string(activity_two.id)
617 test "list timeline does not leak non-public statuses for unfollowed users", %{
621 other_user = insert(:user)
622 {:ok, activity_one} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
624 {:ok, _activity_two} =
625 CommonAPI.post(other_user, %{
626 status: "Marisa is cute.",
627 visibility: "private"
630 {:ok, list} = Pleroma.List.create("name", user)
631 {:ok, list} = Pleroma.List.follow(list, other_user)
633 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
635 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
637 assert id == to_string(activity_one.id)
640 test "muted emotions", %{user: user, conn: conn} do
641 user2 = insert(:user)
642 user3 = insert(:user)
643 {:ok, activity} = CommonAPI.post(user2, %{status: "."})
645 {:ok, _} = CommonAPI.react_with_emoji(activity.id, user3, "🎅")
646 User.mute(user, user3)
648 {:ok, list} = Pleroma.List.create("name", user)
649 {:ok, list} = Pleroma.List.follow(list, user2)
653 |> get("/api/v1/timelines/list/#{list.id}")
654 |> json_response_and_validate_schema(200)
659 "emoji_reactions" => []
666 |> get("/api/v1/timelines/list/#{list.id}?with_muted=true")
667 |> json_response_and_validate_schema(200)
672 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
678 test "filtering", %{user: user, conn: conn} do
679 {:ok, list} = Pleroma.List.create("name", user)
681 local_user = insert(:user)
682 {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Marisa is stupid."})
683 with_media = create_with_media_activity(local_user)
684 {:ok, list} = Pleroma.List.follow(list, local_user)
686 remote_user = insert(:user, local: false)
687 remote_activity = create_remote_activity(remote_user)
688 {:ok, list} = Pleroma.List.follow(list, remote_user)
692 |> get("/api/v1/timelines/list/#{list.id}")
693 |> json_response_and_validate_schema(200)
694 |> Enum.map(& &1["id"])
696 assert local_activity.id in all_ids
697 assert with_media.id in all_ids
698 assert remote_activity.id in all_ids
702 |> get("/api/v1/timelines/list/#{list.id}?local=true")
703 |> json_response_and_validate_schema(200)
704 |> Enum.map(& &1["id"])
706 assert local_activity.id in only_local_ids
707 assert with_media.id in only_local_ids
708 refute remote_activity.id in only_local_ids
710 only_local_media_ids =
712 |> get("/api/v1/timelines/list/#{list.id}?local=true&only_media=true")
713 |> json_response_and_validate_schema(200)
714 |> Enum.map(& &1["id"])
716 refute local_activity.id in only_local_media_ids
717 assert with_media.id in only_local_media_ids
718 refute remote_activity.id in only_local_media_ids
722 |> get("/api/v1/timelines/list/#{list.id}?remote=true")
723 |> json_response_and_validate_schema(200)
724 |> Enum.map(& &1["id"])
726 refute local_activity.id in remote_ids
727 refute with_media.id in remote_ids
728 assert remote_activity.id in remote_ids
731 |> get("/api/v1/timelines/list/#{list.id}?remote=true&only_media=true")
732 |> json_response_and_validate_schema(200) == []
736 |> get("/api/v1/timelines/list/#{list.id}?only_media=true")
737 |> json_response_and_validate_schema(200)
738 |> Enum.map(& &1["id"])
740 refute local_activity.id in only_media_ids
741 assert with_media.id in only_media_ids
742 refute remote_activity.id in only_media_ids
745 |> get("/api/v1/timelines/list/#{list.id}?only_media=true&local=true&remote=true")
746 |> json_response_and_validate_schema(200) == []
750 describe "hashtag" do
751 setup do: oauth_access(["n/a"])
753 @tag capture_log: true
754 test "hashtag timeline", %{conn: conn} do
755 following = insert(:user)
757 {:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
758 with_media = create_with_media_activity(following)
760 remote = insert(:user, local: false)
761 remote_activity = create_remote_activity(remote)
765 |> get("/api/v1/timelines/tag/2hu")
766 |> json_response_and_validate_schema(:ok)
767 |> Enum.map(& &1["id"])
769 assert activity.id in all_ids
770 assert with_media.id in all_ids
771 assert remote_activity.id in all_ids
773 # works for different capitalization too
776 |> get("/api/v1/timelines/tag/2HU")
777 |> json_response_and_validate_schema(:ok)
778 |> Enum.map(& &1["id"])
780 assert activity.id in all_ids
781 assert with_media.id in all_ids
782 assert remote_activity.id in all_ids
786 |> get("/api/v1/timelines/tag/2hu?local=true")
787 |> json_response_and_validate_schema(:ok)
788 |> Enum.map(& &1["id"])
790 assert activity.id in local_ids
791 assert with_media.id in local_ids
792 refute remote_activity.id in local_ids
796 |> get("/api/v1/timelines/tag/2hu?remote=true")
797 |> json_response_and_validate_schema(:ok)
798 |> Enum.map(& &1["id"])
800 refute activity.id in remote_ids
801 refute with_media.id in remote_ids
802 assert remote_activity.id in remote_ids
806 |> get("/api/v1/timelines/tag/2hu?only_media=true")
807 |> json_response_and_validate_schema(:ok)
808 |> Enum.map(& &1["id"])
810 refute activity.id in media_ids
811 assert with_media.id in media_ids
812 refute remote_activity.id in media_ids
816 |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true")
817 |> json_response_and_validate_schema(:ok)
818 |> Enum.map(& &1["id"])
820 refute activity.id in media_local_ids
821 assert with_media.id in media_local_ids
822 refute remote_activity.id in media_local_ids
826 |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true&remote=true")
827 |> json_response_and_validate_schema(:ok)
828 |> Enum.map(& &1["id"])
830 refute activity.id in ids
831 refute with_media.id in ids
832 refute remote_activity.id in ids
835 |> get("/api/v1/timelines/tag/2hu?only_media=true&remote=true")
836 |> json_response_and_validate_schema(:ok) == []
839 test "multi-hashtag timeline", %{conn: conn} do
842 {:ok, activity_test} = CommonAPI.post(user, %{status: "#test"})
843 {:ok, activity_test1} = CommonAPI.post(user, %{status: "#test #test1"})
844 {:ok, activity_none} = CommonAPI.post(user, %{status: "#test #none"})
846 any_test = get(conn, "/api/v1/timelines/tag/test?any[]=test1")
848 [status_none, status_test1, status_test] = json_response_and_validate_schema(any_test, :ok)
850 assert to_string(activity_test.id) == status_test["id"]
851 assert to_string(activity_test1.id) == status_test1["id"]
852 assert to_string(activity_none.id) == status_none["id"]
854 restricted_test = get(conn, "/api/v1/timelines/tag/test?all[]=test1&none[]=none")
856 assert [status_test1] == json_response_and_validate_schema(restricted_test, :ok)
858 all_test = get(conn, "/api/v1/timelines/tag/test?all[]=none")
860 assert [status_none] == json_response_and_validate_schema(all_test, :ok)
863 test "muted emotions", %{conn: conn} do
865 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
869 |> assign(:user, user)
870 |> assign(:token, token)
872 other_user = insert(:user)
873 {:ok, activity} = CommonAPI.post(user, %{status: "test #2hu"})
875 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
876 User.mute(user, other_user)
880 |> get("/api/v1/timelines/tag/2hu")
881 |> json_response_and_validate_schema(200)
886 "emoji_reactions" => []
893 |> get("/api/v1/timelines/tag/2hu?with_muted=true")
894 |> json_response_and_validate_schema(200)
899 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
906 describe "hashtag timeline handling of :restrict_unauthenticated setting" do
909 {:ok, activity1} = CommonAPI.post(user, %{status: "test #tag1"})
910 {:ok, _activity2} = CommonAPI.post(user, %{status: "test #tag1"})
913 |> Ecto.Changeset.change(%{local: false})
914 |> Pleroma.Repo.update()
916 base_uri = "/api/v1/timelines/tag/tag1"
917 error_response = %{"error" => "authorization required for timeline view"}
919 %{base_uri: base_uri, error_response: error_response}
922 defp ensure_authenticated_access(base_uri) do
923 %{conn: auth_conn} = oauth_access(["read:statuses"])
925 res_conn = get(auth_conn, "#{base_uri}?local=true")
926 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
928 res_conn = get(auth_conn, "#{base_uri}?local=false")
929 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
932 test "with default settings on private instances, returns 403 for unauthenticated users", %{
935 error_response: error_response
937 clear_config([:instance, :public], false)
938 clear_config([:restrict_unauthenticated, :timelines])
940 for local <- [true, false] do
941 res_conn = get(conn, "#{base_uri}?local=#{local}")
943 assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
946 ensure_authenticated_access(base_uri)
949 test "with `%{local: true, federated: true}`, returns 403 for unauthenticated users", %{
952 error_response: error_response
954 clear_config([:restrict_unauthenticated, :timelines, :local], true)
955 clear_config([:restrict_unauthenticated, :timelines, :federated], true)
957 for local <- [true, false] do
958 res_conn = get(conn, "#{base_uri}?local=#{local}")
960 assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
963 ensure_authenticated_access(base_uri)
966 test "with `%{local: false, federated: true}`, forbids unauthenticated access to federated timeline",
967 %{conn: conn, base_uri: base_uri, error_response: error_response} do
968 clear_config([:restrict_unauthenticated, :timelines, :local], false)
969 clear_config([:restrict_unauthenticated, :timelines, :federated], true)
971 res_conn = get(conn, "#{base_uri}?local=true")
972 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
974 res_conn = get(conn, "#{base_uri}?local=false")
975 assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
977 ensure_authenticated_access(base_uri)
980 test "with `%{local: true, federated: false}`, forbids unauthenticated access to public timeline" <>
981 "(but not to local public activities which are delivered as part of federated timeline)",
982 %{conn: conn, base_uri: base_uri, error_response: error_response} do
983 clear_config([:restrict_unauthenticated, :timelines, :local], true)
984 clear_config([:restrict_unauthenticated, :timelines, :federated], false)
986 res_conn = get(conn, "#{base_uri}?local=true")
987 assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
989 # Note: local activities get delivered as part of federated timeline
990 res_conn = get(conn, "#{base_uri}?local=false")
991 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
993 ensure_authenticated_access(base_uri)
997 defp create_remote_activity(user) do
1002 "https://www.w3.org/ns/activitystreams#Public",
1003 User.ap_followers(user)
1009 insert(:note_activity, %{
1012 "https://www.w3.org/ns/activitystreams#Public",
1013 User.ap_followers(user)
1020 defp create_with_media_activity(user) do
1021 obj = insert(:attachment_note, user: user)
1023 insert(:note_activity, %{
1025 recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(user)],