2018-12-23 13:11:29 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 13:11:29 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-05-05 05:40:47 -06:00
|
|
|
defmodule Pleroma.Web.StreamerTest do
|
2023-08-01 04:43:50 -06:00
|
|
|
use Pleroma.DataCase
|
2018-05-05 05:40:47 -06:00
|
|
|
|
2019-09-16 04:03:37 -06:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
2019-10-30 18:44:27 -06:00
|
|
|
alias Pleroma.Conversation.Participation
|
2019-01-20 05:00:46 -07:00
|
|
|
alias Pleroma.List
|
|
|
|
alias Pleroma.User
|
2018-05-05 05:40:47 -06:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-03-04 19:52:23 -07:00
|
|
|
alias Pleroma.Web.Streamer
|
2018-05-05 05:40:47 -06:00
|
|
|
|
2019-11-28 02:44:48 -07:00
|
|
|
@moduletag needs_streamer: true, capture_log: true
|
2019-12-15 15:22:01 -07:00
|
|
|
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([:instance, :skip_thread_containment])
|
2019-06-03 07:04:39 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
describe "get_topic/_ (unauthenticated)" do
|
2020-05-12 10:04:47 -06:00
|
|
|
test "allows public" do
|
2020-09-19 10:16:55 -06:00
|
|
|
assert {:ok, "public"} = Streamer.get_topic("public", nil, nil)
|
|
|
|
assert {:ok, "public:local"} = Streamer.get_topic("public:local", nil, nil)
|
|
|
|
assert {:ok, "public:media"} = Streamer.get_topic("public:media", nil, nil)
|
|
|
|
assert {:ok, "public:local:media"} = Streamer.get_topic("public:local:media", nil, nil)
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
|
2023-03-30 19:01:37 -06:00
|
|
|
test "rejects local public streams if restricted_unauthenticated is on" do
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
|
|
|
|
|
|
|
assert {:error, :unauthorized} = Streamer.get_topic("public:local", nil, nil)
|
|
|
|
assert {:error, :unauthorized} = Streamer.get_topic("public:local:media", nil, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rejects remote public streams if restricted_unauthenticated is on" do
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
|
|
|
|
|
|
|
assert {:error, :unauthorized} = Streamer.get_topic("public", nil, nil)
|
|
|
|
assert {:error, :unauthorized} = Streamer.get_topic("public:media", nil, nil)
|
|
|
|
|
|
|
|
assert {:error, :unauthorized} =
|
|
|
|
Streamer.get_topic("public:remote", nil, nil, %{"instance" => "lain.com"})
|
|
|
|
|
|
|
|
assert {:error, :unauthorized} =
|
|
|
|
Streamer.get_topic("public:remote:media", nil, nil, %{"instance" => "lain.com"})
|
|
|
|
end
|
|
|
|
|
2020-10-08 19:01:48 -06:00
|
|
|
test "allows instance streams" do
|
|
|
|
assert {:ok, "public:remote:lain.com"} =
|
|
|
|
Streamer.get_topic("public:remote", nil, nil, %{"instance" => "lain.com"})
|
|
|
|
|
|
|
|
assert {:ok, "public:remote:media:lain.com"} =
|
|
|
|
Streamer.get_topic("public:remote:media", nil, nil, %{"instance" => "lain.com"})
|
|
|
|
end
|
|
|
|
|
2020-05-12 10:04:47 -06:00
|
|
|
test "allows hashtag streams" do
|
2020-09-19 10:16:55 -06:00
|
|
|
assert {:ok, "hashtag:cofe"} = Streamer.get_topic("hashtag", nil, nil, %{"tag" => "cofe"})
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "disallows user streams" do
|
2020-09-19 10:16:55 -06:00
|
|
|
assert {:error, _} = Streamer.get_topic("user", nil, nil)
|
|
|
|
assert {:error, _} = Streamer.get_topic("user:notification", nil, nil)
|
|
|
|
assert {:error, _} = Streamer.get_topic("direct", nil, nil)
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "disallows list streams" do
|
2020-09-19 10:16:55 -06:00
|
|
|
assert {:error, _} = Streamer.get_topic("list", nil, nil, %{"list" => 42})
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
describe "get_topic/_ (authenticated)" do
|
|
|
|
setup do: oauth_access(["read"])
|
|
|
|
|
|
|
|
test "allows public streams (regardless of OAuth token scopes)", %{
|
|
|
|
user: user,
|
|
|
|
token: read_oauth_token
|
|
|
|
} do
|
|
|
|
with oauth_token <- [nil, read_oauth_token] do
|
|
|
|
assert {:ok, "public"} = Streamer.get_topic("public", user, oauth_token)
|
|
|
|
assert {:ok, "public:local"} = Streamer.get_topic("public:local", user, oauth_token)
|
|
|
|
assert {:ok, "public:media"} = Streamer.get_topic("public:media", user, oauth_token)
|
2020-05-12 10:04:47 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
assert {:ok, "public:local:media"} =
|
|
|
|
Streamer.get_topic("public:local:media", user, oauth_token)
|
|
|
|
end
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
|
2023-03-30 19:01:37 -06:00
|
|
|
test "allows local public streams if restricted_unauthenticated is on", %{
|
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
|
|
|
} do
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
|
|
|
|
|
|
|
%{token: read_notifications_token} = oauth_access(["read:notifications"], user: user)
|
|
|
|
%{token: badly_scoped_token} = oauth_access(["irrelevant:scope"], user: user)
|
|
|
|
|
|
|
|
assert {:ok, "public:local"} = Streamer.get_topic("public:local", user, oauth_token)
|
|
|
|
|
|
|
|
assert {:ok, "public:local:media"} =
|
|
|
|
Streamer.get_topic("public:local:media", user, oauth_token)
|
|
|
|
|
|
|
|
for token <- [read_notifications_token, badly_scoped_token] do
|
|
|
|
assert {:error, :unauthorized} = Streamer.get_topic("public:local", user, token)
|
|
|
|
|
|
|
|
assert {:error, :unauthorized} = Streamer.get_topic("public:local:media", user, token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "allows remote public streams if restricted_unauthenticated is on", %{
|
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
|
|
|
} do
|
|
|
|
clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
|
|
|
|
|
|
|
%{token: read_notifications_token} = oauth_access(["read:notifications"], user: user)
|
|
|
|
%{token: badly_scoped_token} = oauth_access(["irrelevant:scope"], user: user)
|
|
|
|
|
|
|
|
assert {:ok, "public"} = Streamer.get_topic("public", user, oauth_token)
|
|
|
|
assert {:ok, "public:media"} = Streamer.get_topic("public:media", user, oauth_token)
|
|
|
|
|
|
|
|
assert {:ok, "public:remote:lain.com"} =
|
|
|
|
Streamer.get_topic("public:remote", user, oauth_token, %{"instance" => "lain.com"})
|
|
|
|
|
|
|
|
assert {:ok, "public:remote:media:lain.com"} =
|
|
|
|
Streamer.get_topic("public:remote:media", user, oauth_token, %{
|
|
|
|
"instance" => "lain.com"
|
|
|
|
})
|
|
|
|
|
|
|
|
for token <- [read_notifications_token, badly_scoped_token] do
|
|
|
|
assert {:error, :unauthorized} = Streamer.get_topic("public", user, token)
|
|
|
|
assert {:error, :unauthorized} = Streamer.get_topic("public:media", user, token)
|
|
|
|
|
|
|
|
assert {:error, :unauthorized} =
|
|
|
|
Streamer.get_topic("public:remote", user, token, %{
|
|
|
|
"instance" => "lain.com"
|
|
|
|
})
|
|
|
|
|
|
|
|
assert {:error, :unauthorized} =
|
|
|
|
Streamer.get_topic("public:remote:media", user, token, %{
|
|
|
|
"instance" => "lain.com"
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "allows user streams (with proper OAuth token scopes)", %{
|
|
|
|
user: user,
|
|
|
|
token: read_oauth_token
|
|
|
|
} do
|
|
|
|
%{token: read_notifications_token} = oauth_access(["read:notifications"], user: user)
|
|
|
|
%{token: read_statuses_token} = oauth_access(["read:statuses"], user: user)
|
|
|
|
%{token: badly_scoped_token} = oauth_access(["irrelevant:scope"], user: user)
|
|
|
|
|
2020-05-12 10:04:47 -06:00
|
|
|
expected_user_topic = "user:#{user.id}"
|
2020-09-19 10:16:55 -06:00
|
|
|
expected_notification_topic = "user:notification:#{user.id}"
|
2020-05-12 10:04:47 -06:00
|
|
|
expected_direct_topic = "direct:#{user.id}"
|
2020-09-19 10:16:55 -06:00
|
|
|
|
|
|
|
for valid_user_token <- [read_oauth_token, read_statuses_token] do
|
|
|
|
assert {:ok, ^expected_user_topic} = Streamer.get_topic("user", user, valid_user_token)
|
|
|
|
|
|
|
|
assert {:ok, ^expected_direct_topic} =
|
|
|
|
Streamer.get_topic("direct", user, valid_user_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
for invalid_user_token <- [read_notifications_token, badly_scoped_token],
|
2022-07-21 04:29:28 -06:00
|
|
|
user_topic <- ["user", "direct"] do
|
2020-09-19 10:16:55 -06:00
|
|
|
assert {:error, :unauthorized} = Streamer.get_topic(user_topic, user, invalid_user_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
for valid_notification_token <- [read_oauth_token, read_notifications_token] do
|
|
|
|
assert {:ok, ^expected_notification_topic} =
|
|
|
|
Streamer.get_topic("user:notification", user, valid_notification_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
for invalid_notification_token <- [read_statuses_token, badly_scoped_token] do
|
|
|
|
assert {:error, :unauthorized} =
|
|
|
|
Streamer.get_topic("user:notification", user, invalid_notification_token)
|
|
|
|
end
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "allows hashtag streams (regardless of OAuth token scopes)", %{
|
|
|
|
user: user,
|
|
|
|
token: read_oauth_token
|
|
|
|
} do
|
|
|
|
for oauth_token <- [nil, read_oauth_token] do
|
|
|
|
assert {:ok, "hashtag:cofe"} =
|
|
|
|
Streamer.get_topic("hashtag", user, oauth_token, %{"tag" => "cofe"})
|
|
|
|
end
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "disallows registering to another user's stream", %{user: user, token: read_oauth_token} do
|
2020-05-12 10:04:47 -06:00
|
|
|
another_user = insert(:user)
|
2020-09-19 10:16:55 -06:00
|
|
|
assert {:error, _} = Streamer.get_topic("user:#{another_user.id}", user, read_oauth_token)
|
|
|
|
|
|
|
|
assert {:error, _} =
|
|
|
|
Streamer.get_topic("user:notification:#{another_user.id}", user, read_oauth_token)
|
|
|
|
|
|
|
|
assert {:error, _} = Streamer.get_topic("direct:#{another_user.id}", user, read_oauth_token)
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "allows list stream that are owned by the user (with `read` or `read:lists` scopes)", %{
|
|
|
|
user: user,
|
|
|
|
token: read_oauth_token
|
|
|
|
} do
|
|
|
|
%{token: read_lists_token} = oauth_access(["read:lists"], user: user)
|
|
|
|
%{token: invalid_token} = oauth_access(["irrelevant:scope"], user: user)
|
2020-05-12 10:04:47 -06:00
|
|
|
{:ok, list} = List.create("Test", user)
|
2020-09-19 10:16:55 -06:00
|
|
|
|
|
|
|
assert {:error, _} = Streamer.get_topic("list:#{list.id}", user, read_oauth_token)
|
|
|
|
|
|
|
|
for valid_token <- [read_oauth_token, read_lists_token] do
|
|
|
|
assert {:ok, _} = Streamer.get_topic("list", user, valid_token, %{"list" => list.id})
|
|
|
|
end
|
|
|
|
|
|
|
|
assert {:error, _} = Streamer.get_topic("list", user, invalid_token, %{"list" => list.id})
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "disallows list stream that are not owned by the user", %{user: user, token: oauth_token} do
|
2020-05-12 10:04:47 -06:00
|
|
|
another_user = insert(:user)
|
|
|
|
{:ok, list} = List.create("Test", another_user)
|
2020-09-19 10:16:55 -06:00
|
|
|
|
|
|
|
assert {:error, _} = Streamer.get_topic("list:#{list.id}", user, oauth_token)
|
|
|
|
assert {:error, _} = Streamer.get_topic("list", user, oauth_token, %{"list" => list.id})
|
2020-05-12 10:04:47 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-16 04:33:25 -06:00
|
|
|
describe "user streams" do
|
|
|
|
setup do
|
2020-09-19 10:16:55 -06:00
|
|
|
%{user: user, token: token} = oauth_access(["read"])
|
2019-06-16 04:33:25 -06:00
|
|
|
notify = insert(:notification, user: user, activity: build(:note_activity))
|
2020-09-19 10:16:55 -06:00
|
|
|
{:ok, %{user: user, notify: notify, token: token}}
|
2019-06-16 04:33:25 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it streams the user's post in the 'user' stream", %{user: user, token: oauth_token} do
|
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
|
2020-09-19 10:16:55 -06:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
stream_name = "user:#{user.id}"
|
|
|
|
assert_receive {:render_with_user, _, _, ^activity, ^stream_name}
|
2020-05-07 03:13:32 -06:00
|
|
|
refute Streamer.filtered_by_user?(user, activity)
|
2020-04-22 09:21:13 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it streams boosts of the user in the 'user' stream", %{user: user, token: oauth_token} do
|
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
2020-04-22 09:21:13 -06:00
|
|
|
|
|
|
|
other_user = insert(:user)
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
|
2020-05-21 05:16:21 -06:00
|
|
|
{:ok, announce} = CommonAPI.repeat(activity.id, user)
|
2020-04-22 09:21:13 -06:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
stream_name = "user:#{user.id}"
|
|
|
|
|
|
|
|
assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce,
|
|
|
|
^stream_name}
|
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
refute Streamer.filtered_by_user?(user, announce)
|
2020-04-22 09:21:13 -06:00
|
|
|
end
|
|
|
|
|
2020-07-02 01:50:26 -06:00
|
|
|
test "it does not stream announces of the user's own posts in the 'user' stream", %{
|
2020-09-19 10:16:55 -06:00
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
2020-07-02 01:50:26 -06:00
|
|
|
} do
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
2020-07-02 01:50:26 -06:00
|
|
|
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
|
|
|
|
{:ok, announce} = CommonAPI.repeat(activity.id, other_user)
|
|
|
|
|
|
|
|
assert Streamer.filtered_by_user?(user, announce)
|
|
|
|
end
|
|
|
|
|
2020-07-04 09:11:37 -06:00
|
|
|
test "it does stream notifications announces of the user's own posts in the 'user' stream", %{
|
2020-09-19 10:16:55 -06:00
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
2020-07-04 09:11:37 -06:00
|
|
|
} do
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
2020-07-04 09:11:37 -06:00
|
|
|
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
|
|
|
|
{:ok, announce} = CommonAPI.repeat(activity.id, other_user)
|
|
|
|
|
|
|
|
notification =
|
|
|
|
Pleroma.Notification
|
|
|
|
|> Repo.get_by(%{user_id: user.id, activity_id: announce.id})
|
|
|
|
|> Repo.preload(:activity)
|
|
|
|
|
|
|
|
refute Streamer.filtered_by_user?(user, notification)
|
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it streams boosts of mastodon user in the 'user' stream", %{
|
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
|
|
|
} do
|
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
2020-05-29 06:08:09 -06:00
|
|
|
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-announce.json")
|
2020-11-23 12:28:55 -07:00
|
|
|
|> Jason.decode!()
|
2020-05-29 06:08:09 -06:00
|
|
|
|> Map.put("object", activity.data["object"])
|
|
|
|
|> Map.put("actor", user.ap_id)
|
|
|
|
|
2020-05-29 14:05:03 -06:00
|
|
|
{:ok, %Pleroma.Activity{data: _data, local: false} = announce} =
|
2020-05-29 06:08:09 -06:00
|
|
|
Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(data)
|
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
stream_name = "user:#{user.id}"
|
|
|
|
|
|
|
|
assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce,
|
|
|
|
^stream_name}
|
|
|
|
|
2020-05-29 06:08:09 -06:00
|
|
|
refute Streamer.filtered_by_user?(user, announce)
|
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it sends notify to in the 'user' stream", %{
|
|
|
|
user: user,
|
|
|
|
token: oauth_token,
|
|
|
|
notify: notify
|
|
|
|
} do
|
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
2019-06-16 04:33:25 -06:00
|
|
|
Streamer.stream("user", notify)
|
2020-09-19 10:16:55 -06:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^notify, "user"}
|
2020-05-07 03:13:32 -06:00
|
|
|
refute Streamer.filtered_by_user?(user, notify)
|
2019-06-16 04:33:25 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it sends notify to in the 'user:notification' stream", %{
|
|
|
|
user: user,
|
|
|
|
token: oauth_token,
|
|
|
|
notify: notify
|
|
|
|
} do
|
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
|
2019-06-16 04:33:25 -06:00
|
|
|
Streamer.stream("user:notification", notify)
|
2020-09-19 10:16:55 -06:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^notify, "user:notification"}
|
2020-05-25 09:27:45 -06:00
|
|
|
refute Streamer.filtered_by_user?(user, notify)
|
|
|
|
end
|
|
|
|
|
2019-07-21 20:43:55 -06:00
|
|
|
test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
|
2020-09-19 10:16:55 -06:00
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
2019-07-21 20:43:55 -06:00
|
|
|
} do
|
|
|
|
blocked = insert(:user)
|
2019-11-19 13:22:10 -07:00
|
|
|
{:ok, _user_relationship} = User.block(user, blocked)
|
2019-07-21 20:43:55 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
|
2019-07-21 20:43:55 -06:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: ":("})
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, _} = CommonAPI.favorite(blocked, activity.id)
|
2019-07-21 20:43:55 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
refute_receive _
|
2019-07-21 20:43:55 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it doesn't send notify to the 'user:notification' stream when a thread is muted", %{
|
2020-09-19 10:16:55 -06:00
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
2019-07-21 20:43:55 -06:00
|
|
|
} do
|
|
|
|
user2 = insert(:user)
|
2020-01-29 03:50:49 -07:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, _} = CommonAPI.add_mute(user, activity)
|
2019-07-21 20:43:55 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
|
2019-07-21 20:43:55 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
|
2020-03-19 11:00:55 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
refute_receive _
|
|
|
|
assert Streamer.filtered_by_user?(user, favorite_activity)
|
2019-07-21 20:43:55 -06:00
|
|
|
end
|
2019-07-24 04:09:06 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
test "it sends favorite to 'user:notification' stream'", %{
|
2020-09-19 10:16:55 -06:00
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
2019-07-24 04:09:06 -06:00
|
|
|
} do
|
|
|
|
user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
|
2020-01-29 03:50:49 -07:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
|
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, "notification.json", notif, "user:notification"}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert notif.activity.id == favorite_activity.id
|
|
|
|
refute Streamer.filtered_by_user?(user, notif)
|
|
|
|
end
|
2019-07-24 04:09:06 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
test "it doesn't send the 'user:notification' stream' when a domain is blocked", %{
|
2020-09-19 10:16:55 -06:00
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
2020-05-07 03:13:32 -06:00
|
|
|
} do
|
|
|
|
user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
|
2019-07-24 04:09:06 -06:00
|
|
|
|
|
|
|
{:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
|
2019-07-24 04:35:16 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
refute_receive _
|
|
|
|
assert Streamer.filtered_by_user?(user, favorite_activity)
|
2019-07-24 04:09:06 -06:00
|
|
|
end
|
2019-11-03 08:05:12 -07:00
|
|
|
|
|
|
|
test "it sends follow activities to the 'user:notification' stream", %{
|
2020-09-19 10:16:55 -06:00
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
2019-11-03 08:05:12 -07:00
|
|
|
} do
|
2020-05-07 03:13:32 -06:00
|
|
|
user2 = insert(:user)
|
2020-03-05 07:31:06 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, _follower, _followed, follow_activity} = CommonAPI.follow(user2, user)
|
2019-11-03 08:05:12 -07:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, "notification.json", notif, "user:notification"}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert notif.activity.id == follow_activity.id
|
|
|
|
refute Streamer.filtered_by_user?(user, notif)
|
2019-11-03 08:05:12 -07:00
|
|
|
end
|
2020-12-01 13:17:52 -07:00
|
|
|
|
2020-12-02 08:16:36 -07:00
|
|
|
test "it sends follow relationships updates to the 'user' stream", %{
|
2020-12-01 13:17:52 -07:00
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
|
|
|
} do
|
|
|
|
user_id = user.id
|
2020-12-02 08:16:36 -07:00
|
|
|
other_user = insert(:user)
|
|
|
|
other_user_id = other_user.id
|
2020-12-01 13:17:52 -07:00
|
|
|
|
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
2020-12-02 08:16:36 -07:00
|
|
|
{:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(user, other_user)
|
2020-12-01 13:17:52 -07:00
|
|
|
|
|
|
|
assert_receive {:text, event}
|
|
|
|
|
2020-12-02 08:16:36 -07:00
|
|
|
assert %{"event" => "pleroma:follow_relationships_update", "payload" => payload} =
|
2020-12-01 13:17:52 -07:00
|
|
|
Jason.decode!(event)
|
|
|
|
|
|
|
|
assert %{
|
|
|
|
"follower" => %{
|
|
|
|
"follower_count" => 0,
|
|
|
|
"following_count" => 0,
|
2020-12-02 08:16:36 -07:00
|
|
|
"id" => ^user_id
|
2020-12-01 13:17:52 -07:00
|
|
|
},
|
|
|
|
"following" => %{
|
|
|
|
"follower_count" => 0,
|
|
|
|
"following_count" => 0,
|
2020-12-02 08:16:36 -07:00
|
|
|
"id" => ^other_user_id
|
2020-12-01 13:17:52 -07:00
|
|
|
},
|
|
|
|
"state" => "follow_pending"
|
|
|
|
} = Jason.decode!(payload)
|
|
|
|
|
|
|
|
assert_receive {:text, event}
|
|
|
|
|
2020-12-02 08:16:36 -07:00
|
|
|
assert %{"event" => "pleroma:follow_relationships_update", "payload" => payload} =
|
2020-12-01 13:17:52 -07:00
|
|
|
Jason.decode!(event)
|
|
|
|
|
|
|
|
assert %{
|
|
|
|
"follower" => %{
|
|
|
|
"follower_count" => 0,
|
|
|
|
"following_count" => 1,
|
2020-12-02 08:16:36 -07:00
|
|
|
"id" => ^user_id
|
2020-12-01 13:17:52 -07:00
|
|
|
},
|
|
|
|
"following" => %{
|
|
|
|
"follower_count" => 1,
|
|
|
|
"following_count" => 0,
|
2020-12-02 08:16:36 -07:00
|
|
|
"id" => ^other_user_id
|
2020-12-01 13:17:52 -07:00
|
|
|
},
|
|
|
|
"state" => "follow_accept"
|
|
|
|
} = Jason.decode!(payload)
|
|
|
|
end
|
2022-09-06 13:24:02 -06:00
|
|
|
|
|
|
|
test "it streams edits in the 'user' stream", %{user: user, token: oauth_token} do
|
|
|
|
sender = insert(:user)
|
|
|
|
{:ok, _, _, _} = CommonAPI.follow(user, sender)
|
|
|
|
|
|
|
|
{:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
|
|
|
|
|
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
|
|
|
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
|
|
|
|
create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
|
|
|
|
|
|
|
|
stream = "user:#{user.id}"
|
|
|
|
assert_receive {:render_with_user, _, "status_update.json", ^create, ^stream}
|
|
|
|
refute Streamer.filtered_by_user?(user, edited)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it streams own edits in the 'user' stream", %{user: user, token: oauth_token} do
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
|
|
|
|
|
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
|
|
|
{:ok, edited} = CommonAPI.update(user, activity, %{status: "mew mew"})
|
|
|
|
create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
|
|
|
|
|
|
|
|
stream = "user:#{user.id}"
|
|
|
|
assert_receive {:render_with_user, _, "status_update.json", ^create, ^stream}
|
|
|
|
refute Streamer.filtered_by_user?(user, edited)
|
|
|
|
end
|
2022-12-05 05:58:48 -07:00
|
|
|
|
|
|
|
test "it streams posts containing followed hashtags on the 'user' stream", %{
|
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
|
|
|
} do
|
|
|
|
hashtag = insert(:hashtag, %{name: "tenshi"})
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, user} = User.follow_hashtag(user, hashtag)
|
|
|
|
|
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
|
|
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "hey #tenshi"})
|
|
|
|
|
|
|
|
assert_receive {:render_with_user, _, "update.json", ^activity, _}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should not stream private posts containing followed hashtags on the 'user' stream", %{
|
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
|
|
|
} do
|
|
|
|
hashtag = insert(:hashtag, %{name: "tenshi"})
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, user} = User.follow_hashtag(user, hashtag)
|
|
|
|
|
|
|
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(other_user, %{status: "hey #tenshi", visibility: "private"})
|
|
|
|
|
|
|
|
refute_receive {:render_with_user, _, "update.json", ^activity, _}
|
|
|
|
end
|
2019-06-16 04:33:25 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
describe "public streams" do
|
|
|
|
test "it sends to public (authenticated)" do
|
|
|
|
%{user: user, token: oauth_token} = oauth_access(["read"])
|
|
|
|
other_user = insert(:user)
|
2018-05-05 05:40:47 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("public", user, oauth_token)
|
2018-05-05 05:40:47 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "Test"})
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity, "public"}
|
2020-09-19 10:16:55 -06:00
|
|
|
refute Streamer.filtered_by_user?(other_user, activity)
|
|
|
|
end
|
2020-04-30 09:52:29 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it sends to public (unauthenticated)" do
|
|
|
|
user = insert(:user)
|
2019-01-20 05:00:46 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("public", nil, nil)
|
2019-01-20 05:00:46 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "Test"})
|
|
|
|
activity_id = activity.id
|
|
|
|
assert_receive {:text, event}
|
|
|
|
assert %{"event" => "update", "payload" => payload} = Jason.decode!(event)
|
|
|
|
assert %{"id" => ^activity_id} = Jason.decode!(payload)
|
2019-01-20 05:00:46 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
{:ok, _} = CommonAPI.delete(activity.id, user)
|
|
|
|
assert_receive {:text, event}
|
|
|
|
assert %{"event" => "delete", "payload" => ^activity_id} = Jason.decode!(event)
|
|
|
|
end
|
2019-01-20 05:00:46 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "handles deletions" do
|
|
|
|
%{user: user, token: oauth_token} = oauth_access(["read"])
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "Test"})
|
2019-01-20 05:00:46 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("public", user, oauth_token)
|
2019-01-20 05:00:46 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
{:ok, _} = CommonAPI.delete(activity.id, other_user)
|
|
|
|
activity_id = activity.id
|
|
|
|
assert_receive {:text, event}
|
|
|
|
assert %{"event" => "delete", "payload" => ^activity_id} = Jason.decode!(event)
|
|
|
|
end
|
2022-09-06 13:24:02 -06:00
|
|
|
|
|
|
|
test "it streams edits in the 'public' stream" do
|
|
|
|
sender = insert(:user)
|
|
|
|
|
|
|
|
Streamer.get_topic_and_add_socket("public", nil, nil)
|
|
|
|
{:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
|
|
|
|
assert_receive {:text, _}
|
|
|
|
|
|
|
|
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
|
|
|
|
|
|
|
|
edited = Pleroma.Activity.normalize(edited)
|
|
|
|
|
|
|
|
%{id: activity_id} = Pleroma.Activity.get_create_by_object_ap_id(edited.object.data["id"])
|
|
|
|
|
|
|
|
assert_receive {:text, event}
|
|
|
|
assert %{"event" => "status.update", "payload" => payload} = Jason.decode!(event)
|
|
|
|
assert %{"id" => ^activity_id} = Jason.decode!(payload)
|
|
|
|
refute Streamer.filtered_by_user?(sender, edited)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it streams multiple edits in the 'public' stream correctly" do
|
|
|
|
sender = insert(:user)
|
|
|
|
|
|
|
|
Streamer.get_topic_and_add_socket("public", nil, nil)
|
|
|
|
{:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
|
|
|
|
assert_receive {:text, _}
|
|
|
|
|
|
|
|
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
|
|
|
|
|
|
|
|
edited = Pleroma.Activity.normalize(edited)
|
|
|
|
|
|
|
|
%{id: activity_id} = Pleroma.Activity.get_create_by_object_ap_id(edited.object.data["id"])
|
|
|
|
|
|
|
|
assert_receive {:text, event}
|
|
|
|
assert %{"event" => "status.update", "payload" => payload} = Jason.decode!(event)
|
|
|
|
assert %{"id" => ^activity_id} = Jason.decode!(payload)
|
|
|
|
refute Streamer.filtered_by_user?(sender, edited)
|
|
|
|
|
|
|
|
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew 2"})
|
|
|
|
|
|
|
|
edited = Pleroma.Activity.normalize(edited)
|
|
|
|
|
|
|
|
%{id: activity_id} = Pleroma.Activity.get_create_by_object_ap_id(edited.object.data["id"])
|
|
|
|
assert_receive {:text, event}
|
|
|
|
assert %{"event" => "status.update", "payload" => payload} = Jason.decode!(event)
|
|
|
|
assert %{"id" => ^activity_id, "content" => "mew mew 2"} = Jason.decode!(payload)
|
|
|
|
refute Streamer.filtered_by_user?(sender, edited)
|
|
|
|
end
|
2018-05-05 05:40:47 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
describe "thread_containment/2" do
|
2020-05-07 03:13:32 -06:00
|
|
|
test "it filters to user if recipients invalid and thread containment is enabled" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:instance, :skip_thread_containment], false)
|
2019-06-03 07:04:39 -06:00
|
|
|
author = insert(:user)
|
2020-09-19 10:16:55 -06:00
|
|
|
%{user: user, token: oauth_token} = oauth_access(["read"])
|
2020-03-28 09:49:03 -06:00
|
|
|
User.follow(user, author, :follow_accept)
|
2019-06-03 07:04:39 -06:00
|
|
|
|
|
|
|
activity =
|
|
|
|
insert(:note_activity,
|
|
|
|
note:
|
|
|
|
insert(:note,
|
|
|
|
user: author,
|
|
|
|
data: %{"to" => ["TEST-FFF"]}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("public", user, oauth_token)
|
2020-05-07 03:13:32 -06:00
|
|
|
Streamer.stream("public", activity)
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity, "public"}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert Streamer.filtered_by_user?(user, activity)
|
2019-06-03 07:04:39 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends message if recipients invalid and thread containment is disabled" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:instance, :skip_thread_containment], true)
|
2019-06-03 07:04:39 -06:00
|
|
|
author = insert(:user)
|
2020-09-19 10:16:55 -06:00
|
|
|
%{user: user, token: oauth_token} = oauth_access(["read"])
|
2020-03-28 09:49:03 -06:00
|
|
|
User.follow(user, author, :follow_accept)
|
2019-06-03 07:04:39 -06:00
|
|
|
|
|
|
|
activity =
|
|
|
|
insert(:note_activity,
|
|
|
|
note:
|
|
|
|
insert(:note,
|
|
|
|
user: author,
|
|
|
|
data: %{"to" => ["TEST-FFF"]}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("public", user, oauth_token)
|
2020-05-07 03:13:32 -06:00
|
|
|
Streamer.stream("public", activity)
|
2019-06-03 07:04:39 -06:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity, "public"}
|
2020-05-07 03:13:32 -06:00
|
|
|
refute Streamer.filtered_by_user?(user, activity)
|
2019-06-03 07:04:39 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:instance, :skip_thread_containment], false)
|
2019-06-03 07:04:39 -06:00
|
|
|
author = insert(:user)
|
2019-10-24 01:42:14 -06:00
|
|
|
user = insert(:user, skip_thread_containment: true)
|
2020-09-19 10:16:55 -06:00
|
|
|
%{token: oauth_token} = oauth_access(["read"], user: user)
|
2020-03-28 09:49:03 -06:00
|
|
|
User.follow(user, author, :follow_accept)
|
2019-06-03 07:04:39 -06:00
|
|
|
|
|
|
|
activity =
|
|
|
|
insert(:note_activity,
|
|
|
|
note:
|
|
|
|
insert(:note,
|
|
|
|
user: author,
|
|
|
|
data: %{"to" => ["TEST-FFF"]}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("public", user, oauth_token)
|
2020-05-07 03:13:32 -06:00
|
|
|
Streamer.stream("public", activity)
|
2019-06-03 07:04:39 -06:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity, "public"}
|
2020-05-07 03:13:32 -06:00
|
|
|
refute Streamer.filtered_by_user?(user, activity)
|
2019-06-03 07:04:39 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-04 09:17:32 -06:00
|
|
|
describe "blocks" do
|
2020-09-19 10:16:55 -06:00
|
|
|
setup do: oauth_access(["read"])
|
|
|
|
|
|
|
|
test "it filters messages involving blocked users", %{user: user, token: oauth_token} do
|
2019-10-04 09:17:32 -06:00
|
|
|
blocked_user = insert(:user)
|
2019-11-19 13:22:10 -07:00
|
|
|
{:ok, _user_relationship} = User.block(user, blocked_user)
|
2018-05-05 05:40:47 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("public", user, oauth_token)
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(blocked_user, %{status: "Test"})
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity, "public"}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert Streamer.filtered_by_user?(user, activity)
|
2019-10-04 09:17:32 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it filters messages transitively involving blocked users", %{
|
|
|
|
user: blocker,
|
|
|
|
token: blocker_token
|
|
|
|
} do
|
2019-10-04 09:17:32 -06:00
|
|
|
blockee = insert(:user)
|
|
|
|
friend = insert(:user)
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("public", blocker, blocker_token)
|
2019-10-04 09:17:32 -06:00
|
|
|
|
2019-11-19 13:22:10 -07:00
|
|
|
{:ok, _user_relationship} = User.block(blocker, blockee)
|
2019-10-04 09:17:32 -06:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity_one} = CommonAPI.post(friend, %{status: "hey! @#{blockee.nickname}"})
|
2019-10-04 09:17:32 -06:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity_one, "public"}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert Streamer.filtered_by_user?(blocker, activity_one)
|
2019-10-04 09:17:32 -06:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"})
|
2019-10-04 09:17:32 -06:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity_two, "public"}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert Streamer.filtered_by_user?(blocker, activity_two)
|
2019-10-04 09:17:32 -06:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity_three} = CommonAPI.post(blockee, %{status: "hey! @#{blocker.nickname}"})
|
2019-10-04 09:17:32 -06:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity_three, "public"}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert Streamer.filtered_by_user?(blocker, activity_three)
|
2019-10-04 09:17:32 -06:00
|
|
|
end
|
2018-05-05 05:40:47 -06:00
|
|
|
end
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
describe "lists" do
|
2020-09-19 10:16:55 -06:00
|
|
|
setup do: oauth_access(["read"])
|
|
|
|
|
|
|
|
test "it doesn't send unwanted DMs to list", %{user: user_a, token: user_a_token} do
|
2020-05-07 03:13:32 -06:00
|
|
|
user_b = insert(:user)
|
|
|
|
user_c = insert(:user)
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-12-01 13:17:52 -07:00
|
|
|
{:ok, user_a, user_b} = User.follow(user_a, user_b)
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, list} = List.create("Test", user_a)
|
|
|
|
{:ok, list} = List.follow(list, user_b)
|
2020-01-29 03:50:49 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("list", user_a, user_a_token, %{"list" => list.id})
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, _activity} =
|
|
|
|
CommonAPI.post(user_b, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "@#{user_c.nickname} Test",
|
|
|
|
visibility: "direct"
|
2020-05-07 03:13:32 -06:00
|
|
|
})
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
refute_receive _
|
|
|
|
end
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it doesn't send unwanted private posts to list", %{user: user_a, token: user_a_token} do
|
2020-05-07 03:13:32 -06:00
|
|
|
user_b = insert(:user)
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, list} = List.create("Test", user_a)
|
|
|
|
{:ok, list} = List.follow(list, user_b)
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("list", user_a, user_a_token, %{"list" => list.id})
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, _activity} =
|
|
|
|
CommonAPI.post(user_b, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "Test",
|
|
|
|
visibility: "private"
|
2020-05-07 03:13:32 -06:00
|
|
|
})
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
refute_receive _
|
|
|
|
end
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it sends wanted private posts to list", %{user: user_a, token: user_a_token} do
|
2020-05-07 03:13:32 -06:00
|
|
|
user_b = insert(:user)
|
2020-01-29 03:50:49 -07:00
|
|
|
|
2020-12-01 13:17:52 -07:00
|
|
|
{:ok, user_a, user_b} = User.follow(user_a, user_b)
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, list} = List.create("Test", user_a)
|
|
|
|
{:ok, list} = List.follow(list, user_b)
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("list", user_a, user_a_token, %{"list" => list.id})
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(user_b, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "Test",
|
|
|
|
visibility: "private"
|
2020-05-07 03:13:32 -06:00
|
|
|
})
|
2018-11-26 17:14:43 -07:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
stream_name = "list:#{list.id}"
|
|
|
|
assert_receive {:render_with_user, _, _, ^activity, ^stream_name}
|
2020-05-07 03:13:32 -06:00
|
|
|
refute Streamer.filtered_by_user?(user_a, activity)
|
|
|
|
end
|
2018-11-26 17:14:43 -07:00
|
|
|
end
|
2019-03-15 07:06:58 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
describe "muted reblogs" do
|
2020-09-19 10:16:55 -06:00
|
|
|
setup do: oauth_access(["read"])
|
|
|
|
|
|
|
|
test "it filters muted reblogs", %{user: user1, token: user1_token} do
|
2020-05-07 03:13:32 -06:00
|
|
|
user2 = insert(:user)
|
|
|
|
user3 = insert(:user)
|
|
|
|
CommonAPI.follow(user1, user2)
|
|
|
|
CommonAPI.hide_reblogs(user1, user2)
|
2019-03-15 07:06:58 -06:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"})
|
2019-06-24 01:14:04 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user", user1, user1_token)
|
2020-05-21 05:16:21 -06:00
|
|
|
{:ok, announce_activity} = CommonAPI.repeat(create_activity.id, user2)
|
2022-08-16 18:22:59 -06:00
|
|
|
stream_name = "user:#{user1.id}"
|
|
|
|
assert_receive {:render_with_user, _, _, ^announce_activity, ^stream_name}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert Streamer.filtered_by_user?(user1, announce_activity)
|
|
|
|
end
|
2020-01-28 08:40:44 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it filters reblog notification for reblog-muted actors", %{
|
|
|
|
user: user1,
|
|
|
|
token: user1_token
|
|
|
|
} do
|
2020-05-07 03:13:32 -06:00
|
|
|
user2 = insert(:user)
|
|
|
|
CommonAPI.follow(user1, user2)
|
|
|
|
CommonAPI.hide_reblogs(user1, user2)
|
2020-01-29 03:50:49 -07:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user", user1, user1_token)
|
2020-05-21 05:16:21 -06:00
|
|
|
{:ok, _announce_activity} = CommonAPI.repeat(create_activity.id, user2)
|
2020-01-28 08:40:44 -07:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, "notification.json", notif, "user"}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert Streamer.filtered_by_user?(user1, notif)
|
|
|
|
end
|
2020-01-28 08:40:44 -07:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it send non-reblog notification for reblog-muted actors", %{
|
|
|
|
user: user1,
|
|
|
|
token: user1_token
|
|
|
|
} do
|
2020-05-07 03:13:32 -06:00
|
|
|
user2 = insert(:user)
|
|
|
|
CommonAPI.follow(user1, user2)
|
|
|
|
CommonAPI.hide_reblogs(user1, user2)
|
2020-01-28 08:40:44 -07:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("user", user1, user1_token)
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, _favorite_activity} = CommonAPI.favorite(user2, create_activity.id)
|
2020-01-28 08:40:44 -07:00
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
assert_receive {:render_with_user, _, "notification.json", notif, "user"}
|
2020-05-07 03:13:32 -06:00
|
|
|
refute Streamer.filtered_by_user?(user1, notif)
|
|
|
|
end
|
2020-01-28 08:40:44 -07:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
describe "muted threads" do
|
|
|
|
test "it filters posts from muted threads" do
|
|
|
|
user = insert(:user)
|
|
|
|
%{user: user2, token: user2_token} = oauth_access(["read"])
|
|
|
|
Streamer.get_topic_and_add_socket("user", user2, user2_token)
|
|
|
|
|
|
|
|
{:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
|
|
|
|
{:ok, _} = CommonAPI.add_mute(user2, activity)
|
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
stream_name = "user:#{user2.id}"
|
|
|
|
assert_receive {:render_with_user, _, _, ^activity, ^stream_name}
|
2020-09-19 10:16:55 -06:00
|
|
|
assert Streamer.filtered_by_user?(user2, activity)
|
|
|
|
end
|
2019-08-15 08:37:30 -06:00
|
|
|
end
|
|
|
|
|
2019-06-24 01:14:04 -06:00
|
|
|
describe "direct streams" do
|
2020-09-19 10:16:55 -06:00
|
|
|
setup do: oauth_access(["read"])
|
2019-06-24 01:14:04 -06:00
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it sends conversation update to the 'direct' stream", %{user: user, token: oauth_token} do
|
2019-06-24 01:14:04 -06:00
|
|
|
another_user = insert(:user)
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("direct", user, oauth_token)
|
2019-06-24 01:14:04 -06:00
|
|
|
|
|
|
|
{:ok, _create_activity} =
|
|
|
|
CommonAPI.post(another_user, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "hey @#{user.nickname}",
|
|
|
|
visibility: "direct"
|
2019-06-24 01:14:04 -06:00
|
|
|
})
|
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
assert_receive {:text, received_event}
|
|
|
|
|
|
|
|
assert %{"event" => "conversation", "payload" => received_payload} =
|
|
|
|
Jason.decode!(received_event)
|
|
|
|
|
|
|
|
assert %{"last_status" => last_status} = Jason.decode!(received_payload)
|
|
|
|
[participation] = Participation.for_user(user)
|
|
|
|
assert last_status["pleroma"]["direct_conversation_id"] == participation.id
|
2019-06-24 01:14:04 -06:00
|
|
|
end
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it doesn't send conversation update to the 'direct' stream when the last message in the conversation is deleted",
|
|
|
|
%{user: user, token: oauth_token} do
|
2019-06-24 01:14:04 -06:00
|
|
|
another_user = insert(:user)
|
|
|
|
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("direct", user, oauth_token)
|
2020-05-07 03:13:32 -06:00
|
|
|
|
2019-06-24 01:14:04 -06:00
|
|
|
{:ok, create_activity} =
|
|
|
|
CommonAPI.post(another_user, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "hi @#{user.nickname}",
|
|
|
|
visibility: "direct"
|
2019-06-24 01:14:04 -06:00
|
|
|
})
|
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
create_activity_id = create_activity.id
|
2022-08-16 18:22:59 -06:00
|
|
|
stream_name = "direct:#{user.id}"
|
|
|
|
assert_receive {:render_with_user, _, _, ^create_activity, ^stream_name}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert_receive {:text, received_conversation1}
|
|
|
|
assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
|
2019-06-24 01:14:04 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, _} = CommonAPI.delete(create_activity_id, another_user)
|
2019-06-24 01:14:04 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
assert_receive {:text, received_event}
|
2019-09-16 04:03:37 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
assert %{"event" => "delete", "payload" => ^create_activity_id} =
|
|
|
|
Jason.decode!(received_event)
|
2019-06-24 01:14:04 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
refute_receive _
|
2019-06-24 01:14:04 -06:00
|
|
|
end
|
|
|
|
|
2021-12-31 09:29:50 -07:00
|
|
|
@tag :erratic
|
2020-09-19 10:16:55 -06:00
|
|
|
test "it sends conversation update to the 'direct' stream when a message is deleted", %{
|
|
|
|
user: user,
|
|
|
|
token: oauth_token
|
|
|
|
} do
|
2019-06-24 01:14:04 -06:00
|
|
|
another_user = insert(:user)
|
2020-09-19 10:16:55 -06:00
|
|
|
Streamer.get_topic_and_add_socket("direct", user, oauth_token)
|
2019-06-24 01:14:04 -06:00
|
|
|
|
|
|
|
{:ok, create_activity} =
|
|
|
|
CommonAPI.post(another_user, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "hi @#{user.nickname}",
|
|
|
|
visibility: "direct"
|
2019-06-24 01:14:04 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, create_activity2} =
|
|
|
|
CommonAPI.post(another_user, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "hi @#{user.nickname} 2",
|
|
|
|
in_reply_to_status_id: create_activity.id,
|
|
|
|
visibility: "direct"
|
2019-06-24 01:14:04 -06:00
|
|
|
})
|
|
|
|
|
2022-08-16 18:22:59 -06:00
|
|
|
stream_name = "direct:#{user.id}"
|
|
|
|
assert_receive {:render_with_user, _, _, ^create_activity, ^stream_name}
|
|
|
|
assert_receive {:render_with_user, _, _, ^create_activity2, ^stream_name}
|
2020-05-07 03:13:32 -06:00
|
|
|
assert_receive {:text, received_conversation1}
|
|
|
|
assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
|
|
|
|
assert_receive {:text, received_conversation1}
|
|
|
|
assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
|
2019-12-15 15:37:33 -07:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
{:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
|
2019-06-24 01:14:04 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
assert_receive {:text, received_event}
|
|
|
|
assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
|
2019-09-16 04:03:37 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
assert_receive {:text, received_event}
|
2019-06-24 01:14:04 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
assert %{"event" => "conversation", "payload" => received_payload} =
|
|
|
|
Jason.decode!(received_event)
|
2019-06-24 01:14:04 -06:00
|
|
|
|
2020-05-07 03:13:32 -06:00
|
|
|
assert %{"last_status" => last_status} = Jason.decode!(received_payload)
|
|
|
|
assert last_status["id"] == to_string(create_activity.id)
|
2019-06-24 01:14:04 -06:00
|
|
|
end
|
|
|
|
end
|
2022-08-19 11:19:38 -06:00
|
|
|
|
|
|
|
describe "stop streaming if token got revoked" do
|
|
|
|
setup do
|
|
|
|
child_proc = fn start, finalize ->
|
|
|
|
fn ->
|
|
|
|
start.()
|
|
|
|
|
|
|
|
receive do
|
|
|
|
{StreamerTest, :ready} ->
|
|
|
|
assert_receive {:render_with_user, _, "update.json", _, _}
|
|
|
|
|
|
|
|
receive do
|
|
|
|
{StreamerTest, :revoked} -> finalize.()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
starter = fn user, token ->
|
|
|
|
fn -> Streamer.get_topic_and_add_socket("user", user, token) end
|
|
|
|
end
|
|
|
|
|
|
|
|
hit = fn -> assert_receive :close end
|
|
|
|
miss = fn -> refute_receive :close end
|
|
|
|
|
|
|
|
send_all = fn tasks, thing -> Enum.each(tasks, &send(&1.pid, thing)) end
|
|
|
|
|
|
|
|
%{
|
|
|
|
child_proc: child_proc,
|
|
|
|
starter: starter,
|
|
|
|
hit: hit,
|
|
|
|
miss: miss,
|
|
|
|
send_all: send_all
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "do not revoke other tokens", %{
|
|
|
|
child_proc: child_proc,
|
|
|
|
starter: starter,
|
|
|
|
hit: hit,
|
|
|
|
miss: miss,
|
|
|
|
send_all: send_all
|
|
|
|
} do
|
|
|
|
%{user: user, token: token} = oauth_access(["read"])
|
|
|
|
%{token: token2} = oauth_access(["read"], user: user)
|
|
|
|
%{user: user2, token: user2_token} = oauth_access(["read"])
|
|
|
|
|
|
|
|
post_user = insert(:user)
|
|
|
|
CommonAPI.follow(user, post_user)
|
|
|
|
CommonAPI.follow(user2, post_user)
|
|
|
|
|
|
|
|
tasks = [
|
|
|
|
Task.async(child_proc.(starter.(user, token), hit)),
|
|
|
|
Task.async(child_proc.(starter.(user, token2), miss)),
|
|
|
|
Task.async(child_proc.(starter.(user2, user2_token), miss))
|
|
|
|
]
|
|
|
|
|
|
|
|
{:ok, _} =
|
|
|
|
CommonAPI.post(post_user, %{
|
|
|
|
status: "hi"
|
|
|
|
})
|
|
|
|
|
|
|
|
send_all.(tasks, {StreamerTest, :ready})
|
|
|
|
|
|
|
|
Pleroma.Web.OAuth.Token.Strategy.Revoke.revoke(token)
|
|
|
|
|
|
|
|
send_all.(tasks, {StreamerTest, :revoked})
|
|
|
|
|
|
|
|
Enum.each(tasks, &Task.await/1)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "revoke all streams for this token", %{
|
|
|
|
child_proc: child_proc,
|
|
|
|
starter: starter,
|
|
|
|
hit: hit,
|
|
|
|
send_all: send_all
|
|
|
|
} do
|
|
|
|
%{user: user, token: token} = oauth_access(["read"])
|
|
|
|
|
|
|
|
post_user = insert(:user)
|
|
|
|
CommonAPI.follow(user, post_user)
|
|
|
|
|
|
|
|
tasks = [
|
|
|
|
Task.async(child_proc.(starter.(user, token), hit)),
|
|
|
|
Task.async(child_proc.(starter.(user, token), hit))
|
|
|
|
]
|
|
|
|
|
|
|
|
{:ok, _} =
|
|
|
|
CommonAPI.post(post_user, %{
|
|
|
|
status: "hi"
|
|
|
|
})
|
|
|
|
|
|
|
|
send_all.(tasks, {StreamerTest, :ready})
|
|
|
|
|
|
|
|
Pleroma.Web.OAuth.Token.Strategy.Revoke.revoke(token)
|
|
|
|
|
|
|
|
send_all.(tasks, {StreamerTest, :revoked})
|
|
|
|
|
|
|
|
Enum.each(tasks, &Task.await/1)
|
|
|
|
end
|
|
|
|
end
|
2018-05-05 05:40:47 -06:00
|
|
|
end
|