Add some hard limits on inserted activities.
[akkoma] / test / web / activity_pub / activity_pub_test.exs
index 90f11ecd4ebd72fc26921aee2d1926a137656103..f7c7c62424374f40e39952bdc478535112b0e20e 100644 (file)
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
   use Pleroma.DataCase
   alias Pleroma.Web.ActivityPub.ActivityPub
@@ -27,6 +31,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
   end
 
   describe "insertion" do
+    test "drops activities beyond a certain limit" do
+      limit = Pleroma.Config.get([:instance, :remote_limit])
+
+      random_text =
+        :crypto.strong_rand_bytes(limit + 1)
+        |> Base.encode64()
+        |> binary_part(0, limit + 1)
+
+      data = %{
+        "ok" => true,
+        "object" => %{
+          "content" => random_text
+        }
+      }
+
+      assert {:error, {:remote_limit_error, _}} = ActivityPub.insert(data)
+    end
+
     test "returns the activity if one with the same id is already in" do
       activity = insert(:note_activity)
       {:ok, new_activity} = ActivityPub.insert(activity.data)
@@ -180,7 +202,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     test "doesn't retrieve unlisted activities" do
       user = insert(:user)
 
-      {:ok, unlisted_activity} =
+      {:ok, _unlisted_activity} =
         CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"})
 
       {:ok, listed_activity} = CommonAPI.post(user, %{"status" => "yeah"})