logo

pleroma

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

set_user_session_id_plug_test.exs (1044B)


  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.Plugs.SetUserSessionIdPlugTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.Plugs.SetUserSessionIdPlug
  7. alias Pleroma.User
  8. setup %{conn: conn} do
  9. session_opts = [
  10. store: :cookie,
  11. key: "_test",
  12. signing_salt: "cooldude"
  13. ]
  14. conn =
  15. conn
  16. |> Plug.Session.call(Plug.Session.init(session_opts))
  17. |> fetch_session
  18. %{conn: conn}
  19. end
  20. test "doesn't do anything if the user isn't set", %{conn: conn} do
  21. ret_conn =
  22. conn
  23. |> SetUserSessionIdPlug.call(%{})
  24. assert ret_conn == conn
  25. end
  26. test "sets the user_id in the session to the user id of the user assign", %{conn: conn} do
  27. Code.ensure_compiled(Pleroma.User)
  28. conn =
  29. conn
  30. |> assign(:user, %User{id: 1})
  31. |> SetUserSessionIdPlug.call(%{})
  32. id = get_session(conn, :user_id)
  33. assert id == 1
  34. end
  35. end