Merge branch 'optimize-command_available' into 'develop'
[akkoma] / test / pleroma / web / mastodon_api / controllers / timeline_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
6 use Pleroma.Web.ConnCase
7
8 import Pleroma.Factory
9 import Tesla.Mock
10
11 alias Pleroma.User
12 alias Pleroma.Web.CommonAPI
13
14 setup do
15 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
16 :ok
17 end
18
19 describe "home" do
20 setup do: oauth_access(["read:statuses"])
21
22 test "does NOT embed account/pleroma/relationship in statuses", %{
23 user: user,
24 conn: conn
25 } do
26 other_user = insert(:user)
27
28 {:ok, _} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
29
30 response =
31 conn
32 |> assign(:user, user)
33 |> get("/api/v1/timelines/home")
34 |> json_response_and_validate_schema(200)
35
36 assert Enum.all?(response, fn n ->
37 get_in(n, ["account", "pleroma", "relationship"]) == %{}
38 end)
39 end
40
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"})
44
45 {:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
46
47 {:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
48
49 conn = get(conn, "/api/v1/timelines/home?exclude_visibilities[]=direct")
50
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
56 end
57
58 test "muted emotions", %{user: user, conn: conn} do
59 other_user = insert(:user)
60 {:ok, activity} = CommonAPI.post(user, %{status: "."})
61
62 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
63 User.mute(user, other_user)
64
65 result =
66 conn
67 |> assign(:user, user)
68 |> get("/api/v1/timelines/home")
69 |> json_response_and_validate_schema(200)
70
71 assert [
72 %{
73 "pleroma" => %{
74 "emoji_reactions" => []
75 }
76 }
77 ] = result
78
79 result =
80 conn
81 |> assign(:user, user)
82 |> get("/api/v1/timelines/home?with_muted=true")
83 |> json_response_and_validate_schema(200)
84
85 assert [
86 %{
87 "pleroma" => %{
88 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
89 }
90 }
91 ] = result
92 end
93 end
94
95 describe "public" do
96 @tag capture_log: true
97 test "the public timeline", %{conn: conn} do
98 user = insert(:user)
99
100 {:ok, activity} = CommonAPI.post(user, %{status: "test"})
101
102 _activity = insert(:note_activity, local: false)
103
104 conn = get(conn, "/api/v1/timelines/public?local=False")
105
106 assert length(json_response_and_validate_schema(conn, :ok)) == 2
107
108 conn = get(build_conn(), "/api/v1/timelines/public?local=True")
109
110 assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
111
112 conn = get(build_conn(), "/api/v1/timelines/public?local=1")
113
114 assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
115
116 # does not contain repeats
117 {:ok, _} = CommonAPI.repeat(activity.id, user)
118
119 conn = get(build_conn(), "/api/v1/timelines/public?local=true")
120
121 assert [_] = json_response_and_validate_schema(conn, :ok)
122 end
123
124 test "the public timeline includes only public statuses for an authenticated user" do
125 %{user: user, conn: conn} = oauth_access(["read:statuses"])
126
127 {:ok, _activity} = CommonAPI.post(user, %{status: "test"})
128 {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "private"})
129 {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "unlisted"})
130 {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
131
132 res_conn = get(conn, "/api/v1/timelines/public")
133 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
134 end
135
136 test "doesn't return replies if follower is posting with blocked user" do
137 %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
138 [blockee, friend] = insert_list(2, :user)
139 {:ok, blocker, friend} = User.follow(blocker, friend)
140 {:ok, _} = User.block(blocker, blockee)
141
142 conn = assign(conn, :user, blocker)
143
144 {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
145
146 {:ok, reply_from_blockee} =
147 CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
148
149 {:ok, _reply_from_friend} =
150 CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
151
152 # Still shows replies from yourself
153 {:ok, %{id: reply_from_me}} =
154 CommonAPI.post(blocker, %{status: "status", in_reply_to_status_id: reply_from_blockee})
155
156 response =
157 get(conn, "/api/v1/timelines/public")
158 |> json_response_and_validate_schema(200)
159
160 assert length(response) == 2
161 [%{"id" => ^reply_from_me}, %{"id" => ^activity_id}] = response
162 end
163
164 test "doesn't return replies if follow is posting with users from blocked domain" do
165 %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
166 friend = insert(:user)
167 blockee = insert(:user, ap_id: "https://example.com/users/blocked")
168 {:ok, blocker, friend} = User.follow(blocker, friend)
169 {:ok, blocker} = User.block_domain(blocker, "example.com")
170
171 conn = assign(conn, :user, blocker)
172
173 {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
174
175 {:ok, reply_from_blockee} =
176 CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
177
178 {:ok, _reply_from_friend} =
179 CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
180
181 res_conn = get(conn, "/api/v1/timelines/public")
182
183 activities = json_response_and_validate_schema(res_conn, 200)
184 [%{"id" => ^activity_id}] = activities
185 end
186
187 test "can be filtered by instance", %{conn: conn} do
188 user = insert(:user, ap_id: "https://lain.com/users/lain")
189 insert(:note_activity, local: false)
190 insert(:note_activity, local: false)
191
192 {:ok, _} = CommonAPI.post(user, %{status: "test"})
193
194 conn = get(conn, "/api/v1/timelines/public?instance=lain.com")
195
196 assert length(json_response_and_validate_schema(conn, :ok)) == 1
197 end
198
199 test "muted emotions", %{conn: conn} do
200 user = insert(:user)
201 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
202
203 conn =
204 conn
205 |> assign(:user, user)
206 |> assign(:token, token)
207
208 other_user = insert(:user)
209 {:ok, activity} = CommonAPI.post(user, %{status: "."})
210
211 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
212 User.mute(user, other_user)
213
214 result =
215 conn
216 |> get("/api/v1/timelines/public")
217 |> json_response_and_validate_schema(200)
218
219 assert [
220 %{
221 "pleroma" => %{
222 "emoji_reactions" => []
223 }
224 }
225 ] = result
226
227 result =
228 conn
229 |> get("/api/v1/timelines/public?with_muted=true")
230 |> json_response_and_validate_schema(200)
231
232 assert [
233 %{
234 "pleroma" => %{
235 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
236 }
237 }
238 ] = result
239 end
240 end
241
242 defp local_and_remote_activities do
243 insert(:note_activity)
244 insert(:note_activity, local: false)
245 :ok
246 end
247
248 describe "public with restrict unauthenticated timeline for local and federated timelines" do
249 setup do: local_and_remote_activities()
250
251 setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
252
253 setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
254
255 test "if user is unauthenticated", %{conn: conn} do
256 res_conn = get(conn, "/api/v1/timelines/public?local=true")
257
258 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
259 "error" => "authorization required for timeline view"
260 }
261
262 res_conn = get(conn, "/api/v1/timelines/public?local=false")
263
264 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
265 "error" => "authorization required for timeline view"
266 }
267 end
268
269 test "if user is authenticated" do
270 %{conn: conn} = oauth_access(["read:statuses"])
271
272 res_conn = get(conn, "/api/v1/timelines/public?local=true")
273 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
274
275 res_conn = get(conn, "/api/v1/timelines/public?local=false")
276 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
277 end
278 end
279
280 describe "public with restrict unauthenticated timeline for local" do
281 setup do: local_and_remote_activities()
282
283 setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
284
285 test "if user is unauthenticated", %{conn: conn} do
286 res_conn = get(conn, "/api/v1/timelines/public?local=true")
287
288 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
289 "error" => "authorization required for timeline view"
290 }
291
292 res_conn = get(conn, "/api/v1/timelines/public?local=false")
293 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
294 end
295
296 test "if user is authenticated", %{conn: _conn} do
297 %{conn: conn} = oauth_access(["read:statuses"])
298
299 res_conn = get(conn, "/api/v1/timelines/public?local=true")
300 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
301
302 res_conn = get(conn, "/api/v1/timelines/public?local=false")
303 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
304 end
305 end
306
307 describe "public with restrict unauthenticated timeline for remote" do
308 setup do: local_and_remote_activities()
309
310 setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
311
312 test "if user is unauthenticated", %{conn: conn} do
313 res_conn = get(conn, "/api/v1/timelines/public?local=true")
314 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
315
316 res_conn = get(conn, "/api/v1/timelines/public?local=false")
317
318 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
319 "error" => "authorization required for timeline view"
320 }
321 end
322
323 test "if user is authenticated", %{conn: _conn} do
324 %{conn: conn} = oauth_access(["read:statuses"])
325
326 res_conn = get(conn, "/api/v1/timelines/public?local=true")
327 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
328
329 res_conn = get(conn, "/api/v1/timelines/public?local=false")
330 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
331 end
332 end
333
334 describe "direct" do
335 test "direct timeline", %{conn: conn} do
336 user_one = insert(:user)
337 user_two = insert(:user)
338
339 {:ok, user_two, user_one} = User.follow(user_two, user_one)
340
341 {:ok, direct} =
342 CommonAPI.post(user_one, %{
343 status: "Hi @#{user_two.nickname}!",
344 visibility: "direct"
345 })
346
347 {:ok, _follower_only} =
348 CommonAPI.post(user_one, %{
349 status: "Hi @#{user_two.nickname}!",
350 visibility: "private"
351 })
352
353 conn_user_two =
354 conn
355 |> assign(:user, user_two)
356 |> assign(:token, insert(:oauth_token, user: user_two, scopes: ["read:statuses"]))
357
358 # Only direct should be visible here
359 res_conn = get(conn_user_two, "api/v1/timelines/direct")
360
361 assert [status] = json_response_and_validate_schema(res_conn, :ok)
362
363 assert %{"visibility" => "direct"} = status
364 assert status["url"] != direct.data["id"]
365
366 # User should be able to see their own direct message
367 res_conn =
368 build_conn()
369 |> assign(:user, user_one)
370 |> assign(:token, insert(:oauth_token, user: user_one, scopes: ["read:statuses"]))
371 |> get("api/v1/timelines/direct")
372
373 [status] = json_response_and_validate_schema(res_conn, :ok)
374
375 assert %{"visibility" => "direct"} = status
376
377 # Both should be visible here
378 res_conn = get(conn_user_two, "api/v1/timelines/home")
379
380 [_s1, _s2] = json_response_and_validate_schema(res_conn, :ok)
381
382 # Test pagination
383 Enum.each(1..20, fn _ ->
384 {:ok, _} =
385 CommonAPI.post(user_one, %{
386 status: "Hi @#{user_two.nickname}!",
387 visibility: "direct"
388 })
389 end)
390
391 res_conn = get(conn_user_two, "api/v1/timelines/direct")
392
393 statuses = json_response_and_validate_schema(res_conn, :ok)
394 assert length(statuses) == 20
395
396 max_id = List.last(statuses)["id"]
397
398 res_conn = get(conn_user_two, "api/v1/timelines/direct?max_id=#{max_id}")
399
400 assert [status] = json_response_and_validate_schema(res_conn, :ok)
401
402 assert status["url"] != direct.data["id"]
403 end
404
405 test "doesn't include DMs from blocked users" do
406 %{user: blocker, conn: conn} = oauth_access(["read:statuses"])
407 blocked = insert(:user)
408 other_user = insert(:user)
409 {:ok, _user_relationship} = User.block(blocker, blocked)
410
411 {:ok, _blocked_direct} =
412 CommonAPI.post(blocked, %{
413 status: "Hi @#{blocker.nickname}!",
414 visibility: "direct"
415 })
416
417 {:ok, direct} =
418 CommonAPI.post(other_user, %{
419 status: "Hi @#{blocker.nickname}!",
420 visibility: "direct"
421 })
422
423 res_conn = get(conn, "api/v1/timelines/direct")
424
425 [status] = json_response_and_validate_schema(res_conn, :ok)
426 assert status["id"] == direct.id
427 end
428 end
429
430 describe "list" do
431 setup do: oauth_access(["read:lists"])
432
433 test "does not contain retoots", %{user: user, conn: conn} do
434 other_user = insert(:user)
435 {:ok, activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
436 {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is stupid."})
437 {:ok, _} = CommonAPI.repeat(activity_one.id, other_user)
438
439 {:ok, list} = Pleroma.List.create("name", user)
440 {:ok, list} = Pleroma.List.follow(list, other_user)
441
442 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
443
444 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
445
446 assert id == to_string(activity_two.id)
447 end
448
449 test "works with pagination", %{user: user, conn: conn} do
450 other_user = insert(:user)
451 {:ok, list} = Pleroma.List.create("name", user)
452 {:ok, list} = Pleroma.List.follow(list, other_user)
453
454 Enum.each(1..30, fn i ->
455 CommonAPI.post(other_user, %{status: "post number #{i}"})
456 end)
457
458 res =
459 get(conn, "/api/v1/timelines/list/#{list.id}?limit=1")
460 |> json_response_and_validate_schema(:ok)
461
462 assert length(res) == 1
463
464 [first] = res
465
466 res =
467 get(conn, "/api/v1/timelines/list/#{list.id}?max_id=#{first["id"]}&limit=30")
468 |> json_response_and_validate_schema(:ok)
469
470 assert length(res) == 29
471 end
472
473 test "list timeline", %{user: user, conn: conn} do
474 other_user = insert(:user)
475 {:ok, _activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
476 {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
477 {:ok, list} = Pleroma.List.create("name", user)
478 {:ok, list} = Pleroma.List.follow(list, other_user)
479
480 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
481
482 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
483
484 assert id == to_string(activity_two.id)
485 end
486
487 test "list timeline does not leak non-public statuses for unfollowed users", %{
488 user: user,
489 conn: conn
490 } do
491 other_user = insert(:user)
492 {:ok, activity_one} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
493
494 {:ok, _activity_two} =
495 CommonAPI.post(other_user, %{
496 status: "Marisa is cute.",
497 visibility: "private"
498 })
499
500 {:ok, list} = Pleroma.List.create("name", user)
501 {:ok, list} = Pleroma.List.follow(list, other_user)
502
503 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
504
505 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
506
507 assert id == to_string(activity_one.id)
508 end
509
510 test "muted emotions", %{user: user, conn: conn} do
511 user2 = insert(:user)
512 user3 = insert(:user)
513 {:ok, activity} = CommonAPI.post(user2, %{status: "."})
514
515 {:ok, _} = CommonAPI.react_with_emoji(activity.id, user3, "🎅")
516 User.mute(user, user3)
517
518 {:ok, list} = Pleroma.List.create("name", user)
519 {:ok, list} = Pleroma.List.follow(list, user2)
520
521 result =
522 conn
523 |> get("/api/v1/timelines/list/#{list.id}")
524 |> json_response_and_validate_schema(200)
525
526 assert [
527 %{
528 "pleroma" => %{
529 "emoji_reactions" => []
530 }
531 }
532 ] = result
533
534 result =
535 conn
536 |> get("/api/v1/timelines/list/#{list.id}?with_muted=true")
537 |> json_response_and_validate_schema(200)
538
539 assert [
540 %{
541 "pleroma" => %{
542 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
543 }
544 }
545 ] = result
546 end
547 end
548
549 describe "hashtag" do
550 setup do: oauth_access(["n/a"])
551
552 @tag capture_log: true
553 test "hashtag timeline", %{conn: conn} do
554 following = insert(:user)
555
556 {:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
557
558 nconn = get(conn, "/api/v1/timelines/tag/2hu")
559
560 assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
561
562 assert id == to_string(activity.id)
563
564 # works for different capitalization too
565 nconn = get(conn, "/api/v1/timelines/tag/2HU")
566
567 assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
568
569 assert id == to_string(activity.id)
570 end
571
572 test "multi-hashtag timeline", %{conn: conn} do
573 user = insert(:user)
574
575 {:ok, activity_test} = CommonAPI.post(user, %{status: "#test"})
576 {:ok, activity_test1} = CommonAPI.post(user, %{status: "#test #test1"})
577 {:ok, activity_none} = CommonAPI.post(user, %{status: "#test #none"})
578
579 any_test = get(conn, "/api/v1/timelines/tag/test?any[]=test1")
580
581 [status_none, status_test1, status_test] = json_response_and_validate_schema(any_test, :ok)
582
583 assert to_string(activity_test.id) == status_test["id"]
584 assert to_string(activity_test1.id) == status_test1["id"]
585 assert to_string(activity_none.id) == status_none["id"]
586
587 restricted_test = get(conn, "/api/v1/timelines/tag/test?all[]=test1&none[]=none")
588
589 assert [status_test1] == json_response_and_validate_schema(restricted_test, :ok)
590
591 all_test = get(conn, "/api/v1/timelines/tag/test?all[]=none")
592
593 assert [status_none] == json_response_and_validate_schema(all_test, :ok)
594 end
595
596 test "muted emotions", %{conn: conn} do
597 user = insert(:user)
598 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
599
600 conn =
601 conn
602 |> assign(:user, user)
603 |> assign(:token, token)
604
605 other_user = insert(:user)
606 {:ok, activity} = CommonAPI.post(user, %{status: "test #2hu"})
607
608 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
609 User.mute(user, other_user)
610
611 result =
612 conn
613 |> get("/api/v1/timelines/tag/2hu")
614 |> json_response_and_validate_schema(200)
615
616 assert [
617 %{
618 "pleroma" => %{
619 "emoji_reactions" => []
620 }
621 }
622 ] = result
623
624 result =
625 conn
626 |> get("/api/v1/timelines/tag/2hu?with_muted=true")
627 |> json_response_and_validate_schema(200)
628
629 assert [
630 %{
631 "pleroma" => %{
632 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
633 }
634 }
635 ] = result
636 end
637 end
638
639 describe "hashtag timeline handling of :restrict_unauthenticated setting" do
640 setup do
641 user = insert(:user)
642 {:ok, activity1} = CommonAPI.post(user, %{status: "test #tag1"})
643 {:ok, _activity2} = CommonAPI.post(user, %{status: "test #tag1"})
644
645 activity1
646 |> Ecto.Changeset.change(%{local: false})
647 |> Pleroma.Repo.update()
648
649 base_uri = "/api/v1/timelines/tag/tag1"
650 error_response = %{"error" => "authorization required for timeline view"}
651
652 %{base_uri: base_uri, error_response: error_response}
653 end
654
655 defp ensure_authenticated_access(base_uri) do
656 %{conn: auth_conn} = oauth_access(["read:statuses"])
657
658 res_conn = get(auth_conn, "#{base_uri}?local=true")
659 assert length(json_response(res_conn, 200)) == 1
660
661 res_conn = get(auth_conn, "#{base_uri}?local=false")
662 assert length(json_response(res_conn, 200)) == 2
663 end
664
665 test "with default settings on private instances, returns 403 for unauthenticated users", %{
666 conn: conn,
667 base_uri: base_uri,
668 error_response: error_response
669 } do
670 clear_config([:instance, :public], false)
671 clear_config([:restrict_unauthenticated, :timelines])
672
673 for local <- [true, false] do
674 res_conn = get(conn, "#{base_uri}?local=#{local}")
675
676 assert json_response(res_conn, :unauthorized) == error_response
677 end
678
679 ensure_authenticated_access(base_uri)
680 end
681
682 test "with `%{local: true, federated: true}`, returns 403 for unauthenticated users", %{
683 conn: conn,
684 base_uri: base_uri,
685 error_response: error_response
686 } do
687 clear_config([:restrict_unauthenticated, :timelines, :local], true)
688 clear_config([:restrict_unauthenticated, :timelines, :federated], true)
689
690 for local <- [true, false] do
691 res_conn = get(conn, "#{base_uri}?local=#{local}")
692
693 assert json_response(res_conn, :unauthorized) == error_response
694 end
695
696 ensure_authenticated_access(base_uri)
697 end
698
699 test "with `%{local: false, federated: true}`, forbids unauthenticated access to federated timeline",
700 %{conn: conn, base_uri: base_uri, error_response: error_response} do
701 clear_config([:restrict_unauthenticated, :timelines, :local], false)
702 clear_config([:restrict_unauthenticated, :timelines, :federated], true)
703
704 res_conn = get(conn, "#{base_uri}?local=true")
705 assert length(json_response(res_conn, 200)) == 1
706
707 res_conn = get(conn, "#{base_uri}?local=false")
708 assert json_response(res_conn, :unauthorized) == error_response
709
710 ensure_authenticated_access(base_uri)
711 end
712
713 test "with `%{local: true, federated: false}`, forbids unauthenticated access to public timeline" <>
714 "(but not to local public activities which are delivered as part of federated timeline)",
715 %{conn: conn, base_uri: base_uri, error_response: error_response} do
716 clear_config([:restrict_unauthenticated, :timelines, :local], true)
717 clear_config([:restrict_unauthenticated, :timelines, :federated], false)
718
719 res_conn = get(conn, "#{base_uri}?local=true")
720 assert json_response(res_conn, :unauthorized) == error_response
721
722 # Note: local activities get delivered as part of federated timeline
723 res_conn = get(conn, "#{base_uri}?local=false")
724 assert length(json_response(res_conn, 200)) == 2
725
726 ensure_authenticated_access(base_uri)
727 end
728 end
729 end