Merge pull request '2022.09 stable' (#208) from develop into stable
[akkoma] / test / pleroma / web / activity_pub / mrf / anti_link_spam_policy_test.exs
index 6867c98534885e2e72281f33b4927a2eb65bf6d9..c3ee03a054f7974e290077c81e9fe27b7476aff1 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # 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 %{
@@ -49,15 +50,39 @@ 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" => "<a href='https://example.com'>hi world!</a>"
+              }
+            ]
+          },
+          "content" => "mew"
+        }
+      }
+
+      {:reject, _} = MRF.filter_one(AntiLinkSpamPolicy, 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)
+      {:ok, _message} = AntiLinkSpamPolicy.filter(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 +90,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
         @linkful_message
         |> Map.put("actor", user.ap_id)
 
-      {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+      {:reject, _} = AntiLinkSpamPolicy.filter(message)
     end
   end