X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Fmastodon_api%2Fcontrollers%2Ftimeline_controller_test.exs;h=aa9006681823441f93c963028078910c9a8701cd;hb=07a48b9293e4046c50b5d424d60a1bf16c7cc198;hp=7ef08f258aaf68e12e17331bf1a21c2d05855fdd;hpb=cb6e7359af353bb19262ac94b92b41a62819523e;p=akkoma diff --git a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs index 7ef08f258..aa9006681 100644 --- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs @@ -288,7 +288,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do get(conn, "/api/v1/timelines/public") |> json_response_and_validate_schema(200) - assert length(response) == 0 + assert response == [] end test "doesn't return replies if follow is posting with users from blocked domain" do @@ -367,6 +367,47 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do } ] = result end + + test "should return local-only posts for authenticated users" do + user = insert(:user) + %{user: _reader, conn: conn} = oauth_access(["read:statuses"]) + + {:ok, %{id: id}} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"}) + + result = + conn + |> get("/api/v1/timelines/public") + |> json_response_and_validate_schema(200) + + assert [%{"id" => ^id}] = result + end + + test "should not return local-only posts for users without read:statuses" do + user = insert(:user) + %{user: _reader, conn: conn} = oauth_access([]) + + {:ok, _activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"}) + + result = + conn + |> get("/api/v1/timelines/public") + |> json_response_and_validate_schema(200) + + assert [] = result + end + + test "should not return local-only posts for anonymous users" do + user = insert(:user) + + {:ok, _activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"}) + + result = + build_conn() + |> get("/api/v1/timelines/public") + |> json_response_and_validate_schema(200) + + assert [] = result + end end defp local_and_remote_activities do @@ -486,7 +527,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do |> assign(:token, insert(:oauth_token, user: user_two, scopes: ["read:statuses"])) # Only direct should be visible here - res_conn = get(conn_user_two, "api/v1/timelines/direct") + res_conn = get(conn_user_two, "/api/v1/timelines/direct") assert [status] = json_response_and_validate_schema(res_conn, :ok) @@ -498,14 +539,14 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do build_conn() |> assign(:user, user_one) |> assign(:token, insert(:oauth_token, user: user_one, scopes: ["read:statuses"])) - |> get("api/v1/timelines/direct") + |> get("/api/v1/timelines/direct") [status] = json_response_and_validate_schema(res_conn, :ok) assert %{"visibility" => "direct"} = status # Both should be visible here - res_conn = get(conn_user_two, "api/v1/timelines/home") + res_conn = get(conn_user_two, "/api/v1/timelines/home") [_s1, _s2] = json_response_and_validate_schema(res_conn, :ok) @@ -518,14 +559,14 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do }) end) - res_conn = get(conn_user_two, "api/v1/timelines/direct") + res_conn = get(conn_user_two, "/api/v1/timelines/direct") statuses = json_response_and_validate_schema(res_conn, :ok) assert length(statuses) == 20 max_id = List.last(statuses)["id"] - res_conn = get(conn_user_two, "api/v1/timelines/direct?max_id=#{max_id}") + res_conn = get(conn_user_two, "/api/v1/timelines/direct?max_id=#{max_id}") assert [status] = json_response_and_validate_schema(res_conn, :ok) @@ -550,7 +591,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do visibility: "direct" }) - res_conn = get(conn, "api/v1/timelines/direct") + res_conn = get(conn, "/api/v1/timelines/direct") [status] = json_response_and_validate_schema(res_conn, :ok) assert status["id"] == direct.id @@ -977,9 +1018,9 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do ensure_authenticated_access(base_uri) end - test "with `%{local: true, federated: false}`, forbids unauthenticated access to public timeline" <> - "(but not to local public activities which are delivered as part of federated timeline)", + test "with `%{local: true, federated: false}`, forbids unauthenticated access to public timeline", %{conn: conn, base_uri: base_uri, error_response: error_response} do + # (but not to local public activities which are delivered as part of federated timeline) clear_config([:restrict_unauthenticated, :timelines, :local], true) clear_config([:restrict_unauthenticated, :timelines, :federated], false) @@ -997,18 +1038,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do describe "bubble" do setup do: oauth_access(["read:statuses"]) - test "it returns nothing if no bubble is configured", %{user: user, conn: conn} do - clear_config([:instance, :local_bubble], []) - {:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "public"}) - - conn = get(conn, "/api/v1/timelines/bubble") - - assert [] = json_response_and_validate_schema(conn, :ok) - end - test "filtering", %{conn: conn, user: user} do clear_config([:instance, :local_bubble], []) - local_user = insert(:user) + # our endpoint host has a port in it so let's set the AP ID + local_user = insert(:user, %{ap_id: "https://localhost/users/user"}) remote_user = insert(:user, %{ap_id: "https://example.com/users/remote_user"}) {:ok, user, local_user} = User.follow(user, local_user) {:ok, _user, remote_user} = User.follow(user, remote_user) @@ -1016,15 +1049,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"}) remote_activity = create_remote_activity(remote_user) - resp = - conn - |> get("/api/v1/timelines/bubble") - |> json_response_and_validate_schema(200) - |> Enum.map(& &1["id"]) - - assert Enum.empty?(resp) - - clear_config([:instance, :local_bubble], ["localhost:4001"]) + # If nothing, only include ours + clear_config([:instance, :local_bubble], []) one_instance = conn @@ -1034,7 +1060,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do assert local_activity.id in one_instance - clear_config([:instance, :local_bubble], ["localhost:4001", "example.com"]) + # If we have others, also include theirs + clear_config([:instance, :local_bubble], ["example.com"]) two_instances = conn