1
0
Fork 0
forked from mirrors/akkoma
akkoma/test/plugs/authentication_plug_test.exs
2018-09-05 18:53:38 +02:00

54 lines
1.1 KiB
Elixir

defmodule Pleroma.Plugs.AuthenticationPlugTest do
use Pleroma.Web.ConnCase, async: true
alias Pleroma.Plugs.AuthenticationPlug
alias Pleroma.User
setup %{conn: conn} do
user = %User{
id: 1,
name: "dude",
password_hash: Comeonin.Pbkdf2.hashpwsalt("guy")
}
conn =
conn
|> assign(:auth_user, user)
%{user: user, conn: conn}
end
test "it does nothing if a user is assigned", %{conn: conn} do
conn =
conn
|> assign(:user, %User{})
ret_conn =
conn
|> AuthenticationPlug.call(%{})
assert ret_conn == conn
end
test "with a correct password in the credentials, it assigns the auth_user", %{conn: conn} do
conn =
conn
|> assign(:auth_credentials, %{password: "guy"})
|> AuthenticationPlug.call(%{})
assert conn.assigns.user == conn.assigns.auth_user
end
test "with a wrong password in the credentials, it does nothing", %{conn: conn} do
conn =
conn
|> assign(:auth_credentials, %{password: "wrong"})
ret_conn =
conn
|> AuthenticationPlug.call(%{})
assert conn == ret_conn
end
end