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
9 defp upload_file(context) do
10 Pleroma.DataCase.ensure_local_uploader(context)
11 File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
14 content_type: "image/jpeg",
15 path: Path.absname("test/fixtures/image_tmp.jpg"),
16 filename: "nice_tf.jpg"
19 {:ok, data} = Upload.store(file)
20 [%{"href" => attachment_url} | _] = data["url"]
21 [attachment_url: attachment_url]
24 setup_all :upload_file
26 test "does not send Content-Disposition header when name param is not set", %{
27 attachment_url: attachment_url
29 conn = get(build_conn(), attachment_url)
30 refute Enum.any?(conn.resp_headers, &(elem(&1, 0) == "content-disposition"))
33 test "sends Content-Disposition header when name param is set", %{
34 attachment_url: attachment_url
36 conn = get(build_conn(), attachment_url <> "?name=\"cofe\".gif")
40 &(&1 == {"content-disposition", "filename=\"\\\"cofe\\\".gif\""})