ChatMessageValidator: Don't validate messages that are too long.

This commit is contained in:
lain 2020-04-20 11:45:11 +02:00
parent c845820911
commit ce23673ca1
2 changed files with 9 additions and 0 deletions

View file

@ -56,6 +56,7 @@ def validate_data(data_cng) do
|> validate_inclusion(:type, ["ChatMessage"]) |> validate_inclusion(:type, ["ChatMessage"])
|> validate_required([:id, :actor, :to, :type, :content]) |> validate_required([:id, :actor, :to, :type, :content])
|> validate_length(:to, is: 1) |> validate_length(:to, is: 1)
|> validate_length(:content, max: Pleroma.Config.get([:instance, :remote_limit]))
|> validate_local_concern() |> validate_local_concern()
end end

View file

@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
describe "chat messages" do describe "chat messages" do
setup do setup do
clear_config([:instance, :remote_limit])
user = insert(:user) user = insert(:user)
recipient = insert(:user, local: false) recipient = insert(:user, local: false)
@ -23,6 +24,13 @@ test "validates for a basic object we build", %{valid_chat_message: valid_chat_m
assert {:ok, _object, _meta} = ObjectValidator.validate(valid_chat_message, []) assert {:ok, _object, _meta} = ObjectValidator.validate(valid_chat_message, [])
end 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", %{ test "does not validate if the actor or the recipient is not in our system", %{
valid_chat_message: valid_chat_message valid_chat_message: valid_chat_message
} do } do