pleroma/test/pleroma/web/plugs/set_user_session_id_plug_te...

44 lines
1.1 KiB
Elixir
Raw Normal View History

2018-12-23 21:11:29 +01:00
# Pleroma: A lightweight social networking server
2022-02-26 07:11:42 +01:00
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
2018-12-23 21:11:29 +01:00
# SPDX-License-Identifier: AGPL-3.0-only
2020-06-23 17:16:47 +02:00
defmodule Pleroma.Web.Plugs.SetUserSessionIdPlugTest do
2018-09-05 21:42:42 +02:00
use Pleroma.Web.ConnCase, async: true
alias Pleroma.Helpers.AuthHelper
2020-06-24 12:07:47 +02:00
alias Pleroma.Web.Plugs.SetUserSessionIdPlug
2018-09-05 21:42:42 +02:00
setup %{conn: conn} do
session_opts = [
store: :cookie,
key: "_test",
signing_salt: "cooldude"
]
conn =
conn
|> Plug.Session.call(Plug.Session.init(session_opts))
|> fetch_session()
2018-09-05 21:42:42 +02:00
%{conn: conn}
end
test "doesn't do anything if the user isn't set", %{conn: conn} do
ret_conn = SetUserSessionIdPlug.call(conn, %{})
2018-09-05 21:42:42 +02:00
assert ret_conn == conn
end
test "sets session token basing on :token assign", %{conn: conn} do
%{user: user, token: oauth_token} = oauth_access(["read"])
2018-12-19 20:14:33 +01:00
ret_conn =
2018-09-05 21:42:42 +02:00
conn
|> assign(:user, user)
|> assign(:token, oauth_token)
2018-09-05 21:42:42 +02:00
|> SetUserSessionIdPlug.call(%{})
assert AuthHelper.get_session_token(ret_conn) == oauth_token.token
2018-09-05 21:42:42 +02:00
end
end