logo

pleroma

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

masto_fe_controller_test.exs (2201B)


  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.MastodonAPI.MastoFEController do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.Config
  7. alias Pleroma.User
  8. import Pleroma.Factory
  9. setup do: clear_config([:instance, :public])
  10. test "put settings", %{conn: conn} do
  11. user = insert(:user)
  12. conn =
  13. conn
  14. |> assign(:user, user)
  15. |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:accounts"]))
  16. |> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
  17. assert _result = json_response(conn, 200)
  18. user = User.get_cached_by_ap_id(user.ap_id)
  19. assert user.mastofe_settings == %{"programming" => "socks"}
  20. end
  21. describe "index/2 redirections" do
  22. setup %{conn: conn} do
  23. session_opts = [
  24. store: :cookie,
  25. key: "_test",
  26. signing_salt: "cooldude"
  27. ]
  28. conn =
  29. conn
  30. |> Plug.Session.call(Plug.Session.init(session_opts))
  31. |> fetch_session()
  32. test_path = "/web/statuses/test"
  33. %{conn: conn, path: test_path}
  34. end
  35. test "redirects not logged-in users to the login page", %{conn: conn, path: path} do
  36. conn = get(conn, path)
  37. assert conn.status == 302
  38. assert redirected_to(conn) == "/web/login"
  39. end
  40. test "redirects not logged-in users to the login page on private instances", %{
  41. conn: conn,
  42. path: path
  43. } do
  44. Config.put([:instance, :public], false)
  45. conn = get(conn, path)
  46. assert conn.status == 302
  47. assert redirected_to(conn) == "/web/login"
  48. end
  49. test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
  50. token = insert(:oauth_token, scopes: ["read"])
  51. conn =
  52. conn
  53. |> assign(:user, token.user)
  54. |> assign(:token, token)
  55. |> get(path)
  56. assert conn.status == 200
  57. end
  58. test "saves referer path to session", %{conn: conn, path: path} do
  59. conn = get(conn, path)
  60. return_to = Plug.Conn.get_session(conn, :return_to)
  61. assert return_to == path
  62. end
  63. end
  64. end