AttachmentValidator: Handle empty mediatypes
This commit is contained in:
parent
be4db41d71
commit
d19c716770
@ -12,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator do
|
||||
@primary_key false
|
||||
embedded_schema do
|
||||
field(:type, :string)
|
||||
field(:mediaType, :string)
|
||||
field(:mediaType, :string, default: "application/octet-stream")
|
||||
field(:name, :string)
|
||||
|
||||
embeds_many(:url, UrlObjectValidator)
|
||||
@ -41,8 +41,16 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator do
|
||||
end
|
||||
|
||||
def fix_media_type(data) do
|
||||
data
|
||||
|> Map.put_new("mediaType", data["mimeType"])
|
||||
data =
|
||||
data
|
||||
|> Map.put_new("mediaType", data["mimeType"])
|
||||
|
||||
if data["mediaType"] == "" do
|
||||
data
|
||||
|> Map.put("mediaType", "application/octet-stream")
|
||||
else
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
def fix_url(data) do
|
||||
|
@ -15,8 +15,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
|
||||
describe "attachments" do
|
||||
test "works with honkerific attachments" do
|
||||
attachment = %{
|
||||
"mediaType" => "image/jpeg",
|
||||
"name" => "298p3RG7j27tfsZ9RQ.jpg",
|
||||
"mediaType" => "",
|
||||
"name" => "",
|
||||
"summary" => "298p3RG7j27tfsZ9RQ.jpg",
|
||||
"type" => "Document",
|
||||
"url" => "https://honk.tedunangst.com/d/298p3RG7j27tfsZ9RQ.jpg"
|
||||
|
@ -13,6 +13,43 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
describe "handle_incoming" do
|
||||
test "handles this" do
|
||||
data = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"actor" => "https://honk.tedunangst.com/u/tedu",
|
||||
"id" => "https://honk.tedunangst.com/u/tedu/honk/x6gt8X8PcyGkQcXxzg1T",
|
||||
"object" => %{
|
||||
"attachment" => [
|
||||
%{
|
||||
"mediaType" => "image/jpeg",
|
||||
"name" => "298p3RG7j27tfsZ9RQ.jpg",
|
||||
"summary" => "298p3RG7j27tfsZ9RQ.jpg",
|
||||
"type" => "Document",
|
||||
"url" => "https://honk.tedunangst.com/d/298p3RG7j27tfsZ9RQ.jpg"
|
||||
}
|
||||
],
|
||||
"attributedTo" => "https://honk.tedunangst.com/u/tedu",
|
||||
"content" => "",
|
||||
"id" => "https://honk.tedunangst.com/u/tedu/chonk/26L4wl5yCbn4dr4y1b",
|
||||
"published" => "2020-05-18T01:13:03Z",
|
||||
"to" => [
|
||||
"https://dontbulling.me/users/lain"
|
||||
],
|
||||
"type" => "ChatMessage"
|
||||
},
|
||||
"published" => "2020-05-18T01:13:03Z",
|
||||
"to" => [
|
||||
"https://dontbulling.me/users/lain"
|
||||
],
|
||||
"type" => "Create"
|
||||
}
|
||||
|
||||
_user = insert(:user, ap_id: data["actor"])
|
||||
_user = insert(:user, ap_id: hd(data["to"]))
|
||||
|
||||
assert {:ok, _activity} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it rejects messages that don't contain content" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|
Loading…
Reference in New Issue
Block a user