Merge branch 'issue/2069' into 'develop'
[akkoma] / test / pleroma / web / plugs / instance_static_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
49 test "overrides any file in static/static" do
50 bundled_index = get(build_conn(), "/static/terms-of-service.html")
51
52 assert html_response(bundled_index, 200) ==
53 File.read!("priv/static/static/terms-of-service.html")
54
55 File.mkdir!(@dir <> "/static")
56 File.write!(@dir <> "/static/terms-of-service.html", "plz be kind")
57
58 index = get(build_conn(), "/static/terms-of-service.html")
59 assert html_response(index, 200) == "plz be kind"
60
61 File.write!(@dir <> "/static/kaniini.html", "<h1>rabbit hugs as a service</h1>")
62 index = get(build_conn(), "/static/kaniini.html")
63 assert html_response(index, 200) == "<h1>rabbit hugs as a service</h1>"
64 end
65 end