2018-12-23 12:11:29 -08:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-01 21:08:45 -08:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 12:11:29 -08:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-05-05 04:40:47 -07:00
|
|
|
defmodule Pleroma.Web.StreamerTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
2019-09-16 03:03:37 -07:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
2020-06-03 07:45:04 -07:00
|
|
|
alias Pleroma.Chat
|
2020-06-06 02:51:10 -07:00
|
|
|
alias Pleroma.Chat.MessageReference
|
2019-10-30 17:44:27 -07:00
|
|
|
alias Pleroma.Conversation.Participation
|
2019-01-20 04:00:46 -08:00
|
|
|
alias Pleroma.List
|
2020-05-29 06:24:41 -07:00
|
|
|
alias Pleroma.Object
|
2019-01-20 04:00:46 -08:00
|
|
|
alias Pleroma.User
|
2018-05-05 04:40:47 -07:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-03-04 18:52:23 -08:00
|
|
|
alias Pleroma.Web.Streamer
|
2020-05-29 06:24:41 -07:00
|
|
|
alias Pleroma.Web.StreamerView
|
2018-05-05 04:40:47 -07:00
|
|
|
|
2019-11-28 01:44:48 -08:00
|
|
|
@moduletag needs_streamer: true, capture_log: true
|
2019-12-15 14:22:01 -08:00
|
|
|
|
2020-03-20 08:33:00 -07:00
|
|
|
setup do: clear_config([:instance, :skip_thread_containment])
|
2019-06-03 06:04:39 -07:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
describe "get_topic without an user" do
|
|
|
|
test "allows public" do
|
|
|
|
assert {:ok, "public"} = Streamer.get_topic("public", nil)
|
|
|
|
assert {:ok, "public:local"} = Streamer.get_topic("public:local", nil)
|
|
|
|
assert {:ok, "public:media"} = Streamer.get_topic("public:media", nil)
|
|
|
|
assert {:ok, "public:local:media"} = Streamer.get_topic("public:local:media", nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "allows hashtag streams" do
|
|
|
|
assert {:ok, "hashtag:cofe"} = Streamer.get_topic("hashtag", nil, %{"tag" => "cofe"})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "disallows user streams" do
|
|
|
|
assert {:error, _} = Streamer.get_topic("user", nil)
|
|
|
|
assert {:error, _} = Streamer.get_topic("user:notification", nil)
|
|
|
|
assert {:error, _} = Streamer.get_topic("direct", nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "disallows list streams" do
|
|
|
|
assert {:error, _} = Streamer.get_topic("list", nil, %{"list" => 42})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "get_topic with an user" do
|
|
|
|
setup do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, %{user: user}}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "allows public streams", %{user: user} do
|
|
|
|
assert {:ok, "public"} = Streamer.get_topic("public", user)
|
|
|
|
assert {:ok, "public:local"} = Streamer.get_topic("public:local", user)
|
|
|
|
assert {:ok, "public:media"} = Streamer.get_topic("public:media", user)
|
|
|
|
assert {:ok, "public:local:media"} = Streamer.get_topic("public:local:media", user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "allows user streams", %{user: user} do
|
|
|
|
expected_user_topic = "user:#{user.id}"
|
|
|
|
expected_notif_topic = "user:notification:#{user.id}"
|
|
|
|
expected_direct_topic = "direct:#{user.id}"
|
|
|
|
assert {:ok, ^expected_user_topic} = Streamer.get_topic("user", user)
|
|
|
|
assert {:ok, ^expected_notif_topic} = Streamer.get_topic("user:notification", user)
|
|
|
|
assert {:ok, ^expected_direct_topic} = Streamer.get_topic("direct", user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "allows hashtag streams", %{user: user} do
|
|
|
|
assert {:ok, "hashtag:cofe"} = Streamer.get_topic("hashtag", user, %{"tag" => "cofe"})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "disallows registering to an user stream", %{user: user} do
|
|
|
|
another_user = insert(:user)
|
|
|
|
assert {:error, _} = Streamer.get_topic("user:#{another_user.id}", user)
|
|
|
|
assert {:error, _} = Streamer.get_topic("user:notification:#{another_user.id}", user)
|
|
|
|
assert {:error, _} = Streamer.get_topic("direct:#{another_user.id}", user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "allows list stream that are owned by the user", %{user: user} do
|
|
|
|
{:ok, list} = List.create("Test", user)
|
|
|
|
assert {:error, _} = Streamer.get_topic("list:#{list.id}", user)
|
|
|
|
assert {:ok, _} = Streamer.get_topic("list", user, %{"list" => list.id})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "disallows list stream that are not owned by the user", %{user: user} do
|
|
|
|
another_user = insert(:user)
|
|
|
|
{:ok, list} = List.create("Test", another_user)
|
|
|
|
assert {:error, _} = Streamer.get_topic("list:#{list.id}", user)
|
|
|
|
assert {:error, _} = Streamer.get_topic("list", user, %{"list" => list.id})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-16 03:33:25 -07:00
|
|
|
describe "user streams" do
|
|
|
|
setup do
|
|
|
|
user = insert(:user)
|
|
|
|
notify = insert(:notification, user: user, activity: build(:note_activity))
|
|
|
|
{:ok, %{user: user, notify: notify}}
|
|
|
|
end
|
|
|
|
|
2020-04-22 08:21:13 -07:00
|
|
|
test "it streams the user's post in the 'user' stream", %{user: user} do
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user", user)
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity}
|
|
|
|
refute Streamer.filtered_by_user?(user, activity)
|
2020-04-22 08:21:13 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it streams boosts of the user in the 'user' stream", %{user: user} do
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user", user)
|
2020-04-22 08:21:13 -07:00
|
|
|
|
|
|
|
other_user = insert(:user)
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
|
2020-05-21 04:16:21 -07:00
|
|
|
{:ok, announce} = CommonAPI.repeat(activity.id, user)
|
2020-04-22 08:21:13 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce}
|
|
|
|
refute Streamer.filtered_by_user?(user, announce)
|
2020-04-22 08:21:13 -07:00
|
|
|
end
|
|
|
|
|
2020-07-02 00:50:26 -07:00
|
|
|
test "it does not stream announces of the user's own posts in the 'user' stream", %{
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
Streamer.get_topic_and_add_socket("user", user)
|
|
|
|
|
|
|
|
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-05-29 05:08:09 -07:00
|
|
|
test "it streams boosts of mastodon user in the 'user' stream", %{user: user} do
|
|
|
|
Streamer.get_topic_and_add_socket("user", user)
|
|
|
|
|
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-announce.json")
|
|
|
|
|> Poison.decode!()
|
|
|
|
|> Map.put("object", activity.data["object"])
|
|
|
|
|> Map.put("actor", user.ap_id)
|
|
|
|
|
2020-05-29 13:05:03 -07:00
|
|
|
{:ok, %Pleroma.Activity{data: _data, local: false} = announce} =
|
2020-05-29 05:08:09 -07:00
|
|
|
Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce}
|
|
|
|
refute Streamer.filtered_by_user?(user, announce)
|
|
|
|
end
|
|
|
|
|
2019-06-16 03:33:25 -07:00
|
|
|
test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user", user)
|
2019-06-16 03:33:25 -07:00
|
|
|
Streamer.stream("user", notify)
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^notify}
|
|
|
|
refute Streamer.filtered_by_user?(user, notify)
|
2019-06-16 03:33:25 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user)
|
2019-06-16 03:33:25 -07:00
|
|
|
Streamer.stream("user:notification", notify)
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^notify}
|
|
|
|
refute Streamer.filtered_by_user?(user, notify)
|
2019-06-16 03:33:25 -07:00
|
|
|
end
|
2019-07-21 19:43:55 -07:00
|
|
|
|
2020-05-29 06:24:41 -07:00
|
|
|
test "it sends chat messages to the 'user:pleroma_chat' stream", %{user: user} do
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
2020-06-03 07:45:04 -07:00
|
|
|
{:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno")
|
2020-05-29 06:24:41 -07:00
|
|
|
object = Object.normalize(create_activity, false)
|
2020-06-03 07:45:04 -07:00
|
|
|
chat = Chat.get(user.id, other_user.ap_id)
|
2020-06-06 02:51:10 -07:00
|
|
|
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
2020-06-03 07:45:04 -07:00
|
|
|
cm_ref = %{cm_ref | chat: chat, object: object}
|
|
|
|
|
2020-05-29 06:24:41 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user:pleroma_chat", user)
|
2020-06-03 07:45:04 -07:00
|
|
|
Streamer.stream("user:pleroma_chat", {user, cm_ref})
|
|
|
|
|
|
|
|
text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref})
|
|
|
|
|
|
|
|
assert text =~ "hey cirno"
|
2020-05-29 06:24:41 -07:00
|
|
|
assert_receive {:text, ^text}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends chat messages to the 'user' stream", %{user: user} do
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
2020-06-03 07:45:04 -07:00
|
|
|
{:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno")
|
2020-05-29 06:24:41 -07:00
|
|
|
object = Object.normalize(create_activity, false)
|
2020-06-03 07:45:04 -07:00
|
|
|
chat = Chat.get(user.id, other_user.ap_id)
|
2020-06-06 02:51:10 -07:00
|
|
|
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
2020-06-03 07:45:04 -07:00
|
|
|
cm_ref = %{cm_ref | chat: chat, object: object}
|
|
|
|
|
2020-05-29 06:24:41 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user", user)
|
2020-06-03 07:45:04 -07:00
|
|
|
Streamer.stream("user", {user, cm_ref})
|
|
|
|
|
|
|
|
text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref})
|
|
|
|
|
|
|
|
assert text =~ "hey cirno"
|
2020-05-29 06:24:41 -07:00
|
|
|
assert_receive {:text, ^text}
|
|
|
|
end
|
|
|
|
|
2020-05-25 08:27:45 -07:00
|
|
|
test "it sends chat message notifications to the 'user:notification' stream", %{user: user} do
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey")
|
|
|
|
|
|
|
|
notify =
|
|
|
|
Repo.get_by(Pleroma.Notification, user_id: user.id, activity_id: create_activity.id)
|
|
|
|
|> Repo.preload(:activity)
|
|
|
|
|
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user)
|
|
|
|
Streamer.stream("user:notification", notify)
|
|
|
|
assert_receive {:render_with_user, _, _, ^notify}
|
|
|
|
refute Streamer.filtered_by_user?(user, notify)
|
|
|
|
end
|
|
|
|
|
2019-07-21 19:43:55 -07:00
|
|
|
test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
blocked = insert(:user)
|
2019-11-19 12:22:10 -08:00
|
|
|
{:ok, _user_relationship} = User.block(user, blocked)
|
2019-07-21 19:43:55 -07:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user)
|
2019-07-21 19:43:55 -07:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: ":("})
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _} = CommonAPI.favorite(blocked, activity.id)
|
2019-07-21 19:43:55 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
refute_receive _
|
2019-07-21 19:43:55 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it doesn't send notify to the 'user:notification' stream when a thread is muted", %{
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
user2 = insert(:user)
|
2020-01-29 02:50:49 -08:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _} = CommonAPI.add_mute(user, activity)
|
2019-07-21 19:43:55 -07:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user)
|
2019-07-21 19:43:55 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
|
2020-03-19 10:00:55 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
refute_receive _
|
|
|
|
assert Streamer.filtered_by_user?(user, favorite_activity)
|
2019-07-21 19:43:55 -07:00
|
|
|
end
|
2019-07-24 03:09:06 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it sends favorite to 'user:notification' stream'", %{
|
2019-07-24 03:09:06 -07:00
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
|
2020-01-29 02:50:49 -08:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user)
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
|
|
|
|
|
|
|
|
assert_receive {:render_with_user, _, "notification.json", notif}
|
|
|
|
assert notif.activity.id == favorite_activity.id
|
|
|
|
refute Streamer.filtered_by_user?(user, notif)
|
|
|
|
end
|
2019-07-24 03:09:06 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it doesn't send the 'user:notification' stream' when a domain is blocked", %{
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
|
2019-07-24 03:09:06 -07:00
|
|
|
|
|
|
|
{:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user)
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
|
2019-07-24 03:35:16 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
refute_receive _
|
|
|
|
assert Streamer.filtered_by_user?(user, favorite_activity)
|
2019-07-24 03:09:06 -07:00
|
|
|
end
|
2019-11-03 07:05:12 -08:00
|
|
|
|
|
|
|
test "it sends follow activities to the 'user:notification' stream", %{
|
|
|
|
user: user
|
|
|
|
} do
|
2020-03-05 06:31:06 -08:00
|
|
|
user_url = user.ap_id
|
2020-05-07 02:13:32 -07:00
|
|
|
user2 = insert(:user)
|
2020-03-05 06:31:06 -08:00
|
|
|
|
|
|
|
body =
|
|
|
|
File.read!("test/fixtures/users_mock/localhost.json")
|
|
|
|
|> String.replace("{{nickname}}", user.nickname)
|
|
|
|
|> Jason.encode!()
|
|
|
|
|
|
|
|
Tesla.Mock.mock_global(fn
|
|
|
|
%{method: :get, url: ^user_url} ->
|
|
|
|
%Tesla.Env{status: 200, body: body}
|
|
|
|
end)
|
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user:notification", user)
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _follower, _followed, follow_activity} = CommonAPI.follow(user2, user)
|
2019-11-03 07:05:12 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, "notification.json", notif}
|
|
|
|
assert notif.activity.id == follow_activity.id
|
|
|
|
refute Streamer.filtered_by_user?(user, notif)
|
2019-11-03 07:05:12 -08:00
|
|
|
end
|
2019-06-16 03:33:25 -07:00
|
|
|
end
|
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it sends to public authenticated" do
|
2018-05-05 04:40:47 -07:00
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("public", other_user)
|
2018-05-05 04:40:47 -07:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "Test"})
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity}
|
|
|
|
refute Streamer.filtered_by_user?(user, activity)
|
2020-04-30 08:52:29 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "works for deletions" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user)
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(other_user, %{status: "Test"})
|
2019-01-20 04:00:46 -08:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("public", user)
|
2019-01-20 04:00:46 -08:00
|
|
|
|
2020-05-07 02:13:32 -07: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
|
2019-01-20 04:00:46 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it sends to public unauthenticated" do
|
|
|
|
user = insert(:user)
|
2019-01-20 04:00:46 -08:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("public", nil)
|
2019-01-20 04:00:46 -08:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "Test"})
|
2020-05-07 02:13:32 -07:00
|
|
|
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 04:00:46 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _} = CommonAPI.delete(activity.id, user)
|
|
|
|
assert_receive {:text, event}
|
|
|
|
assert %{"event" => "delete", "payload" => ^activity_id} = Jason.decode!(event)
|
2018-05-05 04:40:47 -07:00
|
|
|
end
|
|
|
|
|
2019-06-03 06:04:39 -07:00
|
|
|
describe "thread_containment" do
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it filters to user if recipients invalid and thread containment is enabled" do
|
2019-06-03 06:04:39 -07:00
|
|
|
Pleroma.Config.put([:instance, :skip_thread_containment], false)
|
|
|
|
author = insert(:user)
|
2019-10-10 12:35:32 -07:00
|
|
|
user = insert(:user)
|
2020-03-28 08:49:03 -07:00
|
|
|
User.follow(user, author, :follow_accept)
|
2019-06-03 06:04:39 -07:00
|
|
|
|
|
|
|
activity =
|
|
|
|
insert(:note_activity,
|
|
|
|
note:
|
|
|
|
insert(:note,
|
|
|
|
user: author,
|
|
|
|
data: %{"to" => ["TEST-FFF"]}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("public", user)
|
2020-05-07 02:13:32 -07:00
|
|
|
Streamer.stream("public", activity)
|
|
|
|
assert_receive {:render_with_user, _, _, ^activity}
|
|
|
|
assert Streamer.filtered_by_user?(user, activity)
|
2019-06-03 06:04:39 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends message if recipients invalid and thread containment is disabled" do
|
|
|
|
Pleroma.Config.put([:instance, :skip_thread_containment], true)
|
|
|
|
author = insert(:user)
|
2019-10-10 12:35:32 -07:00
|
|
|
user = insert(:user)
|
2020-03-28 08:49:03 -07:00
|
|
|
User.follow(user, author, :follow_accept)
|
2019-06-03 06:04:39 -07:00
|
|
|
|
|
|
|
activity =
|
|
|
|
insert(:note_activity,
|
|
|
|
note:
|
|
|
|
insert(:note,
|
|
|
|
user: author,
|
|
|
|
data: %{"to" => ["TEST-FFF"]}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("public", user)
|
2020-05-07 02:13:32 -07:00
|
|
|
Streamer.stream("public", activity)
|
2019-06-03 06:04:39 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity}
|
|
|
|
refute Streamer.filtered_by_user?(user, activity)
|
2019-06-03 06:04:39 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
|
|
|
|
Pleroma.Config.put([:instance, :skip_thread_containment], false)
|
|
|
|
author = insert(:user)
|
2019-10-24 00:42:14 -07:00
|
|
|
user = insert(:user, skip_thread_containment: true)
|
2020-03-28 08:49:03 -07:00
|
|
|
User.follow(user, author, :follow_accept)
|
2019-06-03 06:04:39 -07:00
|
|
|
|
|
|
|
activity =
|
|
|
|
insert(:note_activity,
|
|
|
|
note:
|
|
|
|
insert(:note,
|
|
|
|
user: author,
|
|
|
|
data: %{"to" => ["TEST-FFF"]}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("public", user)
|
2020-05-07 02:13:32 -07:00
|
|
|
Streamer.stream("public", activity)
|
2019-06-03 06:04:39 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity}
|
|
|
|
refute Streamer.filtered_by_user?(user, activity)
|
2019-06-03 06:04:39 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-04 08:17:32 -07:00
|
|
|
describe "blocks" do
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it filters messages involving blocked users" do
|
2019-10-04 08:17:32 -07:00
|
|
|
user = insert(:user)
|
|
|
|
blocked_user = insert(:user)
|
2019-11-19 12:22:10 -08:00
|
|
|
{:ok, _user_relationship} = User.block(user, blocked_user)
|
2018-05-05 04:40:47 -07:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("public", user)
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(blocked_user, %{status: "Test"})
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity}
|
|
|
|
assert Streamer.filtered_by_user?(user, activity)
|
2019-10-04 08:17:32 -07:00
|
|
|
end
|
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it filters messages transitively involving blocked users" do
|
2019-10-04 08:17:32 -07:00
|
|
|
blocker = insert(:user)
|
|
|
|
blockee = insert(:user)
|
|
|
|
friend = insert(:user)
|
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("public", blocker)
|
2019-10-04 08:17:32 -07:00
|
|
|
|
2019-11-19 12:22:10 -08:00
|
|
|
{:ok, _user_relationship} = User.block(blocker, blockee)
|
2019-10-04 08:17:32 -07:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity_one} = CommonAPI.post(friend, %{status: "hey! @#{blockee.nickname}"})
|
2019-10-04 08:17:32 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity_one}
|
|
|
|
assert Streamer.filtered_by_user?(blocker, activity_one)
|
2019-10-04 08:17:32 -07:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"})
|
2019-10-04 08:17:32 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity_two}
|
|
|
|
assert Streamer.filtered_by_user?(blocker, activity_two)
|
2019-10-04 08:17:32 -07:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity_three} = CommonAPI.post(blockee, %{status: "hey! @#{blocker.nickname}"})
|
2019-10-04 08:17:32 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity_three}
|
|
|
|
assert Streamer.filtered_by_user?(blocker, activity_three)
|
2019-10-04 08:17:32 -07:00
|
|
|
end
|
2018-05-05 04:40:47 -07:00
|
|
|
end
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
describe "lists" do
|
|
|
|
test "it doesn't send unwanted DMs to list" do
|
|
|
|
user_a = insert(:user)
|
|
|
|
user_b = insert(:user)
|
|
|
|
user_c = insert(:user)
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, user_a} = User.follow(user_a, user_b)
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, list} = List.create("Test", user_a)
|
|
|
|
{:ok, list} = List.follow(list, user_b)
|
2020-01-29 02:50:49 -08:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("list", user_a, %{"list" => list.id})
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _activity} =
|
|
|
|
CommonAPI.post(user_b, %{
|
2020-05-12 12:59:26 -07:00
|
|
|
status: "@#{user_c.nickname} Test",
|
|
|
|
visibility: "direct"
|
2020-05-07 02:13:32 -07:00
|
|
|
})
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
refute_receive _
|
|
|
|
end
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it doesn't send unwanted private posts to list" do
|
|
|
|
user_a = insert(:user)
|
|
|
|
user_b = insert(:user)
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, list} = List.create("Test", user_a)
|
|
|
|
{:ok, list} = List.follow(list, user_b)
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("list", user_a, %{"list" => list.id})
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _activity} =
|
|
|
|
CommonAPI.post(user_b, %{
|
2020-05-12 12:59:26 -07:00
|
|
|
status: "Test",
|
|
|
|
visibility: "private"
|
2020-05-07 02:13:32 -07:00
|
|
|
})
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
refute_receive _
|
|
|
|
end
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it sends wanted private posts to list" do
|
|
|
|
user_a = insert(:user)
|
|
|
|
user_b = insert(:user)
|
2020-01-29 02:50:49 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, user_a} = User.follow(user_a, user_b)
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, list} = List.create("Test", user_a)
|
|
|
|
{:ok, list} = List.follow(list, user_b)
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("list", user_a, %{"list" => list.id})
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(user_b, %{
|
2020-05-12 12:59:26 -07:00
|
|
|
status: "Test",
|
|
|
|
visibility: "private"
|
2020-05-07 02:13:32 -07:00
|
|
|
})
|
2018-11-26 16:14:43 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^activity}
|
|
|
|
refute Streamer.filtered_by_user?(user_a, activity)
|
|
|
|
end
|
2018-11-26 16:14:43 -08:00
|
|
|
end
|
2019-03-15 06:06:58 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
describe "muted reblogs" do
|
|
|
|
test "it filters muted reblogs" do
|
|
|
|
user1 = insert(:user)
|
|
|
|
user2 = insert(:user)
|
|
|
|
user3 = insert(:user)
|
|
|
|
CommonAPI.follow(user1, user2)
|
|
|
|
CommonAPI.hide_reblogs(user1, user2)
|
2019-03-15 06:06:58 -07:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"})
|
2019-06-24 00:14:04 -07:00
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user", user1)
|
2020-05-21 04:16:21 -07:00
|
|
|
{:ok, announce_activity} = CommonAPI.repeat(create_activity.id, user2)
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^announce_activity}
|
|
|
|
assert Streamer.filtered_by_user?(user1, announce_activity)
|
|
|
|
end
|
2020-01-28 07:40:44 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it filters reblog notification for reblog-muted actors" do
|
|
|
|
user1 = insert(:user)
|
|
|
|
user2 = insert(:user)
|
|
|
|
CommonAPI.follow(user1, user2)
|
|
|
|
CommonAPI.hide_reblogs(user1, user2)
|
2020-01-29 02:50:49 -08:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user", user1)
|
2020-05-21 04:16:21 -07:00
|
|
|
{:ok, _announce_activity} = CommonAPI.repeat(create_activity.id, user2)
|
2020-01-28 07:40:44 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, "notification.json", notif}
|
|
|
|
assert Streamer.filtered_by_user?(user1, notif)
|
|
|
|
end
|
2020-01-28 07:40:44 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it send non-reblog notification for reblog-muted actors" do
|
|
|
|
user1 = insert(:user)
|
|
|
|
user2 = insert(:user)
|
|
|
|
CommonAPI.follow(user1, user2)
|
|
|
|
CommonAPI.hide_reblogs(user1, user2)
|
2020-01-28 07:40:44 -08:00
|
|
|
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user", user1)
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _favorite_activity} = CommonAPI.favorite(user2, create_activity.id)
|
2020-01-28 07:40:44 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, "notification.json", notif}
|
|
|
|
refute Streamer.filtered_by_user?(user1, notif)
|
|
|
|
end
|
2020-01-28 07:40:44 -08:00
|
|
|
end
|
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
test "it filters posts from muted threads" do
|
2019-08-15 07:37:30 -07:00
|
|
|
user = insert(:user)
|
|
|
|
user2 = insert(:user)
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("user", user2)
|
2019-08-15 07:37:30 -07:00
|
|
|
{:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _} = CommonAPI.add_mute(user2, activity)
|
|
|
|
assert_receive {:render_with_user, _, _, ^activity}
|
|
|
|
assert Streamer.filtered_by_user?(user2, activity)
|
2019-08-15 07:37:30 -07:00
|
|
|
end
|
|
|
|
|
2019-06-24 00:14:04 -07:00
|
|
|
describe "direct streams" do
|
|
|
|
setup do
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends conversation update to the 'direct' stream", %{} do
|
|
|
|
user = insert(:user)
|
|
|
|
another_user = insert(:user)
|
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("direct", user)
|
2019-06-24 00:14:04 -07:00
|
|
|
|
|
|
|
{:ok, _create_activity} =
|
|
|
|
CommonAPI.post(another_user, %{
|
2020-05-12 12:59:26 -07:00
|
|
|
status: "hey @#{user.nickname}",
|
|
|
|
visibility: "direct"
|
2019-06-24 00:14:04 -07:00
|
|
|
})
|
|
|
|
|
2020-05-07 02:13:32 -07: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 00:14:04 -07:00
|
|
|
end
|
|
|
|
|
2019-10-30 17:44:27 -07:00
|
|
|
test "it doesn't send conversation update to the 'direct' stream when the last message in the conversation is deleted" do
|
2019-06-24 00:14:04 -07:00
|
|
|
user = insert(:user)
|
|
|
|
another_user = insert(:user)
|
|
|
|
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("direct", user)
|
2020-05-07 02:13:32 -07:00
|
|
|
|
2019-06-24 00:14:04 -07:00
|
|
|
{:ok, create_activity} =
|
|
|
|
CommonAPI.post(another_user, %{
|
2020-05-12 12:59:26 -07:00
|
|
|
status: "hi @#{user.nickname}",
|
|
|
|
visibility: "direct"
|
2019-06-24 00:14:04 -07:00
|
|
|
})
|
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
create_activity_id = create_activity.id
|
|
|
|
assert_receive {:render_with_user, _, _, ^create_activity}
|
|
|
|
assert_receive {:text, received_conversation1}
|
|
|
|
assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
|
2019-06-24 00:14:04 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _} = CommonAPI.delete(create_activity_id, another_user)
|
2019-06-24 00:14:04 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:text, received_event}
|
2019-09-16 03:03:37 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert %{"event" => "delete", "payload" => ^create_activity_id} =
|
|
|
|
Jason.decode!(received_event)
|
2019-06-24 00:14:04 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
refute_receive _
|
2019-06-24 00:14:04 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends conversation update to the 'direct' stream when a message is deleted" do
|
|
|
|
user = insert(:user)
|
|
|
|
another_user = insert(:user)
|
2020-05-12 09:04:47 -07:00
|
|
|
Streamer.get_topic_and_add_socket("direct", user)
|
2019-06-24 00:14:04 -07:00
|
|
|
|
|
|
|
{:ok, create_activity} =
|
|
|
|
CommonAPI.post(another_user, %{
|
2020-05-12 12:59:26 -07:00
|
|
|
status: "hi @#{user.nickname}",
|
|
|
|
visibility: "direct"
|
2019-06-24 00:14:04 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, create_activity2} =
|
|
|
|
CommonAPI.post(another_user, %{
|
2020-05-12 12:59:26 -07:00
|
|
|
status: "hi @#{user.nickname} 2",
|
|
|
|
in_reply_to_status_id: create_activity.id,
|
|
|
|
visibility: "direct"
|
2019-06-24 00:14:04 -07:00
|
|
|
})
|
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:render_with_user, _, _, ^create_activity}
|
|
|
|
assert_receive {:render_with_user, _, _, ^create_activity2}
|
|
|
|
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 14:37:33 -08:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
{:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
|
2019-06-24 00:14:04 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:text, received_event}
|
|
|
|
assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
|
2019-09-16 03:03:37 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert_receive {:text, received_event}
|
2019-06-24 00:14:04 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert %{"event" => "conversation", "payload" => received_payload} =
|
|
|
|
Jason.decode!(received_event)
|
2019-06-24 00:14:04 -07:00
|
|
|
|
2020-05-07 02:13:32 -07:00
|
|
|
assert %{"last_status" => last_status} = Jason.decode!(received_payload)
|
|
|
|
assert last_status["id"] == to_string(create_activity.id)
|
2019-06-24 00:14:04 -07:00
|
|
|
end
|
|
|
|
end
|
2018-05-05 04:40:47 -07:00
|
|
|
end
|