X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Fmastodon_api%2Fcontrollers%2Ftimeline_controller_test.exs;h=187982d92572b42b0cb21552bbc353de94aa6132;hb=07ea4d73e12c65cf3fd5c194a8eb1f27900ed17f;hp=75a008f4c7e554a6e62bbc61cb9b119a948d351c;hpb=2cb6dc5a3a3bd7e2326fe632a34b74cb150c5821;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 75a008f4c..187982d92 100644 --- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs @@ -91,110 +91,146 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do ] = result end - test "local/remote filtering", %{conn: conn, user: user} do + test "filtering", %{conn: conn, user: user} do local_user = insert(:user) {:ok, user, local_user} = User.follow(user, local_user) {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"}) + with_media = create_with_media_activity(local_user) remote_user = insert(:user, local: false) {:ok, _user, remote_user} = User.follow(user, remote_user) remote_activity = create_remote_activity(remote_user) - resp1 = + without_filter_ids = conn |> get("/api/v1/timelines/home") |> json_response_and_validate_schema(200) - - without_filter_ids = Enum.map(resp1, & &1["id"]) + |> Enum.map(& &1["id"]) assert local_activity.id in without_filter_ids assert remote_activity.id in without_filter_ids + assert with_media.id in without_filter_ids - resp2 = + only_local_ids = conn |> get("/api/v1/timelines/home?local=true") |> json_response_and_validate_schema(200) - - only_local_ids = Enum.map(resp2, & &1["id"]) + |> Enum.map(& &1["id"]) assert local_activity.id in only_local_ids refute remote_activity.id in only_local_ids + assert with_media.id in only_local_ids - resp3 = + only_local_media_ids = conn - |> get("/api/v1/timelines/home?only_remote=true") + |> get("/api/v1/timelines/home?local=true&only_media=true") |> json_response_and_validate_schema(200) + |> Enum.map(& &1["id"]) - only_remote_ids = Enum.map(resp3, & &1["id"]) - - refute local_activity.id in only_remote_ids - assert remote_activity.id in only_remote_ids + refute local_activity.id in only_local_media_ids + refute remote_activity.id in only_local_media_ids + assert with_media.id in only_local_media_ids - resp4 = + remote_ids = conn - |> get("/api/v1/timelines/home?only_remote=true&local=true") + |> get("/api/v1/timelines/home?remote=true") |> json_response_and_validate_schema(200) + |> Enum.map(& &1["id"]) - assert resp4 == [] - end + refute local_activity.id in remote_ids + assert remote_activity.id in remote_ids + refute with_media.id in remote_ids - test "only_media flag", %{conn: conn, user: user} do - other = insert(:user) - {:ok, _, other} = User.follow(user, other) + assert conn + |> get("/api/v1/timelines/home?remote=true&only_media=true") + |> json_response_and_validate_schema(200) == [] - {:ok, without_media} = CommonAPI.post(other, %{status: "some status"}) + assert conn + |> get("/api/v1/timelines/home?remote=true&local=true") + |> json_response_and_validate_schema(200) == [] + end + end - with_media = create_with_media_activity(other) + describe "public" do + @tag capture_log: true + test "the public timeline", %{conn: conn} do + user = insert(:user) - resp1 = - conn - |> get("/api/v1/timelines/home") - |> json_response_and_validate_schema(200) + {:ok, activity} = CommonAPI.post(user, %{status: "test"}) + with_media = create_with_media_activity(user) - without_filter_ids = Enum.map(resp1, & &1["id"]) + remote = insert(:note_activity, local: false) - assert without_media.id in without_filter_ids - assert with_media.id in without_filter_ids + assert conn + |> get("/api/v1/timelines/public?local=False") + |> json_response_and_validate_schema(:ok) + |> length == 3 - resp2 = + local_ids = conn - |> get("/api/v1/timelines/home?only_media=true") - |> json_response_and_validate_schema(200) + |> get("/api/v1/timelines/public?local=True") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) - only_media_ids = Enum.map(resp2, & &1["id"]) + assert activity.id in local_ids + assert with_media.id in local_ids + refute remote.id in local_ids - refute without_media.id in only_media_ids - assert with_media.id in only_media_ids - end - end + local_ids = + conn + |> get("/api/v1/timelines/public?local=True") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) - describe "public" do - @tag capture_log: true - test "the public timeline", %{conn: conn} do - user = insert(:user) + assert activity.id in local_ids + assert with_media.id in local_ids + refute remote.id in local_ids - {:ok, activity} = CommonAPI.post(user, %{status: "test"}) + local_ids = + conn + |> get("/api/v1/timelines/public?local=True&only_media=true") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) - _activity = insert(:note_activity, local: false) + refute activity.id in local_ids + assert with_media.id in local_ids + refute remote.id in local_ids - conn = get(conn, "/api/v1/timelines/public?local=False") + local_ids = + conn + |> get("/api/v1/timelines/public?local=1") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) + + assert activity.id in local_ids + assert with_media.id in local_ids + refute remote.id in local_ids - assert length(json_response_and_validate_schema(conn, :ok)) == 2 + remote_id = remote.id - conn = get(build_conn(), "/api/v1/timelines/public?local=True") + assert [%{"id" => ^remote_id}] = + conn + |> get("/api/v1/timelines/public?remote=true") + |> json_response_and_validate_schema(:ok) - assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok) + with_media_id = with_media.id - conn = get(build_conn(), "/api/v1/timelines/public?local=1") + assert [%{"id" => ^with_media_id}] = + conn + |> get("/api/v1/timelines/public?only_media=true") + |> json_response_and_validate_schema(:ok) - assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok) + assert conn + |> get("/api/v1/timelines/public?remote=true&only_media=true") + |> json_response_and_validate_schema(:ok) == [] # does not contain repeats {:ok, _} = CommonAPI.repeat(activity.id, user) - conn = get(build_conn(), "/api/v1/timelines/public?local=true") - - assert [_] = json_response_and_validate_schema(conn, :ok) + assert [_, _] = + conn + |> get("/api/v1/timelines/public?local=true") + |> json_response_and_validate_schema(:ok) end test "the public timeline includes only public statuses for an authenticated user" do @@ -237,6 +273,24 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do [%{"id" => ^reply_from_me}, %{"id" => ^activity_id}] = response end + test "doesn't return posts from users who blocked you when :blockers_visible is disabled" do + clear_config([:activitypub, :blockers_visible], false) + + %{conn: conn, user: blockee} = oauth_access(["read:statuses"]) + blocker = insert(:user) + {:ok, _} = User.block(blocker, blockee) + + conn = assign(conn, :user, blockee) + + {:ok, _} = CommonAPI.post(blocker, %{status: "hey!"}) + + response = + get(conn, "/api/v1/timelines/public") + |> json_response_and_validate_schema(200) + + assert length(response) == 0 + end + test "doesn't return replies if follow is posting with users from blocked domain" do %{conn: conn, user: blocker} = oauth_access(["read:statuses"]) friend = insert(:user) @@ -621,7 +675,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do ] = result end - test "filering with params", %{user: user, conn: conn} do + test "filtering", %{user: user, conn: conn} do {:ok, list} = Pleroma.List.create("name", user) local_user = insert(:user) @@ -633,52 +687,62 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do remote_activity = create_remote_activity(remote_user) {:ok, list} = Pleroma.List.follow(list, remote_user) - resp1 = - conn |> get("/api/v1/timelines/list/#{list.id}") |> json_response_and_validate_schema(200) - - all_ids = Enum.map(resp1, & &1["id"]) + all_ids = + conn + |> get("/api/v1/timelines/list/#{list.id}") + |> json_response_and_validate_schema(200) + |> Enum.map(& &1["id"]) assert local_activity.id in all_ids assert with_media.id in all_ids assert remote_activity.id in all_ids - resp2 = + only_local_ids = conn |> get("/api/v1/timelines/list/#{list.id}?local=true") |> json_response_and_validate_schema(200) - - only_local_ids = Enum.map(resp2, & &1["id"]) + |> Enum.map(& &1["id"]) assert local_activity.id in only_local_ids assert with_media.id in only_local_ids refute remote_activity.id in only_local_ids - resp3 = + only_local_media_ids = conn - |> get("/api/v1/timelines/list/#{list.id}?only_remote=true") + |> get("/api/v1/timelines/list/#{list.id}?local=true&only_media=true") |> json_response_and_validate_schema(200) + |> Enum.map(& &1["id"]) + + refute local_activity.id in only_local_media_ids + assert with_media.id in only_local_media_ids + refute remote_activity.id in only_local_media_ids - only_remote_ids = Enum.map(resp3, & &1["id"]) + remote_ids = + conn + |> get("/api/v1/timelines/list/#{list.id}?remote=true") + |> json_response_and_validate_schema(200) + |> Enum.map(& &1["id"]) - refute local_activity.id in only_remote_ids - refute with_media.id in only_remote_ids - assert remote_activity.id in only_remote_ids + refute local_activity.id in remote_ids + refute with_media.id in remote_ids + assert remote_activity.id in remote_ids - resp4 = + assert conn + |> get("/api/v1/timelines/list/#{list.id}?remote=true&only_media=true") + |> json_response_and_validate_schema(200) == [] + + only_media_ids = conn |> get("/api/v1/timelines/list/#{list.id}?only_media=true") |> json_response_and_validate_schema(200) - - only_media_ids = Enum.map(resp4, & &1["id"]) + |> Enum.map(& &1["id"]) refute local_activity.id in only_media_ids assert with_media.id in only_media_ids refute remote_activity.id in only_media_ids assert conn - |> get( - "/api/v1/timelines/list/#{list.id}?only_media=true&local=true&only_remote=true" - ) + |> get("/api/v1/timelines/list/#{list.id}?only_media=true&local=true&remote=true") |> json_response_and_validate_schema(200) == [] end end @@ -691,19 +755,85 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do following = insert(:user) {:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"}) + with_media = create_with_media_activity(following) - nconn = get(conn, "/api/v1/timelines/tag/2hu") + remote = insert(:user, local: false) + remote_activity = create_remote_activity(remote) - assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok) + all_ids = + conn + |> get("/api/v1/timelines/tag/2hu") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) - assert id == to_string(activity.id) + assert activity.id in all_ids + assert with_media.id in all_ids + assert remote_activity.id in all_ids # works for different capitalization too - nconn = get(conn, "/api/v1/timelines/tag/2HU") + all_ids = + conn + |> get("/api/v1/timelines/tag/2HU") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) - assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok) + assert activity.id in all_ids + assert with_media.id in all_ids + assert remote_activity.id in all_ids - assert id == to_string(activity.id) + local_ids = + conn + |> get("/api/v1/timelines/tag/2hu?local=true") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) + + assert activity.id in local_ids + assert with_media.id in local_ids + refute remote_activity.id in local_ids + + remote_ids = + conn + |> get("/api/v1/timelines/tag/2hu?remote=true") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) + + refute activity.id in remote_ids + refute with_media.id in remote_ids + assert remote_activity.id in remote_ids + + media_ids = + conn + |> get("/api/v1/timelines/tag/2hu?only_media=true") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) + + refute activity.id in media_ids + assert with_media.id in media_ids + refute remote_activity.id in media_ids + + media_local_ids = + conn + |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) + + refute activity.id in media_local_ids + assert with_media.id in media_local_ids + refute remote_activity.id in media_local_ids + + ids = + conn + |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true&remote=true") + |> json_response_and_validate_schema(:ok) + |> Enum.map(& &1["id"]) + + refute activity.id in ids + refute with_media.id in ids + refute remote_activity.id in ids + + assert conn + |> get("/api/v1/timelines/tag/2hu?only_media=true&remote=true") + |> json_response_and_validate_schema(:ok) == [] end test "multi-hashtag timeline", %{conn: conn} do @@ -793,10 +923,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do %{conn: auth_conn} = oauth_access(["read:statuses"]) res_conn = get(auth_conn, "#{base_uri}?local=true") - assert length(json_response(res_conn, 200)) == 1 + assert length(json_response_and_validate_schema(res_conn, 200)) == 1 res_conn = get(auth_conn, "#{base_uri}?local=false") - assert length(json_response(res_conn, 200)) == 2 + assert length(json_response_and_validate_schema(res_conn, 200)) == 2 end test "with default settings on private instances, returns 403 for unauthenticated users", %{ @@ -810,7 +940,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do for local <- [true, false] do res_conn = get(conn, "#{base_uri}?local=#{local}") - assert json_response(res_conn, :unauthorized) == error_response + assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response end ensure_authenticated_access(base_uri) @@ -827,7 +957,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do for local <- [true, false] do res_conn = get(conn, "#{base_uri}?local=#{local}") - assert json_response(res_conn, :unauthorized) == error_response + assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response end ensure_authenticated_access(base_uri) @@ -839,10 +969,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do clear_config([:restrict_unauthenticated, :timelines, :federated], true) res_conn = get(conn, "#{base_uri}?local=true") - assert length(json_response(res_conn, 200)) == 1 + assert length(json_response_and_validate_schema(res_conn, 200)) == 1 res_conn = get(conn, "#{base_uri}?local=false") - assert json_response(res_conn, :unauthorized) == error_response + assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response ensure_authenticated_access(base_uri) end @@ -854,11 +984,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do clear_config([:restrict_unauthenticated, :timelines, :federated], false) res_conn = get(conn, "#{base_uri}?local=true") - assert json_response(res_conn, :unauthorized) == error_response + assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response # Note: local activities get delivered as part of federated timeline res_conn = get(conn, "#{base_uri}?local=false") - assert length(json_response(res_conn, 200)) == 2 + assert length(json_response_and_validate_schema(res_conn, 200)) == 2 ensure_authenticated_access(base_uri) end