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