strip \r and \r from content-disposition filenames
[akkoma] / test / pleroma / web / plugs / instance_static_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Plugs.InstanceStaticTest do
6 use Pleroma.Web.ConnCase
7
8 @dir "test/tmp/instance_static"
9
10 setup do
11 File.mkdir_p!(@dir)
12 on_exit(fn -> File.rm_rf(@dir) end)
13 end
14
15 setup do: clear_config([:instance, :static_dir], @dir)
16
17 test "overrides index" do
18 bundled_index = get(build_conn(), "/")
19 refute html_response(bundled_index, 200) == "hello world"
20
21 File.write!(@dir <> "/index.html", "hello world")
22
23 index = get(build_conn(), "/")
24 assert html_response(index, 200) == "hello world"
25 end
26
27 test "also overrides frontend files", %{conn: conn} do
28 name = "pelmora"
29 ref = "uguu"
30
31 clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
32
33 bundled_index = get(conn, "/")
34 refute html_response(bundled_index, 200) == "from frontend plug"
35
36 path = "#{@dir}/frontends/#{name}/#{ref}"
37 File.mkdir_p!(path)
38 File.write!("#{path}/index.html", "from frontend plug")
39
40 index = get(conn, "/")
41 assert html_response(index, 200) == "from frontend plug"
42
43 File.write!(@dir <> "/index.html", "from instance static")
44
45 index = get(conn, "/")
46 assert html_response(index, 200) == "from instance static"
47 end
48 end