bcb5f3f602d513b7322784706a171d443a685a0f
[anni] / test / pleroma / upload / filter / exiftool / strip_location_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Upload.Filter.Exiftool.StripLocationTest do
6   use Pleroma.DataCase, async: true
7   alias Pleroma.Upload.Filter
8
9   test "apply exiftool filter" do
10     assert Pleroma.Utils.command_available?("exiftool")
11
12     File.cp!(
13       "test/fixtures/DSCN0010.jpg",
14       "test/fixtures/DSCN0010_tmp.jpg"
15     )
16
17     upload = %Pleroma.Upload{
18       name: "image_with_GPS_data.jpg",
19       content_type: "image/jpeg",
20       path: Path.absname("test/fixtures/DSCN0010.jpg"),
21       tempfile: Path.absname("test/fixtures/DSCN0010_tmp.jpg")
22     }
23
24     assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :filtered}
25
26     {exif_original, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010.jpg"])
27     {exif_filtered, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010_tmp.jpg"])
28
29     refute exif_original == exif_filtered
30     assert String.match?(exif_original, ~r/GPS/)
31     refute String.match?(exif_filtered, ~r/GPS/)
32   end
33
34   test "verify webp, heic, svg  files are skipped" do
35     uploads =
36       ~w{webp heic svg svg+xml}
37       |> Enum.map(fn type ->
38         %Pleroma.Upload{
39           name: "sample.#{type}",
40           content_type: "image/#{type}"
41         }
42       end)
43
44     uploads
45     |> Enum.each(fn upload ->
46       assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :noop}
47     end)
48   end
49 end