logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

session_authentication_plug_test.exs (1454B)


  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.Web.Plugs.SessionAuthenticationPlugTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.User
  7. alias Pleroma.Web.Plugs.SessionAuthenticationPlug
  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. |> assign(:auth_user, %User{id: 1})
  19. %{conn: conn}
  20. end
  21. test "it does nothing if a user is assigned", %{conn: conn} do
  22. conn =
  23. conn
  24. |> assign(:user, %User{})
  25. ret_conn =
  26. conn
  27. |> SessionAuthenticationPlug.call(%{})
  28. assert ret_conn == conn
  29. end
  30. test "if the auth_user has the same id as the user_id in the session, it assigns the user", %{
  31. conn: conn
  32. } do
  33. conn =
  34. conn
  35. |> put_session(:user_id, conn.assigns.auth_user.id)
  36. |> SessionAuthenticationPlug.call(%{})
  37. assert conn.assigns.user == conn.assigns.auth_user
  38. end
  39. test "if the auth_user has a different id as the user_id in the session, it does nothing", %{
  40. conn: conn
  41. } do
  42. conn =
  43. conn
  44. |> put_session(:user_id, -1)
  45. ret_conn =
  46. conn
  47. |> SessionAuthenticationPlug.call(%{})
  48. assert ret_conn == conn
  49. end
  50. end