X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fpleroma%2Fweb%2Factivity_pub%2Fmrf%2Fanti_link_spam_policy_test.exs;h=6182e9717cf3764ddbe56b30d4e2935d23b62701;hb=1f863f0a36ebb0648c3d39ecb7ea9e3d01deab60;hp=6867c98534885e2e72281f33b4927a2eb65bf6d9;hpb=64553ebae2f415b309df5f6b1c13b9972bc65aaa;p=akkoma
diff --git a/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs b/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs
index 6867c9853..6182e9717 100644
--- a/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
import Pleroma.Factory
import ExUnit.CaptureLog
+ alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy
@linkless_message %{
@@ -31,6 +32,28 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
}
}
+ @linkless_update_message %{
+ "type" => "Update",
+ "object" => %{
+ "content" => "hi world!"
+ }
+ }
+
+ @linkful_update_message %{
+ "type" => "Update",
+ "object" => %{
+ "content" => "hi world!"
+ }
+ }
+
+ @response_update_message %{
+ "type" => "Update",
+ "object" => %{
+ "name" => "yes",
+ "type" => "Answer"
+ }
+ }
+
describe "with new user" do
test "it allows posts without links" do
user = insert(:user, local: false)
@@ -41,7 +64,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@linkless_message
|> Map.put("actor", user.ap_id)
+ update_message =
+ @linkless_update_message
+ |> Map.put("actor", user.ap_id)
+
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ {:ok, _update_message} = AntiLinkSpamPolicy.filter(update_message)
end
test "it disallows posts with links" do
@@ -49,15 +77,61 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
assert user.note_count == 0
+ message = %{
+ "type" => "Create",
+ "actor" => user.ap_id,
+ "object" => %{
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{
+ "content" => "hi world!"
+ }
+ ]
+ },
+ "content" => "mew"
+ }
+ }
+
+ update_message = %{
+ "type" => "Update",
+ "actor" => user.ap_id,
+ "object" => %{
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{
+ "content" => "hi world!"
+ }
+ ]
+ },
+ "content" => "mew"
+ }
+ }
+
+ {:reject, _} = MRF.filter_one(AntiLinkSpamPolicy, message)
+ {:reject, _} = MRF.filter_one(AntiLinkSpamPolicy, update_message)
+ end
+
+ test "it allows posts with links for local users" do
+ user = insert(:user)
+
+ assert user.note_count == 0
+
message =
@linkful_message
|> Map.put("actor", user.ap_id)
- {:reject, _} = AntiLinkSpamPolicy.filter(message)
+ update_message =
+ @linkful_update_message
+ |> Map.put("actor", user.ap_id)
+
+ {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ {:ok, _update_message} = AntiLinkSpamPolicy.filter(update_message)
end
- test "it allows posts with links for local users" do
- user = insert(:user)
+ test "it disallows posts with links in history" do
+ user = insert(:user, local: false)
assert user.note_count == 0
@@ -65,7 +139,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@linkful_message
|> Map.put("actor", user.ap_id)
- {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ update_message =
+ @linkful_update_message
+ |> Map.put("actor", user.ap_id)
+
+ {:reject, _} = AntiLinkSpamPolicy.filter(message)
+ {:reject, _} = AntiLinkSpamPolicy.filter(update_message)
end
end
@@ -79,7 +158,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@linkless_message
|> Map.put("actor", user.ap_id)
+ update_message =
+ @linkless_update_message
+ |> Map.put("actor", user.ap_id)
+
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ {:ok, _update_message} = AntiLinkSpamPolicy.filter(update_message)
end
test "it allows posts with links" do
@@ -91,7 +175,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@linkful_message
|> Map.put("actor", user.ap_id)
+ update_message =
+ @linkful_update_message
+ |> Map.put("actor", user.ap_id)
+
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ {:ok, _update_message} = AntiLinkSpamPolicy.filter(update_message)
end
end
@@ -105,7 +194,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@linkless_message
|> Map.put("actor", user.ap_id)
+ update_message =
+ @linkless_update_message
+ |> Map.put("actor", user.ap_id)
+
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ {:ok, _update_message} = AntiLinkSpamPolicy.filter(update_message)
end
test "it allows posts with links" do
@@ -117,7 +211,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@linkful_message
|> Map.put("actor", user.ap_id)
+ update_message =
+ @linkful_update_message
+ |> Map.put("actor", user.ap_id)
+
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ {:ok, _update_message} = AntiLinkSpamPolicy.filter(update_message)
end
end
@@ -136,9 +235,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@linkless_message
|> Map.put("actor", "http://invalid.actor")
+ update_message =
+ @linkless_update_message
+ |> Map.put("actor", "http://invalid.actor")
+
assert capture_log(fn ->
{:reject, _} = AntiLinkSpamPolicy.filter(message)
end) =~ "[error] Could not decode user at fetch http://invalid.actor"
+
+ assert capture_log(fn ->
+ {:reject, _} = AntiLinkSpamPolicy.filter(update_message)
+ end) =~ "[error] Could not decode user at fetch http://invalid.actor"
end
test "it rejects posts with links" do
@@ -146,9 +253,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@linkful_message
|> Map.put("actor", "http://invalid.actor")
+ update_message =
+ @linkful_update_message
+ |> Map.put("actor", "http://invalid.actor")
+
assert capture_log(fn ->
{:reject, _} = AntiLinkSpamPolicy.filter(message)
end) =~ "[error] Could not decode user at fetch http://invalid.actor"
+
+ assert capture_log(fn ->
+ {:reject, _} = AntiLinkSpamPolicy.filter(update_message)
+ end) =~ "[error] Could not decode user at fetch http://invalid.actor"
end
end
@@ -160,7 +275,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@response_message
|> Map.put("actor", user.ap_id)
+ update_message =
+ @response_update_message
+ |> Map.put("actor", user.ap_id)
+
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ {:ok, _update_message} = AntiLinkSpamPolicy.filter(update_message)
end
end
end