2019-09-25 21:53:42 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-09-25 21:53:42 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
import Tesla.Mock
|
|
|
|
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
setup do
|
|
|
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2019-10-08 14:05:57 -06:00
|
|
|
describe "home" do
|
2019-12-19 07:23:27 -07:00
|
|
|
setup do: oauth_access(["read:statuses"])
|
|
|
|
|
2020-05-09 09:05:44 -06:00
|
|
|
test "does NOT embed account/pleroma/relationship in statuses", %{
|
2020-04-01 10:49:09 -06:00
|
|
|
user: user,
|
|
|
|
conn: conn
|
|
|
|
} do
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, _} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
|
2020-04-01 10:49:09 -06:00
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/v1/timelines/home")
|
2020-05-11 05:24:59 -06:00
|
|
|
|> json_response_and_validate_schema(200)
|
2020-04-01 10:49:09 -06:00
|
|
|
|
|
|
|
assert Enum.all?(response, fn n ->
|
|
|
|
get_in(n, ["account", "pleroma", "relationship"]) == %{}
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
|
|
|
|
{:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
conn = get(conn, "/api/v1/timelines/home?exclude_visibilities[]=direct")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert status_ids = json_response_and_validate_schema(conn, :ok) |> Enum.map(& &1["id"])
|
2019-10-08 14:05:57 -06:00
|
|
|
assert public_activity.id in status_ids
|
|
|
|
assert unlisted_activity.id in status_ids
|
|
|
|
assert private_activity.id in status_ids
|
|
|
|
refute direct_activity.id in status_ids
|
|
|
|
end
|
2020-11-16 11:23:25 -07:00
|
|
|
|
|
|
|
test "muted emotions", %{user: user, conn: conn} do
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "."})
|
|
|
|
|
|
|
|
{:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
|
|
|
|
User.mute(user, other_user)
|
|
|
|
|
|
|
|
result =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/v1/timelines/home")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%{
|
|
|
|
"pleroma" => %{
|
|
|
|
"emoji_reactions" => []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] = result
|
|
|
|
|
|
|
|
result =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/v1/timelines/home?with_muted=true")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%{
|
|
|
|
"pleroma" => %{
|
|
|
|
"emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] = result
|
|
|
|
end
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
test "filtering", %{conn: conn, user: user} do
|
2021-01-26 06:55:44 -07:00
|
|
|
local_user = insert(:user)
|
|
|
|
{:ok, user, local_user} = User.follow(user, local_user)
|
|
|
|
{:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"})
|
2021-01-26 07:43:49 -07:00
|
|
|
with_media = create_with_media_activity(local_user)
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 06:55:44 -07:00
|
|
|
remote_user = insert(:user, local: false)
|
|
|
|
{:ok, _user, remote_user} = User.follow(user, remote_user)
|
|
|
|
remote_activity = create_remote_activity(remote_user)
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
without_filter_ids =
|
2021-01-26 01:58:54 -07:00
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/home")
|
|
|
|
|> json_response_and_validate_schema(200)
|
2021-01-26 07:43:49 -07:00
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 06:55:44 -07:00
|
|
|
assert local_activity.id in without_filter_ids
|
|
|
|
assert remote_activity.id in without_filter_ids
|
2021-01-26 07:43:49 -07:00
|
|
|
assert with_media.id in without_filter_ids
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
only_local_ids =
|
2021-01-26 01:58:54 -07:00
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/home?local=true")
|
|
|
|
|> json_response_and_validate_schema(200)
|
2021-01-26 07:43:49 -07:00
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 06:55:44 -07:00
|
|
|
assert local_activity.id in only_local_ids
|
|
|
|
refute remote_activity.id in only_local_ids
|
2021-01-26 07:43:49 -07:00
|
|
|
assert with_media.id in only_local_ids
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
only_local_media_ids =
|
2021-01-26 01:58:54 -07:00
|
|
|
conn
|
2021-01-26 07:43:49 -07:00
|
|
|
|> get("/api/v1/timelines/home?local=true&only_media=true")
|
2021-01-26 01:58:54 -07:00
|
|
|
|> json_response_and_validate_schema(200)
|
2021-01-26 07:43:49 -07:00
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
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
|
|
|
|
|
2021-02-01 04:09:23 -07:00
|
|
|
remote_ids =
|
2021-01-26 07:43:49 -07:00
|
|
|
conn
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/home?remote=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-02-01 04:09:23 -07:00
|
|
|
refute local_activity.id in remote_ids
|
|
|
|
assert remote_activity.id in remote_ids
|
|
|
|
refute with_media.id in remote_ids
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert conn
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/home?remote=true&only_media=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> json_response_and_validate_schema(200) == []
|
2021-01-26 01:58:54 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert conn
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/home?remote=true&local=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> json_response_and_validate_schema(200) == []
|
2021-01-26 01:58:54 -07:00
|
|
|
end
|
2021-01-26 07:43:49 -07:00
|
|
|
end
|
2021-01-26 04:35:31 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
describe "public" do
|
|
|
|
@tag capture_log: true
|
|
|
|
test "the public timeline", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
2021-01-26 04:35:31 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "test"})
|
|
|
|
with_media = create_with_media_activity(user)
|
2021-01-26 04:35:31 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
remote = insert(:note_activity, local: false)
|
2021-01-26 04:35:31 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert conn
|
|
|
|
|> get("/api/v1/timelines/public?local=False")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
|
|
|
|> length == 3
|
|
|
|
|
|
|
|
local_ids =
|
2021-01-26 04:35:31 -07:00
|
|
|
conn
|
2021-01-26 07:43:49 -07:00
|
|
|
|> get("/api/v1/timelines/public?local=True")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 04:35:31 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert activity.id in local_ids
|
|
|
|
assert with_media.id in local_ids
|
|
|
|
refute remote.id in local_ids
|
2021-01-26 04:35:31 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
local_ids =
|
2021-01-26 04:35:31 -07:00
|
|
|
conn
|
2021-01-26 07:43:49 -07:00
|
|
|
|> get("/api/v1/timelines/public?local=True")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 04:35:31 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert activity.id in local_ids
|
|
|
|
assert with_media.id in local_ids
|
|
|
|
refute remote.id in local_ids
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
local_ids =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/public?local=True&only_media=true")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
|
|
|
|> Enum.map(& &1["id"])
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
refute activity.id in local_ids
|
|
|
|
assert with_media.id in local_ids
|
|
|
|
refute remote.id in local_ids
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
local_ids =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/public?local=1")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
|
|
|
|> Enum.map(& &1["id"])
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert activity.id in local_ids
|
|
|
|
assert with_media.id in local_ids
|
|
|
|
refute remote.id in local_ids
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
remote_id = remote.id
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert [%{"id" => ^remote_id}] =
|
|
|
|
conn
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/public?remote=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> json_response_and_validate_schema(:ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
with_media_id = with_media.id
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert [%{"id" => ^with_media_id}] =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/public?only_media=true")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert conn
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/public?remote=true&only_media=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> json_response_and_validate_schema(:ok) == []
|
2020-06-01 05:17:56 -06:00
|
|
|
|
|
|
|
# does not contain repeats
|
|
|
|
{:ok, _} = CommonAPI.repeat(activity.id, user)
|
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert [_, _] =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/public?local=true")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "the public timeline includes only public statuses for an authenticated user" do
|
2019-12-19 07:23:27 -07:00
|
|
|
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, _activity} = CommonAPI.post(user, %{status: "test"})
|
|
|
|
{:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "private"})
|
|
|
|
{:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "unlisted"})
|
|
|
|
{:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
res_conn = get(conn, "/api/v1/timelines/public")
|
2020-05-11 05:24:59 -06:00
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2019-09-25 21:53:42 -06:00
|
|
|
end
|
2020-05-20 08:45:06 -06:00
|
|
|
|
|
|
|
test "doesn't return replies if follower is posting with blocked user" do
|
|
|
|
%{conn: conn, user: blocker} = oauth_access(["read:statuses"])
|
|
|
|
[blockee, friend] = insert_list(2, :user)
|
2020-12-01 13:17:52 -07:00
|
|
|
{:ok, blocker, friend} = User.follow(blocker, friend)
|
2020-05-20 08:45:06 -06:00
|
|
|
{:ok, _} = User.block(blocker, blockee)
|
|
|
|
|
|
|
|
conn = assign(conn, :user, blocker)
|
|
|
|
|
|
|
|
{:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
|
|
|
|
|
|
|
|
{:ok, reply_from_blockee} =
|
|
|
|
CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
|
|
|
|
|
|
|
|
{:ok, _reply_from_friend} =
|
|
|
|
CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
|
|
|
|
|
2020-09-21 08:08:38 -06:00
|
|
|
# Still shows replies from yourself
|
|
|
|
{:ok, %{id: reply_from_me}} =
|
|
|
|
CommonAPI.post(blocker, %{status: "status", in_reply_to_status_id: reply_from_blockee})
|
|
|
|
|
|
|
|
response =
|
|
|
|
get(conn, "/api/v1/timelines/public")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert length(response) == 2
|
|
|
|
[%{"id" => ^reply_from_me}, %{"id" => ^activity_id}] = response
|
2020-05-20 08:45:06 -06:00
|
|
|
end
|
|
|
|
|
2020-10-10 02:41:35 -06:00
|
|
|
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
|
|
|
|
|
2020-05-20 08:45:06 -06:00
|
|
|
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)
|
|
|
|
blockee = insert(:user, ap_id: "https://example.com/users/blocked")
|
2020-12-01 13:17:52 -07:00
|
|
|
{:ok, blocker, friend} = User.follow(blocker, friend)
|
2020-05-20 08:45:06 -06:00
|
|
|
{:ok, blocker} = User.block_domain(blocker, "example.com")
|
|
|
|
|
|
|
|
conn = assign(conn, :user, blocker)
|
|
|
|
|
|
|
|
{:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
|
|
|
|
|
|
|
|
{:ok, reply_from_blockee} =
|
|
|
|
CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
|
|
|
|
|
|
|
|
{:ok, _reply_from_friend} =
|
|
|
|
CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
|
|
|
|
|
2020-06-01 23:50:24 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public")
|
2020-05-20 08:45:06 -06:00
|
|
|
|
|
|
|
activities = json_response_and_validate_schema(res_conn, 200)
|
|
|
|
[%{"id" => ^activity_id}] = activities
|
|
|
|
end
|
2020-07-01 20:12:59 -06:00
|
|
|
|
|
|
|
test "can be filtered by instance", %{conn: conn} do
|
|
|
|
user = insert(:user, ap_id: "https://lain.com/users/lain")
|
|
|
|
insert(:note_activity, local: false)
|
|
|
|
insert(:note_activity, local: false)
|
|
|
|
|
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
|
|
|
|
|
|
|
conn = get(conn, "/api/v1/timelines/public?instance=lain.com")
|
|
|
|
|
|
|
|
assert length(json_response_and_validate_schema(conn, :ok)) == 1
|
|
|
|
end
|
2020-11-16 11:23:25 -07:00
|
|
|
|
|
|
|
test "muted emotions", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> assign(:token, token)
|
|
|
|
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "."})
|
|
|
|
|
|
|
|
{:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
|
|
|
|
User.mute(user, other_user)
|
|
|
|
|
|
|
|
result =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/public")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%{
|
|
|
|
"pleroma" => %{
|
|
|
|
"emoji_reactions" => []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] = result
|
|
|
|
|
|
|
|
result =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/public?with_muted=true")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%{
|
|
|
|
"pleroma" => %{
|
|
|
|
"emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] = result
|
|
|
|
end
|
2019-09-25 21:53:42 -06:00
|
|
|
end
|
|
|
|
|
2020-03-20 04:04:37 -06:00
|
|
|
defp local_and_remote_activities do
|
|
|
|
insert(:note_activity)
|
|
|
|
insert(:note_activity, local: false)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "public with restrict unauthenticated timeline for local and federated timelines" do
|
|
|
|
setup do: local_and_remote_activities()
|
|
|
|
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
2020-03-20 04:04:37 -06:00
|
|
|
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
2020-03-20 04:04:37 -06:00
|
|
|
|
|
|
|
test "if user is unauthenticated", %{conn: conn} do
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
2020-03-20 04:04:37 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
|
2020-03-20 04:04:37 -06:00
|
|
|
"error" => "authorization required for timeline view"
|
|
|
|
}
|
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
2020-03-20 04:04:37 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
|
2020-03-20 04:04:37 -06:00
|
|
|
"error" => "authorization required for timeline view"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "if user is authenticated" do
|
|
|
|
%{conn: conn} = oauth_access(["read:statuses"])
|
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-03-20 04:04:37 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-03-20 04:04:37 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "public with restrict unauthenticated timeline for local" do
|
|
|
|
setup do: local_and_remote_activities()
|
|
|
|
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
2020-03-20 04:04:37 -06:00
|
|
|
|
|
|
|
test "if user is unauthenticated", %{conn: conn} do
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
2020-03-20 04:04:37 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
|
2020-03-20 04:04:37 -06:00
|
|
|
"error" => "authorization required for timeline view"
|
|
|
|
}
|
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-03-20 04:04:37 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "if user is authenticated", %{conn: _conn} do
|
|
|
|
%{conn: conn} = oauth_access(["read:statuses"])
|
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-03-20 04:04:37 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-03-20 04:04:37 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "public with restrict unauthenticated timeline for remote" do
|
|
|
|
setup do: local_and_remote_activities()
|
|
|
|
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
2020-03-20 04:04:37 -06:00
|
|
|
|
|
|
|
test "if user is unauthenticated", %{conn: conn} do
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-03-20 04:04:37 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
2020-03-20 04:04:37 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
|
2020-03-20 04:04:37 -06:00
|
|
|
"error" => "authorization required for timeline view"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "if user is authenticated", %{conn: _conn} do
|
|
|
|
%{conn: conn} = oauth_access(["read:statuses"])
|
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-03-20 04:04:37 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-03-20 04:04:37 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-25 21:53:42 -06:00
|
|
|
describe "direct" do
|
|
|
|
test "direct timeline", %{conn: conn} do
|
|
|
|
user_one = insert(:user)
|
|
|
|
user_two = insert(:user)
|
|
|
|
|
2020-12-01 13:17:52 -07:00
|
|
|
{:ok, user_two, user_one} = User.follow(user_two, user_one)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
{:ok, direct} =
|
|
|
|
CommonAPI.post(user_one, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "Hi @#{user_two.nickname}!",
|
|
|
|
visibility: "direct"
|
2019-09-25 21:53:42 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, _follower_only} =
|
|
|
|
CommonAPI.post(user_one, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "Hi @#{user_two.nickname}!",
|
|
|
|
visibility: "private"
|
2019-09-25 21:53:42 -06:00
|
|
|
})
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
conn_user_two =
|
2019-09-25 21:53:42 -06:00
|
|
|
conn
|
|
|
|
|> assign(:user, user_two)
|
2019-12-19 07:23:27 -07:00
|
|
|
|> 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")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert [status] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
assert %{"visibility" => "direct"} = status
|
|
|
|
assert status["url"] != direct.data["id"]
|
|
|
|
|
|
|
|
# User should be able to see their own direct message
|
|
|
|
res_conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, user_one)
|
2019-12-19 07:23:27 -07:00
|
|
|
|> assign(:token, insert(:oauth_token, user: user_one, scopes: ["read:statuses"]))
|
2019-09-25 21:53:42 -06:00
|
|
|
|> get("api/v1/timelines/direct")
|
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
[status] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
assert %{"visibility" => "direct"} = status
|
|
|
|
|
|
|
|
# Both should be visible here
|
2019-12-19 07:23:27 -07:00
|
|
|
res_conn = get(conn_user_two, "api/v1/timelines/home")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
[_s1, _s2] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
# Test pagination
|
|
|
|
Enum.each(1..20, fn _ ->
|
|
|
|
{:ok, _} =
|
|
|
|
CommonAPI.post(user_one, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "Hi @#{user_two.nickname}!",
|
|
|
|
visibility: "direct"
|
2019-09-25 21:53:42 -06:00
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
res_conn = get(conn_user_two, "api/v1/timelines/direct")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
statuses = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
assert length(statuses) == 20
|
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
max_id = List.last(statuses)["id"]
|
|
|
|
|
|
|
|
res_conn = get(conn_user_two, "api/v1/timelines/direct?max_id=#{max_id}")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert [status] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
assert status["url"] != direct.data["id"]
|
|
|
|
end
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
test "doesn't include DMs from blocked users" do
|
|
|
|
%{user: blocker, conn: conn} = oauth_access(["read:statuses"])
|
2019-09-25 21:53:42 -06:00
|
|
|
blocked = insert(:user)
|
2019-12-19 07:23:27 -07:00
|
|
|
other_user = insert(:user)
|
2019-11-19 13:22:10 -07:00
|
|
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
{:ok, _blocked_direct} =
|
|
|
|
CommonAPI.post(blocked, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "Hi @#{blocker.nickname}!",
|
|
|
|
visibility: "direct"
|
2019-09-25 21:53:42 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, direct} =
|
2019-12-19 07:23:27 -07:00
|
|
|
CommonAPI.post(other_user, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "Hi @#{blocker.nickname}!",
|
|
|
|
visibility: "direct"
|
2019-09-25 21:53:42 -06:00
|
|
|
})
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
res_conn = get(conn, "api/v1/timelines/direct")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
[status] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
assert status["id"] == direct.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "list" do
|
2019-12-19 07:23:27 -07:00
|
|
|
setup do: oauth_access(["read:lists"])
|
|
|
|
|
2020-08-26 07:37:30 -06:00
|
|
|
test "does not contain retoots", %{user: user, conn: conn} do
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
|
|
|
|
{:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is stupid."})
|
|
|
|
{:ok, _} = CommonAPI.repeat(activity_one.id, other_user)
|
|
|
|
|
|
|
|
{:ok, list} = Pleroma.List.create("name", user)
|
|
|
|
{:ok, list} = Pleroma.List.follow(list, other_user)
|
|
|
|
|
|
|
|
conn = get(conn, "/api/v1/timelines/list/#{list.id}")
|
|
|
|
|
|
|
|
assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
|
|
|
|
|
|
|
|
assert id == to_string(activity_two.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "works with pagination", %{user: user, conn: conn} do
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, list} = Pleroma.List.create("name", user)
|
|
|
|
{:ok, list} = Pleroma.List.follow(list, other_user)
|
|
|
|
|
|
|
|
Enum.each(1..30, fn i ->
|
|
|
|
CommonAPI.post(other_user, %{status: "post number #{i}"})
|
|
|
|
end)
|
|
|
|
|
|
|
|
res =
|
|
|
|
get(conn, "/api/v1/timelines/list/#{list.id}?limit=1")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
|
|
|
|
|
|
|
assert length(res) == 1
|
|
|
|
|
|
|
|
[first] = res
|
|
|
|
|
|
|
|
res =
|
|
|
|
get(conn, "/api/v1/timelines/list/#{list.id}?max_id=#{first["id"]}&limit=30")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
|
|
|
|
|
|
|
assert length(res) == 29
|
|
|
|
end
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
test "list timeline", %{user: user, conn: conn} do
|
2019-09-25 21:53:42 -06:00
|
|
|
other_user = insert(:user)
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, _activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
|
|
|
|
{:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
|
2019-09-25 21:53:42 -06:00
|
|
|
{:ok, list} = Pleroma.List.create("name", user)
|
|
|
|
{:ok, list} = Pleroma.List.follow(list, other_user)
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
conn = get(conn, "/api/v1/timelines/list/#{list.id}")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
assert id == to_string(activity_two.id)
|
|
|
|
end
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
test "list timeline does not leak non-public statuses for unfollowed users", %{
|
|
|
|
user: user,
|
|
|
|
conn: conn
|
|
|
|
} do
|
2019-09-25 21:53:42 -06:00
|
|
|
other_user = insert(:user)
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity_one} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
{:ok, _activity_two} =
|
|
|
|
CommonAPI.post(other_user, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "Marisa is cute.",
|
|
|
|
visibility: "private"
|
2019-09-25 21:53:42 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, list} = Pleroma.List.create("name", user)
|
|
|
|
{:ok, list} = Pleroma.List.follow(list, other_user)
|
|
|
|
|
2019-12-19 07:23:27 -07:00
|
|
|
conn = get(conn, "/api/v1/timelines/list/#{list.id}")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
assert id == to_string(activity_one.id)
|
|
|
|
end
|
2020-11-16 11:23:25 -07:00
|
|
|
|
|
|
|
test "muted emotions", %{user: user, conn: conn} do
|
|
|
|
user2 = insert(:user)
|
|
|
|
user3 = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user2, %{status: "."})
|
|
|
|
|
|
|
|
{:ok, _} = CommonAPI.react_with_emoji(activity.id, user3, "🎅")
|
|
|
|
User.mute(user, user3)
|
|
|
|
|
|
|
|
{:ok, list} = Pleroma.List.create("name", user)
|
|
|
|
{:ok, list} = Pleroma.List.follow(list, user2)
|
|
|
|
|
|
|
|
result =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/list/#{list.id}")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%{
|
|
|
|
"pleroma" => %{
|
|
|
|
"emoji_reactions" => []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] = result
|
|
|
|
|
|
|
|
result =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/list/#{list.id}?with_muted=true")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%{
|
|
|
|
"pleroma" => %{
|
|
|
|
"emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] = result
|
|
|
|
end
|
2021-01-26 06:55:44 -07:00
|
|
|
|
2021-02-01 04:09:23 -07:00
|
|
|
test "filtering", %{user: user, conn: conn} do
|
2021-01-26 06:55:44 -07:00
|
|
|
{:ok, list} = Pleroma.List.create("name", user)
|
|
|
|
|
|
|
|
local_user = insert(:user)
|
|
|
|
{:ok, local_activity} = CommonAPI.post(local_user, %{status: "Marisa is stupid."})
|
|
|
|
with_media = create_with_media_activity(local_user)
|
|
|
|
{:ok, list} = Pleroma.List.follow(list, local_user)
|
|
|
|
|
|
|
|
remote_user = insert(:user, local: false)
|
|
|
|
remote_activity = create_remote_activity(remote_user)
|
|
|
|
{:ok, list} = Pleroma.List.follow(list, remote_user)
|
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
all_ids =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/list/#{list.id}")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 06:55:44 -07:00
|
|
|
|
|
|
|
assert local_activity.id in all_ids
|
|
|
|
assert with_media.id in all_ids
|
|
|
|
assert remote_activity.id in all_ids
|
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
only_local_ids =
|
2021-01-26 06:55:44 -07:00
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/list/#{list.id}?local=true")
|
|
|
|
|> json_response_and_validate_schema(200)
|
2021-01-26 07:43:49 -07:00
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 06:55:44 -07:00
|
|
|
|
|
|
|
assert local_activity.id in only_local_ids
|
|
|
|
assert with_media.id in only_local_ids
|
|
|
|
refute remote_activity.id in only_local_ids
|
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
only_local_media_ids =
|
2021-01-26 06:55:44 -07:00
|
|
|
conn
|
2021-01-26 07:43:49 -07:00
|
|
|
|> get("/api/v1/timelines/list/#{list.id}?local=true&only_media=true")
|
2021-01-26 06:55:44 -07:00
|
|
|
|> json_response_and_validate_schema(200)
|
2021-01-26 07:43:49 -07:00
|
|
|
|> 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
|
2021-01-26 06:55:44 -07:00
|
|
|
|
2021-02-01 04:09:23 -07:00
|
|
|
remote_ids =
|
2021-01-26 07:43:49 -07:00
|
|
|
conn
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/list/#{list.id}?remote=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 06:55:44 -07:00
|
|
|
|
2021-02-01 04:09:23 -07:00
|
|
|
refute local_activity.id in remote_ids
|
|
|
|
refute with_media.id in remote_ids
|
|
|
|
assert remote_activity.id in remote_ids
|
2021-01-26 06:55:44 -07:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert conn
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/list/#{list.id}?remote=true&only_media=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> json_response_and_validate_schema(200) == []
|
|
|
|
|
|
|
|
only_media_ids =
|
2021-01-26 06:55:44 -07:00
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/list/#{list.id}?only_media=true")
|
|
|
|
|> json_response_and_validate_schema(200)
|
2021-01-26 07:43:49 -07:00
|
|
|
|> Enum.map(& &1["id"])
|
2021-01-26 06:55:44 -07:00
|
|
|
|
|
|
|
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
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/list/#{list.id}?only_media=true&local=true&remote=true")
|
2021-01-26 06:55:44 -07:00
|
|
|
|> json_response_and_validate_schema(200) == []
|
|
|
|
end
|
2019-09-25 21:53:42 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "hashtag" do
|
2019-12-19 07:23:27 -07:00
|
|
|
setup do: oauth_access(["n/a"])
|
|
|
|
|
2019-09-25 21:53:42 -06:00
|
|
|
@tag capture_log: true
|
|
|
|
test "hashtag timeline", %{conn: conn} do
|
|
|
|
following = insert(:user)
|
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
|
2021-01-26 07:43:49 -07:00
|
|
|
with_media = create_with_media_activity(following)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
remote = insert(:user, local: false)
|
|
|
|
remote_activity = create_remote_activity(remote)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
all_ids =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/tag/2hu")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
|
|
|
|> Enum.map(& &1["id"])
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert activity.id in all_ids
|
|
|
|
assert with_media.id in all_ids
|
|
|
|
assert remote_activity.id in all_ids
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
# works for different capitalization too
|
2021-01-26 07:43:49 -07:00
|
|
|
all_ids =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/tag/2HU")
|
|
|
|
|> json_response_and_validate_schema(:ok)
|
|
|
|
|> Enum.map(& &1["id"])
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
assert activity.id in all_ids
|
|
|
|
assert with_media.id in all_ids
|
|
|
|
assert remote_activity.id in all_ids
|
|
|
|
|
|
|
|
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
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/tag/2hu?remote=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> 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
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2021-01-26 07:43:49 -07:00
|
|
|
ids =
|
|
|
|
conn
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/tag/2hu?only_media=true&local=true&remote=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> 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
|
2021-02-01 04:09:23 -07:00
|
|
|
|> get("/api/v1/timelines/tag/2hu?only_media=true&remote=true")
|
2021-01-26 07:43:49 -07:00
|
|
|
|> json_response_and_validate_schema(:ok) == []
|
2019-09-25 21:53:42 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "multi-hashtag timeline", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity_test} = CommonAPI.post(user, %{status: "#test"})
|
|
|
|
{:ok, activity_test1} = CommonAPI.post(user, %{status: "#test #test1"})
|
|
|
|
{:ok, activity_none} = CommonAPI.post(user, %{status: "#test #none"})
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
any_test = get(conn, "/api/v1/timelines/tag/test?any[]=test1")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
[status_none, status_test1, status_test] = json_response_and_validate_schema(any_test, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
|
|
|
assert to_string(activity_test.id) == status_test["id"]
|
|
|
|
assert to_string(activity_test1.id) == status_test1["id"]
|
|
|
|
assert to_string(activity_none.id) == status_none["id"]
|
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
restricted_test = get(conn, "/api/v1/timelines/tag/test?all[]=test1&none[]=none")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert [status_test1] == json_response_and_validate_schema(restricted_test, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
all_test = get(conn, "/api/v1/timelines/tag/test?all[]=none")
|
2019-09-25 21:53:42 -06:00
|
|
|
|
2020-05-11 05:24:59 -06:00
|
|
|
assert [status_none] == json_response_and_validate_schema(all_test, :ok)
|
2019-09-25 21:53:42 -06:00
|
|
|
end
|
2020-11-16 11:23:25 -07:00
|
|
|
|
|
|
|
test "muted emotions", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> assign(:token, token)
|
|
|
|
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "test #2hu"})
|
|
|
|
|
|
|
|
{:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
|
|
|
|
User.mute(user, other_user)
|
|
|
|
|
|
|
|
result =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/tag/2hu")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%{
|
|
|
|
"pleroma" => %{
|
|
|
|
"emoji_reactions" => []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] = result
|
|
|
|
|
|
|
|
result =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/timelines/tag/2hu?with_muted=true")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%{
|
|
|
|
"pleroma" => %{
|
|
|
|
"emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] = result
|
|
|
|
end
|
2019-09-25 21:53:42 -06:00
|
|
|
end
|
2020-07-07 11:37:11 -06:00
|
|
|
|
|
|
|
describe "hashtag timeline handling of :restrict_unauthenticated setting" do
|
|
|
|
setup do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity1} = CommonAPI.post(user, %{status: "test #tag1"})
|
|
|
|
{:ok, _activity2} = CommonAPI.post(user, %{status: "test #tag1"})
|
|
|
|
|
|
|
|
activity1
|
|
|
|
|> Ecto.Changeset.change(%{local: false})
|
|
|
|
|> Pleroma.Repo.update()
|
|
|
|
|
|
|
|
base_uri = "/api/v1/timelines/tag/tag1"
|
|
|
|
error_response = %{"error" => "authorization required for timeline view"}
|
|
|
|
|
|
|
|
%{base_uri: base_uri, error_response: error_response}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp ensure_authenticated_access(base_uri) do
|
|
|
|
%{conn: auth_conn} = oauth_access(["read:statuses"])
|
|
|
|
|
|
|
|
res_conn = get(auth_conn, "#{base_uri}?local=true")
|
2021-02-16 15:23:35 -07:00
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-07-07 11:37:11 -06:00
|
|
|
|
|
|
|
res_conn = get(auth_conn, "#{base_uri}?local=false")
|
2021-02-16 15:23:35 -07:00
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-07-07 11:37:11 -06:00
|
|
|
end
|
|
|
|
|
2020-08-15 09:30:20 -06:00
|
|
|
test "with default settings on private instances, returns 403 for unauthenticated users", %{
|
|
|
|
conn: conn,
|
|
|
|
base_uri: base_uri,
|
|
|
|
error_response: error_response
|
|
|
|
} do
|
|
|
|
clear_config([:instance, :public], false)
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines])
|
|
|
|
|
|
|
|
for local <- [true, false] do
|
|
|
|
res_conn = get(conn, "#{base_uri}?local=#{local}")
|
|
|
|
|
2021-02-16 15:23:35 -07:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
|
2020-08-15 09:30:20 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
ensure_authenticated_access(base_uri)
|
|
|
|
end
|
|
|
|
|
2020-07-07 11:37:11 -06:00
|
|
|
test "with `%{local: true, federated: true}`, returns 403 for unauthenticated users", %{
|
|
|
|
conn: conn,
|
|
|
|
base_uri: base_uri,
|
|
|
|
error_response: error_response
|
|
|
|
} do
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
|
|
|
|
|
|
|
for local <- [true, false] do
|
|
|
|
res_conn = get(conn, "#{base_uri}?local=#{local}")
|
|
|
|
|
2021-02-16 15:23:35 -07:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
|
2020-07-07 11:37:11 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
ensure_authenticated_access(base_uri)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with `%{local: false, federated: true}`, forbids unauthenticated access to federated timeline",
|
|
|
|
%{conn: conn, base_uri: base_uri, error_response: error_response} do
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :local], false)
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
|
|
|
|
|
|
|
res_conn = get(conn, "#{base_uri}?local=true")
|
2021-02-16 15:23:35 -07:00
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-07-07 11:37:11 -06:00
|
|
|
|
|
|
|
res_conn = get(conn, "#{base_uri}?local=false")
|
2021-02-16 15:23:35 -07:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
|
2020-07-07 11:37:11 -06:00
|
|
|
|
|
|
|
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)",
|
|
|
|
%{conn: conn, base_uri: base_uri, error_response: error_response} do
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :federated], false)
|
|
|
|
|
|
|
|
res_conn = get(conn, "#{base_uri}?local=true")
|
2021-02-16 15:23:35 -07:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
|
2020-07-07 11:37:11 -06:00
|
|
|
|
|
|
|
# Note: local activities get delivered as part of federated timeline
|
|
|
|
res_conn = get(conn, "#{base_uri}?local=false")
|
2021-02-16 15:23:35 -07:00
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-07-07 11:37:11 -06:00
|
|
|
|
|
|
|
ensure_authenticated_access(base_uri)
|
|
|
|
end
|
|
|
|
end
|
2021-01-26 06:55:44 -07:00
|
|
|
|
|
|
|
defp create_remote_activity(user) do
|
|
|
|
obj =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"to" => [
|
|
|
|
"https://www.w3.org/ns/activitystreams#Public",
|
|
|
|
User.ap_followers(user)
|
|
|
|
]
|
|
|
|
},
|
|
|
|
user: user
|
|
|
|
})
|
|
|
|
|
|
|
|
insert(:note_activity, %{
|
|
|
|
note: obj,
|
|
|
|
recipients: [
|
|
|
|
"https://www.w3.org/ns/activitystreams#Public",
|
|
|
|
User.ap_followers(user)
|
|
|
|
],
|
|
|
|
user: user,
|
|
|
|
local: false
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
defp create_with_media_activity(user) do
|
|
|
|
obj = insert(:attachment_note, user: user)
|
|
|
|
|
|
|
|
insert(:note_activity, %{
|
|
|
|
note: obj,
|
|
|
|
recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(user)],
|
|
|
|
user: user
|
|
|
|
})
|
|
|
|
end
|
2019-09-25 21:53:42 -06:00
|
|
|
end
|