ChatMessageValidator: Don't validate messages that are too long.
authorlain <lain@soykaf.club>
Mon, 20 Apr 2020 09:45:11 +0000 (11:45 +0200)
committerlain <lain@soykaf.club>
Mon, 20 Apr 2020 09:45:11 +0000 (11:45 +0200)
lib/pleroma/web/activity_pub/object_validators/chat_message_validator.ex
test/web/activity_pub/object_validator_test.exs

index a4e4460cdb140c87e5e80c7925227bd6c6aedb38..caf2138a78fe2cf75579fb51273e7fae93454374 100644 (file)
@@ -56,6 +56,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatMessageValidator do
     |> validate_inclusion(:type, ["ChatMessage"])
     |> validate_required([:id, :actor, :to, :type, :content])
     |> validate_length(:to, is: 1)
+    |> validate_length(:content, max: Pleroma.Config.get([:instance, :remote_limit]))
     |> validate_local_concern()
   end
 
index bf0bfdfaf4d97b1babc12316674197e0f8df6049..e416e080823e566def799568e810d312aa3e3a84 100644 (file)
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
 
   describe "chat messages" do
     setup do
+      clear_config([:instance, :remote_limit])
       user = insert(:user)
       recipient = insert(:user, local: false)
 
@@ -23,6 +24,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
       assert {:ok, _object, _meta} = ObjectValidator.validate(valid_chat_message, [])
     end
 
+    test "does not validate if the message is longer than the remote_limit", %{
+      valid_chat_message: valid_chat_message
+    } do
+      Pleroma.Config.put([:instance, :remote_limit], 2)
+      refute match?({:ok, _object, _meta}, ObjectValidator.validate(valid_chat_message, []))
+    end
+
     test "does not validate if the actor or the recipient is not in our system", %{
       valid_chat_message: valid_chat_message
     } do