1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.InstanceStaticTest do
6 use Pleroma.Web.ConnCase
8 @dir "test/tmp/instance_static"
12 on_exit(fn -> File.rm_rf(@dir) end)
15 setup do: clear_config([:instance, :static_dir], @dir)
17 test "overrides index" do
18 bundled_index = get(build_conn(), "/")
19 refute html_response(bundled_index, 200) == "hello world"
21 File.write!(@dir <> "/index.html", "hello world")
23 index = get(build_conn(), "/")
24 assert html_response(index, 200) == "hello world"
27 test "also overrides frontend files", %{conn: conn} do
31 clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
33 bundled_index = get(conn, "/")
34 refute html_response(bundled_index, 200) == "from frontend plug"
36 path = "#{@dir}/frontends/#{name}/#{ref}"
38 File.write!("#{path}/index.html", "from frontend plug")
40 index = get(conn, "/")
41 assert html_response(index, 200) == "from frontend plug"
43 File.write!(@dir <> "/index.html", "from instance static")
45 index = get(conn, "/")
46 assert html_response(index, 200) == "from instance static"
49 test "overrides any file in static/static" do
50 bundled_index = get(build_conn(), "/static/terms-of-service.html")
52 assert html_response(bundled_index, 200) ==
53 File.read!("priv/static/static/terms-of-service.html")
55 File.mkdir!(@dir <> "/static")
56 File.write!(@dir <> "/static/terms-of-service.html", "plz be kind")
58 index = get(build_conn(), "/static/terms-of-service.html")
59 assert html_response(index, 200) == "plz be kind"
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>"