logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

frontend_static_plug_test.exs (3084B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
  5. use Pleroma.Web.ConnCase
  6. import Mock
  7. import Mox
  8. alias Pleroma.UnstubbedConfigMock, as: ConfigMock
  9. @dir "test/tmp/instance_static"
  10. setup do
  11. File.mkdir_p!(@dir)
  12. on_exit(fn -> File.rm_rf(@dir) end)
  13. end
  14. setup do: clear_config([:instance, :static_dir], @dir)
  15. test "init will give a static plug config + the frontend type" do
  16. opts =
  17. [
  18. at: "/admin",
  19. frontend_type: :admin
  20. ]
  21. |> Pleroma.Web.Plugs.FrontendStatic.init()
  22. assert opts[:at] == ["admin"]
  23. assert opts[:frontend_type] == :admin
  24. end
  25. test "overrides existing static files", %{conn: conn} do
  26. name = "pelmora"
  27. ref = "uguu"
  28. clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
  29. path = "#{@dir}/frontends/#{name}/#{ref}"
  30. File.mkdir_p!(path)
  31. File.write!("#{path}/index.html", "from frontend plug")
  32. index = get(conn, "/")
  33. assert html_response(index, 200) == "from frontend plug"
  34. end
  35. test "overrides existing static files for the `pleroma/admin` path", %{conn: conn} do
  36. name = "pelmora"
  37. ref = "uguu"
  38. clear_config([:frontends, :admin], %{"name" => name, "ref" => ref})
  39. path = "#{@dir}/frontends/#{name}/#{ref}"
  40. File.mkdir_p!(path)
  41. File.write!("#{path}/index.html", "from frontend plug")
  42. index = get(conn, "/pleroma/admin/")
  43. assert html_response(index, 200) == "from frontend plug"
  44. end
  45. test "exclude invalid path", %{conn: conn} do
  46. name = "pleroma-fe"
  47. ref = "dist"
  48. clear_config([:media_proxy, :enabled], true)
  49. clear_config([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
  50. clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
  51. path = "#{@dir}/frontends/#{name}/#{ref}"
  52. File.mkdir_p!("#{path}/proxy/rr/ss")
  53. File.write!("#{path}/proxy/rr/ss/Ek7w8WPVcAApOvN.jpg:large", "FB image")
  54. ConfigMock
  55. |> stub_with(Pleroma.Test.StaticConfig)
  56. url =
  57. Pleroma.Web.MediaProxy.encode_url("https://pbs.twimg.com/media/Ek7w8WPVcAApOvN.jpg:large")
  58. with_mock Pleroma.ReverseProxy,
  59. call: fn _conn, _url, _opts -> %Plug.Conn{status: :success} end do
  60. assert %Plug.Conn{status: :success} = get(conn, url)
  61. end
  62. end
  63. test "api routes are detected correctly" do
  64. # If this test fails we have probably added something
  65. # new that should be in /api/ instead
  66. expected_routes = [
  67. "api",
  68. "main",
  69. "ostatus_subscribe",
  70. "authorize_interaction",
  71. "oauth",
  72. "objects",
  73. "activities",
  74. "notice",
  75. "users",
  76. "tags",
  77. "mailer",
  78. "inbox",
  79. "relay",
  80. "internal",
  81. ".well-known",
  82. "nodeinfo",
  83. "manifest.json",
  84. "auth",
  85. "proxy",
  86. "phoenix",
  87. "test",
  88. "user_exists",
  89. "check_password"
  90. ]
  91. assert expected_routes == Pleroma.Web.Router.get_api_routes()
  92. end
  93. end