logo

pleroma

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

uploaded_media_plug_test.exs (1316B)


  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.UploadedMediaPlugTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.Upload
  7. defp upload_file(context) do
  8. Pleroma.DataCase.ensure_local_uploader(context)
  9. File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
  10. file = %Plug.Upload{
  11. content_type: "image/jpg",
  12. path: Path.absname("test/fixtures/image_tmp.jpg"),
  13. filename: "nice_tf.jpg"
  14. }
  15. {:ok, data} = Upload.store(file)
  16. [%{"href" => attachment_url} | _] = data["url"]
  17. [attachment_url: attachment_url]
  18. end
  19. setup_all :upload_file
  20. test "does not send Content-Disposition header when name param is not set", %{
  21. attachment_url: attachment_url
  22. } do
  23. conn = get(build_conn(), attachment_url)
  24. refute Enum.any?(conn.resp_headers, &(elem(&1, 0) == "content-disposition"))
  25. end
  26. test "sends Content-Disposition header when name param is set", %{
  27. attachment_url: attachment_url
  28. } do
  29. conn = get(build_conn(), attachment_url <> "?name=\"cofe\".gif")
  30. assert Enum.any?(
  31. conn.resp_headers,
  32. &(&1 == {"content-disposition", "filename=\"\\\"cofe\\\".gif\""})
  33. )
  34. end
  35. end