logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

instance_static_test.exs (2040B)


  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. defmodule Pleroma.Web.InstanceStaticPlugTest do
  5. use Pleroma.Web.ConnCase
  6. @dir "test/tmp/instance_static"
  7. setup do
  8. File.mkdir_p!(@dir)
  9. on_exit(fn -> File.rm_rf(@dir) end)
  10. end
  11. setup do: clear_config([:instance, :static_dir], @dir)
  12. test "overrides index" do
  13. bundled_index = get(build_conn(), "/")
  14. refute html_response(bundled_index, 200) == "hello world"
  15. File.write!(@dir <> "/index.html", "hello world")
  16. index = get(build_conn(), "/")
  17. assert html_response(index, 200) == "hello world"
  18. end
  19. test "also overrides frontend files", %{conn: conn} do
  20. name = "pelmora"
  21. ref = "uguu"
  22. clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
  23. bundled_index = get(conn, "/")
  24. refute html_response(bundled_index, 200) == "from frontend plug"
  25. path = "#{@dir}/frontends/#{name}/#{ref}"
  26. File.mkdir_p!(path)
  27. File.write!("#{path}/index.html", "from frontend plug")
  28. index = get(conn, "/")
  29. assert html_response(index, 200) == "from frontend plug"
  30. File.write!(@dir <> "/index.html", "from instance static")
  31. index = get(conn, "/")
  32. assert html_response(index, 200) == "from instance static"
  33. end
  34. test "overrides any file in static/static" do
  35. bundled_index = get(build_conn(), "/static/terms-of-service.html")
  36. assert html_response(bundled_index, 200) ==
  37. File.read!("priv/static/static/terms-of-service.html")
  38. File.mkdir!(@dir <> "/static")
  39. File.write!(@dir <> "/static/terms-of-service.html", "plz be kind")
  40. index = get(build_conn(), "/static/terms-of-service.html")
  41. assert html_response(index, 200) == "plz be kind"
  42. File.write!(@dir <> "/static/kaniini.html", "<h1>rabbit hugs as a service</h1>")
  43. index = get(build_conn(), "/static/kaniini.html")
  44. assert html_response(index, 200) == "<h1>rabbit hugs as a service</h1>"
  45. end
  46. end