1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.UploadedMediaPlugTest do
6 use Pleroma.Web.ConnCase, async: true
8 alias Pleroma.UnstubbedConfigMock, as: ConfigMock
13 defp upload_file(context) do
15 |> stub_with(Pleroma.Test.StaticConfig)
17 Pleroma.DataCase.ensure_local_uploader(context)
19 File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
22 content_type: "image/jpeg",
23 path: Path.absname("test/fixtures/image_tmp.jpg"),
24 filename: "nice_tf.jpg"
27 {:ok, data} = Upload.store(file)
28 [%{"href" => attachment_url} | _] = data["url"]
29 [attachment_url: attachment_url]
32 setup_all :upload_file
36 |> stub_with(Pleroma.Test.StaticConfig)
41 test "does not send Content-Disposition header when name param is not set", %{
42 attachment_url: attachment_url
44 conn = get(build_conn(), attachment_url)
45 refute Enum.any?(conn.resp_headers, &(elem(&1, 0) == "content-disposition"))
48 test "sends Content-Disposition header when name param is set", %{
49 attachment_url: attachment_url
51 conn = get(build_conn(), attachment_url <> ~s[?name="cofe".gif])
55 &(&1 == {"content-disposition", ~s[inline; filename="\\"cofe\\".gif"]})