2020-07-10 23:46:26 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 21:38:50 +01:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-07-10 23:46:26 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-02-20 13:46:29 +01:00
|
|
|
defmodule Pleroma.Upload.Filter.Exiftool.StripLocationTest do
|
2020-12-21 12:21:40 +01:00
|
|
|
use Pleroma.DataCase, async: true
|
2020-07-10 23:46:26 +02:00
|
|
|
alias Pleroma.Upload.Filter
|
|
|
|
|
|
|
|
test "apply exiftool filter" do
|
2020-07-11 14:48:45 +02:00
|
|
|
assert Pleroma.Utils.command_available?("exiftool")
|
|
|
|
|
2020-07-10 23:46:26 +02:00
|
|
|
File.cp!(
|
|
|
|
"test/fixtures/DSCN0010.jpg",
|
|
|
|
"test/fixtures/DSCN0010_tmp.jpg"
|
|
|
|
)
|
|
|
|
|
|
|
|
upload = %Pleroma.Upload{
|
|
|
|
name: "image_with_GPS_data.jpg",
|
2020-10-13 17:37:24 +02:00
|
|
|
content_type: "image/jpeg",
|
2020-07-10 23:46:26 +02:00
|
|
|
path: Path.absname("test/fixtures/DSCN0010.jpg"),
|
|
|
|
tempfile: Path.absname("test/fixtures/DSCN0010_tmp.jpg")
|
|
|
|
}
|
|
|
|
|
2022-02-20 13:46:29 +01:00
|
|
|
assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :filtered}
|
2020-07-10 23:46:26 +02:00
|
|
|
|
|
|
|
{exif_original, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010.jpg"])
|
|
|
|
{exif_filtered, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010_tmp.jpg"])
|
|
|
|
|
|
|
|
refute exif_original == exif_filtered
|
|
|
|
assert String.match?(exif_original, ~r/GPS/)
|
|
|
|
refute String.match?(exif_filtered, ~r/GPS/)
|
|
|
|
end
|
2020-09-05 00:50:16 +02:00
|
|
|
|
2023-01-05 17:29:06 +01:00
|
|
|
test "verify webp, heic, svg files are skipped" do
|
|
|
|
uploads =
|
|
|
|
~w{webp heic svg svg+xml}
|
|
|
|
|> Enum.map(fn type ->
|
|
|
|
%Pleroma.Upload{
|
|
|
|
name: "sample.#{type}",
|
|
|
|
content_type: "image/#{type}"
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
|
|
|
|
uploads
|
|
|
|
|> Enum.each(fn upload ->
|
|
|
|
assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :noop}
|
|
|
|
end)
|
2020-09-05 00:50:16 +02:00
|
|
|
end
|
2020-07-10 23:46:26 +02:00
|
|
|
end
|