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 replies if follow is posting with users from blocked domain" do
277 %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
278 friend = insert(:user)
279 blockee = insert(:user, ap_id: "https://example.com/users/blocked")
280 {:ok, blocker, friend} = User.follow(blocker, friend)
281 {:ok, blocker} = User.block_domain(blocker, "example.com")
283 conn = assign(conn, :user, blocker)
285 {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
287 {:ok, reply_from_blockee} =
288 CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
290 {:ok, _reply_from_friend} =
291 CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
293 res_conn = get(conn, "/api/v1/timelines/public")
295 activities = json_response_and_validate_schema(res_conn, 200)
296 [%{"id" => ^activity_id}] = activities
299 test "can be filtered by instance", %{conn: conn} do
300 user = insert(:user, ap_id: "https://lain.com/users/lain")
301 insert(:note_activity, local: false)
302 insert(:note_activity, local: false)
304 {:ok, _} = CommonAPI.post(user, %{status: "test"})
306 conn = get(conn, "/api/v1/timelines/public?instance=lain.com")
308 assert length(json_response_and_validate_schema(conn, :ok)) == 1
311 test "muted emotions", %{conn: conn} do
313 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
317 |> assign(:user, user)
318 |> assign(:token, token)
320 other_user = insert(:user)
321 {:ok, activity} = CommonAPI.post(user, %{status: "."})
323 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
324 User.mute(user, other_user)
328 |> get("/api/v1/timelines/public")
329 |> json_response_and_validate_schema(200)
334 "emoji_reactions" => []
341 |> get("/api/v1/timelines/public?with_muted=true")
342 |> json_response_and_validate_schema(200)
347 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
354 defp local_and_remote_activities do
355 insert(:note_activity)
356 insert(:note_activity, local: false)
360 describe "public with restrict unauthenticated timeline for local and federated timelines" do
361 setup do: local_and_remote_activities()
363 setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
365 setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
367 test "if user is unauthenticated", %{conn: conn} do
368 res_conn = get(conn, "/api/v1/timelines/public?local=true")
370 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
371 "error" => "authorization required for timeline view"
374 res_conn = get(conn, "/api/v1/timelines/public?local=false")
376 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
377 "error" => "authorization required for timeline view"
381 test "if user is authenticated" do
382 %{conn: conn} = oauth_access(["read:statuses"])
384 res_conn = get(conn, "/api/v1/timelines/public?local=true")
385 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
387 res_conn = get(conn, "/api/v1/timelines/public?local=false")
388 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
392 describe "public with restrict unauthenticated timeline for local" do
393 setup do: local_and_remote_activities()
395 setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
397 test "if user is unauthenticated", %{conn: conn} do
398 res_conn = get(conn, "/api/v1/timelines/public?local=true")
400 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
401 "error" => "authorization required for timeline view"
404 res_conn = get(conn, "/api/v1/timelines/public?local=false")
405 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
408 test "if user is authenticated", %{conn: _conn} do
409 %{conn: conn} = oauth_access(["read:statuses"])
411 res_conn = get(conn, "/api/v1/timelines/public?local=true")
412 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
414 res_conn = get(conn, "/api/v1/timelines/public?local=false")
415 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
419 describe "public with restrict unauthenticated timeline for remote" do
420 setup do: local_and_remote_activities()
422 setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
424 test "if user is unauthenticated", %{conn: conn} do
425 res_conn = get(conn, "/api/v1/timelines/public?local=true")
426 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
428 res_conn = get(conn, "/api/v1/timelines/public?local=false")
430 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
431 "error" => "authorization required for timeline view"
435 test "if user is authenticated", %{conn: _conn} do
436 %{conn: conn} = oauth_access(["read:statuses"])
438 res_conn = get(conn, "/api/v1/timelines/public?local=true")
439 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
441 res_conn = get(conn, "/api/v1/timelines/public?local=false")
442 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
447 test "direct timeline", %{conn: conn} do
448 user_one = insert(:user)
449 user_two = insert(:user)
451 {:ok, user_two, user_one} = User.follow(user_two, user_one)
454 CommonAPI.post(user_one, %{
455 status: "Hi @#{user_two.nickname}!",
459 {:ok, _follower_only} =
460 CommonAPI.post(user_one, %{
461 status: "Hi @#{user_two.nickname}!",
462 visibility: "private"
467 |> assign(:user, user_two)
468 |> assign(:token, insert(:oauth_token, user: user_two, scopes: ["read:statuses"]))
470 # Only direct should be visible here
471 res_conn = get(conn_user_two, "api/v1/timelines/direct")
473 assert [status] = json_response_and_validate_schema(res_conn, :ok)
475 assert %{"visibility" => "direct"} = status
476 assert status["url"] != direct.data["id"]
478 # User should be able to see their own direct message
481 |> assign(:user, user_one)
482 |> assign(:token, insert(:oauth_token, user: user_one, scopes: ["read:statuses"]))
483 |> get("api/v1/timelines/direct")
485 [status] = json_response_and_validate_schema(res_conn, :ok)
487 assert %{"visibility" => "direct"} = status
489 # Both should be visible here
490 res_conn = get(conn_user_two, "api/v1/timelines/home")
492 [_s1, _s2] = json_response_and_validate_schema(res_conn, :ok)
495 Enum.each(1..20, fn _ ->
497 CommonAPI.post(user_one, %{
498 status: "Hi @#{user_two.nickname}!",
503 res_conn = get(conn_user_two, "api/v1/timelines/direct")
505 statuses = json_response_and_validate_schema(res_conn, :ok)
506 assert length(statuses) == 20
508 max_id = List.last(statuses)["id"]
510 res_conn = get(conn_user_two, "api/v1/timelines/direct?max_id=#{max_id}")
512 assert [status] = json_response_and_validate_schema(res_conn, :ok)
514 assert status["url"] != direct.data["id"]
517 test "doesn't include DMs from blocked users" do
518 %{user: blocker, conn: conn} = oauth_access(["read:statuses"])
519 blocked = insert(:user)
520 other_user = insert(:user)
521 {:ok, _user_relationship} = User.block(blocker, blocked)
523 {:ok, _blocked_direct} =
524 CommonAPI.post(blocked, %{
525 status: "Hi @#{blocker.nickname}!",
530 CommonAPI.post(other_user, %{
531 status: "Hi @#{blocker.nickname}!",
535 res_conn = get(conn, "api/v1/timelines/direct")
537 [status] = json_response_and_validate_schema(res_conn, :ok)
538 assert status["id"] == direct.id
543 setup do: oauth_access(["read:lists"])
545 test "does not contain retoots", %{user: user, conn: conn} do
546 other_user = insert(:user)
547 {:ok, activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
548 {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is stupid."})
549 {:ok, _} = CommonAPI.repeat(activity_one.id, other_user)
551 {:ok, list} = Pleroma.List.create("name", user)
552 {:ok, list} = Pleroma.List.follow(list, other_user)
554 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
556 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
558 assert id == to_string(activity_two.id)
561 test "works with pagination", %{user: user, conn: conn} do
562 other_user = insert(:user)
563 {:ok, list} = Pleroma.List.create("name", user)
564 {:ok, list} = Pleroma.List.follow(list, other_user)
566 Enum.each(1..30, fn i ->
567 CommonAPI.post(other_user, %{status: "post number #{i}"})
571 get(conn, "/api/v1/timelines/list/#{list.id}?limit=1")
572 |> json_response_and_validate_schema(:ok)
574 assert length(res) == 1
579 get(conn, "/api/v1/timelines/list/#{list.id}?max_id=#{first["id"]}&limit=30")
580 |> json_response_and_validate_schema(:ok)
582 assert length(res) == 29
585 test "list timeline", %{user: user, conn: conn} do
586 other_user = insert(:user)
587 {:ok, _activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
588 {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
589 {:ok, list} = Pleroma.List.create("name", user)
590 {:ok, list} = Pleroma.List.follow(list, other_user)
592 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
594 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
596 assert id == to_string(activity_two.id)
599 test "list timeline does not leak non-public statuses for unfollowed users", %{
603 other_user = insert(:user)
604 {:ok, activity_one} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
606 {:ok, _activity_two} =
607 CommonAPI.post(other_user, %{
608 status: "Marisa is cute.",
609 visibility: "private"
612 {:ok, list} = Pleroma.List.create("name", user)
613 {:ok, list} = Pleroma.List.follow(list, other_user)
615 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
617 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
619 assert id == to_string(activity_one.id)
622 test "muted emotions", %{user: user, conn: conn} do
623 user2 = insert(:user)
624 user3 = insert(:user)
625 {:ok, activity} = CommonAPI.post(user2, %{status: "."})
627 {:ok, _} = CommonAPI.react_with_emoji(activity.id, user3, "🎅")
628 User.mute(user, user3)
630 {:ok, list} = Pleroma.List.create("name", user)
631 {:ok, list} = Pleroma.List.follow(list, user2)
635 |> get("/api/v1/timelines/list/#{list.id}")
636 |> json_response_and_validate_schema(200)
641 "emoji_reactions" => []
648 |> get("/api/v1/timelines/list/#{list.id}?with_muted=true")
649 |> json_response_and_validate_schema(200)
654 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
660 test "filtering", %{user: user, conn: conn} do
661 {:ok, list} = Pleroma.List.create("name", user)
663 local_user = insert(:user)
664 {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Marisa is stupid."})
665 with_media = create_with_media_activity(local_user)
666 {:ok, list} = Pleroma.List.follow(list, local_user)
668 remote_user = insert(:user, local: false)
669 remote_activity = create_remote_activity(remote_user)
670 {:ok, list} = Pleroma.List.follow(list, remote_user)
674 |> get("/api/v1/timelines/list/#{list.id}")
675 |> json_response_and_validate_schema(200)
676 |> Enum.map(& &1["id"])
678 assert local_activity.id in all_ids
679 assert with_media.id in all_ids
680 assert remote_activity.id in all_ids
684 |> get("/api/v1/timelines/list/#{list.id}?local=true")
685 |> json_response_and_validate_schema(200)
686 |> Enum.map(& &1["id"])
688 assert local_activity.id in only_local_ids
689 assert with_media.id in only_local_ids
690 refute remote_activity.id in only_local_ids
692 only_local_media_ids =
694 |> get("/api/v1/timelines/list/#{list.id}?local=true&only_media=true")
695 |> json_response_and_validate_schema(200)
696 |> Enum.map(& &1["id"])
698 refute local_activity.id in only_local_media_ids
699 assert with_media.id in only_local_media_ids
700 refute remote_activity.id in only_local_media_ids
704 |> get("/api/v1/timelines/list/#{list.id}?remote=true")
705 |> json_response_and_validate_schema(200)
706 |> Enum.map(& &1["id"])
708 refute local_activity.id in remote_ids
709 refute with_media.id in remote_ids
710 assert remote_activity.id in remote_ids
713 |> get("/api/v1/timelines/list/#{list.id}?remote=true&only_media=true")
714 |> json_response_and_validate_schema(200) == []
718 |> get("/api/v1/timelines/list/#{list.id}?only_media=true")
719 |> json_response_and_validate_schema(200)
720 |> Enum.map(& &1["id"])
722 refute local_activity.id in only_media_ids
723 assert with_media.id in only_media_ids
724 refute remote_activity.id in only_media_ids
727 |> get("/api/v1/timelines/list/#{list.id}?only_media=true&local=true&remote=true")
728 |> json_response_and_validate_schema(200) == []
732 describe "hashtag" do
733 setup do: oauth_access(["n/a"])
735 @tag capture_log: true
736 test "hashtag timeline", %{conn: conn} do
737 following = insert(:user)
739 {:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
740 with_media = create_with_media_activity(following)
742 remote = insert(:user, local: false)
743 remote_activity = create_remote_activity(remote)
747 |> get("/api/v1/timelines/tag/2hu")
748 |> json_response_and_validate_schema(:ok)
749 |> Enum.map(& &1["id"])
751 assert activity.id in all_ids
752 assert with_media.id in all_ids
753 assert remote_activity.id in all_ids
755 # works for different capitalization too
758 |> get("/api/v1/timelines/tag/2HU")
759 |> json_response_and_validate_schema(:ok)
760 |> Enum.map(& &1["id"])
762 assert activity.id in all_ids
763 assert with_media.id in all_ids
764 assert remote_activity.id in all_ids
768 |> get("/api/v1/timelines/tag/2hu?local=true")
769 |> json_response_and_validate_schema(:ok)
770 |> Enum.map(& &1["id"])
772 assert activity.id in local_ids
773 assert with_media.id in local_ids
774 refute remote_activity.id in local_ids
778 |> get("/api/v1/timelines/tag/2hu?remote=true")
779 |> json_response_and_validate_schema(:ok)
780 |> Enum.map(& &1["id"])
782 refute activity.id in remote_ids
783 refute with_media.id in remote_ids
784 assert remote_activity.id in remote_ids
788 |> get("/api/v1/timelines/tag/2hu?only_media=true")
789 |> json_response_and_validate_schema(:ok)
790 |> Enum.map(& &1["id"])
792 refute activity.id in media_ids
793 assert with_media.id in media_ids
794 refute remote_activity.id in media_ids
798 |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true")
799 |> json_response_and_validate_schema(:ok)
800 |> Enum.map(& &1["id"])
802 refute activity.id in media_local_ids
803 assert with_media.id in media_local_ids
804 refute remote_activity.id in media_local_ids
808 |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true&remote=true")
809 |> json_response_and_validate_schema(:ok)
810 |> Enum.map(& &1["id"])
812 refute activity.id in ids
813 refute with_media.id in ids
814 refute remote_activity.id in ids
817 |> get("/api/v1/timelines/tag/2hu?only_media=true&remote=true")
818 |> json_response_and_validate_schema(:ok) == []
821 test "multi-hashtag timeline", %{conn: conn} do
824 {:ok, activity_test} = CommonAPI.post(user, %{status: "#test"})
825 {:ok, activity_test1} = CommonAPI.post(user, %{status: "#test #test1"})
826 {:ok, activity_none} = CommonAPI.post(user, %{status: "#test #none"})
828 any_test = get(conn, "/api/v1/timelines/tag/test?any[]=test1")
830 [status_none, status_test1, status_test] = json_response_and_validate_schema(any_test, :ok)
832 assert to_string(activity_test.id) == status_test["id"]
833 assert to_string(activity_test1.id) == status_test1["id"]
834 assert to_string(activity_none.id) == status_none["id"]
836 restricted_test = get(conn, "/api/v1/timelines/tag/test?all[]=test1&none[]=none")
838 assert [status_test1] == json_response_and_validate_schema(restricted_test, :ok)
840 all_test = get(conn, "/api/v1/timelines/tag/test?all[]=none")
842 assert [status_none] == json_response_and_validate_schema(all_test, :ok)
845 test "muted emotions", %{conn: conn} do
847 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
851 |> assign(:user, user)
852 |> assign(:token, token)
854 other_user = insert(:user)
855 {:ok, activity} = CommonAPI.post(user, %{status: "test #2hu"})
857 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
858 User.mute(user, other_user)
862 |> get("/api/v1/timelines/tag/2hu")
863 |> json_response_and_validate_schema(200)
868 "emoji_reactions" => []
875 |> get("/api/v1/timelines/tag/2hu?with_muted=true")
876 |> json_response_and_validate_schema(200)
881 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
888 describe "hashtag timeline handling of :restrict_unauthenticated setting" do
891 {:ok, activity1} = CommonAPI.post(user, %{status: "test #tag1"})
892 {:ok, _activity2} = CommonAPI.post(user, %{status: "test #tag1"})
895 |> Ecto.Changeset.change(%{local: false})
896 |> Pleroma.Repo.update()
898 base_uri = "/api/v1/timelines/tag/tag1"
899 error_response = %{"error" => "authorization required for timeline view"}
901 %{base_uri: base_uri, error_response: error_response}
904 defp ensure_authenticated_access(base_uri) do
905 %{conn: auth_conn} = oauth_access(["read:statuses"])
907 res_conn = get(auth_conn, "#{base_uri}?local=true")
908 assert length(json_response(res_conn, 200)) == 1
910 res_conn = get(auth_conn, "#{base_uri}?local=false")
911 assert length(json_response(res_conn, 200)) == 2
914 test "with default settings on private instances, returns 403 for unauthenticated users", %{
917 error_response: error_response
919 clear_config([:instance, :public], false)
920 clear_config([:restrict_unauthenticated, :timelines])
922 for local <- [true, false] do
923 res_conn = get(conn, "#{base_uri}?local=#{local}")
925 assert json_response(res_conn, :unauthorized) == error_response
928 ensure_authenticated_access(base_uri)
931 test "with `%{local: true, federated: true}`, returns 403 for unauthenticated users", %{
934 error_response: error_response
936 clear_config([:restrict_unauthenticated, :timelines, :local], true)
937 clear_config([:restrict_unauthenticated, :timelines, :federated], true)
939 for local <- [true, false] do
940 res_conn = get(conn, "#{base_uri}?local=#{local}")
942 assert json_response(res_conn, :unauthorized) == error_response
945 ensure_authenticated_access(base_uri)
948 test "with `%{local: false, federated: true}`, forbids unauthenticated access to federated timeline",
949 %{conn: conn, base_uri: base_uri, error_response: error_response} do
950 clear_config([:restrict_unauthenticated, :timelines, :local], false)
951 clear_config([:restrict_unauthenticated, :timelines, :federated], true)
953 res_conn = get(conn, "#{base_uri}?local=true")
954 assert length(json_response(res_conn, 200)) == 1
956 res_conn = get(conn, "#{base_uri}?local=false")
957 assert json_response(res_conn, :unauthorized) == error_response
959 ensure_authenticated_access(base_uri)
962 test "with `%{local: true, federated: false}`, forbids unauthenticated access to public timeline" <>
963 "(but not to local public activities which are delivered as part of federated timeline)",
964 %{conn: conn, base_uri: base_uri, error_response: error_response} do
965 clear_config([:restrict_unauthenticated, :timelines, :local], true)
966 clear_config([:restrict_unauthenticated, :timelines, :federated], false)
968 res_conn = get(conn, "#{base_uri}?local=true")
969 assert json_response(res_conn, :unauthorized) == error_response
971 # Note: local activities get delivered as part of federated timeline
972 res_conn = get(conn, "#{base_uri}?local=false")
973 assert length(json_response(res_conn, 200)) == 2
975 ensure_authenticated_access(base_uri)
979 defp create_remote_activity(user) do
984 "https://www.w3.org/ns/activitystreams#Public",
985 User.ap_followers(user)
991 insert(:note_activity, %{
994 "https://www.w3.org/ns/activitystreams#Public",
995 User.ap_followers(user)
1002 defp create_with_media_activity(user) do
1003 obj = insert(:attachment_note, user: user)
1005 insert(:note_activity, %{
1007 recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(user)],