Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3KB

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