414cf91864dcf827786fe8e0a3557c37db21558c
[akkoma] / test / plugs / uploaded_media_plug_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.UploadedMediaPlugTest do
6 use Pleroma.Web.ConnCase
7 alias Pleroma.Upload
8
9 setup_all do
10 File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
11
12 file = %Plug.Upload{
13 content_type: "image/jpg",
14 path: Path.absname("test/fixtures/image_tmp.jpg"),
15 filename: "nice_tf.jpg"
16 }
17
18 {:ok, data} = Upload.store(file)
19 [%{"href" => attachment_url} | _] = data["url"]
20 [attachment_url: attachment_url]
21 end
22
23 test "does not send Content-Disposition header when name param is not set", %{
24 attachment_url: attachment_url
25 } do
26 conn = get(build_conn(), attachment_url)
27 refute Enum.any?(conn.resp_headers, &(elem(&1, 0) == "content-disposition"))
28 end
29
30 test "sends Content-Disposition header when name param is set", %{
31 attachment_url: attachment_url
32 } do
33 conn = get(build_conn(), attachment_url <> "?name=\"cofe\".gif")
34
35 assert Enum.any?(
36 conn.resp_headers,
37 &(&1 == {"content-disposition", "filename=\"\\\"cofe\\\".gif\""})
38 )
39 end
40 end