logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

read_description_test.exs (5191B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Upload.Filter.Exiftool.ReadDescriptionTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Upload.Filter
  7. @uploads %Pleroma.Upload{
  8. name: "image_with_imagedescription_and_caption-abstract.jpg",
  9. content_type: "image/jpeg",
  10. path: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
  11. tempfile: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
  12. description: nil
  13. }
  14. test "keeps description when not empty" do
  15. uploads = %Pleroma.Upload{
  16. name: "image_with_imagedescription_and_caption-abstract.jpg",
  17. content_type: "image/jpeg",
  18. path: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
  19. tempfile:
  20. Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
  21. description: "Some description"
  22. }
  23. assert Filter.Exiftool.ReadDescription.filter(uploads) ==
  24. {:ok, :noop}
  25. end
  26. test "otherwise returns ImageDescription when present" do
  27. uploads_after = %Pleroma.Upload{
  28. name: "image_with_imagedescription_and_caption-abstract.jpg",
  29. content_type: "image/jpeg",
  30. path: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
  31. tempfile:
  32. Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
  33. description: "a descriptive white pixel"
  34. }
  35. assert Filter.Exiftool.ReadDescription.filter(@uploads) ==
  36. {:ok, :filtered, uploads_after}
  37. end
  38. test "Ignores warnings" do
  39. uploads = %Pleroma.Upload{
  40. name: "image_with_imagedescription_and_caption-abstract_and_stray_data_after.png",
  41. content_type: "image/png",
  42. path:
  43. Path.absname(
  44. "test/fixtures/image_with_imagedescription_and_caption-abstract_and_stray_data_after.png"
  45. ),
  46. tempfile:
  47. Path.absname(
  48. "test/fixtures/image_with_imagedescription_and_caption-abstract_and_stray_data_after.png"
  49. )
  50. }
  51. assert {:ok, :filtered, %{description: "a descriptive white pixel"}} =
  52. Filter.Exiftool.ReadDescription.filter(uploads)
  53. uploads = %Pleroma.Upload{
  54. name: "image_with_stray_data_after.png",
  55. content_type: "image/png",
  56. path: Path.absname("test/fixtures/image_with_stray_data_after.png"),
  57. tempfile: Path.absname("test/fixtures/image_with_stray_data_after.png")
  58. }
  59. assert {:ok, :filtered, %{description: nil}} = Filter.Exiftool.ReadDescription.filter(uploads)
  60. end
  61. test "otherwise returns iptc:Caption-Abstract when present" do
  62. upload = %Pleroma.Upload{
  63. name: "image_with_caption-abstract.jpg",
  64. content_type: "image/jpeg",
  65. path: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
  66. tempfile: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
  67. description: nil
  68. }
  69. upload_after = %Pleroma.Upload{
  70. name: "image_with_caption-abstract.jpg",
  71. content_type: "image/jpeg",
  72. path: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
  73. tempfile: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
  74. description: "an abstract white pixel"
  75. }
  76. assert Filter.Exiftool.ReadDescription.filter(upload) ==
  77. {:ok, :filtered, upload_after}
  78. end
  79. test "otherwise returns nil" do
  80. uploads = %Pleroma.Upload{
  81. name: "image_with_no_description.jpg",
  82. content_type: "image/jpeg",
  83. path: Path.absname("test/fixtures/image_with_no_description.jpg"),
  84. tempfile: Path.absname("test/fixtures/image_with_no_description.jpg"),
  85. description: nil
  86. }
  87. assert Filter.Exiftool.ReadDescription.filter(uploads) ==
  88. {:ok, :filtered, uploads}
  89. end
  90. test "Return nil when image description from EXIF data exceeds the maximum length" do
  91. clear_config([:instance, :description_limit], 5)
  92. assert Filter.Exiftool.ReadDescription.filter(@uploads) ==
  93. {:ok, :filtered, @uploads}
  94. end
  95. test "Ignores content with only whitespace" do
  96. uploads = %Pleroma.Upload{
  97. name: "non-existant.jpg",
  98. content_type: "image/jpeg",
  99. path:
  100. Path.absname(
  101. "test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg"
  102. ),
  103. tempfile:
  104. Path.absname(
  105. "test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg"
  106. ),
  107. description: nil
  108. }
  109. assert Filter.Exiftool.ReadDescription.filter(uploads) ==
  110. {:ok, :filtered, uploads}
  111. end
  112. test "Return nil when image description from EXIF data can't be read" do
  113. uploads = %Pleroma.Upload{
  114. name: "non-existant.jpg",
  115. content_type: "image/jpeg",
  116. path: Path.absname("test/fixtures/non-existant.jpg"),
  117. tempfile: Path.absname("test/fixtures/non-existant_tmp.jpg"),
  118. description: nil
  119. }
  120. assert Filter.Exiftool.ReadDescription.filter(uploads) ==
  121. {:ok, :filtered, uploads}
  122. end
  123. end