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.MastodonAPI.MastoFEController do
6 use Pleroma.Web.ConnCase
11 import Pleroma.Factory
13 setup do: clear_config([:instance, :public])
15 test "put settings", %{conn: conn} do
20 |> assign(:user, user)
21 |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:accounts"]))
22 |> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
24 assert _result = json_response(conn, 200)
26 user = User.get_cached_by_ap_id(user.ap_id)
27 assert user.mastofe_settings == %{"programming" => "socks"}
30 describe "index/2 redirections" do
31 setup %{conn: conn} do
35 signing_salt: "cooldude"
40 |> Plug.Session.call(Plug.Session.init(session_opts))
43 test_path = "/web/statuses/test"
44 %{conn: conn, path: test_path}
47 test "redirects not logged-in users to the login page", %{conn: conn, path: path} do
48 conn = get(conn, path)
50 assert conn.status == 302
51 assert redirected_to(conn) == "/web/login"
54 test "redirects not logged-in users to the login page on private instances", %{
58 Config.put([:instance, :public], false)
60 conn = get(conn, path)
62 assert conn.status == 302
63 assert redirected_to(conn) == "/web/login"
66 test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
67 token = insert(:oauth_token, scopes: ["read"])
71 |> assign(:user, token.user)
72 |> assign(:token, token)
75 assert conn.status == 200
78 test "saves referer path to session", %{conn: conn, path: path} do
79 conn = get(conn, path)
80 return_to = Plug.Conn.get_session(conn, :return_to)
82 assert return_to == path