http security: allow referrer-policy to be configured
[akkoma] / test / plugs / set_user_session_id_plug_test.exs
1 defmodule Pleroma.Plugs.SetUserSessionIdPlugTest do
2 use Pleroma.Web.ConnCase, async: true
3
4 alias Pleroma.Plugs.SetUserSessionIdPlug
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
19 %{conn: conn}
20 end
21
22 test "doesn't do anything if the user isn't set", %{conn: conn} do
23 ret_conn =
24 conn
25 |> SetUserSessionIdPlug.call(%{})
26
27 assert ret_conn == conn
28 end
29
30 test "sets the user_id in the session to the user id of the user assign", %{conn: conn} do
31 conn =
32 conn
33 |> assign(:user, %User{id: 1})
34 |> SetUserSessionIdPlug.call(%{})
35
36 id = get_session(conn, :user_id)
37 assert id == 1
38 end
39 end