logo

pleroma

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

uploaded_media_plug_test.exs (1556B)


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