forked from AkkomaGang/akkoma
1f863f0a36
Objects who got updated would just pass through several of the MRF policies, undoing moderation in some situations. In the relevant cases we now check not only for Create activities, but also Update activities. I checked which ones checked explicitly on type Create using `grep '"type" => "Create"' lib/pleroma/web/activity_pub/mrf/*`. The following from that list have not been changed: * lib/pleroma/web/activity_pub/mrf/follow_bot_policy.ex * Not relevant for moderation * lib/pleroma/web/activity_pub/mrf/keyword_policy.ex * Already had a test for Update * lib/pleroma/web/activity_pub/mrf/object_age_policy.ex * In practice only relevant when fetching old objects (e.g. through Like or Announce). These are always wrapped in a Create. * lib/pleroma/web/activity_pub/mrf/reject_non_public.ex * We don't allow changing scope with Update, so not relevant here
85 lines
3 KiB
Elixir
85 lines
3 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicyTest do
|
|
use Pleroma.DataCase, async: true
|
|
import Pleroma.Factory
|
|
|
|
alias Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy
|
|
@public "https://www.w3.org/ns/activitystreams#Public"
|
|
|
|
defp generate_messages(actor) do
|
|
{%{
|
|
"actor" => actor.ap_id,
|
|
"type" => "Create",
|
|
"object" => %{},
|
|
"to" => [@public, "f"],
|
|
"cc" => [actor.follower_address, "d"]
|
|
},
|
|
%{
|
|
"actor" => actor.ap_id,
|
|
"type" => "Create",
|
|
"object" => %{"to" => ["f", actor.follower_address], "cc" => ["d", @public]},
|
|
"to" => ["f", actor.follower_address],
|
|
"cc" => ["d", @public]
|
|
}}
|
|
end
|
|
|
|
defp generate_update_messages(actor) do
|
|
{%{
|
|
"actor" => actor.ap_id,
|
|
"type" => "Update",
|
|
"object" => %{},
|
|
"to" => [@public, "f"],
|
|
"cc" => [actor.follower_address, "d"]
|
|
},
|
|
%{
|
|
"actor" => actor.ap_id,
|
|
"type" => "Update",
|
|
"object" => %{"to" => ["f", actor.follower_address], "cc" => ["d", @public]},
|
|
"to" => ["f", actor.follower_address],
|
|
"cc" => ["d", @public]
|
|
}}
|
|
end
|
|
|
|
test "removes from the federated timeline by nickname heuristics 1" do
|
|
actor = insert(:user, %{nickname: "annoying_ebooks@example.com"})
|
|
|
|
{message, except_message} = generate_messages(actor)
|
|
{update_message, except_update_message} = generate_update_messages(actor)
|
|
|
|
assert ForceBotUnlistedPolicy.filter(message) == {:ok, except_message}
|
|
assert ForceBotUnlistedPolicy.filter(update_message) == {:ok, except_update_message}
|
|
end
|
|
|
|
test "removes from the federated timeline by nickname heuristics 2" do
|
|
actor = insert(:user, %{nickname: "cirnonewsnetworkbot@meow.cat"})
|
|
|
|
{message, except_message} = generate_messages(actor)
|
|
{update_message, except_update_message} = generate_update_messages(actor)
|
|
|
|
assert ForceBotUnlistedPolicy.filter(message) == {:ok, except_message}
|
|
assert ForceBotUnlistedPolicy.filter(update_message) == {:ok, except_update_message}
|
|
end
|
|
|
|
test "removes from the federated timeline by actor type Application" do
|
|
actor = insert(:user, %{actor_type: "Application"})
|
|
|
|
{message, except_message} = generate_messages(actor)
|
|
{update_message, except_update_message} = generate_update_messages(actor)
|
|
|
|
assert ForceBotUnlistedPolicy.filter(message) == {:ok, except_message}
|
|
assert ForceBotUnlistedPolicy.filter(update_message) == {:ok, except_update_message}
|
|
end
|
|
|
|
test "removes from the federated timeline by actor type Service" do
|
|
actor = insert(:user, %{actor_type: "Service"})
|
|
|
|
{message, except_message} = generate_messages(actor)
|
|
{update_message, except_update_message} = generate_update_messages(actor)
|
|
|
|
assert ForceBotUnlistedPolicy.filter(message) == {:ok, except_message}
|
|
assert ForceBotUnlistedPolicy.filter(update_message) == {:ok, except_update_message}
|
|
end
|
|
end
|