logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

attachment_validator_test.exs (2259B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Web.ActivityPub.ActivityPub
  7. alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
  8. import Pleroma.Factory
  9. describe "attachments" do
  10. test "works with honkerific attachments" do
  11. attachment = %{
  12. "mediaType" => "",
  13. "name" => "",
  14. "summary" => "298p3RG7j27tfsZ9RQ.jpg",
  15. "type" => "Document",
  16. "url" => "https://honk.tedunangst.com/d/298p3RG7j27tfsZ9RQ.jpg"
  17. }
  18. assert {:ok, attachment} =
  19. AttachmentValidator.cast_and_validate(attachment)
  20. |> Ecto.Changeset.apply_action(:insert)
  21. assert attachment.mediaType == "application/octet-stream"
  22. end
  23. test "it turns mastodon attachments into our attachments" do
  24. attachment = %{
  25. "url" =>
  26. "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
  27. "type" => "Document",
  28. "name" => nil,
  29. "mediaType" => "image/jpeg"
  30. }
  31. {:ok, attachment} =
  32. AttachmentValidator.cast_and_validate(attachment)
  33. |> Ecto.Changeset.apply_action(:insert)
  34. assert [
  35. %{
  36. href:
  37. "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
  38. type: "Link",
  39. mediaType: "image/jpeg"
  40. }
  41. ] = attachment.url
  42. assert attachment.mediaType == "image/jpeg"
  43. end
  44. test "it handles our own uploads" do
  45. user = insert(:user)
  46. file = %Plug.Upload{
  47. content_type: "image/jpg",
  48. path: Path.absname("test/fixtures/image.jpg"),
  49. filename: "an_image.jpg"
  50. }
  51. {:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
  52. {:ok, attachment} =
  53. attachment.data
  54. |> AttachmentValidator.cast_and_validate()
  55. |> Ecto.Changeset.apply_action(:insert)
  56. assert attachment.mediaType == "image/jpeg"
  57. end
  58. end
  59. end