Merge branch '114_email_confirmation' into 'develop'
[akkoma] / test / plugs / session_authentication_plug_test.exs
1 defmodule Pleroma.Plugs.SessionAuthenticationPlugTest do
2 use Pleroma.Web.ConnCase, async: true
3
4 alias Pleroma.Plugs.SessionAuthenticationPlug
5 alias Pleroma.User
6
7 setup %{conn: conn} do
8 session_opts = [
9 store: :cookie,
10 key: "_test",
11 signing_salt: "cooldude"
12 ]
13
14 conn =
15 conn
16 |> Plug.Session.call(Plug.Session.init(session_opts))
17 |> fetch_session
18 |> assign(:auth_user, %User{id: 1})
19
20 %{conn: conn}
21 end
22
23 test "it does nothing if a user is assigned", %{conn: conn} do
24 conn =
25 conn
26 |> assign(:user, %User{})
27
28 ret_conn =
29 conn
30 |> SessionAuthenticationPlug.call(%{})
31
32 assert ret_conn == conn
33 end
34
35 test "if the auth_user has the same id as the user_id in the session, it assigns the user", %{
36 conn: conn
37 } do
38 conn =
39 conn
40 |> put_session(:user_id, conn.assigns.auth_user.id)
41 |> SessionAuthenticationPlug.call(%{})
42
43 assert conn.assigns.user == conn.assigns.auth_user
44 end
45
46 test "if the auth_user has a different id as the user_id in the session, it does nothing", %{
47 conn: conn
48 } do
49 conn =
50 conn
51 |> put_session(:user_id, -1)
52
53 ret_conn =
54 conn
55 |> SessionAuthenticationPlug.call(%{})
56
57 assert ret_conn == conn
58 end
59 end