diff options
Diffstat (limited to 'test/plugs')
-rw-r--r-- | test/plugs/frontend_plug_test.exs | 31 | ||||
-rw-r--r-- | test/plugs/instance_static_test.exs | 64 |
2 files changed, 76 insertions, 19 deletions
diff --git a/test/plugs/frontend_plug_test.exs b/test/plugs/frontend_plug_test.exs new file mode 100644 index 000000000..5f66a5d0c --- /dev/null +++ b/test/plugs/frontend_plug_test.exs @@ -0,0 +1,31 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Plugs.FrontendPlugTest do + use Pleroma.Web.ConnCase + + setup do: clear_config([:frontends]) + + describe "setting private.frontend" do + setup do + conf = Pleroma.Config.get([:frontends]) + {:ok, %{conf: conf}} + end + + test "for admin", %{conn: conn, conf: conf} do + conn = get(conn, frontend_admin_path(conn, :index, [])) + assert get_in(conn.private, [:frontend, :config, "name"]) == conf[:admin]["name"] + end + + test "for mastodon", %{conn: conn, conf: conf} do + conn = get(conn, frontend_mastodon_path(conn, :index, [])) + assert get_in(conn.private, [:frontend, :config, "name"]) == conf[:mastodon]["name"] + end + + test "for primary", %{conn: conn, conf: conf} do + conn = get(conn, frontend_path(conn, :index, [])) + assert get_in(conn.private, [:frontend, :config, "name"]) == conf[:primary]["name"] + end + end +end diff --git a/test/plugs/instance_static_test.exs b/test/plugs/instance_static_test.exs index b8f070d6a..1f70f4645 100644 --- a/test/plugs/instance_static_test.exs +++ b/test/plugs/instance_static_test.exs @@ -6,38 +6,64 @@ defmodule Pleroma.Web.RuntimeStaticPlugTest do use Pleroma.Web.ConnCase @dir "test/tmp/instance_static" + @primary_fe %{"name" => "pleroma", "ref" => "1.2.3"} + @fe_dir Path.join([@dir, "frontends", @primary_fe["name"], @primary_fe["ref"]]) setup do - File.mkdir_p!(@dir) + [@dir, "frontends", @primary_fe["name"], @primary_fe["ref"], "static"] + |> Path.join() + |> File.mkdir_p() + + [@dir, "static"] + |> Path.join() + |> File.mkdir!() + on_exit(fn -> File.rm_rf(@dir) end) + clear_config([:instance, :static_dir], @dir) + clear_config([:frontends, :primary], @primary_fe) end - setup do: clear_config([:instance, :static_dir], @dir) + test "frontend files override files in priv" do + content = "body{ color: red; }" - test "overrides index" do - bundled_index = get(build_conn(), "/") - assert html_response(bundled_index, 200) == File.read!("priv/static/index.html") + conn = get(build_conn(), "/static-fe.css") + refute response(conn, 200) == content - File.write!(@dir <> "/index.html", "hello world") + [@fe_dir, "static-fe.css"] + |> Path.join() + |> File.write!(content) - index = get(build_conn(), "/") - assert html_response(index, 200) == "hello world" + conn = get(build_conn(), "/static-fe.css") + assert response(conn, 200) == content end - test "overrides any file in static/static" do - bundled_index = get(build_conn(), "/static/terms-of-service.html") + test "files in instance/static overrides priv/static" do + content = "no room for Bender" + + conn = get(build_conn(), "/robots.txt") + refute text_response(conn, 200) == content + + [@dir, "robots.txt"] + |> Path.join() + |> File.write!(content) + + conn = get(build_conn(), "/robots.txt") + assert text_response(conn, 200) == content + end - assert html_response(bundled_index, 200) == - File.read!("priv/static/static/terms-of-service.html") + test "files in instance/static overrides frontend files" do + [@fe_dir, "static", "helo.html"] + |> Path.join() + |> File.write!("cofe") - File.mkdir!(@dir <> "/static") - File.write!(@dir <> "/static/terms-of-service.html", "plz be kind") + conn = get(build_conn(), "/static/helo.html") + assert html_response(conn, 200) == "cofe" - index = get(build_conn(), "/static/terms-of-service.html") - assert html_response(index, 200) == "plz be kind" + [@dir, "static", "helo.html"] + |> Path.join() + |> File.write!("moto") - File.write!(@dir <> "/static/kaniini.html", "<h1>rabbit hugs as a service</h1>") - index = get(build_conn(), "/static/kaniini.html") - assert html_response(index, 200) == "<h1>rabbit hugs as a service</h1>" + conn = get(build_conn(), "/static/helo.html") + assert html_response(conn, 200) == "moto" end end |