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.Plugs.SessionAuthenticationPlugTest do
6 use Pleroma.Web.ConnCase, async: true
8 alias Pleroma.Plugs.SessionAuthenticationPlug
11 setup %{conn: conn} do
15 signing_salt: "cooldude"
20 |> Plug.Session.call(Plug.Session.init(session_opts))
22 |> assign(:auth_user, %User{id: 1})
27 test "it does nothing if a user is assigned", %{conn: conn} do
30 |> assign(:user, %User{})
34 |> SessionAuthenticationPlug.call(%{})
36 assert ret_conn == conn
39 test "if the auth_user has the same id as the user_id in the session, it assigns the user", %{
44 |> put_session(:user_id, conn.assigns.auth_user.id)
45 |> SessionAuthenticationPlug.call(%{})
47 assert conn.assigns.user == conn.assigns.auth_user
50 test "if the auth_user has a different id as the user_id in the session, it does nothing", %{
55 |> put_session(:user_id, -1)
59 |> SessionAuthenticationPlug.call(%{})
61 assert ret_conn == conn