Merge branch 'digest-template' into 'develop'
[akkoma] / test / web / activity_pub / mrf / anti_link_spam_policy_test.exs
index a456e863c9045651bc86d65ae8f6ca0c7783d2c9..03dc299ecf7fc3d4bb649956c0b35e295b62c1ff 100644 (file)
@@ -5,6 +5,7 @@
 defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
   use Pleroma.DataCase
   import Pleroma.Factory
+  import ExUnit.CaptureLog
 
   alias Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy
 
@@ -22,6 +23,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
     }
   }
 
+  @response_message %{
+    "type" => "Create",
+    "object" => %{
+      "name" => "yes",
+      "type" => "Answer"
+    }
+  }
+
   describe "with new user" do
     test "it allows posts without links" do
       user = insert(:user)
@@ -106,7 +115,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
         @linkless_message
         |> Map.put("actor", "http://invalid.actor")
 
-      {:reject, _} = AntiLinkSpamPolicy.filter(message)
+      assert capture_log(fn ->
+               {:reject, _} = AntiLinkSpamPolicy.filter(message)
+             end) =~ "[error] Could not decode user at fetch http://invalid.actor"
     end
 
     test "it rejects posts with links" do
@@ -114,7 +125,21 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
         @linkful_message
         |> Map.put("actor", "http://invalid.actor")
 
-      {:reject, _} = AntiLinkSpamPolicy.filter(message)
+      assert capture_log(fn ->
+               {:reject, _} = AntiLinkSpamPolicy.filter(message)
+             end) =~ "[error] Could not decode user at fetch http://invalid.actor"
+    end
+  end
+
+  describe "with contentless-objects" do
+    test "it does not reject them or error out" do
+      user = insert(:user, info: %{note_count: 1})
+
+      message =
+        @response_message
+        |> Map.put("actor", user.ap_id)
+
+      {:ok, _message} = AntiLinkSpamPolicy.filter(message)
     end
   end
 end